Feature request: idempotency for Payment Intents
I can not find in API that Payment intents do support idempotency keys (like charges). This causes potential double-charging situation for me when using off session payments. I am using this code:
const paymentIntent = await stripe.paymentIntents.create({
amount: 1099,
currency: 'usd',
customer: '{{CUSTOMER_ID}}',
payment_method: '{{PAYMENT_METHOD_ID}}',
off_session: true,
confirm: true,
});
In case there is a bug in my code and this code gets executed twice - the client would be charged twice. However if I could add some idempotency value that I could pass to intent creation (lets say it could be order id). That would mean that it would be impossible to create two off_session aut-confirmable payment intents for the same order.
Hey @tautvilas :wave:
The PaymentIntents API can use idempotency keys [1] too. The idempotency key is passed in the request options object and looks like this:
const paymentIntent = await stripe.paymentIntents.create({
amount: 1099,
currency: 'usd',
customer: '{{CUSTOMER_ID}}',
payment_method: '{{PAYMENT_METHOD_ID}}',
off_session: true,
confirm: true,
}, {
idempotencyKey: "random-key",
});
[1] https://stripe.com/docs/api/idempotent_requests?lang=node
Thank you for the quick response! I got confused reading all these different API docs :) Maybe there could be example with payment intents + idempotency in the api too
:) Happy to help.
Hi @cjavilla-stripe I am passing the options in the same in the code snippet you've added here. But I'm getting the following error.
Stripe: Unknown arguments ([object Object]). Did you mean to pass an options object? See https://github.com/stripe/stripe-node/wiki/Passing-Options. (on API request to POST /payment_intents)
Could you please let me know why?
Figured it out. I've been using an older version of stripe. So there the parameter should be idempotency_key instead of idempotencyKey.