Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Attach a Stripe Charge to a NetSuite SalesOrder as a CustomerDeposit using
# Michael Bianco <>
# Description: Example of how to attach a Stripe charge as a CustomerDeposit
# against a SalesOrder in NetSuite
# Usage:
# gem install stripe
# export STRIPE_KEY=sk_test_123
# ruby attach_customer_deposit_to_invoice.rb
require 'stripe'
# Replace this test mode key and run this example on your account
Stripe.api_key = ENV['STRIPE_KEY']
# Associate a card token with a customer. This would be done on your frontend using
# Stripe.js, Checkout, Elements, etc
# Associate the token with the Stripe customer
customer = Stripe::Customer.create(
email: "",
customer.sources.create(card: 'tok_visa')
charge = Stripe::Charge.create(
amount: 200_00,
currency: "usd",
description: "This will be added to the CustomerDeposits's memo in NetSuite.",
metadata: {
# By specifying this key in the charge metadata, you are instructing the NetSuite
# integration to attach a CustomerDeposit against this NetSuite SalesOrder
'netsuite_sales_order_id' => 123
# Wait for the CustomerDeposit to be created in NetSuite
# NOTE your account needs to be connecting to the integration for this to work
loop do
if internal_id = charge.metadata['netsuite_customer_deposit_id']
puts "CustomerDeposit 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.