![](/img/trans.png)
[英]Error creating a payment intent for Stripe with Firebase in NodeJS
[英]Getting stripe payment intent method error
javascript 中的以下代码有效,它返回带有付款方式的响应,例如“pm_1HZDptHMQMk5h2YU0kai****”,我使用这种付款方式来收取付款,条带的响应如下。
“提供的 PaymentMethod 之前与没有客户附件的 PaymentIntent 一起使用,与没有客户附件的连接帐户共享,或者与客户分离。它可能不会再次使用。要多次使用 PaymentMethod,您必须将其附加到客户至上”。
我无法弄清楚我没有在任何地方使用过 paymentMethod 的问题。 但它仍然给我上面的信息。
顺便说一下,我尝试过setup_future_usage: 'on_session' and 'off_session' values
。
var stripe = Stripe('pk_test_51H1xOmHMQMk5h2YUX7ShAMdjy9************************');
var elements = stripe.elements();
var style = {
base: {
color: "#32325d",
}
};
var card = elements.create("card", { style: style });
card.mount("#card-element");
card.on('change', ({error}) => {
const displayError = document.getElementById('card-errors');
if (error) {
displayError.textContent = error.message;
} else {
displayError.textContent = '';
}
});
var form = document.getElementById('payment-form');
form.addEventListener('submit', function(ev) {
ev.preventDefault();
stripe.confirmCardPayment('pi_1HZDaPHMQMk5h2YUga3QwB2E******************', {
payment_method: {
card: card,
billing_details: {
name: 'Jony',
}
},
setup_future_usage: 'on_session'
}).then(function(result) {
if (result.error) {
console.log(result);
// 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') {
alert('success');
// 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.
}
}
});
});
如果您单独创建 PaymentMethod(在您实际将其用于 PaymentIntent 之前),您应该遵循https://stripe.com/docs/payments/save-and-reuse
如果您想创建 PaymentMethod 并通过 PaymentIntent 一次性收费,您应该遵循https://stripe.com/docs/payments/save-during-payment
顺便说一下,我尝试过 setup_future_usage: 'on_session' 和 'off_session' 值。
如果您遵循上面的第二个链接,但不是使用已经存在并以某种方式使用的 PaymentMethod,这将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.