Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Example of how to create a Stripe Subscription and push it into NetSuite using http://SuiteSync.io/
# Michael Bianco <mike@suitesync.io>
# Description: Create a Stripe Subscription
# 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