feat(notifications): add order failed email notification#3188
Open
faisalahammad wants to merge 1 commit into
Open
feat(notifications): add order failed email notification#3188faisalahammad wants to merge 1 commit into
faisalahammad wants to merge 1 commit into
Conversation
Adds a new `order_failed` notification trigger that sends an email to the customer when an order is marked as failed. Covers both the initial checkout failure and the terminal recurring payment failure that occurs after all retry rules are exhausted. Subscribes to two existing action hooks: - `lifterlms_order_status_failed` (fires on every `llms-failed` transition) - `llms_automatic_payment_maximum_retries_reached` (fires from LLMS_Order::maybe_schedule_retry() when retries are exhausted) A per-request static cache in the controller prevents a double-send when both hooks fire for the same order in a single request. Fixes gocodebox#3049
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.
Summary
Adds a new
order_failedemail notification that fires when an order is marked asllms-failed. Covers both the initial checkout failure and the terminal recurring payment failure (after all retry rules are exhausted). Customer is on by default, product author and custom recipients are opt-in.Fixes #3049
Changes
New:
includes/notifications/controllers/class.llms.notification.controller.order.failed.phpNew controller
LLMS_Notification_Controller_Order_Failedthat subscribes to two existing action hooks:lifterlms_order_status_failed— fires on every transition intollms-failed. Covers initial checkout failure.llms_automatic_payment_maximum_retries_reached— fires fromLLMS_Order::maybe_schedule_retry()when retry rules are exhausted. Covers terminal recurring failure.A per-request static cache (
self::$sent) keyed by order ID prevents a double-send when both hooks fire for the same order in one request (e.g. when the terminal retry failure cascades into thellms-failedstatus transition).Why: keeps the existing source files in
LLMS_Controller_OrdersandLLMS_Orderuntouched, reuses every existing abstract, and gives the trigger full admin UI (subject, body, merge codes, per-recipient opt-in) for free.New:
includes/notifications/views/class.llms.notification.view.order.failed.phpNew view
LLMS_Notification_View_Order_Failedwith email body, subject, title, and a{{RETRY_NOTICE}}merge code that switches between "We have exhausted all automatic retry attempts..." for recurring orders and "No further payments will be attempted..." for one-time orders. Deleted-product guard on{{PRODUCT_TITLE_LINK}}falls back to the plain title.Modified:
includes/notifications/class.llms.notifications.phpAdded
'order_failed'to the$triggersarray inload(). Autoloader already maps the directories.New:
tests/phpunit/unit-tests/notifications/class-llms-test-notification-order-failed.phpTest class extending
LLMS_NotificationTestCase. Coverstest_is_registered,test_set_merge_data(six merge codes plus{{FAKE_CODE}}pass-through), andtest_get_title.New:
.changelogs/order-failed-notification.ymlStandard changelog entry,
significance: minor,type: added.Testing
PHPUnit (run locally):
Result: 3 new tests pass, 14 assertions. The full notifications group (29 tests) is green except for one pre-existing incomplete test (
LLMS_Test_Notification_Achievement_Earned::test_set_merge_data— unrelated to this change).PHPCS:
Result: clean.
Manual end-to-end test (in
TESTING_INSTRUCTIONS.md):llms-failedfrom the admin order edit screen.Build
lifterlms-fix-3049.zipavailable for manual install:WP Admin → Plugins → Upload Plugin → Install Now → Activate.
Coexistence with
payment_retryWhen a recurring payment finally fails after retries are exhausted, the site can send two related emails if both are enabled:
payment_retryemail from the retry sequence.order_failedemail at terminal failure.The terminal email is the one that matters and cannot be derived from the retry email (different merge codes, different message), so they are kept separate. To avoid duplicates, disable the email channel on
payment_retryunder LifterLMS → Settings → Notifications.