简体   繁体   中英

Tax Rate in new Stripe Checkout


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)

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'
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM