Orphaned orders caused by invalid/expired coupon
-
Detail
When adding an expired/invalid coupon to an order created through the API an orphaned order is created and anadonned in an unexpected state.
The request and response is shown below and followed by the detail of what appears to be the buggy behaviour.
Request and Response JSON
Request
URI: https://domain.tld/wp-json/wc-pos/orders/ Method: POST Status Code: 400
{ "meta_data":[ {"key":"_pos_by",value":132}, {"key":"_pos_print"}, {"key":"_pos_type","value":"pos"}, {"key":"pos-tip","value":0}, {"key":"_pos-vat-number","value":null} ], "customer_note":"", "line_items":[ { "meta_data":[ {"key":"_reduced_stock","value":false} ], "product_id":52, "name":"Fluid Acrylic - Transparent Red Iron Oxide", "quantity":1,"total":"0","subtotal":"4.5" } ], "coupon_lines":[ { "code":"expired", "discount":"4.5", "meta_data":[ {"key":"_pos_id","value":237} ] } ] }
Response
{"code":"woocommerce_rest_invalid_coupon","message":"This coupon has expired.","data":{"status":400}}
Expected Result
As happened one would expect the API to return an error. However one would expect one of three things to happen in the database1. No order should be created. This is the ideal solution.
2. If an order must be created then the order number should be returned in the error message and once the error is corrected the POS should update this same order for the remainder of the transaction.
3. Alternatively, if an order has to be created, then it should be closed and set toFailed
(orCancelled
).Any of these three would be a reasonable way to handle the situation.
Actual Result
As can be seen the API does indeed respond correctly stating that the coupon has expired.
However an order is created in WooCommerce and is then abandonned in a state of “Payment Pending”. The order number is not returned in the error and so when the erroneous coupon is removed and the cashier agains checks out the order a second order is produced rather than the first one being updated.
Furthermore it is left in that state with the value of the coupon deducted from the total and yet there is no coupon showing that can be removed.
This behaviour means that any time a customer presents an invalidated coupon the store manager/admin needs to browse to the orders in WooCommerce and manually update the orphaned order to cancelled/failed or delete it. This is something that seems needlessly tiresome.
How to Reproduce
- Create a coupon which is either expired or has some restriction (any restriction).
- Open POS and perform a full sync.
- Create an order making sure to do something that will cause the coupon to fail.
- Apply the invalid coupon.
- Press
Checkout
- Clear the error and remove the coupon.
- Checkout and complete
- Examine the WooCommerce orders list, you will find two orders. One completed and one in
Payment Pending
- The topic ‘Orphaned orders caused by invalid/expired coupon’ is closed to new replies.