gpt4 book ai didi

node.js - 引用错误: clientSecret is not defined in stripe

转载 作者:太空宇宙 更新时间:2023-11-03 23:53:09 24 4
gpt4 key购买 nike

我正在尝试将付款请求按钮集成到 Stripe 中。为此,我遵循文档(https://stripe.com/docs/stripe-js/elements/payment-request-button#complete-payment-intents)。我的 chrome 上有这个按钮。付款完成时

paymentRequest.on('paymentmethod', function(ev) {
stripe.confirmPaymentIntent(clientSecret, {
payment_method: ev.paymentMethod.id,
}).then(function(confirmResult) {
if (confirmResult.error) {
console.log("error")
ev.complete('fail');
} else {
ev.complete('success');
stripe.handleCardPayment(clientSecret).then(function(result) {
if (result.error) {
console.log(result.error)
} else {
console.log("Success")
}
});
}
});
});

我收到错误 clientSecret 未定义。我不确定从哪里可以获得客户端 key

付款方式 API未提供clientSecret

当我调用source API时,我得到了clientSecret

但无法同时运行 source paymentMethod API

请指导我完成集成的正确方法。提前致谢

最佳答案

来自Stripe Docs

clientSecret: The client secret of this PaymentIntent. Used for client-side retrieval using a publishable key. The client secret can be used to complete a payment from your frontend. It should not be stored, logged, embedded in URLs, or exposed to anyone other than the customer. Make sure that you have TLS enabled on any page that includes the client secret.

因此 clientSecret 被定义为 paymentintent 对象的属性。

付款意图对象(示例):

{
"id": "pi_1FpUmEKZaRsxp2y4c9OPoTjM",
"object": "payment_intent",
"amount": 3000,
"amount_capturable": 0,
amount_received": 0,
"application": null,
"application_fee_amount": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic",
"charges": {
"object": "list",
"data": [],
"has_more": false,
"url": "/v1/charges?payment_intent=pi_1FpUmEKZaRsxp2y4c9OPoTjM"
},
"client_secret": "pi_1FpUmEKZaRsxp2y4c9OPoTjM_secret_tv9tsgAQbAlNRYqm8MAzmYPuE",
"confirmation_method": "automatic",
"created": 1576307458,
"currency": "eur",
"customer": null,
"description": null,
"invoice": null,
"last_payment_error": null,
"livemode": false,
"metadata": {},
"next_action": null,
"on_behalf_of": null,
"payment_method": null,
"payment_method_options": {
"card": {
"installments": null,
"request_three_d_secure": "automatic"
}
},
"payment_method_types": [
"card"
],
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "requires_payment_method",
"transfer_data": null,
"transfer_group": null
}

作为 documentation 中的步骤 2您可以将您的 clientSecret 检索为 paymentintent.client_secret。要在代码中执行以下操作:

 const clientSecret  = paymentRequest.client_secret

如果其他人使用 php,请不要忘记将其用作字符串而不是变量:

submitButton.addEventListener('click', function(ev) {
stripe.confirmCardPayment('<?php echo ($intent->client_secret);?>', {
payment_method: {card: card}
}).then(function(result) {
if (result.error) {
// Show error to your customer (e.g., insufficient funds)
console.log(result.error.message);
} else {
// The payment has been processed!
if (result.paymentIntent.status === 'succeeded') {
// Show a success message to your customer
// There's a risk of the customer closing the window before callback
// execution. Set up a webhook or plugin to listen for the
// payment_intent.succeeded event that handles any business critical
// post-payment actions.
}
}
});
});

关于node.js - 引用错误: clientSecret is not defined in stripe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58519874/

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