Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example of using Stripe to pay a NetSuite invoice using
# Michael Bianco <>
# Link:
# Description: Use Stripe to pay a NetSuite Invoice by specifying an invoice ID
require 'stripe'
# Replace this test mode key and run this example on your account
Stripe.api_key = ENV['STRIPE_KEY']
# Create a card token to be associated with a customer. This is normally done
# on your payment frontend using Stripe.js
card_token = Stripe::Token.create(
:card => {
:number => '4242424242424242',
:exp_month => 8,
:exp_year => (>>24).year,
:cvc => "314"
# Associate the token with the Stripe customer
customer = Stripe::Customer.create(
:description => "New NetSuite Customer",
:email => "",
charge = Stripe::Charge.create(
:amount => 200_00,
:currency => "usd",
:customer =>,
:description => "This is added to the NetSuite customer payment's memo",
: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 connected to SuiteSync for this to work
loop do
if internal_id = charge.metadata['netsuite_customer_payment_id']
puts "CustomerPayment Internal ID: #{internal_id}"
puts "Waiting for Charge to translate to NetSuite..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.