Add editable, previewable payment-due email template #203

Merged
thatguygriff merged 1 commits from feature/editable-payment-due-email into main 2026-09-17 20:40:37 +00:00
Member

Summary

Studio admins requested the ability to view and edit the "Payment due" email. That notice — sent by the daily billing scan — was previously fixed wording baked into PaymentDueMailer. This adds a Studio Settings → Payment Due Email screen where the template can be viewed, edited, and previewed against sample values.

What changed

  • PaymentDueEmailTemplate — stores subject/body/item-line as new us_payment_due_email_* options, each falling back to the built-in default when blank. Renders via {token} substitution. Body tokens: {student_name}, {items}, {total_due}, {credit}, {etransfer}, {reference}; item-line tokens: {label}, {due_date}, {currency}, {amount}.
  • PaymentDueMailer — now takes a PaymentDueEmailTemplate (defaulted, so existing wiring is unchanged), builds a token map from the same consolidated items/credit/e-transfer/reference data, and renders the stored template. The default template reproduces the previous wording exactly.
  • PaymentEmailController — the view/edit/save/reset admin page, gated on manage_billing with a nonce, including a server-rendered sample preview.
  • PaymentEmailPreviewEndpointPOST /wp-json/us-scheduler/v1/payment-email/preview (manage_billing) + payment-email-admin.js drive a debounced live preview of unsaved edits; degrades to the server-rendered preview when JS is off.
  • Submenu registered under Studio Settings; endpoint wired in RestRegistrar.
  • Bumped to 1.6.0 with a CHANGELOG entry.

Compatibility

New options default gracefully to the built-in wording, so existing sites need no migration and send the identical notice until an admin edits it.

Verification

  • phpunit: 1027 tests, 2971 assertions — OK (new suites for the template, controller, and endpoint; mailer test updated)
  • phpstan (level 10): no errors
  • phpcs: clean
  • no-debug check: clean
## Summary Studio admins requested the ability to view and edit the "Payment due" email. That notice — sent by the daily billing scan — was previously fixed wording baked into `PaymentDueMailer`. This adds a **Studio Settings → Payment Due Email** screen where the template can be viewed, edited, and previewed against sample values. ## What changed - **`PaymentDueEmailTemplate`** — stores subject/body/item-line as new `us_payment_due_email_*` options, each falling back to the built-in default when blank. Renders via `{token}` substitution. Body tokens: `{student_name}`, `{items}`, `{total_due}`, `{credit}`, `{etransfer}`, `{reference}`; item-line tokens: `{label}`, `{due_date}`, `{currency}`, `{amount}`. - **`PaymentDueMailer`** — now takes a `PaymentDueEmailTemplate` (defaulted, so existing wiring is unchanged), builds a token map from the same consolidated items/credit/e-transfer/reference data, and renders the stored template. The default template reproduces the previous wording exactly. - **`PaymentEmailController`** — the view/edit/save/reset admin page, gated on `manage_billing` with a nonce, including a server-rendered sample preview. - **`PaymentEmailPreviewEndpoint`** — `POST /wp-json/us-scheduler/v1/payment-email/preview` (`manage_billing`) + `payment-email-admin.js` drive a debounced live preview of unsaved edits; degrades to the server-rendered preview when JS is off. - Submenu registered under Studio Settings; endpoint wired in `RestRegistrar`. - Bumped to **1.6.0** with a CHANGELOG entry. ## Compatibility New options default gracefully to the built-in wording, so existing sites need **no migration** and send the identical notice until an admin edits it. ## Verification - `phpunit`: 1027 tests, 2971 assertions — OK (new suites for the template, controller, and endpoint; mailer test updated) - `phpstan` (level 10): no errors - `phpcs`: clean - no-debug check: clean
Kydoimos added 1 commit 2026-09-17 20:33:44 +00:00
Add editable, previewable payment-due email template
CI / Coding Standards (pull_request) Successful in 29s
CI / Tests (PHP 8.2) (pull_request) Successful in 31s
CI / Tests (PHP 8.3) (pull_request) Successful in 31s
CI / Tests (PHP 8.5) (pull_request) Successful in 31s
CI / No Debug Code (pull_request) Successful in 9s
CI / Tests (PHP 8.1) (pull_request) Successful in 44s
CI / Static Analysis (pull_request) Successful in 51s
CI / Build Plugin Zip (pull_request) Skipped
a2c609803e
The "Payment due" notice the daily billing scan sends was fixed wording
baked into PaymentDueMailer. Studio admins can now view, edit and preview
its subject and body under Studio Settings -> Payment Due Email.

- PaymentDueEmailTemplate stores subject/body/item-line as us_payment_due_email_*
  options, each falling back to the built-in default when blank, and renders
  via {token} substitution.
- PaymentDueMailer now builds a token map from the same consolidated
  items/credit/e-transfer/reference data and renders the stored template; the
  default template reproduces the previous wording exactly.
- PaymentEmailController serves the view/edit/save/reset admin page
  (manage_billing, nonce-checked) with a server-rendered sample preview.
- PaymentEmailPreviewEndpoint (POST us-scheduler/v1/payment-email/preview,
  manage_billing) + payment-email-admin.js drive a live preview of unsaved edits.
- Submenu wired under Studio Settings; endpoint wired in RestRegistrar.
- Bump to 1.6.0 and add CHANGELOG entry. New options default gracefully, so
  existing sites need no migration and send the identical notice until edited.

Co-authored-by: anthropic/claude-opus-4-8
thatguygriff merged commit 694366a6c8 into main 2026-09-17 20:40:37 +00:00
thatguygriff deleted branch feature/editable-payment-due-email 2026-09-17 20:40:37 +00:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Unsupervised/unsupervised-scheduler#203