Skip to content

Instantly share code, notes, and snippets.

@iloveitaly
Last active February 9, 2024 22:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save iloveitaly/d8364b99d81cbf3535db20556f98c153 to your computer and use it in GitHub Desktop.
Save iloveitaly/d8364b99d81cbf3535db20556f98c153 to your computer and use it in GitHub Desktop.
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