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 |
This comment has been minimized.
This comment has been minimized.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Thanks for this gist, very useful.
It's very strange that Avalara doesn't include any information about subscription creation and level of metadata for it.