<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Jonathan Gescheit</title>
    <description>The latest articles on Forem by Jonathan Gescheit (@jonathanges).</description>
    <link>https://forem.com/jonathanges</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F486925%2F9a91b1f8-bdb5-4e2d-93f2-eff6a9521619.png</url>
      <title>Forem: Jonathan Gescheit</title>
      <link>https://forem.com/jonathanges</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jonathanges"/>
    <language>en</language>
    <item>
      <title>Using Avalara’s AvaTax with Stripe Subscriptions</title>
      <dc:creator>Jonathan Gescheit</dc:creator>
      <pubDate>Sat, 10 Oct 2020 16:14:58 +0000</pubDate>
      <link>https://forem.com/jonathanges/using-avalara-s-avatax-with-stripe-subscriptions-3k21</link>
      <guid>https://forem.com/jonathanges/using-avalara-s-avatax-with-stripe-subscriptions-3k21</guid>
      <description>&lt;h2&gt;
  
  
  It’s supposed to be easy. Eventually, it is.
&lt;/h2&gt;

&lt;p&gt;If you use &lt;a href="https://stripe.com/"&gt;Stripe&lt;/a&gt; to charge users and plan on using &lt;a href="https://www.avalara.com/us/en/products/sales-and-use-tax/avatax.html"&gt;Avalara’s AvaTax&lt;/a&gt; for charging sales tax, you’re probably looking for a simple plug &amp;amp; play solution. It very much is this type of solution, but it isn’t very well documented. &lt;/p&gt;

&lt;p&gt;This post is all about laying out the required steps to making it work quickly and easily.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Examples are written in node.js but can easily be converted to any language Stripe’s API supports.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  First Step: Ask Stripe to Allow Your Account to Use The &lt;code&gt;pay_immediately&lt;/code&gt; flag
&lt;/h3&gt;

&lt;p&gt;Contact Stripe’s support and ask them to enable the usage of the &lt;code&gt;pay_immediately&lt;/code&gt; flag for you for the purpose of integrating AvaTax.&lt;/p&gt;

&lt;p&gt;For AvaTax to integrate with Stripe, you have to give AvaTax to a chance to catch new invoices and add the sales tax to the invoice. You do this by sending the attribute &lt;code&gt;pay_immediately = false&lt;/code&gt; upon subscription creation. &lt;strong&gt;This flag is not well documented anywhere and is disabled by default&lt;/strong&gt;. &lt;br&gt;
Avalara do &lt;a href="https://help.avalara.com/FYHP/AvaTax_for_Stripe_Invoicing/Install_and_Configure_Avalara_AvaTax_for_Stripe_Invoicing#Configure_sales_tax_calculation_for_subscriptions"&gt;mention it in their documentation&lt;/a&gt;, but it’s easy to miss.&lt;/p&gt;
&lt;h3&gt;
  
  
  Second Step: Update Address Details in The Customer’s Metadata
&lt;/h3&gt;

&lt;p&gt;Add address details that AvaTax will use to calculate the tax for future invoices. This can happen at any time prior to creating the subscription.&lt;br&gt;
Only &lt;code&gt;Address_PostalCode&lt;/code&gt; and &lt;code&gt;Address_Country&lt;/code&gt; are mandatory but you can add &lt;a href="https://help.avalara.com/FYHP/AvaTax_for_Stripe_Invoicing/Install_and_Configure_Avalara_AvaTax_for_Stripe_Invoicing/Metadata_Specifications#Customer_metadata"&gt;more details&lt;/a&gt; to make the tax calculation more accurate.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stripe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;stripe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;STRIPE_KEY&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;customer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;stripe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;customers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;CUSTOMER_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Address_PostalCode&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;10001&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Valid Postal Code&lt;/span&gt;
      &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Address_Country&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;US&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="c1"&gt;// ISO-3166-1 alpha-2 Country Code&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;       
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Third Step: Add The &lt;code&gt;pay_immediately = false&lt;/code&gt; to Your Subscription Creation Request
&lt;/h3&gt;

&lt;p&gt;When you create the subscription, add the attribute &lt;code&gt;pay_immediately&lt;/code&gt; with the value &lt;code&gt;false&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stripe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;stripe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;STRIPE_KEY&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;subscription&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;stripe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subscriptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;customer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;CUSTOMER_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PRICE_ID&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;pay_immediately&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Fourth Step: Wait for Webhook Events
&lt;/h3&gt;

&lt;p&gt;Your invoice will not be charged immediately (as you requested), and AvaTax will pick it up. This could take a couple of seconds.&lt;br&gt;
&lt;a href="https://help.avalara.com/FYHP/AvaTax_for_Stripe_Invoicing/Install_and_Configure_Avalara_AvaTax_for_Stripe_Invoicing#Connect_AvaTax_to_Stripe_Invoicing"&gt;Avalara’s webhooks&lt;/a&gt; will allow you to know what happened with your invoice under their care.&lt;/p&gt;

&lt;p&gt;That’s it. It’s fairly easy and straightforward, but it’s rather hard to find good documentation for it.&lt;/p&gt;

</description>
      <category>stripe</category>
      <category>avalara</category>
      <category>subscriptions</category>
      <category>payments</category>
    </item>
  </channel>
</rss>
