【发布时间】:2021-04-22 09:50:38
【问题描述】:
当用户填写卡信息并单击提交按钮时,我想对所有连接的帐户实施直接收费。 这是 Stripe 提供者。
<Elements stripe={stripePromise}>
{
stripePromise && (
<CheckoutForm
/>
)
}
</Elements>
当提交按钮点击时调用。
const handleStripeSubmit = async (payment_intents, publishableKey, values) => {
for (const intentItem of payment_intents) {
const stripeloaded =await loadStripe(publishableKey, {
stripeAccount: intentItem.stripeAccount
});
const loadResult = await stripeloaded.confirmCardPayment(intentItem.clientSecret, {
payment_method: {
card: elements.getElement(CardNumberElement),
billing_details: {
name: 'Jenny Rosen',
},
}
});
// setStripe(useStripe);
if (!stripe || !elements) {
// Stripe.js has not yet loaded.
// Make sure to disable form submission until Stripe.js has loaded.
// return;
}
const result = await stripe.confirmCardPayment(intentItem.clientSecret, {
payment_method: {
card: elements.getElement(CardNumberElement),
billing_details: {
name: 'Jenny Rosen',
},
}
});
if (result.error) {
// Show error to your customer (e.g., insufficient funds)
window.alert(result.error.message);
} else if (result.paymentIntent.status === 'succeeded') {
// The payment has been processed!
window.alert('success');
}
}
React 钩子值 stripe 仅表示 Stripe 提供者 loadStripe 连接帐户 id。 由于 loadStripe 是一个承诺,我尝试了 loadStripe 返回值,但它也会出错。
const stripeloaded =await loadStripe(publishableKey, {
stripeAccount: intentItem.stripeAccount
});
const loadResult = await stripeloaded.confirmCardPayment(intentItem.clientSecret, {
payment_method: {
card: elements.getElement(CardNumberElement),
billing_details: {
name: 'Jenny Rosen',
},
}
});
有没有人有一个关于批量付款确认的好主意?
【问题讨论】: