From 73eeee175f911d7443d03c3354530e99164f0de8 Mon Sep 17 00:00:00 2001 From: Abubeker Yasin Date: Mon, 15 Jun 2026 11:26:51 +0300 Subject: [PATCH] Update payments.service.ts --- .../src/modules/payments/payments.service.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/apps/edr-passenger-api/src/modules/payments/payments.service.ts b/apps/edr-passenger-api/src/modules/payments/payments.service.ts index fe80ae88e..59438c4ad 100644 --- a/apps/edr-passenger-api/src/modules/payments/payments.service.ts +++ b/apps/edr-passenger-api/src/modules/payments/payments.service.ts @@ -43,6 +43,14 @@ const NON_TERMINAL_STATUSES: PaymentIntentStatus[] = [ export class PaymentsService { private readonly logger = new Logger(PaymentsService.name); + /** + * DEMO ONLY: when true, a WALLET "payment" is treated as instantly successful — the wallet + * balance check and debit are skipped and the booking is confirmed + ticket issued as if fully + * paid. Lets the happy-path be demoed while a real provider (e.g. Telebirr) is unavailable. + * Never enable in production. Toggle with WALLET_DEMO_AUTO_SUCCEED in the env. + */ + private readonly walletDemoAutoSucceed = true; + constructor( private prisma: PrismaService, private seatsService: SeatsService, @@ -196,6 +204,35 @@ export class PaymentsService { private async initiateWalletPayment( booking: Prisma.BookingGetPayload<{ include: { seats: true } }>, ): Promise { + // DEMO ONLY (WALLET_DEMO_AUTO_SUCCEED): pretend the payment succeeded — no balance check, + // no debit — and run the exact same finalize path a real successful payment uses + // (booking → CONFIRMED, seats confirmed, ticket issued). Remove once a real provider works. + if (this.walletDemoAutoSucceed) { + this.logger.warn( + `WALLET_DEMO_AUTO_SUCCEED enabled — faking a successful WALLET payment for booking ${booking.bookingRef} (${booking.id})`, + ); + const demoIntent = await this.prisma.paymentIntent.upsert({ + where: { bookingId: booking.id }, + update: { + status: PaymentIntentStatus.PROCESSING, + failureCode: null, + method: PaymentMethodType.WALLET, + }, + create: { + bookingId: booking.id, + amountMinor: booking.totalMinor, + method: PaymentMethodType.WALLET, + status: PaymentIntentStatus.PROCESSING, + providerRef: `WALLET-DEMO-${Date.now()}`, + }, + }); + await this.finalizePaymentSuccess({ intentId: demoIntent.id }); + const settled = await this.prisma.paymentIntent.findUniqueOrThrow({ + where: { id: demoIntent.id }, + }); + return this.formatIntentResponse(settled); + } + const debitResult = await this.prisma.$transaction(async (tx) => { const wallet = await tx.walletAccount.findUnique({ where: { passengerId: booking.passengerId },