Handle payment fail and cancel events

This commit is contained in:
Linus Flood
2025-01-08 15:02:03 +01:00
parent 20714d0c3b
commit 5889bdd79d
3 changed files with 51 additions and 21 deletions

View File

@@ -11,6 +11,7 @@ import {
import { serverClient } from "@/lib/trpc/server"
import PaymentCallback from "@/components/HotelReservation/EnterDetails/Payment/PaymentCallback"
import { trackPaymentEvent } from "@/utils/tracking"
import type { LangParams, PageArgs } from "@/types/params"
@@ -47,15 +48,31 @@ export default async function PaymentCallbackPage({
? bookingStatus.metadata.errorCode.toString()
: PaymentErrorCodeEnum.Failed.toString()
)
trackPaymentEvent({
event: "paymentFail",
hotelId: searchObject.get("hotel"),
errorMessage:
bookingStatus?.metadata?.errorMessage ??
`No error message found for booking ${confirmationNumber}, status: ${status}`,
})
} catch (error) {
console.error(
`[payment-callback] failed to get booking status for ${confirmationNumber}, status: ${status}`
)
if (status === "cancel") {
searchObject.set("errorCode", PaymentErrorCodeEnum.Cancelled.toString())
trackPaymentEvent({
event: "paymentCancel",
hotelId: searchObject.get("hotel"),
})
}
if (status === "error") {
searchObject.set("errorCode", PaymentErrorCodeEnum.Failed.toString())
trackPaymentEvent({
event: "paymentFail",
hotelId: searchObject.get("hotel"),
errorMessage: `Failed to get booking status for ${confirmationNumber}, status: ${status}`,
})
}
}
}