Last active
November 2, 2016 14:43
-
-
Save iloveitaly/c674c22b0901efe64a541f934f332776 to your computer and use it in GitHub Desktop.
Example of how to link a NetSuite customer to a Stripe customer http://SuiteSync.io/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Michael Bianco <mike@suitesync.io> | |
# Description: Link a NetSuite Customer record to a corresponding Stripe record | |
# requires the following environment variables: | |
# | |
# STRIPE_KEY | |
# NETSUITE_EMAIL | |
# NETSUITE_PASSWORD | |
# NETSUITE_ACCOUNT | |
require 'stripe' | |
require 'netsuite' | |
# Replace this test mode key and run this example on your account | |
Stripe.api_key = ENV['STRIPE_TEST_KEY'] | |
NetSuite.configure do | |
reset! | |
# NOTE that API versions > 2015_1 require a more complicated authentication setup | |
api_version '2015_1' | |
read_timeout 60 * 3 | |
silent ENV['NETSUITE_SILENT'].nil? || ENV['NETSUITE_SILENT'] == 'true' | |
email ENV['NETSUITE_EMAIL'] | |
password ENV['NETSUITE_PASSWORD'] | |
account ENV['NETSUITE_ACCOUNT'] | |
soap_header({ | |
'platformMsgs:preferences' => { | |
'platformMsgs:ignoreReadOnlyFields' => true, | |
} | |
}) | |
end | |
# Create a card token to be associated with a customer | |
# This is done on your payment using Stripe Checkout (http://stripe.com/checkout) | |
# or a custom form using Stripe.js (https://stripe.com/docs/custom-form) | |
card_token = Stripe::Token.create( | |
:card => { | |
:number => '4242424242424242', | |
:exp_month => 8, | |
:exp_year => (Date.today>>24).year, | |
:cvc => "314", | |
} | |
) | |
stripe_customer = Stripe::Customer.create(description: "Example Stripe Customer") | |
stripe_customer.sources.create(card: card_token.id) | |
# setting the external ID (or a custom field) to the Stripe Customer ID | |
# facilitates communication between Stripe and NetSuite | |
ns_customer = NetSuite::Records::Customer.new( | |
external_id: stripe_customer.id, | |
entity_id: Time.now.to_i, | |
company_name: "A Great NetSuite Company" | |
) | |
# if the external ID is being used by other integrations, a custom field can be created | |
# to link the NetSuite customer to the Stripe customer | |
ns_customer.custom_field_list.custbody_suitesync_customer_id = stripe_customer.id | |
ns_customer.add |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment