Skip to main content
Lunar sends customer-facing order updates through a single registry of Laravel notifications, sendable automatically on a state change or on demand from the admin.

Overview

Customer notifications are entries in the OrderNotificationManifest, 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.
Every default is active on a fresh install. The shipped, ready-for-pickup, provisioned, return, cancellation, and refund emails sit behind the 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 the Lunar\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.
The fulfilment-scoped defaults are not manually sendable because the “Notify customer” composers are order-scoped. The manifest still answers 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 before placed_at is stamped, so the paid rollup 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 sends payment-received as 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, not refunded. refunded and partially-refunded are payment-status rollups, which fire without a notify flag whenever the ledger changes. The refund operation dispatches its own gated event, resolved through refund-issued. Registering a notification on: ['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-level fulfilled or returned rollups, 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-level cancelled state send nothing. A pickup is a counter handover, the others are back-office moves, and an order-level cancellation is covered by order-cancelled.
  • The notify flag gates the operation-driven sends. ship(notify: false), cancel(notify: false), a RefundRequest with notify: false, and the matching toggles in the admin all suppress the email. Placement (placed) and payment-status triggers (paid, and anything registered on refunded or partially-refunded) carry no flag, so a capture that makes a placed order paid always sends payment-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, in OrderNotifications::withoutSending():
Only the automatic customer emails are skipped. Order events still fire, so placement still creates the initial fulfilment and commits stock. The mute is read when each event fires, so a send that would otherwise wait for an enclosing transaction to commit is skipped too. 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 own x-mail::message component, so the header, footer, colors, and logo come from the application’s markdown mail layout. Publish it to change them:
This copies Laravel’s components to 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:
This copies them to 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:
Every string the templates render comes from 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’s boot() method:
The replacement keeps the key’s triggers only if it passes them again, so repeat the on list (and scope, for a fulfilment-scoped entry). Or remove the entry altogether:
A consumer class that should render the admin’s free-text message implements 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 on scope (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 a payment_status or fulfilment_status state $name, or one of the event keys placed, cancelled, and refund-issued. For a fulfilment-scoped entry it is a per-fulfilment FulfilmentState name. 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: a Lunar\Core\Enums\NotificationScope case, Order or Fulfilment, deciding what the notification is constructed with.
This replaces the 1.x config('lunar.orders.notifications') array; there is no notifications key in config/lunar/orders.php. Class references belong in the container, not config, so register from a service provider’s boot() method.

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

This delegates to Lunar\Core\Contracts\Actions\Orders\NotifiesCustomer:
  • $notification is a key registered on the manifest as manual (manual: true) and order-scoped. An unknown key, a manual: false entry, or a fulfilment-scoped entry such as order-shipped throws Lunar\Core\Exceptions\OrderActionException.
  • $recipients, when empty, resolves to the order’s billingAddress/shippingAddress contact 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-notification activity log entry is recorded per recipient.
  • Lunar\Core\Events\Orders\OrderCustomerNotified is dispatched once, with the order, the notification key, and the resolved recipients.
A notification that should render the free-text $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:
The routing decision, in order:
  1. If the notification implements Lunar\Core\Contracts\ResolvesOrderMailRoute, its mailRouteForOrder(Order $order): string|array|null wins outright. Use this when the recipient is not an order contact at all (an account email, an ops inbox).
  2. Otherwise, if it implements Lunar\Core\Contracts\RoutesToOrderContact, its orderContactType(): 'billing'|'shipping' picks which contact to use. A per-fulfilment “your parcel has shipped” notification would route to shipping this way.
  3. Otherwise the default is the billing contact.
  4. Whichever contact is chosen, if it has no contact_email, the other contact is used instead.
None of the default notifications implement either contract, so they all route to the billing contact with the shipping contact as the fallback. A subclass can add one:
The defaults send synchronously, like any notification without 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 from OrderNotifications::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.