feat(SW-2116): Use refId instead of confirmationNumber
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
import {
|
||||
BOOKING_CONFIRMATION_NUMBER,
|
||||
BookingErrorCodeEnum,
|
||||
PaymentCallbackStatusEnum,
|
||||
} from "@/constants/booking"
|
||||
@@ -8,7 +9,10 @@ import {
|
||||
details,
|
||||
} from "@/constants/routes/hotelReservation"
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
import { getBooking } from "@/server/routers/booking/utils"
|
||||
import { getServiceToken } from "@/server/tokenManager"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
import HandleErrorCallback from "@/components/HotelReservation/EnterDetails/Payment/PaymentCallback/HandleErrorCallback"
|
||||
import HandleSuccessCallback from "@/components/HotelReservation/EnterDetails/Payment/PaymentCallback/HandleSuccessCallback"
|
||||
|
||||
@@ -20,7 +24,7 @@ export default async function PaymentCallbackPage({
|
||||
}: PageArgs<
|
||||
LangParams,
|
||||
{
|
||||
status: PaymentCallbackStatusEnum
|
||||
status?: PaymentCallbackStatusEnum
|
||||
confirmationNumber?: string
|
||||
hotel?: string
|
||||
}
|
||||
@@ -30,15 +34,42 @@ export default async function PaymentCallbackPage({
|
||||
const status = searchParams.status
|
||||
const confirmationNumber = searchParams.confirmationNumber
|
||||
|
||||
if (!status || !confirmationNumber) {
|
||||
notFound()
|
||||
}
|
||||
|
||||
let token = ""
|
||||
const session = await auth()
|
||||
if (session) {
|
||||
token = session.token.access_token
|
||||
} else {
|
||||
const serviceToken = await getServiceToken()
|
||||
if (serviceToken) {
|
||||
token = serviceToken.access_token
|
||||
}
|
||||
}
|
||||
|
||||
if (!token) {
|
||||
notFound()
|
||||
}
|
||||
|
||||
const booking = await getBooking(confirmationNumber, params.lang, token)
|
||||
|
||||
if (!booking) {
|
||||
notFound()
|
||||
}
|
||||
|
||||
const { refId } = booking
|
||||
|
||||
if (status === PaymentCallbackStatusEnum.Success && confirmationNumber) {
|
||||
const confirmationUrl = `${bookingConfirmation(lang)}?${BOOKING_CONFIRMATION_NUMBER}=${confirmationNumber}`
|
||||
const confirmationUrl = `${bookingConfirmation(lang)}?RefId=${encodeURIComponent(refId)}`
|
||||
console.log(
|
||||
`[payment-callback] rendering success callback with confirmation number: ${confirmationNumber}`
|
||||
)
|
||||
|
||||
return (
|
||||
<HandleSuccessCallback
|
||||
confirmationNumber={confirmationNumber}
|
||||
refId={refId}
|
||||
successRedirectUrl={confirmationUrl}
|
||||
/>
|
||||
)
|
||||
@@ -49,10 +80,10 @@ export default async function PaymentCallbackPage({
|
||||
|
||||
let errorMessage = undefined
|
||||
|
||||
if (confirmationNumber) {
|
||||
if (refId) {
|
||||
try {
|
||||
const bookingStatus = await serverClient().booking.status({
|
||||
confirmationNumber,
|
||||
refId,
|
||||
})
|
||||
|
||||
// TODO: how to handle errors for multiple rooms?
|
||||
|
||||
Reference in New Issue
Block a user