Autopay offered to clients: database 4.3.7 adds settings.config_invoice_offer_autopay and recurring_invoices.recurring_invoice_offer_autopay, an invoice from a recurring invoice with no autopay offers Set up autopay in its email and on its guest and portal pages, guest/guest_autopay.php sets it up with no sign-in through a Stripe Checkout Session in setup mode (name, email and agreement kept in its metadata and the recurring invoice's history), the card is saved and autopay turned on when Stripe sends them back, agents are told and the client gets a confirmation, the portal turns it on with a saved card, Settings > Invoices and each recurring invoice's Autopay card can turn the offer off; 26.12.3 changelog

This commit is contained in:
johnnyq
2026-12-01 14:55:29 -05:00
parent 0b770dcdf0
commit 25dac4cee2
19 changed files with 872 additions and 6 deletions

View File

@@ -437,10 +437,67 @@ function billingInvoiceEmail(array $invoice, array $opts = []) {
'kind' => 'Invoice', 'tone' => 'primary', 'title' => "Invoice $number",
'intro' => ['Here is your invoice' . ($scope !== '' ? " for \"$scope\"" : '') . '.' . ($owed ? ' Payment is due by ' . billingEmailDate($invoice['invoice_due']) . '.' : '')],
'summary' => $summary, 'strong' => $owed ? 'Balance due' : 'Balance',
'offer' => billingAutopayOfferEmail($invoice),
'after' => [($pay ? 'You can pay online by card from the invoice page, and download it as a PDF. ' : 'You can download it as a PDF from the invoice page. ') . $contact_line],
]];
}
/**
* The autopay an invoice email offers (autopayOffer(), functions/billing_pay.php) -
* emailHtml()'s offer box, or null when there is none to offer.
*/
function billingAutopayOfferEmail(array $invoice) {
$offer = autopayOffer($invoice);
if (!$offer) {
return null;
}
$what = $offer['title'] !== $offer['number'] ? "the invoice for \"{$offer['title']}\"" : "the invoice from {$offer['number']}";
return [
'title' => 'Pay automatically from now on',
'text' => "Set up autopay once, and $what each {$offer['period']} is charged to your card on its due date - no paying each one by hand. It takes a minute, with no sign-in."
. ($offer['this_invoice'] ? ' This invoice is included, on ' . billingEmailDate($invoice['invoice_due']) . '.' : ''),
'button' => ['label' => 'Set up autopay', 'url' => $offer['url']],
'small' => ($offer['fee'] !== '' ? "Each charge has a card fee added: {$offer['fee']}. " : '') . autopayChangeText(),
];
}
/** How a client changes the card or turns autopay off - in the client portal when it is on, else by asking. */
function autopayChangeText() {
global $config_client_portal_enable;
return 'To change the card or turn autopay off later, ' . (!empty($config_client_portal_enable) ? 'sign in to the client portal or ask us.' : 'just ask us.');
}
/**
* Confirm autopay set up from an invoice's link (guest/guest_autopay.php) to
* whoever set it up - the recurring invoice, the card, what is charged and
* when. $offer is autopayOffer() as it stood, $invoice the invoice it was set
* up from. Who it went to.
*/
function billingMailAutopayOn($email, $name, array $offer, $card_label, array $invoice) {
$recurring = $offer['recurring'];
$summary = ['Recurring invoice' => $offer['number']];
if ($offer['title'] !== $offer['number']) {
$summary['For'] = $offer['title'];
}
$summary['Each ' . $offer['period']] = billingMoney($offer['amount'], $offer['currency']);
$summary['Card'] = $card_label;
$summary['Next invoice'] = billingEmailDate($recurring['recurring_invoice_next_date']);
$first = $offer['this_invoice']
? 'The first charge is invoice ' . billingNumber('invoice', $invoice) . ', on its due date, ' . billingEmailDate($invoice['invoice_due']) . '.'
: 'Invoice ' . billingNumber('invoice', $invoice) . " isn't charged by autopay - pay it as usual if it is still owed. Autopay starts with the next one.";
return billingEmailQueue([['email' => (string) $email, 'name' => (string) $name]], 'Autopay is on for ' . $offer['title'], [
'kind' => 'Autopay', 'tone' => 'success', 'preview' => "Each invoice is charged to $card_label on its due date",
'title' => 'Autopay is on',
'intro' => ["Thank you - from now on, each invoice from recurring invoice {$offer['number']} is charged to $card_label on its due date, and a receipt is emailed each time. $first"],
'summary' => $summary, 'strong' => 'Each ' . $offer['period'],
'after' => array_values(array_filter([
$offer['fee'] !== '' ? "Each charge has a card fee added: {$offer['fee']}." : '',
'Your card details are kept by Stripe, our payment processor - not by us. ' . autopayChangeText(),
])),
'footnote' => 'You received this email because you set up autopay for ' . $recurring['client_name'] . ' with ' . (billingCompany()['company_name'] ?? 'us') . '.',
], ['about' => 'invoice:' . intval($invoice['invoice_id'])]);
}
/** A quote email - [subject, email]. $opts: note. */
function billingQuoteEmail(array $quote, array $opts = []) {
$number = billingNumber('quote', $quote);

View File

@@ -470,6 +470,299 @@ function invoiceAutopayStatus(array $invoice, array $state, $autopay) {
'detail' => "$done on its due date, $due - for what is still owed then."];
}
/* -------------------------------------------------------- Offering autopay */
/*
* An invoice from a recurring invoice with no autopay offers it - a Set up
* autopay button in its email and on its page that opens
* guest/guest_autopay.php from the invoice's own link, so no sign-in is
* needed: the client agrees, adds a card through Stripe's form, and autopay
* is on for that recurring invoice. Settings > Invoices turns the offer off
* for everyone, and a recurring invoice's page for one.
*/
/** Whether invoices offer autopay - Settings > Invoices > Paid online (DB 4.3.7). */
function autopayOfferOn() {
global $mysqli;
static $on = null;
if ($on === null) {
$on = settingsColumnExists($mysqli, 'config_invoice_offer_autopay')
&& intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT config_invoice_offer_autopay FROM settings WHERE company_id = 1"))[0] ?? 0) === 1;
}
return $on;
}
/**
* Why a recurring invoice's client isn't offered autopay - '' when they are,
* or would be once an invoice from it is sent. Its autopay is already on,
* cards are off, the offer is off here or in Settings > Invoices, it is
* paused or archived, or it bills more than a card can take. $recurring is
* billingRow('recurring').
*/
function autopayOfferBlocked(array $recurring) {
if (intval($recurring['recurring_payment_id'] ?? 0) > 0) {
return 'Autopay is on';
}
if (!billingStripeProvider()) {
return "Card payments are off - Stripe isn't set up in Payment Providers";
}
if (!autopayOfferOn()) {
return 'Offering autopay is off in Settings > Invoices';
}
if (intval($recurring['recurring_invoice_offer_autopay'] ?? 1) !== 1) {
return 'Turned off for this recurring invoice';
}
if (intval($recurring['recurring_invoice_status']) !== 1 || !empty($recurring['recurring_invoice_archived_at'])) {
return "It isn't active";
}
if (!billingOnlinePayAllowed($recurring['recurring_invoice_amount'])) {
return 'It bills more than the card limit in Payment Providers';
}
return '';
}
/**
* The autopay an invoice offers for the recurring invoice it came from - or
* null when it offers none (autopayOfferBlocked(), or the invoice is
* cancelled or not billed). autopayOfferDetails() says what is in it.
*/
function autopayOffer(array $invoice) {
$recurring_id = intval($invoice['invoice_recurring_invoice_id'] ?? 0);
if ($recurring_id <= 0 || in_array((string) $invoice['invoice_status'], ['Cancelled', 'Non-Billable'], true) || (string) ($invoice['invoice_url_key'] ?? '') === '') {
return null;
}
$recurring = billingRow('recurring', $recurring_id, false);
if (!$recurring || intval($recurring['recurring_invoice_client_id']) !== intval($invoice['invoice_client_id']) || autopayOfferBlocked($recurring) !== '') {
return null;
}
return autopayOfferDetails($invoice, $recurring);
}
/**
* What autopay for $recurring, offered from $invoice, comes to - ['recurring'
* => its row, 'number', 'title' => its scope, else its number, 'amount',
* 'currency', 'period' => month, quarter or year, 'fee' => the card fee's
* terms, or '', 'this_invoice' => whether $invoice is charged too - still
* owed, and due after today, 'url' => the setup page].
*/
function autopayOfferDetails(array $invoice, array $recurring) {
$currency = (string) $recurring['recurring_invoice_currency_code'];
$owed = in_array((string) $invoice['invoice_status'], ['Draft', 'Sent', 'Viewed', 'Partial'], true)
&& round(floatval($invoice['invoice_amount']) - invoicePaid($invoice['invoice_id']), 2) > 0;
$number = billingNumber('recurring', $recurring);
return [
'recurring' => $recurring,
'number' => $number,
'title' => trim((string) $recurring['recurring_invoice_scope']) !== '' ? trim((string) $recurring['recurring_invoice_scope']) : $number,
'amount' => floatval($recurring['recurring_invoice_amount']),
'currency' => $currency,
'period' => recurringInvoicePeriodWord($recurring['recurring_invoice_frequency']),
'fee' => billingCardFeeTerms(billingCardFeeFor($invoice['invoice_client_id']), $currency),
'this_invoice' => $owed && (string) $invoice['invoice_due'] > date('Y-m-d'),
'url' => autopayOfferUrl($invoice),
];
}
/** The page that sets autopay up from an invoice's link. */
function autopayOfferUrl(array $invoice) {
global $config_base_url;
return "https://$config_base_url/guest/guest_autopay.php?invoice_id=" . intval($invoice['invoice_id']) . '&url_key=' . rawurlencode((string) $invoice['invoice_url_key']);
}
/**
* What the client agrees to, raw - the charges, the card fee when they pay
* one, and until when. Kept in the recurring invoice's history.
*/
function autopayConsentText(array $offer) {
$company = billingCompany();
return 'I authorize ' . ($company['company_name'] ?? 'you') . " to charge the card I add for each invoice from recurring invoice {$offer['number']}"
. ($offer['title'] !== $offer['number'] ? " ({$offer['title']})" : '') . ' on its due date'
. ($offer['fee'] !== '' ? ", plus a card fee of {$offer['fee']}" : '') . ', until autopay is turned off.';
}
/**
* Start setting autopay up from an invoice's link: the client's Stripe
* customer, made now when they have none, and a Checkout Session that saves
* a card to it - Stripe's own form, on the page. Who agreed and to what goes
* in its metadata, for autopayCheckoutFinish() when Stripe sends them back.
* Its client secret, or '' with $error for the client. $name and $email raw.
*/
function autopayCheckoutStart(array $invoice, $name, $email, &$error = '') {
global $mysqli, $config_base_url;
$offer = autopayOffer($invoice);
$name = trim(mb_substr(preg_replace('/\s+/u', ' ', (string) $name) ?? '', 0, 80));
$email = trim(mb_substr((string) $email, 0, 120));
if (!$offer) {
$error = "Autopay can't be set up from this invoice just now - get in touch and we'll help.";
return '';
}
if ($name === '') {
$error = 'Enter your name.';
return '';
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error = 'Enter your email address, for the confirmation.';
return '';
}
$provider = billingStripeProvider();
$stripe = billingStripeClient();
$client_id = intval($invoice['invoice_client_id']);
$provider_id = intval($provider['payment_provider_id']);
$invoice_id = intval($invoice['invoice_id']);
$invoice_number = billingNumber('invoice', $invoice);
$recurring_id = intval($offer['recurring']['recurring_invoice_id']);
$ids = ['itflow_autopay_invoice_id' => $invoice_id, 'itflow_recurring_invoice_id' => $recurring_id, 'itflow_client_id' => $client_id];
for ($try = 0; $try < 2; $try++) {
$customer = billingStripeCustomer($client_id);
try {
if ($customer === '') {
// One customer a client - two setups at once take turns here
$lock = "itflow_stripe_customer_$client_id";
mysqli_query($mysqli, "SELECT GET_LOCK('$lock', 15)");
try {
$customer = billingStripeCustomer($client_id);
if ($customer === '') {
$made = $stripe->customers->create([
'name' => (string) $offer['recurring']['client_name'],
'email' => $email,
'metadata' => ['itflow_client_id' => $client_id, 'consent_by' => $name],
]);
$customer = (string) $made->id;
mysqli_query($mysqli, "INSERT INTO client_payment_provider SET client_id = $client_id, payment_provider_id = $provider_id,
payment_provider_client = '" . escapeSql($customer) . "', client_payment_provider_created_at = NOW()");
logAudit("Stripe", "Create", "Guest $name ($email) created Stripe customer for {$offer['recurring']['client_name']} as $customer, setting up autopay from invoice $invoice_number", $client_id);
}
} finally {
mysqli_query($mysqli, "SELECT RELEASE_LOCK('$lock')");
}
}
$session = $stripe->checkout->sessions->create([
'mode' => 'setup',
'ui_mode' => 'embedded_page',
'currency' => strtolower($offer['currency']),
'customer' => $customer,
'payment_method_types' => ['card'],
'return_url' => "https://$config_base_url/guest/guest_post.php?guest_autopay_done=1&invoice_id=$invoice_id&url_key=" . rawurlencode((string) $invoice['invoice_url_key']) . '&session_id={CHECKOUT_SESSION_ID}',
'metadata' => $ids + [
'itflow_consent_name' => $name,
'itflow_consent_email' => $email,
'itflow_consent' => mb_substr(autopayConsentText($offer), 0, 500),
],
'setup_intent_data' => ['description' => "Autopay for recurring invoice {$offer['number']}", 'metadata' => $ids],
]);
return (string) $session->client_secret;
} catch (\Throwable $e) {
// A customer Stripe no longer has - forgotten, and made again once
if ($try === 0 && $customer !== '' && billingStripeCustomerGone($e)) {
billingStripeCustomerForget($client_id, $customer);
continue;
}
logApp("Stripe", "error", "Setting up autopay from invoice $invoice_number couldn't start: " . $e->getMessage());
break;
}
}
$error = "Card details can't be taken just now - try again in a few minutes.";
return '';
}
/**
* Finish setting autopay up once Stripe sends the client back from
* autopayCheckoutStart()'s form: the session checked with Stripe - complete,
* and for this invoice, its recurring invoice and the client's customer -
* the card saved, and autopay on for the recurring invoice with it, in place
* of any it had. Kept in its history with what they agreed to, logged, the
* agents told and the client sent a confirmation. Coming back to the same
* address again changes nothing. ['ok' => bool, 'again' => true when it was
* done already, 'card' => "Visa •••• 4242", 'emailed' => whether the
* confirmation went, 'error' => for the client].
*/
function autopayCheckoutFinish(array $invoice, $session_id) {
global $mysqli;
$fail = function ($error) {
return ['ok' => false, 'again' => false, 'emailed' => false, 'card' => '', 'error' => $error];
};
$session_id = (string) $session_id;
$provider = billingStripeProvider();
$stripe = billingStripeClient();
$recurring = intval($invoice['invoice_recurring_invoice_id'] ?? 0) ? billingRow('recurring', $invoice['invoice_recurring_invoice_id'], false) : null;
$client_id = intval($invoice['invoice_client_id']);
if (!$provider || !$stripe || !$recurring || intval($recurring['recurring_invoice_client_id']) !== $client_id || !preg_match('/^cs_[A-Za-z0-9_]{8,250}$/', $session_id)) {
return $fail("Autopay couldn't be set up from that link - get in touch and we'll help.");
}
$recurring_id = intval($recurring['recurring_invoice_id']);
$invoice_id = intval($invoice['invoice_id']);
$invoice_number = billingNumber('invoice', $invoice);
// The same return twice at once - a double click, a reload - takes turns, and the second finds it done
$lock = "itflow_autopay_$recurring_id";
mysqli_query($mysqli, "SELECT GET_LOCK('$lock', 15)");
try {
$done = mysqli_fetch_row(mysqli_query($mysqli, "SELECT history_description FROM history WHERE history_recurring_invoice_id = $recurring_id
AND history_status = 'Autopay' AND history_description LIKE '%" . escapeSql(addcslashes($session_id, '%_\\')) . "%' LIMIT 1"));
if ($done) {
return ['ok' => true, 'again' => true, 'emailed' => false, 'card' => preg_match('/ with (.+?) by /u', (string) $done[0], $m) ? $m[1] : '', 'error' => ''];
}
if (intval($recurring['recurring_invoice_status']) !== 1 || !empty($recurring['recurring_invoice_archived_at'])) {
return $fail("This recurring invoice has ended, so autopay wasn't set up. Nothing will be charged.");
}
$offer = autopayOfferDetails($invoice, $recurring);
$customer = billingStripeCustomer($client_id);
try {
$session = $stripe->checkout->sessions->retrieve($session_id, []);
$meta = $session->metadata ? $session->metadata->toArray() : [];
if ((string) $session->mode !== 'setup' || intval($meta['itflow_autopay_invoice_id'] ?? 0) !== $invoice_id
|| intval($meta['itflow_recurring_invoice_id'] ?? 0) !== $recurring_id || $customer === '' || (string) $session->customer !== $customer) {
return $fail("That card setup isn't for this invoice - nothing has changed.");
}
if ((string) $session->status !== 'complete' || empty($session->setup_intent)) {
return $fail("Your card wasn't added, so autopay isn't on yet - try again.");
}
$setup_intent = $stripe->setupIntents->retrieve(is_string($session->setup_intent) ? $session->setup_intent : $session->setup_intent->id, []);
$pm_id = is_string($setup_intent->payment_method) ? $setup_intent->payment_method : (string) ($setup_intent->payment_method->id ?? '');
if ((string) $setup_intent->status !== 'succeeded' || $pm_id === '') {
return $fail("Your card wasn't added, so autopay isn't on yet - try again.");
}
$pm = $stripe->paymentMethods->retrieve($pm_id, []);
} catch (\Throwable $e) {
logApp("Stripe", "error", "Setting up autopay from invoice $invoice_number couldn't be confirmed ($session_id): " . $e->getMessage());
return $fail("We couldn't confirm your card with Stripe just now - reload this page in a minute, or get in touch.");
}
$provider_id = intval($provider['payment_provider_id']);
$pm_sql = escapeSql($pm_id);
$description = !empty($pm->card)
? "{$pm->card->brand} - {$pm->card->last4} | Exp " . intval($pm->card->exp_month) . '/' . intval($pm->card->exp_year)
: 'Card';
// The card - saved once, however often it comes back
$saved_id = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT saved_payment_id FROM client_saved_payment_methods
WHERE saved_payment_client_id = $client_id AND saved_payment_provider_id = $provider_id AND saved_payment_provider_method = '$pm_sql' LIMIT 1"))[0] ?? 0);
if (!$saved_id) {
mysqli_query($mysqli, "INSERT INTO client_saved_payment_methods SET saved_payment_provider_method = '$pm_sql', saved_payment_description = '" . escapeSql($description) . "',
saved_payment_client_id = $client_id, saved_payment_provider_id = $provider_id, saved_payment_created_at = NOW()");
$saved_id = intval(mysqli_insert_id($mysqli));
}
$currency = escapeSql($recurring['recurring_invoice_currency_code']);
mysqli_query($mysqli, "DELETE FROM recurring_payments WHERE recurring_payment_recurring_invoice_id = $recurring_id");
mysqli_query($mysqli, "INSERT INTO recurring_payments SET recurring_payment_currency_code = '$currency', recurring_payment_account_id = " . intval($provider['payment_provider_account']) . ",
recurring_payment_method = 'Credit Card', recurring_payment_recurring_invoice_id = $recurring_id, recurring_payment_saved_payment_id = $saved_id");
$card = billingCardParts($description)['label'];
$name = trim((string) ($meta['itflow_consent_name'] ?? '')) ?: 'The client';
$email = trim((string) ($meta['itflow_consent_email'] ?? ''));
$who = $email !== '' ? "$name ($email)" : $name;
$consent = trim((string) ($meta['itflow_consent'] ?? ''));
billingLog('recurring', $recurring_id, 'Autopay', "Autopay turned on with $card by $who from invoice $invoice_number's link" . ($consent !== '' ? ", agreeing: \"$consent\"" : '') . " - Stripe $session_id");
logAudit("Recurring Invoice", "Auto Payment", "Guest $who turned on Auto Pay with $card for Recurring Invoice {$offer['number']} from invoice $invoice_number's link", $client_id, $recurring_id);
appNotify("Autopay", "$name set up autopay for {$recurring['client_name']}'s recurring invoice {$offer['number']} with $card, from invoice $invoice_number's link",
"/agent/recurring_invoice.php?recurring_invoice_id=$recurring_id", $client_id, $recurring_id);
$emailed = $email !== '' && filter_var($email, FILTER_VALIDATE_EMAIL) && billingEmailReady() && billingMailAutopayOn($email, $name, $offer, $card, $invoice);
return ['ok' => true, 'again' => false, 'card' => $card, 'emailed' => $emailed, 'error' => ''];
} finally {
mysqli_query($mysqli, "SELECT RELEASE_LOCK('$lock')");
}
}
/* ------------------------------------------------------- Choosing and paying */
/**

View File

@@ -85,7 +85,7 @@ const DEMO_MODE_LOCKS = [
'message' => "Card payments and payment providers are turned off in the demo.",
'keys' => ['add_payment_provider', 'check_payment_provider', 'check_payment_provider_connection', 'delete_payment_provider', 'edit_payment_provider',
'record_payment_provider_fees', 'turn_payment_provider_off', 'turn_payment_provider_on', 'delete_saved_payment', 'create_stripe_checkout',
'create_stripe_customer', 'stripe_save_card', 'set_recurring_payment', 'portal_pay'],
'create_stripe_customer', 'stripe_save_card', 'set_recurring_payment', 'portal_pay', 'guest_autopay_checkout', 'guest_autopay_done', 'set_recurring_offer_autopay'],
],
[
'message' => "AI providers can't be set up in the demo.",

View File

@@ -43,6 +43,8 @@ const EMAIL_REPLY_MARKER = '##- Please type your reply above this line -##';
* callout a paragraph that stands out, in the tone's colour
* button ['label' => ..., 'url' => ..., 'show_url' => true to print the address under it,
* for a link that has to be copied whole]
* offer something more they can do, in a box of its own after the button - ['title', 'text',
* 'button' => ['label', 'url'], 'small' => a line under its button] (autopay, say)
* after paragraphs after the button, smaller
* history earlier messages, under a rule at the end - ['label' => the heading, 'items' => [...]],
* each item ['by', 'org', 'action', 'when', 'text' => plain text, 'client' => true for
@@ -146,6 +148,19 @@ function emailHtml(array $email) {
$body .= '<p style="margin:-10px 0 18px;font-size:12px;line-height:1.5;color:' . $muted . ';word-break:break-all;">Or copy this into your browser: ' . $e($email['button']['url']) . '</p>';
}
}
if (!empty($email['offer']['button']['url'])) {
$offer = $email['offer'];
$primary = $tones['primary'];
$body .= '<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="margin:0 0 22px;background:#f5f9ff;border:1px solid #cfe2ff;border-radius:8px;"><tr>'
. '<td style="padding:16px 18px;' . $font . '">'
. (trim((string) ($offer['title'] ?? '')) !== '' ? '<div style="margin:0 0 6px;font-size:15px;font-weight:700;color:' . $text . ';">' . $e($offer['title']) . '</div>' : '')
. (trim((string) ($offer['text'] ?? '')) !== '' ? '<p style="margin:0 0 14px;font-size:14px;line-height:1.55;color:' . $text . ';">' . nl2br($e($offer['text'])) . '</p>' : '')
. '<table role="presentation" cellpadding="0" cellspacing="0"><tr><td bgcolor="#ffffff" style="border:1px solid ' . $primary . ';border-radius:6px;">'
. '<a href="' . $e($offer['button']['url']) . '" style="display:inline-block;padding:9px 20px;font-size:14px;font-weight:600;color:' . $primary . ';text-decoration:none;border-radius:6px;' . $font . '">' . $e($offer['button']['label']) . '</a>'
. '</td></tr></table>'
. (trim((string) ($offer['small'] ?? '')) !== '' ? '<p style="margin:10px 0 0;font-size:12px;line-height:1.5;color:' . $muted . ';">' . nl2br($e($offer['small'])) . '</p>' : '')
. '</td></tr></table>';
}
foreach ((array) ($email['after'] ?? []) as $text_value) {
$body .= '<p style="margin:0 0 12px;font-size:13px;line-height:1.55;color:' . $muted . ';">' . nl2br($e($text_value)) . '</p>';
}

View File

@@ -338,6 +338,7 @@ function settingsFields() {
'config_invoice_late_fee_percent' => ['page' => 'invoice', 'section' => 'Late fees', 'label' => 'Late fee %', 'words' => 'late fee percent'],
'config_invoice_paid_notification_email' => ['page' => 'invoice', 'section' => 'Paid online', 'label' => 'Email invoices paid online to', 'words' => 'paid notification email stripe payment'],
'config_invoice_paid_lead_to_client' => ['page' => 'invoice', 'section' => 'Paid online', 'label' => 'A lead that pays an invoice becomes a client', 'words' => 'lead client convert paid payment'] + $on_off,
'config_invoice_offer_autopay' => ['page' => 'invoice', 'section' => 'Paid online', 'label' => 'Offer autopay on recurring invoices', 'words' => 'autopay automatic payment recurring card offer set up'] + $on_off,
'config_send_invoice_reminders' => ['page' => 'invoice', 'section' => 'Reminders and statements', 'label' => 'Email payment reminders', 'words' => 'overdue reminder dunning past due'] + $on_off,
'reminder_before' => ['page' => 'invoice', 'section' => 'Reminders and statements', 'label' => 'Remind before it is due', 'words' => 'reminder days before due'],
'reminder_after' => ['page' => 'invoice', 'section' => 'Reminders and statements', 'label' => 'Remind after it is due', 'words' => 'reminder days late overdue'],