How to Apply VAT to Stripe Subscription with the Right Parameter?

This topic was automatically generated from Slack. You can find the original thread here.

Hello the team ! I have a small problem, I use a flow to create a subscription with Stripe, but the VAT does not apply. Any idea how to pass the right parameter? In the Stripe documentation, they talk about a parameter

// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys
const stripe = require('stripe')('sk_test_5dXxvFIaZj0dx4k01oBghT9F');

const subscription = await stripe.subscriptions.create({
  customer: 'cus_13729he8947269',
  items: [{price: 'price_HGd7M3DV3IMXkC', quantity: 1}],
  automatic_tax: {enabled: true},
  payment_behavior: 'default_incomplete',
  expand: ['latest_invoice'],
});

how can I define a VAT number to a new subscription created via the Stripe Node SDK?

To define a VAT number for a new subscription using the Stripe Node SDK, you’ll need to create a customer with the VAT number and then create a subscription for that customer. Here’s an example using the Stripe Node SDK: First, install the Stripe package: bash npm install stripe Then, use the following code to create a customer with a VAT number and create a subscription: const stripe = require('stripe')('your_stripe_api_key'); async function createCustomerWithVAT(vatNumber, email) { const customer = await stripe.customers.create({ email: email, tax_id_data: [ { type: 'eu_vat', value: vatNumber, }, ], }); return customer; } async function createSubscription(customerId, priceId) { const subscription = await stripe.subscriptions.create({ customer: customerId, items: [ { price: priceId, }, ], }); return subscription; } (async () => { const vatNumber = 'your_vat_number'; const email = '[customer@example.com](mailto:customer@example.com)'; const priceId = 'your_price_id'; const customer = await createCustomerWithVAT(vatNumber, email); const subscription = await createSubscription(customer.id, priceId); console.log('Customer created:', customer); console.log('Subscription created:', subscription); })(); Replace 'your_stripe_api_key', 'your_vat_number', '[customer@example.com](mailto:customer@example.com)', and 'your_price_id' with your actual values. This code will create a customer with the specified VAT number and email, and then create a subscription for that customer using the specified price ID.

Sounds like the VAT number is applied to the customer resources, not the subscription. Very easy to mix up, I too would have thought the VAT was associated with the subscription.

But I suppose that makes sense, the customer can have multiple subscriptions, but only has one VAT.

My customer already have

Capture d’écran 2023-04-20 à 16.08.48.png

Thx by the way for the response

But when i read the API Stripe, i think we need to add this parameters

“automatic_tax: {enabled: true}”

Yes, that’s possible. You’d think the subscription would inherit the tax info by default, but you might need to pass that parameter to the subscription creation request.

As a side note, did you have issues trying to use the Stripe Node.js scaffold steps before you switched to using the Node.js library instead?

I will try :wink:

Just curious! Because I was trying the scaffolding myself and the form encoding was not working well. I ended up switching to the Stripe Node.js SDK instead.