Stripe/React/Firebase: Value should be a PaymentIntent client secret. You specified: a SetupIntent client secret

huangapple go评论57阅读模式
英文:

Stripe/React/Firebase: Value should be a PaymentIntent client secret. You specified: a SetupIntent client secret

问题

我正在尝试为一个具有7天免费试用期的订阅产品注册客户。

const customer = await stripe.customers.create({
  email,
  name,
  payment_method: paymentMethod,
  invoice_settings: { default_payment_method: paymentMethod },
});

const params = {
  customer: customer.id,
  items: [{ price: "price_1N1TKrGxUje7SlyIeNldQvLT" }],
  payment_settings: {
    payment_method_options: {
      card: {
        request_three_d_secure: "any",
      },
    },
    payment_method_types: ["card"],
    save_default_payment_method: "on_subscription",
  },
  trial_period_days: 7,
  expand: ["pending_setup_intent"],
};

if (promo) params.promotion_code = promo;
if (countrycode) params.currency = countrycode;

// 创建订阅
const subscription = await stripe.subscriptions.create(params);

// 返回付款客户端密钥
response.json({
  message: "Subscription successfully initiated",
  clientSecret: subscription.pending_setup_intent.client_secret,
  subID: subscription.id,
});
} catch (err) {
  console.error(err);
  response.status(500).json({ message: "Internal server error" });
}

它们似乎在Stripe中都正常进行,支付将在7天后标记,但我收到以下控制台错误:

IntegrationError: stripe.confirmCardPayment意图密钥的值无效值应为PaymentIntent客户端密钥您指定了SetupIntent客户端密钥

在前端,我使用以下代码:

const confirmPayment = await stripe?.confirmCardPayment(response.clientSecret);

我应该如何在哪里将SetupIntent的密钥切换到PaymentIntent?

英文:

I am trying to sign a customer up to a subscription product that has a 7 day free trial.

const customer = await stripe.customers.create({
email,
name,
payment_method: paymentMethod,
invoice_settings: { default_payment_method: paymentMethod },
});


const params = {
customer: customer.id,
items: [{ price: "price_1N1TKrGxUje7SlyIeNldQvLT" }],
payment_settings: {
                  payment_method_options: {
                    card: {
                      request_three_d_secure: "any",
                    },
                  },
                  payment_method_types: ["card"],
                  save_default_payment_method: "on_subscription",
                },
                trial_period_days: 7,
                expand: ["pending_setup_intent"],
            }

            if (promo) params.promotion_code = promo;
            if (countrycode) params.currency = countrycode;

            // Create a subscription
            const subscription = await stripe.subscriptions.create(params);
            
              // Send back the client secret for payment
            response.json({
              message: "Subscription successfully initiated",
              clientSecret: subscription.pending_setup_intent.client_secret,
              subID:subscription.id,
            });
          } catch (err) {
            console.error(err);
            response.status(500).json({ message: "Internal server error" });
          }

They appear to go into Stripe all OK with payment being marked to happen in 7 days, but I get the following console error:

IntegrationError: Invalid value for stripe.confirmCardPayment intent secret: value should be a PaymentIntent client secret. You specified: a SetupIntent client secret.

In the front end I am using:

const confirmPayment = await stripe?.confirmCardPayment(
response.clientSecret
);

How or where do I swap over the intent secret from SetupIntent to PaymentIntent?

答案1

得分: 1

不要翻译代码部分:

"Instead of using stripe?.confirmCardPayment you should used instead stripe?.confirmCardSetup[0].

On an unrelated topic, I noticed you are passing a "default" paymentMethod to the customer with this code

payment_method: paymentMethod,
invoice_settings: { default_payment_method: paymentMethod },

if you're already collecting the PaymentMethod before creating the customer/subscription you don't need to recollect it after creating the subscription. The invoice_settings.default_payment_method on the customer is the Payment Method used to pay all subscription/one-off invoices if no other PaymentMethod is specified.

英文:

Instead of using stripe?.confirmCardPayment you should used instead stripe?.confirmCardSetup[0].

On an unrelated topic, I noticed you are passing a "default"
paymentMethod to the customer with this code

payment_method: paymentMethod,
invoice_settings: { default_payment_method: paymentMethod },

if you're already collecting the PaymentMethod before creating the customer/subscription you don't need to recollect it after creating the subscription. The invoice_settings.default_payment_method on the customer is the Payment Method used to pay all subscription/one-off invoices if no other PaymentMethod is specified.

huangapple
  • 本文由 发表于 2023年5月26日 15:43:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76338675.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定