英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论