feat(payment): add raw logs, IP/UA capture, exponential backoff, inventory hold, IPaymentGateway interface and admin health check
Deploy Canina / deploy (push) Successful in 1m53s

This commit is contained in:
parsa aghaei committed 2026-08-16 12:24:20 +03:30
1 parent 5ace474d71
commit 6e98b8779d
18 files changed
+11978 -9477

No files matched your search

+31
View File
@@ -244,6 +244,7 @@ export class OrdersService {
const isOnline = createOrderDto.paymentMethod === 'online';
const initialStatus = isOnline ? 'pending_payment' : 'processing';
const reservationExpiry = new Date(Date.now() + 15 * 60 * 1000); // 15 minutes hold
const createdOrder = await this.prisma.order.create({
data: {
@@ -260,11 +261,20 @@ export class OrdersService {
orderItems: {
create: orderItemsData,
},
inventoryReservations: {
create: orderItemsData.map((item) => ({
productId: item.productId,
quantity: item.quantity,
expiresAt: reservationExpiry,
status: isOnline ? 'ACTIVE' : 'CONSUMED',
})),
},
},
include: {
orderItems: {
include: { product: true },
},
inventoryReservations: true,
},
});
@@ -391,4 +401,25 @@ export class OrdersService {
}
}
}
/**
* Release inventory reservations that expired without successful payment
*/
async releaseExpiredInventoryReservations() {
const now = new Date();
const expiredReservations = await this.prisma.inventoryReservation.updateMany({
where: {
status: 'ACTIVE',
expiresAt: { lte: now },
},
data: {
status: 'RELEASED',
},
});
return {
releasedCount: expiredReservations.count,
executedAt: now,
};
}
}