Overview
Customer notifications are entries in theOrderNotificationManifest, a container-bound registry that ships a set of branded defaults and that a consuming application extends, trims, or replaces. Each entry is a single Laravel Notification class that can fire two ways:
- Automatically, when the order or one of its fulfilments enters one of the entry’s trigger states.
- Manually, composed and sent on demand, either from the admin’s “Notify customer” action or by calling
$order->notifyCustomer()directly.
notify flag of the operation that fires it, so a quiet ship, cancel, or refund sends nothing. The order confirmation and payment received emails are not gated: they follow placement and the ledger, so only muting or a forget() stops them. Any default can be switched off with a one-line forget() from a service provider.
Default notifications
Lunar registers the following notifications out of the box. All classes live in theLunar\Core\Notifications namespace.
What each one contains:
- Order confirmation: reference, placed date, a line summary with totals, the billing and shipping addresses, and the current payment state. Renders the optional admin message when resent by hand.
- Payment received: sent when a capture takes an already placed order to
paid, such as an authorize-then-capture flow or an offline payment marked paid in the admin. Shows the order total. - Order shipped: the lines in the fulfilment and one row per tracking reference (carrier, tracking number, link).
- Ready for pickup: the lines to pick up and the name of the fulfilment’s location.
- Order provisioned: the lines provisioned. Core records no download link, so none is rendered; a store that has one re-registers the key with its own class.
- Return received: the lines received back. A refund that follows sends its own email.
- Order cancelled: the cancellation, with the cancel reason’s label when one was recorded.
- Refund issued: the refund, with the amount read from the latest successful refund transaction on the order.
- Partial fulfilment update: a manual-only “part of your order is still to come” email listing the lines still outstanding (ordered quantity minus the quantity on fulfilments that have gone to the customer and any refunded units that will not ship), so a delay notice is a pick-and-send rather than free text.
- Order update: a general-purpose update rendering the admin’s free-text message.
sendable(NotificationScope::Fulfilment), so an application can build its own resend path for them. With the defaults it returns nothing, since all four are registered manual: false; re-register a key with manual: true to include it.
Trigger rules
- Only placed orders receive emails. Every automatic listener returns early while
$order->isPlaced()is false, so a draft order is never emailed, whether it is shipped, cancelled or refunded. A card checkout records its capture beforeplaced_atis stamped, so thepaidrollup fires on an unplaced order and is skipped, and the order confirmation that follows carries the payment state. The customer gets one email, not two. A later capture on a placed order sendspayment-receivedas intended. - Emails send once the change commits. A listener that fires inside a database transaction defers the send until that transaction commits, so a rolled-back checkout or shipment sends nothing. The email is built from freshly loaded models, so it carries the committed state: the tracking saved with a shipment, the payment status recorded by the capture.
- The refund event key is
refund-issued, notrefunded.refundedandpartially-refundedare payment-status rollups, which fire without anotifyflag whenever the ledger changes. The refund operation dispatches its own gated event, resolved throughrefund-issued. Registering a notificationon: ['refunded']sends it on every rollup to that state, which is rarely what a store wants. - Per-fulfilment states only. The defaults register against fulfilment states (
shipped,returned, and so on), never the order-levelfulfilledorreturnedrollups, so a customer is emailed once per parcel rather than once per parcel and again when the order rolls up. picked-up,in-progress,pending, and the fulfilment-levelcancelledstate send nothing. A pickup is a counter handover, the others are back-office moves, and an order-level cancellation is covered byorder-cancelled.- The
notifyflag gates the operation-driven sends.ship(notify: false),cancel(notify: false), aRefundRequestwithnotify: false, and the matching toggles in the admin all suppress the email. Placement (placed) and payment-status triggers (paid, and anything registered onrefundedorpartially-refunded) carry no flag, so a capture that makes a placed order paid always sendspayment-received.
A payment driver that places the order inside
authorize() must record its capture transactions before stamping placed_at, or the placed-order rule above cannot suppress the duplicate “paid” email at checkout. The first-party Stripe and PayPal drivers do this; see Extending payments.Muting notifications
Wrap code that should not email customers, such as an order import or a back-office repair script, inOrderNotifications::withoutSending():
withoutSending() returns the callback’s return value, and OrderNotifications::isMuted() reports whether a mute is active.
An order created with
placed_at already set dispatches OrderPlaced from the created event, before its lines and addresses exist. An import that builds orders that way should mute notifications, or create the order unplaced and set placed_at once its lines and addresses are saved.Customizing the default emails
There are four layers, from the lightest touch to a full replacement. All of them live in the consuming application.The layout
Every default template extends Laravel’s ownx-mail::message component, so the header, footer, colors, and logo come from the application’s markdown mail layout. Publish it to change them:
resources/views/vendor/mail. The header text is config('app.name'), the color theme is html/themes/default.css, and the footer is part of html/message.blade.php. A store that has already themed its Laravel mail gets branded Lunar emails with no further work, and the application’s own emails share the same look.
The templates
To change what an email shows, publish Lunar’s templates:resources/views/vendor/lunar/mail, where Laravel looks before falling back to the package copy. Edit a file there and the shipped one is ignored.
OrderUpdate has no template: it builds a plain mail message from its greeting, intro, and outro strings, so publishing the views does not change it. Re-register order-update to restyle it.
For the fulfilment-scoped templates and the partial fulfilment update, lines is an array of rows shaped ['description' => string, 'option' => ?string, 'quantity' => int].
The templates share a set of partials under mail/partials, so a change to one applies everywhere it is used:
Templates are markdown mail views. Keep content flush to the left margin (indented lines become code blocks) and use
<x-mail::table> for tables. Pass any value that goes into a table cell through Lunar\Core\Notifications\MailTable::cell(), which escapes the | and line breaks that would otherwise split the row.
The copy
To reword an email without touching its structure, publish the language files:lang/vendor/lunar/<locale>/notifications.php. Each notification has a label (the admin dropdown entry), a subject, and its body copy (heading, intro, outro, plus tracking or outstanding where a template has an extra paragraph), with the greeting, sign-off, table headings, and field labels (address headings, payment status, cancel reason, refund amount, pickup location) shared under the partials key. Lunar ships these strings in all sixteen of its supported locales.
Replacing or removing a notification
When a store needs a different structure entirely, or data the default does not carry, re-register the key with its own class from a service provider’sboot() method:
on list (and scope, for a fulfilment-scoped entry). Or remove the entry altogether:
Lunar\Core\Contracts\Notifications\AcceptsCustomerMessage; see Sending a notification manually.
The notification manifest
withoutSending() and isMuted() are described under Muting notifications.
Access it through the OrderNotifications facade:
key: a unique identifier, used in$order->notifyCustomer()calls (manual, order-scoped entries only) and admin dropdowns.notification: the notification class. It is constructed differently depending onscope(see below).label: the dropdown label shown in the admin; defaults to the key, translated through__().on: the list of keys that fire it automatically. For an order-scoped entry that is apayment_statusorfulfilment_statusstate$name, or one of the event keysplaced,cancelled, andrefund-issued. For a fulfilment-scoped entry it is a per-fulfilmentFulfilmentStatename. Leave empty for a manual-only notification.manual: whether it appears in the admin’s send list (and so can be resent by hand even when it also fires automatically).scope: aLunar\Core\Enums\NotificationScopecase,OrderorFulfilment, deciding what the notification is constructed with.
Scope
NotificationScope::Order notifications are constructed as new $class($order) by the automatic listeners and new $class($order, $message) by a manual send, and are sent through the order. NotificationScope::Fulfilment notifications are constructed with the fulfilment (new $class($fulfilment)) so they can read tracking and line details. The fulfilment-scoped defaults also take an optional second ?string $message and render it, for an application’s own resend path. Either scope is delivered through the order’s notification routing, a fulfilment-scoped one as $fulfilment->order->notify(...). Automatic fulfilment-scoped sends use the same manifest; see Fulfilments.
Sending a notification manually
Lunar\Core\Contracts\Actions\Orders\NotifiesCustomer:
$notificationis a key registered on the manifest as manual (manual: true) and order-scoped. An unknown key, amanual: falseentry, or a fulfilment-scoped entry such asorder-shippedthrowsLunar\Core\Exceptions\OrderActionException.$recipients, when empty, resolves to the order’sbillingAddress/shippingAddresscontact emails (deduplicated, blanks removed). If that resolves to nothing, the action throws.- Each recipient is sent the notification directly (bypassing the order’s own mail routing, since the recipient is already explicit), and an
email-notificationactivity log entry is recorded per recipient. Lunar\Core\Events\Orders\OrderCustomerNotifiedis dispatched once, with the order, the notification key, and the resolved recipients.
$message implements Lunar\Core\Contracts\Notifications\AcceptsCustomerMessage (a marker interface documenting the __construct(Order $order, ?string $message = null) shape notifyCustomer() relies on). Every order-scoped default implements it; the fulfilment-scoped defaults do not, since they are constructed with a fulfilment.
Mail routing defaults
For automatic sends (dispatched through$order->notify(...) or $fulfilment->order->notify(...), not the explicit-recipient path above), Order implements Laravel’s routeNotificationForMail() so notifications work without extra setup:
- If the notification implements
Lunar\Core\Contracts\ResolvesOrderMailRoute, itsmailRouteForOrder(Order $order): string|array|nullwins outright. Use this when the recipient is not an order contact at all (an account email, an ops inbox). - Otherwise, if it implements
Lunar\Core\Contracts\RoutesToOrderContact, itsorderContactType(): 'billing'|'shipping'picks which contact to use. A per-fulfilment “your parcel has shipped” notification would route toshippingthis way. - Otherwise the default is the billing contact.
- Whichever contact is chosen, if it has no
contact_email, the other contact is used instead.
ShouldQueue, once the change that fired them has committed. A mailer that fails therefore throws in the request that placed, shipped, or refunded the order, after that change is already saved. Configure a working mailer before going live. To queue one, subclass it, add Illuminate\Contracts\Queue\ShouldQueue, and re-register the key.
Admin
The order screen’s “Notify customer” action populates its notification dropdown fromOrderNotifications::sendable(), lets staff pick recipients from the order’s contacts (or add an extra address), and calls $order->notifyCustomer(), so a notification sent from the admin leaves the same activity-log trail as one sent through the API. With the defaults registered the dropdown offers the order confirmation, payment received, order cancelled, refund issued, partial fulfilment update, and order update entries.
The fulfilment controls (ship, ready-for-pickup, provision, return) show a “notify customer” toggle only when a notification is registered for the state they produce, which with the defaults is always. The cancel and refund dialogs always show the toggle in the panel. In Filament they show it when a notification is registered on cancelled or refund-issued.
Capturing a payment has no toggle in either admin; see the trigger rules above.