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

next.js - Stripe auto tax calculation in checkout sessions is not working with multiple payment options - Stack Overflow

programmeradmin1浏览0评论

I've set up Stripe integration with my nextjs website, where I use Stripe hosted checkout page, automatic tax calculation, and dynamic payment methods

First, I had only card method, so when a user would go to checkout, he would have the card method with its inputs and auto tax calculation works normally as soon as the customer enter his address details.

Then I added other payment methods, which showed up as radio buttons, with no default selection and now the auto tax calculations aren't triggered unless the customer chooses a payment method and refocuses the zip input in address details, otherwise, the tax remains zero, and when clicking checkout, stripe calculates it and throws an amount mismatch error error status:400, checkout_amount_mismatch - expected_amount , showing a message below the payment button to the customer Your order has been updated. Please review the updated total and submit payment again., and shows the tax amount and rate, so the customer has to click the payment button twice, once for tax calculation, and then he would be faced with this message and has to click again to finalize checkout, which is a very bad UX, and I'm sure most customers would fill in their address details first before choosing the payment method, so they will be faced with this issue. After checking Stripe documentation and other sources, I learned that the cause was that Stripe needs the payment method as a parameter in order to calculate the taxes, and when there was only card method it was default selected.

Is there a way to set a default payment method from them so that I can keep my multiple payment methods and at the same time keep auto tax calculation? Or any other alternative solution to this, other than building my own custom checkout page?

Here is my Stripe checkout.create object content:

{
 line_items: [],
 mode: 'payment',
 shipping_address_collection: {
     allowed_countries: ['US'],
  },
  customer_creation: 'always',
  phone_number_collection: { enabled: true },
  billing_address_collection: 'required',
  tax_id_collection: { enabled: true },
  allow_promotion_codes: true,
  automatic_tax: { enabled: true },
  success_url: `${getBaseUri()}/stripe-success/{CHECKOUT_SESSION_ID}`,
  cancel_url: `${getBaseUri()}?canceled=true`,
  shipping_options: activeShippingRates.map((item) => {
     return {
       shipping_rate: item.id,
     }
    }),
 }

Any help would be appreciated

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论