woocommerce / woocommerce-gateway-stripe

The official Stripe Payment Gateway for WooCommerce
https://wordpress.org/plugins/woocommerce-gateway-stripe/
229 stars 197 forks source link

Prevent loading the subscriptions repairing class after all affected subscriptions were repaired #3238

Open a-danae opened 2 days ago

a-danae commented 2 days ago

Describe the bug The WC_Stripe_Subscriptions_Repairer_Legacy_SEPA_Tokens class to repair subscriptions using Legacy SEPA tokens must only be loaded when there are subscriptions to be repaired.

Currently, we always initialize this class on init. This is suboptimal given that there will be a point when no subscription is using a Legacy SEPA token.

When working on this issue, keep in mind that this repaired class must still be available when there are actions scheduled because this class contains their callbacks. The scheduled actions are wc_stripe_schedule_subscriptions_legacy_sepa_token_repairs and wc_stripe_subscriptions_legacy_sepa_token_repair.

To Reproduce Steps to reproduce the behavior:

  1. Enable WC Subscriptions
  2. Ensure none of the subscriptions use a Legacy SEPA token
  3. Notice that the repairer class is still initialized

Expected behavior

When there are no subscriptions using a Legacy SEPA token as its payment method, the repairer class must not be loaded.

Additional context

Follow-up issue for the review by @james-allan in https://github.com/woocommerce/woocommerce-gateway-stripe/pull/3139#issuecomment-2174502742

When doing regression tests for the actual repairing, we can change the value of the payment_method to stripe_sepa of the subscriptions we want to repair in the wc_orders table, instead of following the full steps from this other PR.