Record Stripe fees every 15 minutes instead of once a night - a new Payment Provider Fees cron job runs the fee recorder that Nightly Tasks used to, Nightly Tasks no longer does, the recorder holds a lock so the job and Record fees now can't both record the same fee, and the payment provider screens no longer say fees are recorded each night

This commit is contained in:
johnnyq
2026-11-04 14:38:32 -05:00
parent 66d08c00be
commit e472c95a11
7 changed files with 104 additions and 27 deletions

View File

@@ -170,7 +170,7 @@ ob_start();
<input type="checkbox" class="form-check-input" name="record_fees" value="1" id="paymentProviderRecordFees" <?= $records_fees ? 'checked' : '' ?> data-provider-fees-switch>
<label class="form-check-label" for="paymentProviderRecordFees">Record its fees as expenses</label>
</div>
<div class="form-text ps-5">Each night, its fee on each card payment is recorded as an expense from the account above.</div>
<div class="form-text ps-5">Its fee on each card payment is recorded as an expense from the account above, a few minutes after Stripe settles the payment.</div>
</div>
<div data-provider-fees>

View File

@@ -8,7 +8,7 @@
* and how many are still to record), its saved cards and the autopay on
* them, and its card payments in the last 30 days. Check connection asks
* the provider whose account the key is; Record fees now does what the
* nightly run does. Add and Edit are one window
* Payment Provider Fees job does every few minutes. Add and Edit are one window
* (modals/payment_provider/payment_provider_edit.php); the rest are
* admin/post/payment_provider.php.
*/
@@ -155,7 +155,7 @@ $csrf = $_SESSION['csrf_token'];
<?php } ?>
<?php if ($activity['waiting']) { ?>
<span class="badge <?= $activity['stale'] ? 'bg-warning-subtle text-warning-emphasis border border-warning-subtle' : 'text-bg-light border' ?> fw-normal mt-1" data-provider-fees-waiting="<?= $activity['waiting'] ?>"
title="<?= $activity['stale'] ? 'Some are more than two days old - the nightly run should have had them' : 'The nightly run records them once Stripe has settled them' ?>"><?= $activity['waiting'] ?> to record</span>
title="<?= $activity['stale'] ? 'Some are more than two days old - the Payment Provider Fees job in Maintenance > Cron should have had them' : 'Recorded a few minutes after Stripe settles them' ?>"><?= $activity['waiting'] ?> to record</span>
<?php } ?>
<?php } else { ?>
<span class="text-body-secondary">Not recorded</span>
@@ -187,7 +187,7 @@ $csrf = $_SESSION['csrf_token'];
<i class="fas fa-fw fa-plug text-secondary me-2"></i>Check connection
</a>
<?php if ($fees_on && $activity['waiting']) { ?>
<a class="dropdown-item" href="post.php?record_payment_provider_fees=<?= $provider_id ?>&csrf_token=<?= $csrf ?>" title="What the nightly run does - for the card payments whose fee is still to record">
<a class="dropdown-item" href="post.php?record_payment_provider_fees=<?= $provider_id ?>&csrf_token=<?= $csrf ?>" title="What the Payment Provider Fees job does every few minutes - for the card payments whose fee is still to record">
<i class="fas fa-fw fa-receipt text-secondary me-2"></i>Record fees now
</a>
<?php } ?>

View File

@@ -165,7 +165,7 @@ if (isset($_GET['check_payment_provider_connection'])) {
}
// Record fees now - what the nightly run does, for the payments whose fee is still to record
// Record fees now - what the Payment Provider Fees job does every few minutes, for the payments whose fee is still to record
if (isset($_GET['record_payment_provider_fees'])) {
validateCSRFToken();
@@ -182,6 +182,10 @@ if (isset($_GET['record_payment_provider_fees'])) {
}
$done = paymentProviderRecordFees($row);
if ($done['busy']) {
flashAlert('<strong>' . escapeHtml($name) . '</strong>\'s fees are being recorded right now by the scheduled run - look again in a minute', 'info');
redirect();
}
$said = [];
if ($done['recorded']) {
$said[] = 'Recorded its fee on ' . $done['recorded'] . ' payment' . ($done['recorded'] === 1 ? '' : 's') . ' - ' . paymentProviderMoneyText($done['amount']);