UNPROCESSABLE_ENTITY - ORDER_ALREADY_COMPLETED leads to wrong order state, maybe race condition?

Created on 8 January 2025, 28 days ago

Problem/Motivation

We've run into the following issue several times now. Orders using PayPal checkout raise the following error:

Payment failed via PayPal Checkout for XX,XX € using PayPal.
Message: {"name":"UNPROCESSABLE_ENTITY","details":[{"issue":"ORDER_ALREADY_COMPLETED","description":"The order cannot be patched after it is completed."}],"message":"The requested action could not be performed, semantically incorrect, or failed business validation.","debug_id":"xxx","links":[{"href":"https://developer.paypal.com/api/rest/reference/orders/v2/errors/#ORDER_ALREADY_COMPLETED","rel":"information_link","method":"GET"}]}.

Right before this, we see the following in the order log:
Order moved from Draft to Eingegangen by the Place order transition.

But after the PayPal Error the order (that is indeed already paid!) is in "Draft" state again!

That's a major issue, because nobody sees this paid order and the order is never processed and shipped, while paid. Clients are angry, giving bad ratings.

The nature of this issue looks like a race condition to me. Maybe the PayPal Webhook updates the order very fast, while the regular order completion is not yet finished? Or maybe something else?

Steps to reproduce

Set up PayPal Checkout and see this from time to time, while 95% of all orders with PayPal Checkout just run fine!

Proposed resolution

Remaining tasks

User interface changes

None

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.0

Component

PayPal Checkout

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Anybody
  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Anybody Porta Westfalica

    Just thought about it again and the race condition theory does not fully make sense to me, as the error is reported from PayPal itself, so it looks like the payment is sent to PayPal twice in certain cases? So maybe it's a race condition the other way around?

    Any code-wise ideas how this might happen?

  • 🇩🇪Germany Anybody Porta Westfalica

    Another thing I just recognized is, that the order balance is NOT 0 but is still equal to the order total, like it was unpaid, while it actually IS paid and the payment status also shows "Completed"!

    So this bug seems to entirely screw things up.

  • 🇩🇪Germany Anybody Porta Westfalica
Production build 0.71.5 2024