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:
@@ -2,8 +2,9 @@
|
||||
/*
|
||||
* Client Portal
|
||||
* An invoice - as it prints, with what is owed and by when alongside, Pay,
|
||||
* the PDF, the payments made with their receipts, and the recurring
|
||||
* invoice it came from. On a phone, what is owed comes first.
|
||||
* the PDF, autopay offered when the recurring invoice it came from has none,
|
||||
* the payments made with their receipts, and the recurring invoice it came
|
||||
* from. On a phone, what is owed comes first.
|
||||
*
|
||||
* SCOPING: the invoice must be the session's client's, and not a draft.
|
||||
*/
|
||||
@@ -62,6 +63,11 @@ if ($recurring && $owing && intval($recurring['recurring_payment_saved_payment_i
|
||||
}
|
||||
}
|
||||
}
|
||||
// No autopay on it - offered: turned on with a card they have saved, or set up from the invoice's own link with a new one (functions/billing_pay.php)
|
||||
$autopay_offer = $recurring ? autopayOffer($invoice) : null;
|
||||
$offer_cards = $autopay_offer ? array_filter(billingSavedCards($session_client_id), function ($card) {
|
||||
return !$card['card']['expired'];
|
||||
}) : [];
|
||||
|
||||
$paper = [
|
||||
'type' => 'invoice',
|
||||
@@ -145,6 +151,34 @@ $paper = [
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<?php if ($autopay_offer) { ?>
|
||||
<section class="itflow-portal-panel mb-4" data-autopay-offer>
|
||||
<div class="itflow-portal-panel-body">
|
||||
<div class="fw-semibold mb-1"><i class="fas fa-sync-alt text-primary me-2"></i>Pay automatically from now on</div>
|
||||
<p class="small text-body-secondary mb-3">Set up autopay once, and the invoice for <?= escapeHtml($autopay_offer['title']) ?> each <?= escapeHtml($autopay_offer['period']) ?> is charged to your card on its due date<?= $autopay_offer['this_invoice'] ? ' - this one too' : '' ?>.</p>
|
||||
<?php if ($offer_cards) { ?>
|
||||
<form action="post.php" method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="set_recurring_payment" value="1">
|
||||
<input type="hidden" name="recurring_invoice_id" value="<?= intval($recurring['recurring_invoice_id']) ?>">
|
||||
<div class="input-group mb-2">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-credit-card"></i></span>
|
||||
<select class="form-select" name="saved_payment_id" aria-label="Card to charge">
|
||||
<?php foreach (array_reverse($offer_cards) as $card) { ?>
|
||||
<option value="<?= intval($card['saved_payment_id']) ?>">Pay with <?= escapeHtml($card['card']['label']) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-outline-primary w-100"><i class="fas fa-sync-alt me-2"></i>Turn on autopay</button>
|
||||
<div class="form-text"><?= escapeHtml(autopayConsentText($autopay_offer)) ?> <a href="<?= escapeHtml($autopay_offer['url']) ?>">Use another card</a></div>
|
||||
</form>
|
||||
<?php } else { ?>
|
||||
<a class="btn btn-outline-primary w-100" href="<?= escapeHtml($autopay_offer['url']) ?>"><i class="fas fa-sync-alt me-2"></i>Set up autopay</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($payments) { ?>
|
||||
<section class="itflow-portal-panel mb-4">
|
||||
<div class="itflow-portal-panel-head">
|
||||
|
||||
@@ -1760,13 +1760,22 @@ if (isset($_POST['set_recurring_payment'])) {
|
||||
$recurring_payment_id = mysqli_insert_id($mysqli);
|
||||
|
||||
logAudit("Recurring Invoice", "Auto Payment", "$session_contact_name created Auto Pay for Recurring Invoice $recurring_invoice_prefix$recurring_invoice_number in the amount of " . billingMoney($recurring_invoice_amount, $recurring_invoice_currency_code), $session_client_id, $recurring_invoice_id);
|
||||
// In its history, and the agents told - as when it is set up from an invoice's link (autopayCheckoutFinish())
|
||||
$card_label = billingCardParts(stripslashes($saved_payment_description))['label'];
|
||||
billingLog('recurring', $recurring_invoice_id, 'Autopay', "Autopay turned on with $card_label by " . stripslashes($session_contact_name) . ' (' . stripslashes($session_contact_email) . ') in the client portal');
|
||||
appNotify("Autopay", stripslashes($session_contact_name) . " set up autopay for " . $session_client_name . "'s recurring invoice " . stripslashes($recurring_invoice_prefix) . "$recurring_invoice_number with $card_label, in the client portal",
|
||||
"/agent/recurring_invoice.php?recurring_invoice_id=$recurring_invoice_id", $session_client_id, $recurring_invoice_id);
|
||||
|
||||
flashAlert("Automatic payment with $saved_payment_description turned on for recurring invoice $recurring_invoice_prefix$recurring_invoice_number");
|
||||
} else {
|
||||
// Delete
|
||||
mysqli_query($mysqli, "DELETE FROM recurring_payments WHERE recurring_payment_recurring_invoice_id = $recurring_invoice_id");
|
||||
$was_on = mysqli_affected_rows($mysqli) > 0;
|
||||
|
||||
logAudit("Recurring Invoice", "Auto Payment", "$session_contact_name removed Auto Pay for Recurring Invoice $recurring_invoice_prefix$recurring_invoice_number in the amount of " . billingMoney($recurring_invoice_amount, $recurring_invoice_currency_code), $session_client_id, $recurring_invoice_id);
|
||||
if ($was_on) {
|
||||
billingLog('recurring', $recurring_invoice_id, 'Autopay', 'Autopay turned off by ' . stripslashes($session_contact_name) . ' (' . stripslashes($session_contact_email) . ') in the client portal');
|
||||
}
|
||||
|
||||
flashAlert("Automatic payment turned off for recurring invoice $recurring_invoice_prefix$recurring_invoice_number");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user