Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create a Stripe Subscription with required information for Avalara's integration
# Michael Bianco <mike@suitesync.io>
# Description: Create a Stripe Subscription with required information for Avalara's
# Stripe Subscription integration.
# Learn more: https://gist.github.com/iloveitaly/7b9b288d203f6ac7f75d8eda14e07c18
# Usage:
#
# export STRIPE_KEY=sk_test
# gem install stripe
# ruby stripe_create_subscription_with_avalara.rb
require 'stripe'
Stripe.api_key = ENV['STRIPE_KEY']
customer = Stripe::Customer.create({
email: 'customer@example.com',
# NOTE some/all of these metadata fields are required. Exactly details about
# which fields are required in your case are indicated by Avalara
metadata: {
'Address_Line1' => '3180 18th St',
'Address_City' => 'San Francisco',
'Address_State' => 'CA',
# NOTE these two parameters are mandatory
'Address_PostalCode' => '94110',
'Address_Country' => 'US'
}
})
# 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}",
)
# 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 this feature needs to be enabled on your Stripe account
# this allows Avalara to push line items into the automated invoices
pay_immediately: false,
})
# 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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.