createPayment node.js sdk api call times out but still creates payment

I am using the Square api in a node.js backend (square - npm) to create credit card payments using the paymentsApi.createPayment() method as a promise and using a .then() block to handle success and a .catch() block to handle failure.

Infrequently this call will take longer than 3000ms, which is the timeout I passed in when creating the Client. When that happens, an error is thrown and caught by my .catch() block and the user trying to process a card is told something went wrong and to try again.

The problem, though, is that in those cases the card actually does eventually run, but we don’t process the success. So, our software doesn’t record that a successful transaction occurred, and the user doesn’t realize they were successful so they try again. We figure it out because, of course, we have duplicate card transactions from the user running the card repeatedly.

Obviously, I can increase the timeout length to have fewer of these happen, but that is messy. Is there a way to cancel the api call if it times out? This seems like a huge hole in the node.js SDK that it will throw a timeout error while simultaneously actually successfully running the card.

At this time there isn’t a way to cancel a payment that’s in flight. Each payment is idempotent. If a call to CreatePayment times out in your application cause you didn’t get a response from Square you can call CreatePayment again with the same idempotency_key. If the payment was successful on the first request then your application will get the payment response. If Square never received the first request then we will process the payment and return a response. For more on how Square uses idempotency please see our documentation. :slightly_smiling_face:

Thanks, that’s helpful!