Merged in revert-pr-1925 (pull request #1927)
Revert "Feat/sw 2323 find booking (pull request #1925)" Approved-by: Anton Gunnarsson
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
import {
|
||||
BookingErrorCodeEnum,
|
||||
PaymentCallbackStatusEnum,
|
||||
} from "@/constants/booking"
|
||||
import { details } from "@/constants/routes/hotelReservation"
|
||||
|
||||
import HandleErrorCallback from "@/components/HotelReservation/EnterDetails/Payment/PaymentCallback/HandleErrorCallback"
|
||||
|
||||
import type { LangParams, PageArgs } from "@/types/params"
|
||||
|
||||
export default async function PaymentCallbackCancelPage({
|
||||
params,
|
||||
}: PageArgs<LangParams>) {
|
||||
console.log(`[payment-callback] cancel callback started`)
|
||||
const lang = params.lang
|
||||
|
||||
const returnUrl = details(lang)
|
||||
const searchObject = new URLSearchParams()
|
||||
|
||||
searchObject.set("errorCode", BookingErrorCodeEnum.TransactionCancelled)
|
||||
|
||||
return (
|
||||
<HandleErrorCallback
|
||||
returnUrl={returnUrl.toString()}
|
||||
searchObject={searchObject}
|
||||
status={PaymentCallbackStatusEnum.Cancel}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
import {
|
||||
BookingErrorCodeEnum,
|
||||
PaymentCallbackStatusEnum,
|
||||
} from "@/constants/booking"
|
||||
import { details } from "@/constants/routes/hotelReservation"
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
|
||||
import HandleErrorCallback from "@/components/HotelReservation/EnterDetails/Payment/PaymentCallback/HandleErrorCallback"
|
||||
import { calculateRefId } from "@/utils/refId"
|
||||
|
||||
import type { LangParams, PageArgs } from "@/types/params"
|
||||
|
||||
export default async function PaymentCallbackErrorPage({
|
||||
params,
|
||||
searchParams,
|
||||
}: PageArgs<
|
||||
LangParams,
|
||||
{
|
||||
confirmationNumber?: string
|
||||
}
|
||||
>) {
|
||||
console.log(`[payment-callback] error callback started`)
|
||||
|
||||
const lang = params.lang
|
||||
const confirmationNumber = searchParams.confirmationNumber
|
||||
|
||||
const returnUrl = details(lang)
|
||||
const searchObject = new URLSearchParams()
|
||||
|
||||
let errorMessage = undefined
|
||||
|
||||
if (confirmationNumber) {
|
||||
const refId = calculateRefId(confirmationNumber, "")
|
||||
|
||||
try {
|
||||
const bookingStatus = await serverClient().booking.confirmationError({
|
||||
refId,
|
||||
})
|
||||
|
||||
// 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}`
|
||||
|
||||
searchObject.set(
|
||||
"errorCode",
|
||||
error
|
||||
? error.errorCode.toString()
|
||||
: BookingErrorCodeEnum.TransactionFailed
|
||||
)
|
||||
} catch {
|
||||
console.error(
|
||||
`[payment-callback] failed to get booking status for ${confirmationNumber}`
|
||||
)
|
||||
|
||||
searchObject.set("errorCode", BookingErrorCodeEnum.TransactionFailed)
|
||||
errorMessage = `Failed to get booking status for ${confirmationNumber}`
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<HandleErrorCallback
|
||||
returnUrl={returnUrl.toString()}
|
||||
searchObject={searchObject}
|
||||
status={PaymentCallbackStatusEnum.Error}
|
||||
errorMessage={errorMessage}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import {
|
||||
BOOKING_CONFIRMATION_NUMBER,
|
||||
BookingErrorCodeEnum,
|
||||
PaymentCallbackStatusEnum,
|
||||
} from "@/constants/booking"
|
||||
import {
|
||||
bookingConfirmation,
|
||||
details,
|
||||
} from "@/constants/routes/hotelReservation"
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
|
||||
import HandleErrorCallback from "@/components/HotelReservation/EnterDetails/Payment/PaymentCallback/HandleErrorCallback"
|
||||
import HandleSuccessCallback from "@/components/HotelReservation/EnterDetails/Payment/PaymentCallback/HandleSuccessCallback"
|
||||
|
||||
import type { LangParams, PageArgs } from "@/types/params"
|
||||
|
||||
export default async function PaymentCallbackPage({
|
||||
params,
|
||||
searchParams,
|
||||
}: PageArgs<
|
||||
LangParams,
|
||||
{
|
||||
status: PaymentCallbackStatusEnum
|
||||
confirmationNumber?: string
|
||||
hotel?: string
|
||||
}
|
||||
>) {
|
||||
console.log(`[payment-callback] callback started`)
|
||||
const lang = params.lang
|
||||
const status = searchParams.status
|
||||
const confirmationNumber = searchParams.confirmationNumber
|
||||
|
||||
if (status === PaymentCallbackStatusEnum.Success && confirmationNumber) {
|
||||
const confirmationUrl = `${bookingConfirmation(lang)}?${BOOKING_CONFIRMATION_NUMBER}=${confirmationNumber}`
|
||||
console.log(
|
||||
`[payment-callback] rendering success callback with confirmation number: ${confirmationNumber}`
|
||||
)
|
||||
|
||||
return (
|
||||
<HandleSuccessCallback
|
||||
confirmationNumber={confirmationNumber}
|
||||
successRedirectUrl={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()
|
||||
: BookingErrorCodeEnum.TransactionFailed
|
||||
)
|
||||
} catch {
|
||||
console.error(
|
||||
`[payment-callback] failed to get booking status for ${confirmationNumber}, status: ${status}`
|
||||
)
|
||||
if (status === PaymentCallbackStatusEnum.Cancel) {
|
||||
searchObject.set("errorCode", BookingErrorCodeEnum.TransactionCancelled)
|
||||
}
|
||||
if (status === PaymentCallbackStatusEnum.Error) {
|
||||
searchObject.set("errorCode", BookingErrorCodeEnum.TransactionFailed)
|
||||
errorMessage = `Failed to get booking status for ${confirmationNumber}, status: ${status}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<HandleErrorCallback
|
||||
returnUrl={returnUrl.toString()}
|
||||
searchObject={searchObject}
|
||||
status={status}
|
||||
errorMessage={errorMessage}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
import { bookingConfirmation } from "@/constants/routes/hotelReservation"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
|
||||
import HandleSuccessCallback from "@/components/HotelReservation/EnterDetails/Payment/PaymentCallback/HandleSuccessCallback"
|
||||
import { setLang } from "@/i18n/serverContext"
|
||||
import { calculateRefId } from "@/utils/refId"
|
||||
|
||||
import type { LangParams, PageArgs } from "@/types/params"
|
||||
|
||||
export default async function PaymentCallbackSuccessPage({
|
||||
params,
|
||||
searchParams,
|
||||
}: PageArgs<
|
||||
LangParams,
|
||||
{
|
||||
confirmationNumber?: string
|
||||
}
|
||||
>) {
|
||||
const confirmationNumber = searchParams.confirmationNumber
|
||||
|
||||
setLang(params.lang)
|
||||
|
||||
if (!confirmationNumber) {
|
||||
notFound()
|
||||
}
|
||||
|
||||
const paymentSuccessCounter = createCounter("payment", "success")
|
||||
const metricsPaymentSuccess = paymentSuccessCounter.init({
|
||||
confirmationNumber,
|
||||
})
|
||||
|
||||
metricsPaymentSuccess.start()
|
||||
|
||||
const refId = calculateRefId(confirmationNumber, "")
|
||||
|
||||
return (
|
||||
<HandleSuccessCallback
|
||||
refId={refId}
|
||||
successRedirectUrl={bookingConfirmation(params.lang)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user