Skip to content

Conversation

lmcrean
Copy link

@lmcrean lmcrean commented Sep 2, 2025

Problem Statement

After cancelling a subscription, the status is inconsistent across different areas (#78):

  • Backend Orders: shows "pending subscription" (Wrong)
  • My Account > Subscriptions: shows "pending subscription" (Wrong)
  • My Account > Orders: shows "cancelled" (Correct)

Root Cause

Subscription cancellation events weren't properly synchronized between orders, subscriptions, and renewal orders. The gateway was missing status propagation logic.

Solution

Add centralized cancellation handling and status synchronization:

  1. Unified cancellation handler - Single method to handle all cancellation scenarios (payment cancelled, billing request cancelled, subscription cancelled)

  2. Status synchronization hooks - Ensure parent orders reflect subscription status changes and vice versa

  3. Metadata cleanup - Clear pending payment flags when cancellation occurs

Changes

  • class-wc-gocardless-gateway.php: Add handle_subscription_cancellation() method
  • class-wc-gocardless-gateway-addons.php: Add sync_parent_order_status() hook
  • Update webhook handlers to use centralized cancellation logic

Testing

  1. Create subscription order
  2. Cancel subscription from frontend/backend
  3. Verify all areas show "cancelled" status consistently

Unit Test Instructions

# Install dependencies
composer install

# Run cancellation tests
vendor/bin/phpunit --testdox --filter="Test_Cancellation_Simplified|Test_Parent_Order_Sync"

Expected: 13/13 tests pass validating subscription cancellation logic

…tatus synchronization

- Introduced a new method `handle_subscription_cancellation` to manage subscription cancellations consistently across orders.
- Added `sync_parent_order_status` method to update the parent order status when all associated subscriptions are cancelled.
- Updated existing cancellation logic to utilize the new centralized handling for improved maintainability.
@lmcrean
Copy link
Author

lmcrean commented Sep 3, 2025

Confirmed in unit testing, does anyone have access to trying on local machine with the paid subscription plugin? @diegocurbelo @peterwilsoncc @joemcgill @dkotter

@jeffpaul jeffpaul added this to the 3.0.0 milestone Sep 30, 2025
@jeffpaul jeffpaul requested a review from dkotter September 30, 2025 15:11
@jeffpaul jeffpaul linked an issue Sep 30, 2025 that may be closed by this pull request
@jeffpaul jeffpaul modified the milestones: 3.0.0, 3.0.1 Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent subscription status display after cancellation
2 participants