#heymato
1 messages ยท Page 1 of 1 (latest)
Hey! Taking over for my colleague. Let me catch up.
The idea behind using idempotency key is for safely retrying requests without accidentally performing the same operation twice.
To perform an idempotent request, provide an additional idempotency_key element to the request options.
This is an example using curl for example:
curl https://api.stripe.com/v1/charges \
-u sk_test_51LFx4JF1SIVBSMvIt9b4wQdU6HaIJihHN3trk4Gsatf6s4HhFq8hUnzNXfabz4e3G7DohAQQr1saKyb823PPBGck00zimBeeF9: \
-H "Idempotency-Key: ITMCr8ZsHd0PNUcf" \
-d amount=2000 \
-d currency=aud \
-d description="My First Test Charge (created for API docs at https://www.stripe.com/docs/api)" \
-d source=tok_amex
You set a unique random String ( up to 255 characters long) as a header for the request, in order to be treated as a idempotency request
Here is a video that explain very well the concept and how to implement it:
https://stripe.com/docs/videos/developer-foundations?video=idempotency-and-retries
Yes, well I stumbeled upon this video and, since I'm new to next/react/firebase...., I started to freak out a little bit. That's why I'm here
I understand on how to generate a uuid and pass it to the stripe.paymentIntents.create
I just do not understand how I know if and request is duplicate or new in my firebase functions. Do I need to store data in my react code ?
This is something you define when implementing your business logic. For example, when generating the idempotency key for a payment_intent confirmation, you opt for the customerId and a cartId as a Idempotency-Key. If the payment attempt is sent by fault another time then the user won't be charged twice
OK, I also read about the problem with status 500. How do I fix this then in this scenario?
Are you talking about this?
Subsequent requests with the same key return the same result, including 500 errors.
You need to generate a new Idempotency-Key, after you make sure that you fixed the 500 in your integration
So, I capture this in mijn webhooks somewhere and pass it to my businesslogic (react) for that particular customer? Or am I saying something really stupid ?
Not sure I'm following the webhook proposition, what do you mean ?
I need to apologise for that. My knowledge of stripe/react/next/firebase is still limited. It' just that I need to implement stripe on a exisiting website and now I read about the idempotency-keys and I'm a bit lost.
I invite you to follow the video first and do a sample integration in your local environment and test. You implement the idempotency in your backend part
At the moment this is my code on firebase in which I check if a customer already exists and create a paymentIntent for him. I understand I need to add the idempotency key here as well but I'm not sure how
I checked this video but I'm not sure how to implement this in my code.
You can refer to the nodeJs integration.
https://stripe.com/docs/api/idempotent_requests?lang=node
Something like this:
await stripe.paymentIntents.create(paymentIntentParams,{
idempotencyKey: "1JuLMaCyKsN2LoHH"
});