I am developing an e-commerce solution having Blazor WASM for the client, Blazor Server for the admin, and API for CRUD and payment operations. I am using the latest (44.9) version of Stripe via a test account.
The problem is I am getting this error after clicking the pay button.
Here is the test dashboard of Stripe:
I did some research and came across this stripe-hosted page documentation. Stripe Hosted The difference is I am using PriceData
rather than Price ID
.
Here is my Stripe calling API:
[HttpPost]
[Authorize]
[ActionName("Create")]
public async Task<IActionResult> Create([FromBody] StripePaymentDTO paymentDTO)
{
try
{
var domain = _configuration.GetValue<string>("Client_URL");
var options = new SessionCreateOptions
{
SuccessUrl = domain + paymentDTO.SuccessUrl,
CancelUrl = domain + paymentDTO.CancelUrl,
LineItems = new List<SessionLineItemOptions>(),
Mode = "payment",
PaymentMethodTypes = new List<string> { "card" }
};
foreach (var item in paymentDTO.Order.OrderDetails)
{
var sessionLineItem = new SessionLineItemOptions
{
PriceData = new SessionLineItemPriceDataOptions
{
UnitAmount = (long)(item.Price * 100), //20.00 -> 2000
Currency = "USD",
ProductData = new SessionLineItemPriceDataProductDataOptions
{
Name = item.Product.Name
}
},
Quantity = item.Count
};
options.LineItems.Add(sessionLineItem);
}
var service = new SessionService();
Session session = await service.CreateAsync(options);
return Ok(new SuccessModelDTO()
{
Data = session.Id + ";" + session.PaymentIntentId
});
}
catch (Exception ex)
{
return BadRequest(new ErrorModelDTO()
{
ErrorMessage = ex.Message
});
}
}
How can I fix this issue?