最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Tax Rate in new Stripe Checkout - Stack Overflow

programmeradmin1浏览0评论


I've implemented the new Stripe Checkout on my NodeJS server, but I cannot specify the Tax Rate for Invoicing.

As per my understanding Tax Rates should be specified in the Payment Intent API. Fact is that the new Checkout automatically creates a Payment Intent via its CreateSession (see payment_intent_data), but I'm not able to insert a Tax Rate upon its creation.

How can this be done? What I want to achieve is to have the user know the Tax % both in the Checkout UI and in the final email invoice.

This is my code:

return stripe.checkout.sessions.create({
    payment_method_types: [paymentMethod],
    line_items: [{
        name: name,
        description: description,
        images: [imageUrl],
        amount: amount,
        currency: currency,
        quantity: 1
    }],
    success_url: successUrl,
    cancel_url: cancelUrl,
    customer: stripeId,
    payment_intent_data: {
        receipt_email: email,
        metadata: {
            userId: userId,
            amount: amount,
            currency: currency,
            ref: ref,
            stripeId: stripeId,
            details: details
        }
    }
}).then(session => {
    return res.send(session)


I've implemented the new Stripe Checkout on my NodeJS server, but I cannot specify the Tax Rate for Invoicing.

As per my understanding Tax Rates should be specified in the Payment Intent API. Fact is that the new Checkout automatically creates a Payment Intent via its CreateSession (see payment_intent_data), but I'm not able to insert a Tax Rate upon its creation.

How can this be done? What I want to achieve is to have the user know the Tax % both in the Checkout UI and in the final email invoice.

This is my code:

return stripe.checkout.sessions.create({
    payment_method_types: [paymentMethod],
    line_items: [{
        name: name,
        description: description,
        images: [imageUrl],
        amount: amount,
        currency: currency,
        quantity: 1
    }],
    success_url: successUrl,
    cancel_url: cancelUrl,
    customer: stripeId,
    payment_intent_data: {
        receipt_email: email,
        metadata: {
            userId: userId,
            amount: amount,
            currency: currency,
            ref: ref,
            stripeId: stripeId,
            details: details
        }
    }
}).then(session => {
    return res.send(session)
Share Improve this question edited Jun 4, 2024 at 13:50 Bora M. Alper 3,8441 gold badge26 silver badges36 bronze badges asked May 12, 2019 at 9:38 r4id4r4id4 6,0778 gold badges47 silver badges81 bronze badges 6
  • 1 Tax Rates only apply to Invoice objects, which are primarily used in conjunction with Subscriptions, not the one time payment 'line items' created by this checkout session. stripe.com/docs/api/subscriptions/… stripe.com/docs/api/payment_intents/create I might email Stripe with a feature request on this! – duck Commented May 12, 2019 at 16:48
  • @duck thanks for your reply. So there is no way to insert Tax Rate in one time payment 'line items' ? :( I could I let user know the % of tax charged? – r4id4 Commented May 12, 2019 at 17:39
  • 1 I mean, it's a list of hashes, so I suppose you could add your own line item for the tax amount, but it wouldn't use Stripe's Tax Rate atm – duck Commented May 12, 2019 at 18:04
  • @r4id4 I'm looking for an identical setup. Have you managed to achieve it, and if so, how? – Bytech Commented Oct 18, 2019 at 9:17
  • Unfortunately no – r4id4 Commented Oct 18, 2019 at 20:08
 |  Show 1 more comment

4 Answers 4

Reset to default 7

At the time of this answer, Stripe Checkout does not support Tax Rates.

One alternative is to collect payment details using "setup" mode Checkout [1], then create a PaymentIntent [2] from your server with the PaymentMethod collected in Checkout and the Tax Rate you'd like to use.

[1] https://stripe.com/docs/payments/checkout/collecting

[2] https://stripe.com/docs/api/payment_intents/create

Stripe checkout support now Tax rates.

From "Stripe.net" 35.12.0 version, you can set a default tax rate when you create a new session.

var options = new SessionCreateOptions {
    PaymentMethodTypes = new List<string> {
        "card",
    },
    SubscriptionData = new SessionSubscriptionDataOptions {
        DefaultTaxRates = new List<string> {
            _STRIPE_OPTIONS.Tax // Your tax rate id
        },
        Items = new List<SessionSubscriptionDataItemOptions> {
            new SessionSubscriptionDataItemOptions {
                Plan = request.PlanId, // Your plan id
            },
        },
    },
    Customer = customer.StripeCustomerId,
    SuccessUrl = _STRIPE_OPTIONS.SuccessUrl,
    CancelUrl = _STRIPE_OPTIONS.CancelUrl
};

var service = new SessionService();
var session = service.Create(options);

Don't forgot to update your webhook version if you are using one.

Tax rates are now in beta on Stripe Checkout for one-time payments, see here: https://stripe.com/docs/payments/checkout/taxes

You can email to join the beta program and try it out.

Right now, note that dynamic tax rates are only supported in US, Europe and certain countries specified here (https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-dynamic_tax_rates) so watch out

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

const taxRate = await stripe.taxRates.create({ // Here
    display_name: 'Sales Tax',
    percentage: 7.25,
    inclusive: false
});

const session = await stripe.checkout.sessions.create({
    line_items: [
        {
            'price_data': {
                'currency': 'usd',
                'unit_amount': 20,
                'product_data': {
                    'name': 'T-shirt',
                },
            },
            'quantity': 2,
            'tax_rates': [taxRate.id] // Here
        },
    ],
    mode: 'payment',
    success_url: 'https://example.com/success',
    cancel_url: 'https://example.com/cancel'
});
发布评论

评论列表(0)

  1. 暂无评论