.net - 您无法使用 PaymentMethod 创建费用。请改用支付意图 API

标签 .net reactjs stripe-payments

部分客户端代码,用于从 strip 获取 token 并将其发送到后端

const cardElement = elements.getElement(CardElement);
const {error, paymentMethod} = await stripe.createPaymentMethod({
   type: 'card',
   card: cardElement,
});

    try {
      const { id } = paymentMethod;
      console.log(id)
      const response = await axios.post(
        "https://localhost:44325/api/Payment",
        {
          token: id,
        }
      );

  
    } catch (error) {
      console.log("CheckoutForm.js 28 | ", error);
    }
  } 

后端

public async Task Test(string token)
        {
            StripeConfiguration.ApiKey = "SecretKey";
        var options = new ChargeCreateOptions()
        {
            Amount = 12345,
            Currency = "usd",

            Description = "Donation from me",
            Source = token
        };
        var service = new ChargeService();

        try
        {
            var charge = service.Create(options);
        }
        catch (StripeException e)
        {

        }
    }

我得到您无法使用 PaymentMethod 创建费用。请改用 Payment Intents API。 如何使用客户端的 token 发送到 stripe payment?

最佳答案

Stripe 上的费用 API (/v1/charges) 可与 token 、卡(附加 token )和来源配合使用。

PaymentIntents API (/v1/payment_intents) 可与 PaymentMethods 配合使用(技术上也可与遗留附加 token (又名 Card 对象)和 Sources 配合使用,但后两者与您的用例无关)。

您的集成正在创建一个 PaymentMethod 对象。但是你的后端正在创建一个 Charge,它不能一起工作。

您需要创建一个 PaymentIntent,创建它并传递 confirm: true 参数以在其上创建付款。 https://stripe.com/docs/api/payment_intents/create

关于.net - 您无法使用 PaymentMethod 创建费用。请改用支付意图 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66989191/

相关文章:

c# - 从 ASP.NET 打印到网络打印机

react-native - 为什么没有使用 React Native Router Flux + Redux 触发 React Native Drawer?

go - 使用 Stripe 将费用与客户相关联

c# - .NET/C# - 反射 - 曾经使用过的 System.IO.File

asp.net - OData 和区分大小写

c# - 获取匿名方法的目标

javascript - 如何确保 API 调用在 React 中加载另一个页面之前完成

reactjs - 我如何构建这个 React Native 部分列表实现

ruby - 如何在非 SSL 或 http 网站上使用 Stripe?

ssl - 处理付款和搭载 ssl