I have a cart of items that I am using Stripe Api as a method of payment but I get the exception of missing the param amount,
Stripe.StripeException: 'Missing required param: amount.'
why am I getting the issue since I am including an amount?
public IActionResult CheckOut(string stripeEmail, string stripeToken, bool charged)
{
var customers = new CustomerService();
var charges = new ChargeService();
var customer = customers.Create(new CustomerCreateOptions{
Email=stripeEmail,
Source=stripeToken
});
var charge = charges.Create(new ChargeCreateOptions
{
Amount = ViewBag.stripe,
Description = "product purchased",
Currency = "usd",
Customer = customer.Id,
ReceiptEmail = stripeEmail,
});
Inside my index I declared the viewbags as:
ViewBag.total = Cost(ViewBag.pricing, ViewBag.tax);
ViewBag.stripe = ViewBag.total * 100;
The cost method I used for ViewBag.total:
public double Cost(double total, double tax)
{
return total + tax;
}
What I have tried:
What I tried is creating another var amount which equals the ViewBag.stripe
var customers = new CustomerService();
var charges = new ChargeService();
var amount = ViewBag.stripe;
var customer = customers.Create(new CustomerCreateOptions{
Email=stripeEmail,
Source=stripeToken
});
I then tried changing ViewBag.stripe in my index to:
ViewBag.total = Cost(ViewBag.pricing, ViewBag.tax);
ViewBag.stripe = StripeTotal(ViewBag.total);
And having my StripeTotal method return ViewBag.total * 100 instead
public double StripeTotal(double amount)
{
return ViewBag.total * 100;
}
I have also tried changing it to
Amount = Convert.ToInt32(ViewBag.stripeTotal)
but instead of the error that I am missing amount, I get another error so this did not work either
I further tried searching online but I just cant seem to find a similar case