Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Create a Stripe Subscription with required information for Avalara's integration
# Michael Bianco <>
# Description: Create a Stripe Subscription with required information for Avalara's
# Stripe Subscription integration.
# Learn more:
# 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: '',
# 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
customer.sources.create(card: 'tok_visa')
plan = Stripe::Plan.create(
amount: 100_00,
interval: 'month',
currency: 'usd',
name: 'A Example Plan',
id: "random_#{}",
# Subscriptions are automatically pushed to NetSuite as an invoice each billing period
# 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