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.
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.
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.
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.
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 !
- Create a new customer and store the customer id on your backend:
new_customer = stripe.Customer.create(
email = user.email
)
- 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"
)
- 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'],
)
Create a tax object on your Stripe Dashboard with your tax rate
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']]
)
- 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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With