diff --git a/packages/backend/src/open_payments/payment/outgoing/errors.ts b/packages/backend/src/open_payments/payment/outgoing/errors.ts index b8b6945a84..74b2fdffb8 100644 --- a/packages/backend/src/open_payments/payment/outgoing/errors.ts +++ b/packages/backend/src/open_payments/payment/outgoing/errors.ts @@ -110,5 +110,9 @@ export enum LifecycleError { MissingBalance = 'MissingBalance', MissingQuote = 'MissingQuote', MissingExpiration = 'MissingExpiration', - Unauthorized = 'Unauthorized' + Unauthorized = 'Unauthorized', + + // To be thrown when a Quote has expired + QuoteExpired = 'QuoteExpired' + } diff --git a/packages/backend/src/open_payments/payment/outgoing/lifecycle.ts b/packages/backend/src/open_payments/payment/outgoing/lifecycle.ts index 4f0034839a..47f76b1641 100644 --- a/packages/backend/src/open_payments/payment/outgoing/lifecycle.ts +++ b/packages/backend/src/open_payments/payment/outgoing/lifecycle.ts @@ -1,4 +1,4 @@ -import { LifecycleError } from './errors' +import { LifecycleError, OutgoingPaymentError } from './errors' import { OutgoingPayment, OutgoingPaymentState, @@ -17,6 +17,11 @@ export async function handleSending( ): Promise { if (!payment.quote) throw LifecycleError.MissingQuote + // Check if the current time is greater than or equal to when the Quote should be expiring + if (Date.now() >= payment.quote.expiresAt.getTime()) { + throw LifecycleError.QuoteExpired + } + const receiver = await deps.receiverService.get(payment.receiver) // TODO: Query TigerBeetle transfers by code to distinguish sending debits from withdrawals