Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
85 stars 31 forks source link

Fix "Subscriptions by Payment Gateway" in WC → Status when HPOS is enabled #386

Closed Jinksi closed 1 year ago

Jinksi commented 1 year ago

Fixes #384

Description

This PR refactors the WCS_Admin_System_Status::get_subscriptions_by_gateway() to provide the correct subscription count by status & payment gateway when HPOS is enabled.

This function is used when rendering Subscriptions by Payment Gateway in WooCommerce → Status and the WCS Rest API.

How to test this PR

  1. Enable HPOS + no syncing.
  2. Purchase a few subscriptions with 1 or more payment gateways.
  3. Change the status of 1 or more subscriptions (e.g. move to trash, cancel, place on hold).
  4. Go to WooCommerce → Status and find Subscriptions by Payment Gateway.
  5. Ensure these values are correct by comparing with WooCommerce → Subscriptions and filtering by Payment Gateway.
  6. Enable HPOS syncing and wait for the sync to complete.
  7. Ensure the WooCommerce → Status → Subscriptions by Payment Gateway are correct.
  8. Disable HPOS.
  9. Ensure the WooCommerce → Status → Subscriptions by Payment Gateway are correct.

WCS REST API

I have tested the output provided to the /wp-json/wc/v3/system_status endpoint when WCS is enabled, and can confirm that the results are correct with both HPOS enabled/disabled.

This can be tested (optional) by:

  1. Enable the WooCommerce Rest API.
  2. Using Postman or similar, prepare a GET request, setting up Basic Auth as per guide above.
    1. If not using HTTPS, replace is_ssl() with a truthy value on this line within WC.
  3. Send a GET request to /wp-json/wc/v3/system_status.
  4. The relevant values will be output under subscriptions.subscriptions_by_payment_gateway.

Example:

"subscriptions_by_payment_gateway": {
    "square_credit_card": {
        "wc-active": "1",
        "wc-cancelled": "1",
        "wc-on-hold": "2"
    },
    "woocommerce_payments": {
        "trash": "1",
        "wc-active": "3",
        "wc-cancelled": "2",
        "wc-on-hold": "1"
    }
},

Product impact