feat(SW-2116): Use refId instead of confirmationNumber
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
import { getBookingConfirmation } from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import BookingConfirmation from "@/components/HotelReservation/BookingConfirmation"
|
||||
@@ -6,9 +8,14 @@ import type { LangParams, PageArgs } from "@/types/params"
|
||||
|
||||
export default async function BookingConfirmationPage({
|
||||
searchParams,
|
||||
}: PageArgs<LangParams, { confirmationNumber: string }>) {
|
||||
void getBookingConfirmation(searchParams.confirmationNumber)
|
||||
return (
|
||||
<BookingConfirmation confirmationNumber={searchParams.confirmationNumber} />
|
||||
)
|
||||
}: PageArgs<LangParams, { RefId?: string }>) {
|
||||
const refId = searchParams.RefId
|
||||
|
||||
if (!refId) {
|
||||
notFound()
|
||||
}
|
||||
|
||||
void getBookingConfirmation(refId)
|
||||
|
||||
return <BookingConfirmation refId={refId} />
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ export default async function GuaranteePaymentCallbackPage({
|
||||
}: PageArgs<
|
||||
LangParams,
|
||||
{
|
||||
status: PaymentCallbackStatusEnum
|
||||
RefId: string
|
||||
status?: PaymentCallbackStatusEnum
|
||||
RefId?: string
|
||||
confirmationNumber?: string
|
||||
ancillary?: string
|
||||
}
|
||||
@@ -30,7 +30,7 @@ export default async function GuaranteePaymentCallbackPage({
|
||||
const status = searchParams.status
|
||||
const confirmationNumber = searchParams.confirmationNumber
|
||||
const refId = searchParams.RefId
|
||||
if (!refId) {
|
||||
if (!status || !confirmationNumber || !refId) {
|
||||
notFound()
|
||||
}
|
||||
const isAncillaryFlow = searchParams.ancillary
|
||||
@@ -43,6 +43,7 @@ export default async function GuaranteePaymentCallbackPage({
|
||||
return (
|
||||
<GuaranteeCallback
|
||||
returnUrl={myStayUrl}
|
||||
refId={refId}
|
||||
confirmationNumber={confirmationNumber}
|
||||
lang={lang}
|
||||
/>
|
||||
@@ -54,10 +55,10 @@ export default async function GuaranteePaymentCallbackPage({
|
||||
|
||||
let errorMessage = undefined
|
||||
|
||||
if (confirmationNumber) {
|
||||
if (refId) {
|
||||
try {
|
||||
const bookingStatus = await serverClient().booking.status({
|
||||
confirmationNumber,
|
||||
refId,
|
||||
})
|
||||
|
||||
const error = bookingStatus.errors.find((e) => e.errorCode)
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
getProfileSafely,
|
||||
getSavedPaymentCardsSafely,
|
||||
} from "@/lib/trpc/memoizedRequests"
|
||||
import { decrypt } from "@/server/routers/utils/encryption"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
import AdditionalInfoForm from "@/components/HotelReservation/FindMyBooking/AdditionalInfoForm"
|
||||
@@ -35,6 +34,7 @@ import Image from "@/components/Image"
|
||||
import { getIntl } from "@/i18n"
|
||||
import { setLang } from "@/i18n/serverContext"
|
||||
import MyStayProvider from "@/providers/MyStay"
|
||||
import { parseRefId } from "@/utils/refId"
|
||||
import { isValidSession } from "@/utils/session"
|
||||
import { getCurrentWebUrl } from "@/utils/url"
|
||||
|
||||
@@ -54,19 +54,18 @@ export default async function MyStay({
|
||||
notFound()
|
||||
}
|
||||
|
||||
const value = decrypt(refId)
|
||||
if (!value) {
|
||||
const { confirmationNumber, lastName } = parseRefId(refId)
|
||||
if (!confirmationNumber) {
|
||||
return notFound()
|
||||
}
|
||||
|
||||
const session = await auth()
|
||||
const isLoggedIn = isValidSession(session)
|
||||
|
||||
const [confirmationNumber, lastName] = value.split(",")
|
||||
const bv = cookies().get("bv")?.value
|
||||
let bookingConfirmation
|
||||
if (isLoggedIn) {
|
||||
bookingConfirmation = await getBookingConfirmation(confirmationNumber)
|
||||
bookingConfirmation = await getBookingConfirmation(refId)
|
||||
} else if (bv) {
|
||||
const params = new URLSearchParams(bv)
|
||||
const firstName = params.get("firstName")
|
||||
@@ -113,9 +112,7 @@ export default async function MyStay({
|
||||
const fromDate = dt(booking.checkInDate).format("YYYY-MM-DD")
|
||||
const toDate = dt(booking.checkOutDate).format("YYYY-MM-DD")
|
||||
|
||||
const linkedReservationsPromise = getLinkedReservations({
|
||||
rooms: booking.linkedReservations,
|
||||
})
|
||||
const linkedReservationsPromise = getLinkedReservations(booking.refId)
|
||||
|
||||
const ancillariesInput = {
|
||||
fromDate,
|
||||
@@ -187,7 +184,7 @@ export default async function MyStay({
|
||||
breakfastPackages={breakfastPackages}
|
||||
lang={params.lang}
|
||||
linkedReservationsPromise={linkedReservationsPromise}
|
||||
refId={refId}
|
||||
refId={booking.refId}
|
||||
roomCategories={roomCategories}
|
||||
savedCreditCards={savedCreditCards}
|
||||
>
|
||||
@@ -215,7 +212,6 @@ export default async function MyStay({
|
||||
packages={breakfastPackages}
|
||||
user={user}
|
||||
savedCreditCards={savedCreditCards}
|
||||
refId={refId}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
getProfileSafely,
|
||||
getSavedPaymentCardsSafely,
|
||||
} from "@/lib/trpc/memoizedRequests"
|
||||
import { decrypt } from "@/server/routers/utils/encryption"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
import AdditionalInfoForm from "@/components/HotelReservation/FindMyBooking/AdditionalInfoForm"
|
||||
@@ -35,6 +34,7 @@ import Image from "@/components/Image"
|
||||
import { getIntl } from "@/i18n"
|
||||
import { setLang } from "@/i18n/serverContext"
|
||||
import MyStayProvider from "@/providers/MyStay"
|
||||
import { parseRefId } from "@/utils/refId"
|
||||
import { isValidSession } from "@/utils/session"
|
||||
import { getCurrentWebUrl } from "@/utils/url"
|
||||
|
||||
@@ -54,18 +54,19 @@ export default async function MyStay({
|
||||
notFound()
|
||||
}
|
||||
|
||||
const value = decrypt(refId)
|
||||
if (!value) {
|
||||
const { confirmationNumber, lastName } = parseRefId(refId)
|
||||
|
||||
if (!confirmationNumber) {
|
||||
return notFound()
|
||||
}
|
||||
|
||||
const session = await auth()
|
||||
const isLoggedIn = isValidSession(session)
|
||||
|
||||
const [confirmationNumber, lastName] = value.split(",")
|
||||
const bv = cookies().get("bv")?.value
|
||||
let bookingConfirmation
|
||||
if (isLoggedIn) {
|
||||
bookingConfirmation = await getBookingConfirmation(confirmationNumber)
|
||||
bookingConfirmation = await getBookingConfirmation(refId)
|
||||
} else if (bv) {
|
||||
const params = new URLSearchParams(bv)
|
||||
const firstName = params.get("firstName")
|
||||
@@ -110,9 +111,7 @@ export default async function MyStay({
|
||||
const fromDate = dt(booking.checkInDate).format("YYYY-MM-DD")
|
||||
const toDate = dt(booking.checkOutDate).format("YYYY-MM-DD")
|
||||
|
||||
const linkedReservationsPromise = getLinkedReservations({
|
||||
rooms: booking.linkedReservations,
|
||||
})
|
||||
const linkedReservationsPromise = getLinkedReservations(booking.refId)
|
||||
|
||||
const ancillariesInput = {
|
||||
fromDate,
|
||||
@@ -184,7 +183,7 @@ export default async function MyStay({
|
||||
breakfastPackages={breakfastPackages}
|
||||
lang={params.lang}
|
||||
linkedReservationsPromise={linkedReservationsPromise}
|
||||
refId={refId}
|
||||
refId={booking.refId}
|
||||
roomCategories={roomCategories}
|
||||
savedCreditCards={savedCreditCards}
|
||||
>
|
||||
@@ -212,7 +211,6 @@ export default async function MyStay({
|
||||
packages={breakfastPackages}
|
||||
user={user}
|
||||
savedCreditCards={savedCreditCards}
|
||||
refId={refId}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user