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

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

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

问题

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

  1. const customer = await stripe.customers.create({
  2. email,
  3. name,
  4. payment_method: paymentMethod,
  5. invoice_settings: { default_payment_method: paymentMethod },
  6. });
  7. const params = {
  8. customer: customer.id,
  9. items: [{ price: "price_1N1TKrGxUje7SlyIeNldQvLT" }],
  10. payment_settings: {
  11. payment_method_options: {
  12. card: {
  13. request_three_d_secure: "any",
  14. },
  15. },
  16. payment_method_types: ["card"],
  17. save_default_payment_method: "on_subscription",
  18. },
  19. trial_period_days: 7,
  20. expand: ["pending_setup_intent"],
  21. };
  22. if (promo) params.promotion_code = promo;
  23. if (countrycode) params.currency = countrycode;
  24. // 创建订阅
  25. const subscription = await stripe.subscriptions.create(params);
  26. // 返回付款客户端密钥
  27. response.json({
  28. message: "Subscription successfully initiated",
  29. clientSecret: subscription.pending_setup_intent.client_secret,
  30. subID: subscription.id,
  31. });
  32. } catch (err) {
  33. console.error(err);
  34. response.status(500).json({ message: "Internal server error" });
  35. }

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

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

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

  1. 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.

  1. const customer = await stripe.customers.create({
  2. email,
  3. name,
  4. payment_method: paymentMethod,
  5. invoice_settings: { default_payment_method: paymentMethod },
  6. });
  7. const params = {
  8. customer: customer.id,
  9. items: [{ price: "price_1N1TKrGxUje7SlyIeNldQvLT" }],
  10. payment_settings: {
  11. payment_method_options: {
  12. card: {
  13. request_three_d_secure: "any",
  14. },
  15. },
  16. payment_method_types: ["card"],
  17. save_default_payment_method: "on_subscription",
  18. },
  19. trial_period_days: 7,
  20. expand: ["pending_setup_intent"],
  21. }
  22. if (promo) params.promotion_code = promo;
  23. if (countrycode) params.currency = countrycode;
  24. // Create a subscription
  25. const subscription = await stripe.subscriptions.create(params);
  26. // Send back the client secret for payment
  27. response.json({
  28. message: "Subscription successfully initiated",
  29. clientSecret: subscription.pending_setup_intent.client_secret,
  30. subID:subscription.id,
  31. });
  32. } catch (err) {
  33. console.error(err);
  34. response.status(500).json({ message: "Internal server error" });
  35. }

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

  1. 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:

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

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

  1. payment_method: paymentMethod,
  2. 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

  1. payment_method: paymentMethod,
  2. 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:

确定