Files
unsupervised-scheduler/templates/admin/payment-email.php
T
Kydoimosandanthropic/claude-opus-4-8 a2c609803e
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
Add editable, previewable payment-due email template
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
2026-09-17 17:33:23 -03:00

98 lines
4.9 KiB
PHP

<?php
declare(strict_types=1);
if (! defined('ABSPATH')) {
exit;
}
/**
* @var string $subject
* @var string $body
* @var string $itemLine
* @var array<string, string> $tokens
* @var array<string, string> $itemTokens
* @var string $previewNonce
* @var string $previewUrl
* @var array{subject: string, body: string} $preview
* @var string $notice
*/
?>
<div class="wrap">
<h1><?php esc_html_e('Payment Due Email', 'unsupervised-schedular'); ?></h1>
<?php if ('' !== $notice) : ?>
<div class="notice notice-success inline">
<p><?php echo esc_html($notice); ?></p>
</div>
<?php endif; ?>
<p class="description">
<?php esc_html_e('This is the email a student receives when the daily billing scan finds payments due for them. Edit the subject and body below, then preview the result with sample values. Leave a field blank to use the built-in default.', 'unsupervised-schedular'); ?>
</p>
<form method="post" id="usc-payment-email-form">
<?php wp_nonce_field('usc_payment_email_action'); ?>
<input type="hidden" name="usc_action" value="save">
<table class="form-table">
<tr>
<th scope="row"><label for="usc-pe-subject"><?php esc_html_e('Subject', 'unsupervised-schedular'); ?></label></th>
<td>
<input type="text" name="subject" id="usc-pe-subject" class="large-text" value="<?php echo esc_attr($subject); ?>">
</td>
</tr>
<tr>
<th scope="row"><label for="usc-pe-body"><?php esc_html_e('Body', 'unsupervised-schedular'); ?></label></th>
<td>
<textarea name="body" id="usc-pe-body" class="large-text code" rows="10"><?php echo esc_textarea($body); ?></textarea>
<p class="description"><?php esc_html_e('Available tokens:', 'unsupervised-schedular'); ?></p>
<ul>
<?php foreach ($tokens as $token => $description) : ?>
<li><code><?php echo esc_html($token); ?></code> — <?php echo esc_html($description); ?></li>
<?php endforeach; ?>
</ul>
</td>
</tr>
<tr>
<th scope="row"><label for="usc-pe-item-line"><?php esc_html_e('Item line', 'unsupervised-schedular'); ?></label></th>
<td>
<input type="text" name="item_line" id="usc-pe-item-line" class="large-text code" value="<?php echo esc_attr($itemLine); ?>">
<p class="description"><?php esc_html_e('The template for each charge in the {items} block. Available tokens:', 'unsupervised-schedular'); ?></p>
<ul>
<?php foreach ($itemTokens as $token => $description) : ?>
<li><code><?php echo esc_html($token); ?></code> — <?php echo esc_html($description); ?></li>
<?php endforeach; ?>
</ul>
</td>
</tr>
</table>
<?php submit_button(esc_html__('Save Template', 'unsupervised-schedular')); ?>
</form>
<h2><?php esc_html_e('Reset to default', 'unsupervised-schedular'); ?></h2>
<p class="description"><?php esc_html_e('Discards your custom subject, body and item line, restoring the built-in default template.', 'unsupervised-schedular'); ?></p>
<form method="post" onsubmit="return confirm('<?php echo esc_js(esc_html__('Reset the payment due email to its default template?', 'unsupervised-schedular')); ?>');">
<?php wp_nonce_field('usc_payment_email_action'); ?>
<input type="hidden" name="usc_action" value="reset">
<?php submit_button(esc_html__('Reset to default', 'unsupervised-schedular'), 'delete', 'submit', true); ?>
</form>
<h2><?php esc_html_e('Preview', 'unsupervised-schedular'); ?></h2>
<p class="description"><?php esc_html_e('Rendered with sample values. Updates as you edit above.', 'unsupervised-schedular'); ?></p>
<table class="form-table">
<tr>
<th scope="row"><?php esc_html_e('Subject', 'unsupervised-schedular'); ?></th>
<td><strong id="usc-pe-preview-subject"><?php echo esc_html($preview['subject']); ?></strong></td>
</tr>
<tr>
<th scope="row"><?php esc_html_e('Body', 'unsupervised-schedular'); ?></th>
<td><pre id="usc-pe-preview-body" style="white-space:pre-wrap;background:#fff;border:1px solid #ccd0d4;padding:12px;margin:0;max-width:640px;"><?php echo esc_html($preview['body']); ?></pre></td>
</tr>
</table>
</div>
<script>
window.uscPaymentEmailPreview = {
url: <?php echo wp_json_encode($previewUrl); ?>,
nonce: <?php echo wp_json_encode($previewNonce); ?>
};
</script>