Repository navigation
fix: stop sending two emails for one failed renewal - #64
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 onisActive, so a checkbuilt on that call alone would leave the customer with nothing at all when the
merchant had merely parked their own notification.
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 assertionson the composer-pinned PHPUnit 9.6; the same onthe CI toolchain (PHPUnit 12.5), whose 21 notices are pre-existing and
unchanged from
main.phpcsexit 0; PHPCompatibilityWP clean on 7.4, 8.0, 8.2, 8.4 and 8.5.removing the stand-down guard; dropping the
isActivegate; dropping theconditional-logic gate; matching any event instead of the announced one;
announcing both events on the terminal failure; deleting the expiry dispatch.
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
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.
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.txtgains an FAQ entry anddocs/email-customization.mdis updated todescribe the fixed behaviour.
changelog.txtis left to the Prepare Releaseaction, per this repo's convention.
tests/bootstrap.phpgains aGFCommon::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.