Skip to content

fix: stop sending two emails for one failed renewal - #64

Merged
wzul merged 1 commit into
mainfrom
fix/notification-double-send
Sep 25, 2026
Merged

wzul merged 1 commit into
mainfrom
fix/notification-double-send

Conversation

@wzul

@wzul wzul commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

fix: stop sending two emails for one failed renewal

A customer received two emails when a renewal failed and the merchant had
configured a notification on Subscription Payment Failed: the merchant's
notification, plus the plugin's built-in dunning email. A failure that exhausted
the retry ladder produced two more, because the same moment was announced twice
— as Subscription Payment Failed and again as Subscription Expired.

Both were reproduced on a live install before being fixed. One failure, with a
notification configured, produced exactly two messages.

The fix

The built-in email is a fallback, so it now stands down when Gravity Forms
will send a notification for the failure event itself. The stand-down is decided
the way core decides it, not by counting configured notifications:

  • isActive. A notification the merchant switched off is not a replacement.
    GFCommon::get_notifications() does not filter on isActive, so a check
    built on that call alone would leave the customer with nothing at all when the
    merchant had merely parked their own notification.
  • Conditional logic. A notification that cannot fire for this entry is not a
    replacement either, so the fallback still covers those entries. Core's own
    GFCommon::evaluate_conditional_logic() is called rather than reimplemented.

An operator pressing Send update-card link is unaffected: that is a
deliberate act by support, not the automated fallback.

On the terminal failure only the expiry is announced, and the built-in email is
not sent on that path at all — the card-update link stops working the moment the
subscription is expired, so mailing one would hand the customer a link that is
already dead. Customers are dunned on every attempt before that, while action is
still possible.

Verification

  • 505 tests, 1021 assertions on the composer-pinned PHPUnit 9.6; the same on
    the CI toolchain (PHPUnit 12.5), whose 21 notices are pre-existing and
    unchanged from main.
  • phpcs exit 0; PHPCompatibilityWP clean on 7.4, 8.0, 8.2, 8.4 and 8.5.
  • Seven sabotage runs, each confirmed to bite before being reverted:
    removing the stand-down guard; dropping the isActive gate; dropping the
    conditional-logic gate; matching any event instead of the announced one;
    announcing both events on the terminal failure; deleting the expiry dispatch.
  • The first sabotage run exposed a real gap in my own tests: all six
    predicate tests still passed with the guard removed, because none of them
    proved anybody called it. That wiring is now covered, and re-running the same
    sabotage fails.

Potential Risks & Review Items

  • Behaviour change. A merchant who configures a Subscription Payment Failed
    notification now receives one email where they previously received two. That is
    the intent, but it is the kind of change worth a second pair of eyes.
  • The terminal path now sends less than before. An exhausted ladder no longer
    emails the customer a card-update link, because the subscription is expired in
    the same pass and the link would be dead on arrival. The customer was already
    dunned on each earlier attempt. If the expectation is that the final email
    should still carry a link, this needs revisiting — but that would require
    leaving the subscription updatable, which is a larger change.
  • readme.txt gains an FAQ entry and docs/email-customization.md is updated to
    describe the fixed behaviour. changelog.txt is left to the Prepare Release
    action, per this repo's convention.
  • tests/bootstrap.php gains a GFCommon::evaluate_conditional_logic() stub.
    It reproduces core's "no rules means true" behaviour because that case is the
    one that decides the guard; a stub defaulting to false would have hidden the
    bug this PR fixes.

A customer received two emails when a renewal failed and the merchant had
configured a notification on Subscription Payment Failed: the merchant's
notification, and the plugin's built-in dunning email. A failure that exhausted
the retry ladder produced two more, because the same moment was announced twice
-- as Subscription Payment Failed and again as Subscription Expired.

Both were reproduced on a live install before being fixed. One failure with a
configured notification produced exactly two messages.

The built-in email is a fallback, so it now stands down when Gravity Forms will
send a notification for the failure event itself. The stand-down is decided the
way core decides it, not by counting configured notifications:

  - isActive. A notification the merchant switched off is not a replacement.
    GFCommon::get_notifications() does not filter on isActive, so a check built
    on that call alone would leave the customer with nothing at all when the
    merchant had merely parked their own notification.
  - conditional logic. A notification that cannot fire for this entry is not a
    replacement either, so the fallback still covers those entries.

An operator pressing "Send update-card link" is unaffected: that is a
deliberate act by support, not the automated fallback, and it still sends.

On the terminal failure only the expiry is announced, and the built-in email is
not sent on that path at all. The card-update link stops working the moment the
subscription is expired, so an email carrying one would hand the customer a
link that is already dead. Customers are dunned on every attempt before that,
while action is still possible.

Seven sabotage runs, each confirmed to bite before being reverted: removing the
stand-down guard; dropping the isActive gate; dropping the conditional-logic
gate; matching any event instead of the announced one; announcing both events;
deleting the expiry dispatch. The first sabotage run exposed a real gap in the
tests -- all six predicate tests passed with the guard removed, because none of
them proved anybody called it. That wiring is now covered.
@wzul
wzul merged commit e290f17 into main Sep 25, 2026
7 checks passed
@wzul
wzul deleted the fix/notification-double-send branch September 25, 2026 09:44
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.

1 participant