• 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 database

    1. 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 to Failed (or Cancelled).

    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

    1. Create a coupon which is either expired or has some restriction (any restriction).
    2. Open POS and perform a full sync.
    3. Create an order making sure to do something that will cause the coupon to fail.
    4. Apply the invalid coupon.
    5. Press Checkout
    6. Clear the error and remove the coupon.
    7. Checkout and complete
    8. Examine the WooCommerce orders list, you will find two orders. One completed and one in Payment Pending
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author bizswoop

    (@bizswoop)

    We really appreciate the detailed overview, specific request responses and reproduction steps. This is extremely helpful for us to evaluate and review the issue. We have added this item to our queue to review and evaluating optimizations.

    The good news, we do have several features and code improvements planned for coupon functionality in the POS to add advanced parity with WooCommerce coupon functionality in upcoming releases this year.

    Thread Starter yknivag

    (@yknivag)

    Thank you for your prompt reply. If there is any further information you require for your investigation please do reply.

    I look forward to seeing what improvements you make.

    If you are working towards parity with WC core you may want to consider that it too is not bug free, see both https://github.com/woocommerce/woocommerce/issues/26641 and the other but linked therein.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Orphaned orders caused by invalid/expired coupon’ is closed to new replies.