Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe parameter_invalid_integer

I am trying to setup PaymentIntents API from Stripe and the amount needed to be passed to the API is very confusing.

Stripe Docs: All API requests expect amounts to be provided in a currency’s smallest unit. For example, to charge 10 USD, provide an amount value of 1000 (i.e., 1000 cents). For zero-decimal currencies, still provide amounts as an integer but without multiplying by 100. For example, to charge ¥500, provide an amount value of 500.

My frontend code to pass my backend the price:

const { data: clientSecret } = await axios.post("http://127.0.0.1:8000/paymentIntent/", {
        amount: price * 100
      });

My backend:

@api_view(['POST'])
def payment(request):
    try:
        amount = request.amount
        paymentIntent = stripe.PaymentIntent.create(
            amount = amount,
            currency = "usd",
            # capture_method='manual',
            # metadata={'integration_check': 'accept_a_payment'},
        ) 

        data = paymentIntent.client_secret

If I put amount = 45 (random number for example), the payment intent works and everything goes through. If I put amount as the price from the request sent from my frontend,, it says this error message:

{
  "error": {
    "code": "parameter_invalid_integer",
    "doc_url": "https://stripe.com/docs/error-codes/parameter-invalid-integer",
    "message": "Invalid integer: {\"amount\":4300}",
    "param": "amount",
    "type": "invalid_request_error"
  }
}

In the above error the price of the item is $43 so I just pass in 43 x 100, isn't that correct? Maybe the amount isn't being passed as an integer but It looks fine to me.

like image 396
BigSteppaJC Avatar asked Dec 31 '25 01:12

BigSteppaJC


1 Answers

The error is saying you've passed a value of {\"amount\":4300} -- it looks like you're accidentally passing some object instead of the integer value.

eg: you're sending something like amount={\"amount\":4300} instead of the expected amount=4300.

You need to review how amount is being passed around and provided to the Payment Intent create call.

Update (not a fix): Try using a different variable name:

requestAmount = request.amount
paymentIntent = stripe.PaymentIntent.create(
  amount = requestAmount,
  currency = "usd",
) 

Update 2: Likely need to parse the json body:

data = json.loads(request.body)
paymentIntent = stripe.PaymentIntent.create(
  amount = data.amount,
  currency = "usd",
) 
like image 189
Nolan H Avatar answered Jan 01 '26 15:01

Nolan H