feat(SW-2116): Use refId instead of confirmationNumber

This commit is contained in:
Michael Zetterberg
2025-05-04 11:11:15 +02:00
parent f681fa7675
commit b910b6a313
59 changed files with 491 additions and 310 deletions

View File

@@ -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)

View File

@@ -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?