Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iloveitaly/e686784d0310a5b4ccb42df3187a943b to your computer and use it in GitHub Desktop.
Save iloveitaly/e686784d0310a5b4ccb42df3187a943b to your computer and use it in GitHub Desktop.
# Michael Bianco <mike@suitesync.io>
# Description: Create a NetSuite Invoice using the Stripe Invoice AP.I
# Simplified version of a similar example: https://gist.github.com/iloveitaly/30e366a516e294b699b6
# Usage:
#
# export STRIPE_KEY=sk_test
# gem install stripe
# ruby create_standalone_netsuite_invoice_using_stripe.rb
require 'stripe'
Stripe.api_key = ENV['STRIPE_KEY']
# 1. Create a customer and add a card
customer = Stripe::Customer.create(email: "sample@example.com")
customer.sources.create(card: 'tok_visa')
# 2. Create & pay a Stripe invoice
Stripe::InvoiceItem.create({
customer: customer.id,
amount: 200_00,
currency: "usd",
# item in NetSuite is matched based on the description passed to the line item
# https://dashboard.suitesync.io/docs/invoices#standalone-invoice-items
description: "Line Item 1",
})
Stripe::InvoiceItem.create({
customer: customer.id,
amount: 200_00,
currency: "usd",
description: "Line Item 2",
})
Stripe::InvoiceItem.create({
customer: customer.id,
amount: 80_00,
currency: "usd",
description: "Sales Tax",
})
invoice = Stripe::Invoice.create(customer: customer.id)
# This creates a stripe charge using the saved card on the customer
invoice.pay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment