Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe throws invalid integer error

I am unable to charge the amount $49.99 in stripe. I am going through the following links but nothing workout

Stripe Checkout Price error - Invalid Integer

Stripe Rails: Invalid integer: 1.06

I would like to charge the amount as it is. I don't want to round off the payment

 stripe.charges.create({
    // Charge the customer in stripe
// amount: req.query.amount,
    amount: 49.99,
    currency: 'usd',
    customer: req.customer
  }).then(function(charge) {
    // Use and save the charge info in our db
    var successTransaction = {
      stripeId: charge.customer,
      transactionId: charge.id,
      amount: charge.amount,
      currency: charge.currency,
      message: charge.outcome.seller_message,
      paidStatus: charge.paid,
      summary: charge
    };
like image 490
Sam Avatar asked Aug 02 '17 06:08

Sam


People also ask

What is an invalid integer?

You are getting this error because you want to convert a string into integer. You can do this only if your string contains an integer value not the combination of character and integer value.

What does Stripe payment error mean?

The customer must use another card or method of payment. processing_error. An error occurred while processing the card. The payment needs to be attempted again. If it still can't be processed, try again later.

What does errors Code Card_decline_rate_limit_exceeded mean?

card_decline_rate_limit_exceeded. This card has been declined too many times. You can try to charge this card again after 24 hours. We suggest reaching out to your customer to make sure they have entered all of their information correctly and that there are no issues with their card.


2 Answers

Stripe allow only integer value in price so need to change your price (amount) into cent by (*100 ) so now your code amount is 499 and in stripe sdashboard you see the 49.99 for more details check the link :

https://stripe.com/docs/api#charges

In other words, Stripe's API always takes smallest supported unit as input (without need to configure anything), for example, amount of 1 means 1-Cent not 1-Dollar.

like image 79
Priyanka Sankhala Avatar answered Sep 17 '22 19:09

Priyanka Sankhala


You can use the following method as it will help you to use the decimal value as the amount and display the same amount in the invoice and during payment.

amount: Math.round(49.99 * 100)

like image 26
Vatsal Rajgor Avatar answered Sep 18 '22 19:09

Vatsal Rajgor