Attach a Stripe Charge to a NetSuite SalesOrder as a CustomerDeposit using 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: 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 https://stripe.com/docs/custom-form | |
# Associate the token with the Stripe customer | |
customer = Stripe::Customer.create( | |
email: "new-netsuite@example.com", | |
) | |
customer.sources.create(card: 'tok_visa') | |
charge = Stripe::Charge.create( | |
amount: 200_00, | |
currency: "usd", | |
customer: customer.id, | |
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 | |
charge.refresh | |
if internal_id = charge.metadata['netsuite_customer_deposit_id'] | |
puts "CustomerDeposit 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