# What is the best practice to handle http code 502 while creating payment

**URL:** <https://developer.squareup.com/forums/t/what-is-the-best-practice-to-handle-http-code-502-while-creating-payment/25393>\
**Category:** Questions\
**Tags:** payments-api\
**Created:** [February 18, 2026, 10:07pm UTC](https://developer.squareup.com/forums/t/what-is-the-best-practice-to-handle-http-code-502-while-creating-payment/25393 "2026-02-18T22:07:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alfred](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@Alfred](https://developer.squareup.com/forums/u/Alfred)\
**Post date:** [February 18, 2026, 10:07pm UTC](https://developer.squareup.com/forums/t/what-is-the-best-practice-to-handle-http-code-502-while-creating-payment/25393/1 "2026-02-18T22:07:31Z")

</div>

Dear Team,

We noticed sometimes payment API returned http code 502 while creating payment;  
In this situation, both the customer and our application didn’t know the payment result, the customer usually thought the payment is failed, so he paid it again, it might turn out that he paid twice finally.

May I know your suggestion on how our application should handle http code 502 from payment API? we want to ensure the customer make the payment only once.

Thanks in advance.  
Best Regards,

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [February 18, 2026, 10:52pm UTC](https://developer.squareup.com/forums/t/what-is-the-best-practice-to-handle-http-code-502-while-creating-payment/25393/2 "2026-02-18T22:52:07Z")

</div>

In this case you can retry the payment with the same `idempotency_key`. If the customer was already charged it will just return the payment response. If they weren’t charged we would then process the payment. 🙂

---

<div class="post-metadata">

**Author:** ![Alfred](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@Alfred](https://developer.squareup.com/forums/u/Alfred)\
**Post date:** [February 24, 2026, 9:21pm UTC](https://developer.squareup.com/forums/t/what-is-the-best-practice-to-handle-http-code-502-while-creating-payment/25393/3 "2026-02-24T21:21:55Z")

</div>

Hi Bryan,

Thanks for the feedback, we will improve the application based on your advice.

Meanwhile, we are interested in the cause of the http code 502, we understood that it’s the standard code for something abnormal in API proxy, but could we know the the root cause of it? such as, whether it was caused by API QPS limitation, etc.

Below are two of the payments with this issue, if any other info is required, please let us know.

Thanks in advance.

- Feb 15th, Payment ID: X3WgOJcJhJTKmsQnQG4DRRXydvXZY

- Feb 22nd, Payment ID: lwnC17tnr5H0izu6libNcc1ShfCZY

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [February 24, 2026, 9:41pm UTC](https://developer.squareup.com/forums/t/what-is-the-best-practice-to-handle-http-code-502-while-creating-payment/25393/4 "2026-02-24T21:41:56Z")

</div>

I took a look at your [API logs](https://developer.squareup.com/apps/sq0idp-X5g7B-QAtnOvyEFik1fuSg/log) and I don’t see any `5xx` errors being returned from Square for those payments. 🙂

---

<div class="post-metadata">

**Author:** ![Alfred](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@Alfred](https://developer.squareup.com/forums/u/Alfred)\
**Post date:** [February 24, 2026, 10:21pm UTC](https://developer.squareup.com/forums/t/what-is-the-best-practice-to-handle-http-code-502-while-creating-payment/25393/5 "2026-02-24T22:21:25Z")

</div>

I checked API log just now, I can’t find 5xx errors neither, but I can’t find the log for the two payments as well, did you find them? in that case, could you please share the timestamp of the API request in the API log?

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [February 24, 2026, 10:54pm UTC](https://developer.squareup.com/forums/t/what-is-the-best-practice-to-handle-http-code-502-while-creating-payment/25393/6 "2026-02-24T22:54:18Z")

</div>

No, I didn’t find the logs. 🙂

---

<div class="post-metadata">

**Author:** ![Alfred](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@Alfred](https://developer.squareup.com/forums/u/Alfred)\
**Post date:** [February 24, 2026, 11:17pm UTC](https://developer.squareup.com/forums/t/what-is-the-best-practice-to-handle-http-code-502-while-creating-payment/25393/7 "2026-02-24T23:17:59Z")

</div>

but the payments exist if you query them in DB or through API explorer, right?

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [February 25, 2026, 12:42am UTC](https://developer.squareup.com/forums/t/what-is-the-best-practice-to-handle-http-code-502-while-creating-payment/25393/8 "2026-02-25T00:42:42Z")

</div>

Yes, these are successful payments that have been refunded. 🙂
