【发布时间】:2021-07-03 10:48:02
【问题描述】:
用于从条带获取令牌并将其发送到后端的部分客户端代码
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。 如何使用来自客户端的令牌发送条带付款?
【问题讨论】:
标签: .net reactjs stripe-payments