Part of client code for getting token from stripe and send it to backend
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);
}
}
Backend
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)
{
}
}
And I get You cannot create a charge with a PaymentMethod. Use the Payment Intents API instead. How I can send to stripe payment with token from client?