Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Example of using Stripe to pay a NetSuite invoice using http://SuiteSync.io
# Michael Bianco <mike@suitesync.io>
require 'stripe'
# Replace this test mode key and run this example on your account
Stripe.api_key = 'sk_test_123'
# Create a card token to be associated with a customer. This is normally done
# on your payment frontend 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"
}
)
# Associate the token with the Stripe customer
customer = Stripe::Customer.create(
:description => "New NetSuite Customer",
:email => "new-netsuite@example.com",
)
customer.sources.create(card: card_token.id)
charge = Stripe::Charge.create(
:amount => 200_00,
:currency => "usd",
:customer => customer.id,
:description => "This will be added to the CustomerPayment's memo in NetSuite.",
:metadata => {
# By specifying this key in the charge metadata, you are instructing the NetSuite
# integration to apply the CustomerPayment against this NetSuite invoice ID
'netsuite_invoice_id' => 123
}
)
# Wait for the CustomerPayment to be created in NetSuite
# NOTE your account needs to be connecting to the integration for this to work
loop do
charge.refresh
if internal_id = charge.metadata['netsuite_customer_payment_id']
puts "CustomerPayment Internal ID: #{internal_id}"
exit(0)
end
puts "Waiting for Charge to translate to NetSuite..."
sleep(1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment