Example of how to create a Stripe Subscription and push it into NetSuite 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: Create a Stripe Subscription | |
# Link: https://gist.github.com/iloveitaly/c07975fe902a1c6259558c181d8602d4 | |
# Usage: | |
# | |
# export STRIPE_KEY=sk_test | |
# gem install stripe | |
# ruby stripe_create_subscription.rb | |
require 'stripe' | |
Stripe.api_key = ENV['STRIPE_KEY'] | |
customer = Stripe::Customer.create({ | |
description: "First Customer", | |
email: 'customer@example.com', | |
# NOTE optionally pass the vat ID over to the customer | |
# business_vat_id: '123', | |
# This information is pulled over to shipping address in NetSuite | |
# https://dashboard.suitesync.io/docs/customers#billing--shipping-address | |
shipping: { | |
name: 'First Last', | |
phone: '123 123 1234', | |
address: { | |
line1: '3180 18th St', | |
city: 'San Francisco', | |
postal_code: '94110', | |
state: 'CA', | |
country: 'US', | |
} | |
}, | |
# Custom fields can be pulled from the customer to NetSuite | |
# https://dashboard.suitesync.io/docs/field-customization | |
# metadata: { | |
# netsuite_custom_user_id: '123' | |
# } | |
}) | |
# For billing address information to come over, include the billing address with the token information | |
# https://dashboard.suitesync.io/docs/customers#billing--shipping-address | |
customer.sources.create(card: 'tok_visa') | |
plan = Stripe::Plan.create( | |
amount: 100_00, | |
interval: 'month', | |
currency: 'usd', | |
name: 'A Example Plan', | |
id: "random_#{Time.now.to_i}", | |
# you can provide an ID of an existing item in Netsuite you'd like to use, or let SuiteSync create an item for you | |
# https://dashboard.suitesync.io/docs/field-customization | |
# metadata: { | |
# netsuite_non_inventory_sale_item_id: 123 | |
# } | |
) | |
# Subscriptions are automatically pushed to NetSuite as an invoice each billing period | |
# https://dashboard.suitesync.io/docs/subscriptions | |
customer.subscriptions.create({ | |
plan: plan.id, | |
# NOTE if you are using Avalara's integration with Stripe subscriptions you'll | |
# need to make sure this option is passed when the subscription is created | |
# pay_immediately: false, | |
# data specified on the subscription can be linked to each subsequent invoice created from this subscription | |
# https://dashboard.suitesync.io/docs/field-customization | |
# metadata: { | |
# netsuite_class_id: 123, | |
# netsuite_department_id: 123 | |
# } | |
}) | |
# An invoice is automatically generated and pushed to Stripe | |
invoice = customer.invoices.first |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment