Skip to content

feat(membership): guard auto_renew against missing gateway renewal credential#1230

Merged
superdav42 merged 1 commit into
mainfrom
feature/membership-renewal-credential-guard
May 20, 2026
Merged

feat(membership): guard auto_renew against missing gateway renewal credential#1230
superdav42 merged 1 commit into
mainfrom
feature/membership-renewal-credential-guard

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

Summary

Adds a defensive guard so a recurring auto-renewing membership cannot be marked
auto_renew=1 when the underlying gateway has no renewable credential on file.

Why

End-to-end reproduction on 2026-05-19 with PayPal Payments for WooCommerce
(PPCP) 4.0.4 + WooCommerce Subscriptions 7.7.0 + Ultimate Multisite WooCommerce
2.0.12 produced a checkout that looked completely successful:

  • WC order completed
  • WC subscription active
  • UM membership active, auto_renew=1, gateway=woocommerce

…but on the PayPal side the order was captured with intent=CAPTURE (one-shot
sale). The WC subscription has no _ppcp_* / _paypal_subscription_id /
_ppcp_billing_agreement_id / vault meta. A month later, the WC subscription
renewal has nothing to charge -> fails -> UM membership cascade-cancels with no
recoverable trace for the customer or admin.

This PR introduces a hookable contract so gateways and addons can declare
"this membership has no renewable artifact on my side", and the model degrades
gracefully before the silent cancellation cascade has a chance to fire.

How

A new wu_membership_has_renewal_credential filter (default null = unknown)
runs at the end of Membership::save() whenever the membership is recurring,
auto-renewing, and on a paid gateway (i.e. not ''/free/manual).

If a listener returns explicit false, the model:

  • forces auto_renew off,
  • writes a wu_renewal_credential_missing meta timestamp,
  • logs WARNING to membership-{id},
  • fires wu_membership_renewal_credential_missing exactly once (idempotent on re-save).

Default behaviour is unchanged: gateways that do not register an opinion let
auto_renew stand. Free / manual / empty gateway memberships are skipped.

The companion verifier for PPCP one-shot recurring purchases lives in
ultimate-multisite-woocommerce (separate PR).

Verification

  • vendor/bin/phpunit --filter '/Membership_Test::test_(save_(preserves|downgrades|keeps|skips)|filter_receives)/' -- 9 tests, 22 assertions, OK.
  • vendor/bin/phpcs inc/models/class-membership.php tests/WP_Ultimo/Models/Membership_Test.php -- no new violations introduced (pre-existing Yoda + doc-comment violations remain unchanged on both files; present on main).
  • vendor/bin/phpstan analyse inc/models/class-membership.php tests/WP_Ultimo/Models/Membership_Test.php -- no errors.

Test coverage

Case Expected
No filter listener auto_renew preserved, no flag
Filter returns true auto_renew preserved, no flag
Filter returns false auto_renew=false, flag set, action fires once
Re-save with flag already set auto_renew stays off, action does NOT re-fire
Non-recurring membership Guard skipped
Empty / free / manual gateway Guard skipped
Filter signature Listener receives (?bool $verified, Membership $m)

Files

  • inc/models/class-membership.php -- maybe_downgrade_auto_renew_without_credential() + use Psr\Log\LogLevel; + save() integration.
  • tests/WP_Ultimo/Models/Membership_Test.php -- 8 new test methods (1 with a 3-row data provider).

Out of scope

  • The PPCP-specific verifier (lives in the WooCommerce addon).
  • Fixing PPCP itself to request intent=SUBSCRIPTION for recurring carts (PPCP-side bug, follow-up issue).

aidevops.sh v3.15.68 plugin for OpenCode v1.15.5 with claude-sonnet-4-6 spent 57m and 106 tokens on this as a headless worker.

…edential

When a recurring auto-renewing membership saves on a paid gateway, run a
new `wu_membership_has_renewal_credential` filter. If a listener returns
`false` — i.e. it knows the gateway side has no renewable artifact (no
PayPal billing-agreement, no Stripe customer/subscription, no saved
vault) — the membership:

- has `auto_renew` forced to false on save,
- stores a `wu_renewal_credential_missing` meta timestamp,
- emits a WARNING to `membership-{id}` log,
- fires `wu_membership_renewal_credential_missing` once.

The default filter value is `null` (unknown), so existing gateways that
do not opt in are unaffected. Free / manual / empty gateway memberships
are also skipped. Once the flag is set, subsequent saves keep auto_renew
off without re-logging or re-firing the action, even if the filter is
later removed.

This protects customers whose checkout completed successfully but whose
gateway integration mis-classified a recurring purchase as a one-shot
sale (e.g. PPCP `intent=CAPTURE` on a WooCommerce subscription product),
where the renewal a month later would otherwise cascade-cancel the
membership with no recoverable trace.

Refs end-to-end repro on 2026-05-19 with PPCP 4.0.4 + WooCommerce
Subscriptions 7.7.0 + Ultimate Multisite WooCommerce 2.0.12 producing
WC order completed, WC subscription active, UM membership active, but
WC subscription `_ppcp_paypal_intent=CAPTURE` and no PayPal-side
subscription/billing-agreement to charge at renewal.

Tests cover: no listener, listener returns true/false, idempotent
re-save when flag already set, non-recurring skip, exempt gateways
(empty/free/manual), filter receives membership instance.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

Warning

Rate limit exceeded

@superdav42 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 56 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d0160f48-2d46-4569-a17b-8270b0c0bfd2

📥 Commits

Reviewing files that changed from the base of the PR and between 0e5bd6f and 97d7777.

📒 Files selected for processing (2)
  • inc/models/class-membership.php
  • tests/WP_Ultimo/Models/Membership_Test.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/membership-renewal-credential-guard

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@superdav42 superdav42 merged commit 9b0762f into main May 20, 2026
11 checks passed
@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@superdav42
Copy link
Copy Markdown
Collaborator Author

Summary

Adds a defensive guard so a recurring auto-renewing membership cannot be marked
auto_renew=1 when the underlying gateway has no renewable credential on file.

Why

End-to-end reproduction on 2026-05-19 with PayPal Payments for WooCommerce
(PPCP) 4.0.4 + WooCommerce Subscriptions 7.7.0 + Ultimate Multisite WooCommerce
2.0.12 produced a checkout that looked completely successful:

  • WC order completed
  • WC subscription active
  • UM membership active, auto_renew=1, gateway=woocommerce
    …but on the PayPal side the order was captured with intent=CAPTURE (one-shot
    sale). The WC subscription has no _ppcp_* / _paypal_subscription_id /
    _ppcp_billing_agreement_id / vault meta. A month later, the WC subscription
    renewal has nothing to charge -> fails -> UM membership cascade-cancels with no
    recoverable trace for the customer or admin.
    This PR introduces a hookable contract so gateways and addons can declare
    "this membership has no renewable artifact on my side", and the model degrades
    gracefully before the silent cancellation cascade has a chance to fire.

How

A new wu_membership_has_renewal_credential filter (default null = unknown)
runs at the end of Membership::save() whenever the membership is recurring,
auto-renewing, and on a paid gateway (i.e. not ''/free/manual).
If a listener returns explicit false, the model:

  • forces auto_renew off,
  • writes a wu_renewal_credential_missing meta timestamp,
  • logs WARNING to membership-{id},
  • fires wu_membership_renewal_credential_missing exactly once (idempotent on re-save).
    Default behaviour is unchanged: gateways that do not register an opinion let
    auto_renew stand. Free / manual / empty gateway memberships are skipped.
    The companion verifier for PPCP one-shot recurring purchases lives in
    ultimate-multisite-woocommerce (separate PR).

Verification

  • vendor/bin/phpunit --filter '/Membership_Test::test_(save_(preserves|downgrades|keeps|skips)|filter_receives)/' -- 9 tests, 22 assertions, OK.
  • vendor/bin/phpcs inc/models/class-membership.php tests/WP_Ultimo/Models/Membership_Test.php -- no new violations introduced (pre-existing Yoda + doc-comment violations remain unchanged on both files; present on main).
  • vendor/bin/phpstan analyse inc/models/class-membership.php tests/WP_Ultimo/Models/Membership_Test.php -- no errors.

Test coverage

Case Expected
No filter listener auto_renew preserved, no flag
Filter returns true auto_renew preserved, no flag
Filter returns false auto_renew=false, flag set, action fires once
Re-save with flag already set auto_renew stays off, action does NOT re-fire
Non-recurring membership Guard skipped
Empty / free / manual gateway Guard skipped
Filter signature Listener receives (?bool $verified, Membership $m)

Files

  • inc/models/class-membership.php -- maybe_downgrade_auto_renew_without_credential() + use Psr\Log\LogLevel; + save() integration.
  • tests/WP_Ultimo/Models/Membership_Test.php -- 8 new test methods (1 with a 3-row data provider).

Out of scope

  • The PPCP-specific verifier (lives in the WooCommerce addon).
  • Fixing PPCP itself to request intent=SUBSCRIPTION for recurring carts (PPCP-side bug, follow-up issue).

aidevops.sh v3.15.68 plugin for OpenCode v1.15.5 with claude-sonnet-4-6 spent 57m and 106 tokens on this as a headless worker.


Merged via PR #1230 to main.
Merged by deterministic merge pass (pulse-wrapper.sh).

1 similar comment
@superdav42
Copy link
Copy Markdown
Collaborator Author

Summary

Adds a defensive guard so a recurring auto-renewing membership cannot be marked
auto_renew=1 when the underlying gateway has no renewable credential on file.

Why

End-to-end reproduction on 2026-05-19 with PayPal Payments for WooCommerce
(PPCP) 4.0.4 + WooCommerce Subscriptions 7.7.0 + Ultimate Multisite WooCommerce
2.0.12 produced a checkout that looked completely successful:

  • WC order completed
  • WC subscription active
  • UM membership active, auto_renew=1, gateway=woocommerce
    …but on the PayPal side the order was captured with intent=CAPTURE (one-shot
    sale). The WC subscription has no _ppcp_* / _paypal_subscription_id /
    _ppcp_billing_agreement_id / vault meta. A month later, the WC subscription
    renewal has nothing to charge -> fails -> UM membership cascade-cancels with no
    recoverable trace for the customer or admin.
    This PR introduces a hookable contract so gateways and addons can declare
    "this membership has no renewable artifact on my side", and the model degrades
    gracefully before the silent cancellation cascade has a chance to fire.

How

A new wu_membership_has_renewal_credential filter (default null = unknown)
runs at the end of Membership::save() whenever the membership is recurring,
auto-renewing, and on a paid gateway (i.e. not ''/free/manual).
If a listener returns explicit false, the model:

  • forces auto_renew off,
  • writes a wu_renewal_credential_missing meta timestamp,
  • logs WARNING to membership-{id},
  • fires wu_membership_renewal_credential_missing exactly once (idempotent on re-save).
    Default behaviour is unchanged: gateways that do not register an opinion let
    auto_renew stand. Free / manual / empty gateway memberships are skipped.
    The companion verifier for PPCP one-shot recurring purchases lives in
    ultimate-multisite-woocommerce (separate PR).

Verification

  • vendor/bin/phpunit --filter '/Membership_Test::test_(save_(preserves|downgrades|keeps|skips)|filter_receives)/' -- 9 tests, 22 assertions, OK.
  • vendor/bin/phpcs inc/models/class-membership.php tests/WP_Ultimo/Models/Membership_Test.php -- no new violations introduced (pre-existing Yoda + doc-comment violations remain unchanged on both files; present on main).
  • vendor/bin/phpstan analyse inc/models/class-membership.php tests/WP_Ultimo/Models/Membership_Test.php -- no errors.

Test coverage

Case Expected
No filter listener auto_renew preserved, no flag
Filter returns true auto_renew preserved, no flag
Filter returns false auto_renew=false, flag set, action fires once
Re-save with flag already set auto_renew stays off, action does NOT re-fire
Non-recurring membership Guard skipped
Empty / free / manual gateway Guard skipped
Filter signature Listener receives (?bool $verified, Membership $m)

Files

  • inc/models/class-membership.php -- maybe_downgrade_auto_renew_without_credential() + use Psr\Log\LogLevel; + save() integration.
  • tests/WP_Ultimo/Models/Membership_Test.php -- 8 new test methods (1 with a 3-row data provider).

Out of scope

  • The PPCP-specific verifier (lives in the WooCommerce addon).
  • Fixing PPCP itself to request intent=SUBSCRIPTION for recurring carts (PPCP-side bug, follow-up issue).

aidevops.sh v3.15.68 plugin for OpenCode v1.15.5 with claude-sonnet-4-6 spent 57m and 106 tokens on this as a headless worker.


Merged via PR #1230 to main.
Merged by deterministic merge pass (pulse-wrapper.sh).

@github-actions
Copy link
Copy Markdown

Performance Test Results

Performance test results for d641e34 are in 🛎️!

Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown.

URL: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 41 37.83 MB 875.00 ms (+36.00 ms / +4% ) 184.00 ms (+23.50 ms / +13% ) 1070.50 ms (+27.50 ms / +3% ) 2050.00 ms (+50.00 ms / +2% ) 1970.50 ms (+52.65 ms / +3% ) 82.50 ms
1 56 49.14 MB 949.00 ms 148.00 ms 1100.00 ms 2078.00 ms 2003.10 ms 74.90 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-feedback-scanned Merged PR already scanned for quality feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant