Saved cards expiring: each night cards expiring next month or lately are read back from Stripe so a card the bank replaced keeps its new expiry, and for each card on autopay for an active recurring invoice the client's primary and billing contacts are emailed a month before the month it expires and again in it (once just after, within 60 days, for one that ran out unannounced) with an Add your new card link that needs no sign-in and puts the new card in place of the old on every recurring invoice it paid, the team gets a Card Expiring notification each time and an Autopay Failed notification with Stripe's reason when an autopay charge doesn't go through, the portal no longer turns away a card Stripe has renewed, Settings > Invoices > Paid online can turn the client emails off and Saved Cards shows when each card was checked and when the team was told (DB 4.3.8, functions/card_expiry.php, guest/guest_card_update.php); 26.12.4 changelog

This commit is contained in:
johnnyq
2026-12-01 21:22:51 -05:00
parent 19c09b670c
commit 8b2426c841
16 changed files with 828 additions and 10 deletions

View File

@@ -0,0 +1,38 @@
<?php
/*
* ITFlow - Database update to version 4.3.8 (from 4.3.7)
* Included by admin/database_updates.php - do not access directly
*
* settings.config_invoice_card_expiry_reminders - whether a client whose card on autopay is about to run out is
* emailed, a month before and again in the month it runs out, with a link to add their new card with no
* sign-in (1, Settings > Invoices > Paid online). The team is notified either way (functions/card_expiry.php).
* client_saved_payment_methods.saved_payment_checked_at - when the card was last read back from Stripe, which
* keeps a card the bank replaced up to date.
* client_saved_payment_methods.saved_payment_reminded_expiry and saved_payment_reminded - the expiry (yyyymm)
* the reminders went out for, and which: 1 a month before, 2 in the month it runs out. A new expiry starts again.
* client_saved_payment_methods.saved_payment_update_key - the key in the link the reminder sends, which opens
* guest/guest_card_update.php for that card. Cleared once the card is replaced.
*
* Re-runnable: each column is made only where it isn't there.
*/
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
$itflow_card_columns = [
['settings', 'config_invoice_card_expiry_reminders', "tinyint(1) NOT NULL DEFAULT 1", 'config_invoice_offer_autopay'],
['client_saved_payment_methods', 'saved_payment_checked_at', "datetime DEFAULT NULL", 'saved_payment_updated_at'],
['client_saved_payment_methods', 'saved_payment_reminded_expiry', "int(11) DEFAULT NULL", 'saved_payment_checked_at'],
['client_saved_payment_methods', 'saved_payment_reminded', "tinyint(1) NOT NULL DEFAULT 0", 'saved_payment_reminded_expiry'],
['client_saved_payment_methods', 'saved_payment_update_key', "varchar(64) DEFAULT NULL", 'saved_payment_reminded'],
];
foreach ($itflow_card_columns as [$itflow_table, $itflow_column, $itflow_type, $itflow_after]) {
$itflow_exists = mysqli_query($mysqli, "SELECT 1 FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '$itflow_table' AND COLUMN_NAME = '$itflow_column' LIMIT 1");
if (!$itflow_exists || mysqli_num_rows($itflow_exists) === 0) {
$itflow_after_exists = mysqli_query($mysqli, "SELECT 1 FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '$itflow_table' AND COLUMN_NAME = '$itflow_after' LIMIT 1");
$itflow_place = $itflow_after_exists && mysqli_num_rows($itflow_after_exists) > 0 ? " AFTER `$itflow_after`" : '';
mysqli_query($mysqli, "ALTER TABLE `$itflow_table` ADD `$itflow_column` $itflow_type$itflow_place");
}
}