Fixed hotelId in payment error events
This commit is contained in:
@@ -30,7 +30,6 @@ export default async function PaymentCallbackPage({
|
|||||||
const lang = params.lang
|
const lang = params.lang
|
||||||
const status = searchParams.status
|
const status = searchParams.status
|
||||||
const confirmationNumber = searchParams.confirmationNumber
|
const confirmationNumber = searchParams.confirmationNumber
|
||||||
const hotelId = searchParams.hotel
|
|
||||||
|
|
||||||
if (status === "success" && confirmationNumber) {
|
if (status === "success" && confirmationNumber) {
|
||||||
const confirmationUrl = `${bookingConfirmation(lang)}?${BOOKING_CONFIRMATION_NUMBER}=${confirmationNumber}`
|
const confirmationUrl = `${bookingConfirmation(lang)}?${BOOKING_CONFIRMATION_NUMBER}=${confirmationNumber}`
|
||||||
@@ -42,6 +41,8 @@ export default async function PaymentCallbackPage({
|
|||||||
const returnUrl = payment(lang)
|
const returnUrl = payment(lang)
|
||||||
const searchObject = new URLSearchParams()
|
const searchObject = new URLSearchParams()
|
||||||
|
|
||||||
|
let errorMessage = undefined
|
||||||
|
|
||||||
if (confirmationNumber) {
|
if (confirmationNumber) {
|
||||||
try {
|
try {
|
||||||
const bookingStatus = await serverClient().booking.status({
|
const bookingStatus = await serverClient().booking.status({
|
||||||
@@ -51,37 +52,26 @@ export default async function PaymentCallbackPage({
|
|||||||
// TODO: how to handle errors for multiple rooms?
|
// TODO: how to handle errors for multiple rooms?
|
||||||
const error = bookingStatus.errors.find((e) => e.errorCode)
|
const error = bookingStatus.errors.find((e) => e.errorCode)
|
||||||
|
|
||||||
|
errorMessage =
|
||||||
|
error?.description ??
|
||||||
|
`No error message found for booking ${confirmationNumber}, status: ${status}`
|
||||||
|
|
||||||
searchObject.set(
|
searchObject.set(
|
||||||
"errorCode",
|
"errorCode",
|
||||||
error
|
error
|
||||||
? error.errorCode.toString()
|
? error.errorCode.toString()
|
||||||
: PaymentErrorCodeEnum.Failed.toString()
|
: PaymentErrorCodeEnum.Failed.toString()
|
||||||
)
|
)
|
||||||
trackPaymentEvent({
|
|
||||||
event: "paymentFail",
|
|
||||||
hotelId,
|
|
||||||
errorMessage:
|
|
||||||
bookingStatus?.metadata?.errorMessage ??
|
|
||||||
`No error message found for booking ${confirmationNumber}, status: ${status}`,
|
|
||||||
})
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(
|
console.error(
|
||||||
`[payment-callback] failed to get booking status for ${confirmationNumber}, status: ${status}`
|
`[payment-callback] failed to get booking status for ${confirmationNumber}, status: ${status}`
|
||||||
)
|
)
|
||||||
if (status === "cancel") {
|
if (status === "cancel") {
|
||||||
searchObject.set("errorCode", PaymentErrorCodeEnum.Cancelled.toString())
|
searchObject.set("errorCode", PaymentErrorCodeEnum.Cancelled.toString())
|
||||||
trackPaymentEvent({
|
|
||||||
event: "paymentCancel",
|
|
||||||
hotelId,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if (status === "error") {
|
if (status === "error") {
|
||||||
searchObject.set("errorCode", PaymentErrorCodeEnum.Failed.toString())
|
searchObject.set("errorCode", PaymentErrorCodeEnum.Failed.toString())
|
||||||
trackPaymentEvent({
|
errorMessage = `Failed to get booking status for ${confirmationNumber}, status: ${status}`
|
||||||
event: "paymentFail",
|
|
||||||
hotelId,
|
|
||||||
errorMessage: `Failed to get booking status for ${confirmationNumber}, status: ${status}`,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,6 +80,8 @@ export default async function PaymentCallbackPage({
|
|||||||
<PaymentCallback
|
<PaymentCallback
|
||||||
returnUrl={returnUrl.toString()}
|
returnUrl={returnUrl.toString()}
|
||||||
searchObject={searchObject}
|
searchObject={searchObject}
|
||||||
|
status={status}
|
||||||
|
errorMessage={errorMessage}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,15 +7,20 @@ import { detailsStorageName } from "@/stores/enter-details"
|
|||||||
|
|
||||||
import { createQueryParamsForEnterDetails } from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
import { createQueryParamsForEnterDetails } from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
||||||
import LoadingSpinner from "@/components/LoadingSpinner"
|
import LoadingSpinner from "@/components/LoadingSpinner"
|
||||||
|
import { trackPaymentEvent } from "@/utils/tracking"
|
||||||
|
|
||||||
import type { PersistedState } from "@/types/stores/enter-details"
|
import type { PersistedState } from "@/types/stores/enter-details"
|
||||||
|
|
||||||
export default function PaymentCallback({
|
export default function PaymentCallback({
|
||||||
returnUrl,
|
returnUrl,
|
||||||
searchObject,
|
searchObject,
|
||||||
|
status,
|
||||||
|
errorMessage,
|
||||||
}: {
|
}: {
|
||||||
returnUrl: string
|
returnUrl: string
|
||||||
searchObject: URLSearchParams
|
searchObject: URLSearchParams
|
||||||
|
status: "error" | "success" | "cancel"
|
||||||
|
errorMessage?: string
|
||||||
}) {
|
}) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
@@ -29,11 +34,25 @@ export default function PaymentCallback({
|
|||||||
searchObject
|
searchObject
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (status === "cancel") {
|
||||||
|
trackPaymentEvent({
|
||||||
|
event: "paymentCancel",
|
||||||
|
hotelId: detailsStorage.booking.hotel,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (status === "error") {
|
||||||
|
trackPaymentEvent({
|
||||||
|
event: "paymentFail",
|
||||||
|
hotelId: detailsStorage.booking.hotel,
|
||||||
|
errorMessage,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (searchParams.size > 0) {
|
if (searchParams.size > 0) {
|
||||||
router.replace(`${returnUrl}?${searchParams.toString()}`)
|
router.replace(`${returnUrl}?${searchParams.toString()}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [returnUrl, router, searchObject])
|
}, [returnUrl, router, searchObject, status, errorMessage])
|
||||||
|
|
||||||
return <LoadingSpinner />
|
return <LoadingSpinner />
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user