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.