How to get a different idempotency key when correcting errors

I am testing out my web payments sdk connecting to create payment from the payments api, and when I test for an error using incorrect cvc or zip code, and then correct it and try again I get an error returned rror: The provided idempotency key has already been used.

How can I get a new one if someone changes info in the payment form after getting an error?

Idempotency keys can be anything, but they need to be unique. Virtually all popular programming languages provide a function for generating unique strings. You should use one of these language calls.

Language Recommended function
Ruby SecureRandom.uuid
PHP uniqid
Java UUID.randomUUID
Python uuid
C# Guid.NewGuid
Node.js crypto.randomUUID

:slightly_smiling_face:

I get that. I am using a function for that, but then I guess I need to call it again if they provide an incorrect zip code and then correct it? Cause I get an error on the key when trying to resubmit.

Yes, that’s correct after you get a decline from the CreatePayment request. :slightly_smiling_face:

Hi I am also looking into this, may I ask how you solved the problem?

When an error occurs all of the examples pass the error and do nothing else?

Did you reload the page after the error?

Just pondering the flow of this.

Thanks

I never finished it. Sorry!

As a work around, I ended up creating a new idempotency key for every call to CreatePayment, It only seems to matter at this point. Testing continues!!

I found a rather simple solution for me. In the ‘sq-payment-flow.js’ file I added this to line 30 (may be slightly different in yours )
window.paymentFlowMessageEl.innerText = message + ‘\r\n\r\n please edit errors and re-send’;

The card window remains unchanged with this message under the send button. I find they can edit any portion of the entry then hit ‘pay’ and it works