17

I'm trying to set up the new Stripe Checkout Create session. I'm not able to set the tax rate on the subscription during the session creation as the subscription is automatically created by Stripe.

I have set up a Tax rate on the dashboard with the default 20% VAT Rate. I want this applied automatically to all subscriptions. Can anybody guide me through this?

stripe.checkout.Session.create(
    payment_method_types=['card'],
    subscription_data={
        'items': [{
            'plan': plan.stripe_plan_name,
            'quantity': 1
        }],
    },
    customer_email = user.email,
    success_url='https://www.jetpackdata.com/success',
    cancel_url='https://www.jetpackdata.com/cancel'
)

And Picked by stripe.redirectToCheckout on the client-side.

I'm listening on the webhooks for 'checkout.session.completed' to upgrade the account on my backend.

I'm listening to 'invoice.created' and when the status=draft, I set the default tax rate (As we have an hour during which it can be modified after creation).

Should I listen to instead 'customer.subscription.created' and set it directly on the subscription instead of setting it on every invoice?

The first client subscription purchase doesn't seem to apply the tax rate as the status doesn't remain in draft for an hour as it does during the subscription cycle. Is it because I'm in Test mode?

Any help would be appreciated.

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
Shankar ARUL
  • 12,642
  • 11
  • 68
  • 69

3 Answers3

5

Reaching out to Stripe Technical support, i got this:

"At the present moment, we don't currently have the ability to set a tax rate through Checkout, but it is a feature that is on our roadmap to be added in the future."

So here's a workaround in the meanwhile for those who need to set taxes on Subscription with the new Stripe Checkout Session. The following outline will help you add a tax on your subscription right from the first invoice and the subsequent subscription invoices !

  1. Create a new customer and store the customer id on your backend:
new_customer = stripe.Customer.create(
    email = user.email
)
  1. Create an invoice items for your Tax on the subscription plan: (This will be automatically pulled into the first subscription plan)
new_tax_invoice = stripe.InvoiceItem.create(
    customer=new_customer['id'],
    amount=int(plan.price*20),
    currency="eur",
    description="VAT"
)
  1. Create a Stripe Session checkout and handover the stripe_session.id to stripe.redirectToCheckout on the client side
stripe_session = stripe.checkout.Session.create(
    payment_method_types=['card'],
    subscription_data={
        'items': [{
        'plan': plan.stripe_plan_name,
        'quantity': 1
        }],
    },
    customer = new_customer['id'],
    success_url=app.config['STRIPE_SUCCESS_URL'],
    cancel_url=app.config['STRIPE_CANCEL_URL'],
)
  1. Create a tax object on your Stripe Dashboard with your tax rate

  2. Listen to the Stripe Webhook for customer.subscription.created and update the subscription object with the default tax rates id that you got from step 4

if stripe_webhook['type'] == 'customer.subscription.created':
    stripe.Subscription.modify(
        stripe_webhook['data']['object']['id'],
        default_tax_rates = [app.config['STRIPE_TAX_RATE']]
    )
  1. Listen to the Stripe Webhook for checkout.session.completed and do the necessary housekeeping on your backend with the stripe_subscription_id and stripe_customer_id
Shankar ARUL
  • 12,642
  • 11
  • 68
  • 69
  • This solution kinda works. Beware that your tax exports won't be correct since the added invoice item will not be recognized as tax. Also, Stripe will show an incorrect amount for future payments on the Stripe Checkout page: "Then XXX per year/month" – Youri Thielen Oct 23 '19 at 08:52
  • That won't work at all, you can't add VAT as an item, otherwise you will have to apply VAT to that item too. It makes no sense that advised that. At the present moment you can't do VAT with Checkout, period. We've been waiting for this feature for month/years now but it's just not comming – Tibo Aug 27 '20 at 08:54
  • `default_tax_rates` is available now in the Checkout product: https://stripe.com/docs/payments/checkout/set-up-a-subscription#tax-rates – jeremyhoover Aug 29 '20 at 14:39
2

You can't set tax rates on subscriptions created with Sessions for now. It's something that Stripe is working on but for now you'll have to create subscriptions with tax rates via the API.

Paul Asjes
  • 5,361
  • 1
  • 18
  • 20
  • 2
    Does that mean I can't use Checkout at all (for now), or is there a workaround? – molsson Aug 18 '19 at 19:00
  • 3
    I suppose what I really would like to know is this: is VAT support for Checkout coming in a few weeks, a few months or is it more than a year away? – molsson Aug 18 '19 at 19:37
  • It's late Dec. and tax rate is still not supported on the "new" Checkout. So that was at least a few months away @moisson. – Frenchcooc Dec 24 '19 at 07:50
  • what a headache ! – Tibo Aug 27 '20 at 08:50
  • Good news is that it's on the way and you can currently request an invite to the beta: https://twitter.com/JoshuaAckerman/status/1298707874202267648 – Paul Asjes Aug 28 '20 at 06:22
0

Create the object of "stripe.taxRates.create()", then, assign the "id" to "tax_rates" as shown below:

tax_rate = stripe.TaxRate.create( # Here
    display_name='Sales Tax',
    percentage=7.25,
    inclusive=False 
)

stripe.checkout.Session.create(
    line_items=[
        {
            'price_data': {
                'currency': 'usd',
                'unit_amount': 20,
                'product_data': {
                    'name': 'T-shirt',
                },
            },
            'quantity': 2,
            'tax_rates': [tax_rate['id']] # Here
        },
    ],
    mode="payment",
    success_url="https://example.com/success",
    cancel_url="https://example.com/cancel"
)
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129