Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe Checkout - Create Session - Apply Tax Rates on subscriptions

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.

like image 589
Shankar ARUL Avatar asked Jul 24 '19 13:07

Shankar ARUL


People also ask

Does stripe automatically take out taxes?

Stripe Tax—a paid product that automatically calculates the tax on your transactions without the need to define the rates and rules. Fees only apply after you've added at least one location where you're registered to calculate and remit tax.

How do you calculate tax on an invoice?

To calculate the sales tax that is included in a company's receipts, divide the total amount received (for the items that are subject to sales tax) by "1 + the sales tax rate". In other words, if the sales tax rate is 6%, divide the sales taxable receipts by 1.06.

How do you calculate tax exclusive price?

Tax methodology for tax-exclusive pricingThe tax amounts for all tax codes are added to the sub-total to derive the total for the transaction. You buy an item for 1,000 plus 10% goods and services tax. If the amount of 1,000 is tax-exclusive, 10% tax is added to it, increasing the total to 1,100.


2 Answers

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
like image 123
Shankar ARUL Avatar answered Oct 24 '22 04:10

Shankar ARUL


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.

like image 38
Paul Asjes Avatar answered Oct 24 '22 04:10

Paul Asjes