feat(SW-1259): Enter details multiroom * refactor: remove per-step URLs * WIP: map multiroom data * fix: lint errors in details page * fix: made useEnterDetailsStore tests pass * fix: WIP refactor enter details store * fix: WIP enter details store update * fix: added room index to select correct room * fix: added logic for navigating between steps and rooms * fix: update summary to work with store changes * fix: added room and total price calculation * fix: removed unused code and added test for breakfast included * refactor: move store selectors into helpers * refactor: session storage state for multiroom booking * feat: update enter details accordion navigation * fix: added room index to each form component so they select correct room * fix: added unique id to input to handle case when multiple inputs have same name * fix: update payment step with store changes * fix: rebase issues * fix: now you should only be able to go to a step if previous room is completed * refactor: cleanup * fix: if no availability just skip that room for now * fix: add select-rate Summary and adjust typings Approved-by: Arvid Norlin
88 lines
2.4 KiB
TypeScript
88 lines
2.4 KiB
TypeScript
import { redirect } from "next/navigation"
|
|
|
|
import {
|
|
BOOKING_CONFIRMATION_NUMBER,
|
|
PaymentErrorCodeEnum,
|
|
} from "@/constants/booking"
|
|
import {
|
|
bookingConfirmation,
|
|
details,
|
|
} from "@/constants/routes/hotelReservation"
|
|
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"
|
|
|
|
export default async function PaymentCallbackPage({
|
|
params,
|
|
searchParams,
|
|
}: PageArgs<
|
|
LangParams,
|
|
{
|
|
status: "error" | "success" | "cancel"
|
|
confirmationNumber?: string
|
|
hotel?: string
|
|
}
|
|
>) {
|
|
console.log(`[payment-callback] callback started`)
|
|
const lang = params.lang
|
|
const status = searchParams.status
|
|
const confirmationNumber = searchParams.confirmationNumber
|
|
|
|
if (status === "success" && confirmationNumber) {
|
|
const confirmationUrl = `${bookingConfirmation(lang)}?${BOOKING_CONFIRMATION_NUMBER}=${confirmationNumber}`
|
|
|
|
console.log(`[payment-callback] redirecting to: ${confirmationUrl}`)
|
|
redirect(confirmationUrl)
|
|
}
|
|
|
|
const returnUrl = details(lang)
|
|
const searchObject = new URLSearchParams()
|
|
|
|
let errorMessage = undefined
|
|
|
|
if (confirmationNumber) {
|
|
try {
|
|
const bookingStatus = await serverClient().booking.status({
|
|
confirmationNumber,
|
|
})
|
|
|
|
// TODO: how to handle errors for multiple rooms?
|
|
const error = bookingStatus.errors.find((e) => e.errorCode)
|
|
|
|
errorMessage =
|
|
error?.description ??
|
|
`No error message found for booking ${confirmationNumber}, status: ${status}`
|
|
|
|
searchObject.set(
|
|
"errorCode",
|
|
error
|
|
? error.errorCode.toString()
|
|
: PaymentErrorCodeEnum.Failed.toString()
|
|
)
|
|
} catch (error) {
|
|
console.error(
|
|
`[payment-callback] failed to get booking status for ${confirmationNumber}, status: ${status}`
|
|
)
|
|
if (status === "cancel") {
|
|
searchObject.set("errorCode", PaymentErrorCodeEnum.Cancelled.toString())
|
|
}
|
|
if (status === "error") {
|
|
searchObject.set("errorCode", PaymentErrorCodeEnum.Failed.toString())
|
|
errorMessage = `Failed to get booking status for ${confirmationNumber}, status: ${status}`
|
|
}
|
|
}
|
|
}
|
|
|
|
return (
|
|
<PaymentCallback
|
|
returnUrl={returnUrl.toString()}
|
|
searchObject={searchObject}
|
|
status={status}
|
|
errorMessage={errorMessage}
|
|
/>
|
|
)
|
|
}
|