Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Example of creating a NetSuite invoice using SuiteTalk and paying it using Stripe and http://SuiteSync.io/
# Michael Bianco <mike@suitesync.io>
# Description: Example of creating a NetSuite invoice using SuiteTalk and paying
# it using a Stripe payment.
# https://dashboard.suitesync.io/docs/payment-application
#
# Usage:
#
# export STRIPE_KEY=sk_test NETSUITE_EMAIL=user@company.com NETSUITE_PASSWORD=password NETSUITE_ACCOUNT=
# gem install stripe netsuite
# ruby create_and_pay_netsuite_invoice_with_stripe.rb
require 'stripe'
require 'netsuite'
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
# 1. Create NetSuite Invoice
# NOTE static NS variables that are defined upstream by your app
ns_item_id = 384208
ns_customer_id = 383315
ns_invoice = NetSuite::Records::Invoice.new(
entity: { internal_id: ns_customer_id },
item_list: { item: [
{
item: { internal_id: ns_item_id },
quantity: 2,
rate: 100.0
}
] }
)
NetSuite::Utilities.backoff { ns_invoice.add }
# 2. Create a Stripe Charge
charge = Stripe::Charge.create(
amount: 200_00,
currency: "usd",
source: 'tok_visa',
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
# https://dashboard.suitesync.io/docs/field-customization
'netsuite_invoice_id' => 123
}
)
# NOTE if your Stripe account is connected to SuiteSync, a link to the CustomerPayment
# created by this charge will appear in the metadata
puts "Stripe Charge: #{charge.id}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment