首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从.NET调用JS方法

从.NET调用JS方法
EN

Stack Overflow用户
提问于 2021-04-17 07:45:48
回答 1查看 37关注 0票数 1

我需要帮助从.NET c#后端调用Javascript方法。

据我所知,我需要从后端获取paymentIntent并将其发布到客户端,然后调用stripe.confirmCardPayment

这是Javascript的样子:

代码语言: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#代码的样子:

代码语言:javascript
运行
复制
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;
  }
}
EN

Stack Overflow用户

回答已采纳

发布于 2021-04-17 12:40:33

guide to accepting a payment中介绍了此流程。在每个服务器端代码示例中,您可以选择".NET“选项卡来查看您首选的服务器语言的代码。

您还没有展示您最初是如何收集付款详细信息的,所以我假设您使用的是已附加到已知客户的付款方法。您还没有展示如何将支付数据发送回客户端,但是在您的javascript代码片段中,看起来您拥有整个intent对象。我不建议这样做,而是建议只发送您需要的内容。在这里,假设只有一个在confirmCardPayment中使用的client_secretpayment_method_id

票数 2
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67133399

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档