#heymato

1 messages ยท Page 1 of 1 (latest)

sacred hatchBOT
south cobalt
#

๐Ÿ‘‹ happy to help

#

will be with you shortly

balmy bloom
#

Me too, have to go to the toilet first ๐Ÿ™‚

#

I'm here

wild skiff
#

Hey! Taking over for my colleague. Let me catch up.

balmy bloom
#

ok

#

Whenever you are ready

wild skiff
#

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

balmy bloom
#

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 ?

wild skiff
#

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

balmy bloom
#

OK, I also read about the problem with status 500. How do I fix this then in this scenario?

wild skiff
#

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

balmy bloom
#

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 ?

wild skiff
#

Not sure I'm following the webhook proposition, what do you mean ?

balmy bloom
#

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.

wild skiff
#

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

balmy bloom
#

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

balmy bloom
wild skiff