我需要帮助从.NET c#后端调用Javascript方法。
据我所知,我需要从后端获取paymentIntent并将其发布到客户端,然后调用stripe.confirmCardPayment
这是Javascript的样子:
// Pass the failed PaymentIntent to your client from your server
stripe.confirmCardPayment(intent.client_secret, {
payment_method: intent.last_payment_error.payment_method.id
}).then(function(result) {
if (result.error) {
// Show error to your customer
console.log(result.error.message);
} else {
if (result.paymentIntent.status === 'succeeded') {
// The payment is complete!
}
}
});
下面是我的.NET c#代码的样子:
try
{
var service = new PaymentIntentService();
var options = new PaymentIntentCreateOptions
{
Amount = 1099,
Currency = "usd",
Customer = "{{CUSTOMER_ID}}",
PaymentMethod = "{{PAYMENT_METHOD_ID}}",
Confirm = true,
OffSession = true,
};
service.Create(options);
}
catch (StripeException e)
{
switch (e.StripeError.ErrorType)
{
case "card_error":
// Error code will be authentication_required if authentication is needed
Console.WriteLine("Error code: " + e.StripeError.Code);
var paymentIntentId = e.StripeError.PaymentIntent.Id;
var service = new PaymentIntentService();
var paymentIntent = service.Get(paymentIntentId);
Console.WriteLine(paymentIntent.Id);
break;
default:
break;
}
}
发布于 2021-04-17 12:40:33
此guide to accepting a payment中介绍了此流程。在每个服务器端代码示例中,您可以选择".NET“选项卡来查看您首选的服务器语言的代码。
您还没有展示您最初是如何收集付款详细信息的,所以我假设您使用的是已附加到已知客户的付款方法。您还没有展示如何将支付数据发送回客户端,但是在您的javascript代码片段中,看起来您拥有整个intent
对象。我不建议这样做,而是建议只发送您需要的内容。在这里,假设只有一个在confirmCardPayment
中使用的client_secret
和payment_method_id
。
https://stackoverflow.com/questions/67133399
复制相似问题