mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 11:21:18 +00:00
fix: (passenger): block payment initiation too close to the booking deadline
This commit is contained in:
@@ -13,11 +13,17 @@ export const MAX_PAYMENT_HOURS = 2;
|
||||
export const CUTOFF_MINUTES = 30;
|
||||
|
||||
/**
|
||||
* payment_deadline = MIN(booking_time + MAX_PAYMENT_HOURS, segment_departure - checkinMinutes)
|
||||
*
|
||||
* checkinMinutes defaults to CUTOFF_MINUTES but callers should pass the route-level
|
||||
* checkinMinutesBefore so that each route's own window is respected.
|
||||
* How long a passenger is given to finish one provider payment session, once opened.
|
||||
* 5 minutes of actual paying (redirect → PIN/OTP → provider callback) + 1 minute of slack.
|
||||
*/
|
||||
export const PAYMENT_SESSION_MINUTES = 6;
|
||||
|
||||
|
||||
export const MIN_PAYMENT_WINDOW_MINUTES = 7;
|
||||
|
||||
export const PAYMENT_SETTLE_MARGIN_SECONDS = 60;
|
||||
|
||||
|
||||
export function computePaymentDeadline(
|
||||
createdAt: Date,
|
||||
departureAt: Date,
|
||||
@@ -27,3 +33,19 @@ export function computePaymentDeadline(
|
||||
const cutoffDeadline = new Date(departureAt.getTime() - checkinMinutes * 60 * 1000);
|
||||
return maxDeadline < cutoffDeadline ? maxDeadline : cutoffDeadline;
|
||||
}
|
||||
|
||||
|
||||
export function canOpenPaymentSession(
|
||||
paymentDeadline: Date,
|
||||
now: Date = new Date(),
|
||||
): boolean {
|
||||
return paymentDeadline.getTime() - now.getTime() >= MIN_PAYMENT_WINDOW_MINUTES * 60 * 1000;
|
||||
}
|
||||
|
||||
export function computePaymentSessionExpiry(
|
||||
paymentDeadline: Date,
|
||||
now: Date = new Date(),
|
||||
): Date {
|
||||
const sessionEnd = new Date(now.getTime() + PAYMENT_SESSION_MINUTES * 60 * 1000);
|
||||
return sessionEnd < paymentDeadline ? sessionEnd : paymentDeadline;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user