woocommerce-android icon indicating copy to clipboard operation
woocommerce-android copied to clipboard

[Orders] Add support for `is_editable`, `needs_payment`, and `needs_processing`

Open iamgabrielma opened this issue 2 years ago • 0 comments

Reference: p1658236518810329-slack-C025A8VV728

Stores using WC6.6+ can use the new Order-related endpoints is_editable, needs_payment, needs_processing.

Why?

At the moment, certain checks like order statuses, payment eligibility, or refund eligibility, may depend on a nil-check for the Order's datePaid property where we assume that if an order has a non-nil datePaid, it has been effectively paid, this however causes different problems, for example:

  • If the merchant switches order status manually
  • Plugins that modify datePaid
  • Custom order statuses
  • Orders where all products are Virtual and Downloadable

More context: p2-p91TBi-8to

Logic to be implemented:

This can be taken directly from the Woocommerce core implementation:

  • is_editable: If Order status is pending, on-hold, or auto-draft, the Order is editable: https://github.com/woocommerce/woocommerce/blob/3611d4643791bad87a0d3e6e73e031bb80447417/plugins/woocommerce/includes/class-wc-order.php#L1520-L1523
  • needs_payment: If the Order status is pending, or failed, and the Order total is > 0, the Order needs payment: https://github.com/woocommerce/woocommerce/blob/3611d4643791bad87a0d3e6e73e031bb80447417/plugins/woocommerce/includes/class-wc-order.php#L1395-L1402
  • needs_processing: All Orders need processing, except these where the Order only contains Virtual and Downloadable products: https://github.com/woocommerce/woocommerce/blob/3611d4643791bad87a0d3e6e73e031bb80447417/plugins/woocommerce/includes/class-wc-order.php#L1537-L1567 . Note that "needsProcessing" is not the same as "Order Status processing", the first one is an Order state, while the second one is an Order status.
  • We also need fallbacks for each property, in case the merchant is not on WC6.6+. Here's the fallback implementation example on iOS: https://github.com/woocommerce/woocommerce-ios/blob/bf903fb6b3ece4535f17076644f0dc922c61a9e9/Networking/Networking/Model/Order.swift#L190-L195

iamgabrielma avatar Jul 20 '22 10:07 iamgabrielma