mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 09:09:01 +00:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user