Stop auto-failing manual payments (TPago/bank/cash) after the pending TTL.
Exclude manual providers from booking cleanup, hold them via the 72h sweep instead, and let admins reopen failed payments to pending. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -5,11 +5,20 @@
|
||||
// abandoned checkout would otherwise hold those seats forever. This job cancels
|
||||
// pending tickets whose payment is still 'pending' (i.e. never paid and not
|
||||
// awaiting admin approval) after a configurable TTL, freeing the seats.
|
||||
//
|
||||
// Two exclusions:
|
||||
// - Manual-verification providers (bank transfer / TPago / cash) are never
|
||||
// auto-failed; they are settled by an admin and instead follow the 72h on-hold
|
||||
// sweep. See holdSweep.ts and MANUAL_PAYMENT_PROVIDERS.
|
||||
// - Staleness is measured from `updatedAt`, not `createdAt`, so an admin action
|
||||
// (e.g. reopening a payment to 'pending' via /reopen) restarts the TTL rather
|
||||
// than being immediately re-failed on the next run.
|
||||
|
||||
import { and, eq, lt, inArray } from 'drizzle-orm';
|
||||
import { and, eq, lt, inArray, notInArray } from 'drizzle-orm';
|
||||
import { db, dbAll, tickets, payments } from '../db/index.js';
|
||||
import { getNow, toDbDate } from './utils.js';
|
||||
import { getLock } from './stores/lock.js';
|
||||
import { MANUAL_PAYMENT_PROVIDERS } from './manualProviders.js';
|
||||
|
||||
function getTtlMs(): number {
|
||||
const minutes = parseInt(process.env.PENDING_BOOKING_TTL_MINUTES || '30', 10);
|
||||
@@ -20,8 +29,9 @@ function getTtlMs(): number {
|
||||
* Cancel stale pending bookings. Returns the number of tickets cancelled.
|
||||
*
|
||||
* A booking is considered stale when its payment is still 'pending' (not
|
||||
* 'pending_approval', which means an admin is reviewing a manual transfer) and
|
||||
* older than PENDING_BOOKING_TTL_MINUTES.
|
||||
* 'pending_approval', which means an admin is reviewing a manual transfer),
|
||||
* uses a non-manual provider, and has not been touched (updatedAt) for
|
||||
* PENDING_BOOKING_TTL_MINUTES.
|
||||
*/
|
||||
export async function cleanupStalePendingBookings(): Promise<number> {
|
||||
const cutoff = toDbDate(new Date(Date.now() - getTtlMs()));
|
||||
@@ -35,7 +45,8 @@ export async function cleanupStalePendingBookings(): Promise<number> {
|
||||
.from(payments)
|
||||
.where(and(
|
||||
eq((payments as any).status, 'pending'),
|
||||
lt((payments as any).createdAt, cutoff)
|
||||
notInArray((payments as any).provider, [...MANUAL_PAYMENT_PROVIDERS]),
|
||||
lt((payments as any).updatedAt, cutoff)
|
||||
))
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user