Fix ticket generation

This commit is contained in:
Roba Boru
2026-07-21 14:52:17 +03:00
parent 3af0e70db5
commit 34563e078e
2 changed files with 16 additions and 4 deletions

View File

@@ -826,6 +826,19 @@ export class PaymentsService {
});
if (!intent) throw new NotFoundException("PaymentIntent not found");
if (intent.status === PaymentIntentStatus.SUCCEEDED) {
// Idempotency guard — but still repair missing tickets. They can be absent
// when the first finalization threw from generate() after the transaction
// committed: the caller got a 500, retried, and now hits this early-return.
const ticketCount = await this.prisma.ticket.count({ where: { bookingId: intent.bookingId } });
if (ticketCount === 0) {
try {
await this.ticketsService.generate(intent.bookingId);
} catch (err) {
this.logger.error(
`Error generating ticket on idempotency retry for booking ${intent.bookingId}: ${err instanceof Error ? err.message : String(err)}`,
);
}
}
return { alreadyFinalized: true };
}
if (intent.status === PaymentIntentStatus.CANCELLED) {
@@ -877,9 +890,8 @@ export class PaymentsService {
await this.ticketsService.generate(booking.id);
} catch (err) {
this.logger.error(
`Error generating ticket: ${err instanceof Error ? err.message : String(err)}`,
`Error generating ticket for booking ${booking.id}: ${err instanceof Error ? err.message : String(err)}`,
);
throw err;
}
try {