Skip to content

Remind customers of payments falling due and overdue - #1068

Merged
KrzysztofPajak merged 7 commits into
developfrom
feature/payment-due-reminders
Nov 19, 2026
Merged

KrzysztofPajak merged 7 commits into
developfrom
feature/payment-due-reminders

Conversation

@KrzysztofPajak

@KrzysztofPajak KrzysztofPajak commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Type: feature

Issue

Orders bought on credit (trade credit, Payments.OnAccount) have a payment due date, an overdue rule (PaymentExtensions.IsPaymentOverdue), an "Overdue payments only" order filter and BlockWhenOverdue, but nobody tells the customer. The reminder e-mails were left out of #1001.

Solution

  • IPaymentReminderService.SendPaymentReminders(utcNow) (Grand.Business.Checkout), run daily by the new scheduled task Payment due reminders. For each store it finds the unpaid orders bought on credit (PaymentExtensions.UnpaidOnCredit: not deleted, not cancelled, payment Pending / Authorized / Partially paid):
    • due within OrderSettings.PaymentReminderDaysBefore days (today included) → e-mail OrderPaymentDue.CustomerNotification;
    • past the due date → e-mail OrderPaymentOverdue.CustomerNotification. An order already overdue (e.g. the task was off) gets only this one.
  • The queries return order ids only; each order is loaded when its e-mail is sent, so an old shop with many unpaid orders is not read into memory at once.
  • Each e-mail is sent once per order: Order.PaymentReminderSentOnUtc / Order.PaymentOverdueNoticeSentOnUtc, written with a field update (a full save could overwrite a payment saved in the meantime), followed by EntityUpdated<Order>. No repeat and no escalation.
  • When sending fails (exception), the order is not marked: it is logged, the run goes on with the other orders and stores, and the next run tries again. When nothing is queued because the template is inactive or not available for the store, the order is marked anyway, so switching the template on later does not mail every order that fell due meanwhile.
  • A staff-only order note records each queued e-mail ("Payment due reminder e-mail sent" / "Payment overdue e-mail sent").
  • Recipient: the order's billing e-mail, as for every other customer order e-mail. The company owner of a sub-account is not copied.
  • A new due date is a new term: IOrderService.UpdatePaymentTerms (used by the "Payment terms" popup instead of a full UpdateOrder) writes only the purchase order number, the due date and, when the date changed, clears both markers, so the new date gets its own reminder and notice. The dates are compared in UTC, because LiteDB reads a stored date back in local time; saving the same date keeps the markers.
  • Setting Payment reminder (days before the due date) on Settings → Sales → Order settings, Admin and Store panels, store-scoped, default 3, 0 = on the due date, allowed range 0–365 (OrderSettings.MaxPaymentReminderDaysBefore). The service clamps a stored value to the same range, so one store's value cannot stop the run for the others.
  • PaymentExtensions.UnpaidOnCredit replaces the same predicate repeated in CompanyCreditService, GetOrderQueryHandler (overdue filter) and IsPaymentOverdue.
  • Templates: order number, PO number (when set), order date, total, due date and a "View order details" button. They use only existing Order tokens. {{Order.PaymentDueDate}} is the long date in the server's culture when sent by the task; a template can fix the format with the date filter, e.g. {{Order.PaymentDueDate | date: 'dd.MM.yyyy'}}.
  • Installer: the task (enabled, 1440 min), both templates and the index PaymentDueDateUtc on orders. MigrationPaymentDueReminders (2.5) adds the same to existing installations, with the task disabled: an existing shop may have orders that have been overdue for months, so the operator decides when those customers are told. Resources in DefaultLanguage.xml and Upgrade/en_250.xml.

Out of scope: copying the company owner, repeated overdue notices, a payment link in the e-mail (bank transfer and on-account orders have none), showing the markers in the panel (the order notes and the message queue show what was sent). Tax display and social links in e-mails sent by a scheduled task follow the task's store, not the order's; fixed separately for every e-mail in #1069.

Breaking changes

  • IOrderMessageProviderService gains SendPaymentDueReminderCustomerMessage and SendPaymentOverdueCustomerMessage, and IOrderService gains UpdatePaymentTerms. An implementation outside this repository has to add them.
  • The "Payment terms" popup saves through UpdatePaymentTerms instead of UpdateOrder.

Testing

  1. Admin → System → Schedule tasks: "Payment due reminders" is listed (enabled on a fresh install, disabled after an upgrade).
  2. Settings → Sales → Order settings: set "Payment reminder (days before the due date)" to 3; -1 and 366 are refused. Repeat in the Store panel.
  3. Place an order with "On account" for a customer with trade credit. In Sales → Payment transactions → the transaction → Payment terms, set the due date to tomorrow. Run the task now. The message queue holds "Payment for order #N due on …" for the billing e-mail, and the order has the note "Payment due reminder e-mail sent". Run it again: nothing new.
  4. Set the due date to yesterday and run the task: "Payment for order #N is overdue" is queued once. Change only the PO number in the popup and run the task: nothing new. Change the date again: the reminder or notice for the new date is queued.
  5. Mark the order as paid, set another past date, run the task: nothing is sent.
  6. dotnet test: Grand.Business.Checkout.Tests 938, Grand.Business.Messages.Tests 153, Grand.Modules.Tests 402, Grand.Web.Admin.Tests 2065, Grand.Web.Store.Tests 241, Grand.Mapping.Tests 238 passed. Not checked in a browser (this worktree has no installed database).

Copilot AI balanced review requested due to automatic review settings November 19, 2026 04:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Comment on lines +40 to +44
catch (Exception ex)
{
logService.LogError(ex, "UpgradeProcess - PaymentDueReminders {Step} (2.5)", name);
success = false;
}
support added 3 commits November 19, 2026 08:01
The reminders, the company credit, the overdue order list and IsPaymentOverdue each repeated the same predicate; they now use PaymentExtensions.UnpaidOnCredit.
The rule that a new due date sends the reminders again moves out of the controller. Only the purchase order number, the due date and the reminder markers are written, so a marker set by the reminder task meanwhile is not overwritten, and the due date is compared in UTC: LiteDB reads it back in local time.
Up to 365 days in the settings and in the task, so one store's value cannot stop the run for every store. A reminder that failed is not marked and is sent on the next run; a failed write no longer leaves the loop. Orders are loaded one by one from their ids, and the marker write publishes EntityUpdated.
Comment on lines +109 to +113
catch (Exception ex)
{
//not marked when the e-mail could not be queued: the next run tries again
logger.LogError(ex, "Payment reminder for order {OrderId} failed", orderId);
}
@KrzysztofPajak
KrzysztofPajak merged commit bd4f98b into develop Nov 19, 2026
9 checks passed
@KrzysztofPajak
KrzysztofPajak deleted the feature/payment-due-reminders branch November 19, 2026 15:02
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.

2 participants