gpt4 book ai didi

javascript - 使用 Stripe 时出现 handleCardPayment 错误

转载 作者:行者123 更新时间:2023-11-30 19:18:59 24 4
gpt4 key购买 nike

我目前遇到错误:

Invalid value for stripe.handleCardPayment intent secret: value should be a client secret of the form ${id}secret${secret}. You specified: pi_1FCNbuIxBpL3Mx4OJYi5hKML.

我首先从我在 Vue.js 中完成的前端向我在 Laravel 中完成的后端发出一个 axios 请求,它创建了一个支付意图(即 pi_1FCNbuIxBpL3Mx4OJYi5hKML)。

 StripePackage::setApiKey('sk_test_xxxxxxxxxxx');

$intent = \Stripe\PaymentIntent::create([
'amount' => 1099,
'currency' => 'eur',
]);

return $intent;

我将此支付意向设置为一个名为 data_secret 的全局定义数据变量,它是提交支付按钮中的引用:

<button id='test' class='pay-with-stripe' @click='pay' type="button" style="margin-top:20px;" :data-secret="data_secret">Pay with card</button>

单击此按钮时调用支付方法,该方法又使用 Stripe handleCardPaymentMethod:

var cardButton = document.getElementById("test");
var clientSecret = cardButton.dataset.secret;

this.stripe.handleCardPayment(
clientSecret, this.card, {
payment_method_data: {
billing_details: {name: 'Test Name'}
}
}
).

这会触发前面提到的错误。

我一直在关注此文档,但看不到问题所在:https://stripe.com/docs/payments/payment-intents/web

最佳答案

Stripe.js 的 handleCardPayment 方法使用 PaymentIntent 的 client_secret 字段 [0](看起来像“pi_123_secret_123”),而不是 PaymentIntent 的 ID(即“pi_123”) .

看起来您的代码正在设置 PaymentIntent ID 而不是前端的 client_secret。

[0] https://stripe.com/docs/api/payment_intents/object#payment_intent_object-client_secret

关于javascript - 使用 Stripe 时出现 handleCardPayment 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57689519/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com