fix email sender all flow
This commit is contained in:
@@ -183,6 +183,10 @@ async function applyGatewayStatus(
|
||||
if (newStatus === "PAID" && !isConflict) {
|
||||
void notifyPaymentPaid(payment.id);
|
||||
}
|
||||
// E3.3 — pembayaran kadaluarsa/gagal: kabari user supaya bisa retry.
|
||||
if (newStatus === "EXPIRED" || newStatus === "FAILED") {
|
||||
void notifyPaymentFailed(payment.id);
|
||||
}
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
@@ -504,6 +508,35 @@ async function notifyPaymentPaid(paymentId: string) {
|
||||
});
|
||||
}
|
||||
|
||||
/** E3.3 — kabari user kalau pembayaran expired/gagal supaya bisa retry. */
|
||||
async function notifyPaymentFailed(paymentId: string) {
|
||||
const payment = await prisma.payment.findUnique({
|
||||
where: { id: paymentId },
|
||||
include: {
|
||||
booking: {
|
||||
include: {
|
||||
user: { select: { email: true, name: true } },
|
||||
trip: { select: { id: true, title: true } },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!payment) return;
|
||||
await emailService.send({
|
||||
to: payment.booking.user.email,
|
||||
idempotencyKey: `payment_expired-${payment.id}`,
|
||||
template: {
|
||||
template: "payment_expired",
|
||||
data: {
|
||||
userName: payment.booking.user.name,
|
||||
tripTitle: payment.booking.trip.title,
|
||||
tripId: payment.booking.trip.id,
|
||||
amount: payment.amount,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Re-export untuk testing langsung kalau perlu (tetap private dari modul lain).
|
||||
export const _internal = { applyGatewayStatus };
|
||||
export type { MidtransTransactionStatus };
|
||||
|
||||
Reference in New Issue
Block a user