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:
@@ -420,6 +420,41 @@ if (isset($_POST['set_recurring_payment'])) {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Whether a recurring invoice's invoices offer the client autopay while it
|
||||
* has none - its switch in the Autopay card (autopayOffer(),
|
||||
* functions/billing_pay.php).
|
||||
*/
|
||||
if (isset($_POST['set_recurring_offer_autopay'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_sales', 2);
|
||||
|
||||
$recurring_invoice_id = intval($_POST['recurring_invoice_id'] ?? 0);
|
||||
$recurring = billingRow('recurring', $recurring_invoice_id);
|
||||
if (!$recurring || !array_key_exists('recurring_invoice_offer_autopay', $recurring)) {
|
||||
flashAlert('That recurring invoice no longer exists.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$client_id = intval($recurring['recurring_invoice_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
$offer = empty($_POST['offer_autopay']) ? 0 : 1;
|
||||
$number = billingNumber('recurring', $recurring);
|
||||
if ($offer !== intval($recurring['recurring_invoice_offer_autopay'])) {
|
||||
mysqli_query($mysqli, "UPDATE recurring_invoices SET recurring_invoice_offer_autopay = $offer WHERE recurring_invoice_id = $recurring_invoice_id");
|
||||
billingLog('recurring', $recurring_invoice_id, 'Autopay', ($offer ? 'Autopay offered to the client again' : 'Autopay no longer offered to the client') . ' - by ' . stripslashes($session_name));
|
||||
logAudit("Recurring Invoice", "Edit", "$session_name " . ($offer ? 'turned on' : 'turned off') . " offering autopay for recurring invoice " . escapeSql($number), $client_id, $recurring_invoice_id);
|
||||
}
|
||||
|
||||
flashAlert($offer ? 'Invoices from <strong>' . escapeHtml($number) . '</strong> offer the client autopay' : 'Invoices from <strong>' . escapeHtml($number) . "</strong> no longer offer the client autopay");
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isExportRequest('export_recurring_invoices')) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
@@ -89,6 +89,10 @@ while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$autopay_id = intval($recurring['recurring_payment_saved_payment_id'] ?? 0);
|
||||
// The card fee autopay adds, when the client pays one (functions/billing_pay.php)
|
||||
$autopay_fee = billingCardFeeFor($client_id);
|
||||
// Autopay offered to the client in each invoice's email and on its page, while it has none - its switch, and why it isn't offered now when it isn't
|
||||
$offer_switch = array_key_exists('recurring_invoice_offer_autopay', $recurring) && !$autopay_id && billingStripeProvider();
|
||||
$offer_on = intval($recurring['recurring_invoice_offer_autopay'] ?? 0) === 1;
|
||||
$offer_blocked = $offer_switch ? autopayOfferBlocked($recurring) : '';
|
||||
|
||||
// Override Tab Title // No Sanitizing needed as this var will only be used in the tab title
|
||||
$tab_title = $recurring['client_name'];
|
||||
@@ -381,7 +385,27 @@ echo agentBannersHtml($client_id);
|
||||
</form>
|
||||
<div class="form-text"><?= $autopay_id ? 'Charged on the due date of each invoice it makes.' : 'Charge a card on file on the due date of each invoice it makes.' ?><?= $autopay_fee ? ' With the ' . escapeHtml(billingCardFeeText($autopay_fee, $recurring['recurring_invoice_currency_code'] ?? '')) . ' card fee, as a line on the invoice.' : '' ?></div>
|
||||
<?php } else { ?>
|
||||
<div class="small text-body-secondary">No card on file for <?= escapeHtml($recurring['client_name']) ?>. Once they save one paying an invoice online, it can be charged here automatically.</div>
|
||||
<div class="small text-body-secondary">No card on file for <?= escapeHtml($recurring['client_name']) ?>. Once they save one, it can be charged here automatically.</div>
|
||||
<?php } ?>
|
||||
<?php if ($offer_switch) { ?>
|
||||
<form action="post.php" method="post" class="border-top mt-3 pt-3" data-offer-autopay>
|
||||
<input type="hidden" name="csrf_token" value="<?= $csrf ?>">
|
||||
<input type="hidden" name="set_recurring_offer_autopay" value="1">
|
||||
<input type="hidden" name="recurring_invoice_id" value="<?= $recurring_invoice_id ?>">
|
||||
<div class="form-check form-switch mb-1">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="offerAutopay" name="offer_autopay" value="1" onchange="this.form.submit()" <?= $offer_on ? 'checked' : '' ?> <?= $can_edit ? '' : 'disabled' ?>>
|
||||
<label class="form-check-label" for="offerAutopay">Offer autopay to the client</label>
|
||||
</div>
|
||||
<div class="form-text mt-0">
|
||||
<?php if (!$offer_on) { ?>
|
||||
Off - its invoices don't ask the client to set up autopay.
|
||||
<?php } elseif ($offer_blocked !== '') { ?>
|
||||
Not offered just now - <?= escapeHtml(lcfirst($offer_blocked)) ?>.
|
||||
<?php } else { ?>
|
||||
Each invoice it makes has a Set up autopay button, in its email and on its page - the client adds a card and turns autopay on, with no sign-in.
|
||||
<?php } ?>
|
||||
</div>
|
||||
</form>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user