Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Apply a Stripe payment to multiple NetSuite Invoices using http://SuiteSync.io/
# Michael Bianco <mike@suitesync.io>
# Description: Create a Stripe payment and apply it to multiple NetSuite Invoices
# Usage:
#
# export STRIPE_KEY=sk_test
# gem install stripe
# ruby stripe_multiple_netsuite_invoice_application.rb
require 'stripe'
Stripe.api_key = ENV['STRIPE_KEY']
customer = Stripe::Customer.create(
# the customer can be auto-linked to an existing NetSuite customer by email
# https://dashboard.suitesync.io/docs/preventing-duplicate-customers#automatically-detecting-duplicate-customers-by-emai
email: "existing-customer@example.com"
)
customer.sources.create(source: 'tok_visa')
Stripe::Charge.create(
customer: customer.id,
amount: 100_00,
currency: 'usd',
description: "Some information about the payment for accounting",
# https://dashboard.suitesync.io/docs/payment-application#matching-one-payment-to-multiple-invoices
metadata: {
apply_to_invoices: 'INV1,INV2,INV3,INV34'
}
)
# Or you can create a standalone charge without a customer
Stripe::Charge.create(
amount: 100_00,
currency: 'usd',
source: 'tok_visa',
description: "Some information about the payment for accounting",
# https://dashboard.suitesync.io/docs/payment-application#matching-one-payment-to-multiple-invoices
metadata: {
apply_to_invoices: 'INV1,INV2,INV3,INV4'
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment