Created
June 13, 2017 23:01
-
-
Save iloveitaly/e686784d0310a5b4ccb42df3187a943b to your computer and use it in GitHub Desktop.
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: 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