用于从条带获取令牌并将其发送到后端的客户端代码的一部分
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);
}
}
Run Code Online (Sandbox Code Playgroud)
后端
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 …Run Code Online (Sandbox Code Playgroud)