feat(SW-2116): remove payment-callback rewrite logic
This commit is contained in:
committed by
Michael Zetterberg
parent
bf79168216
commit
a839d05e09
@@ -0,0 +1,29 @@
|
|||||||
|
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 PaymentCallbackPage({
|
||||||
|
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}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
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 type { LangParams, PageArgs } from "@/types/params"
|
||||||
|
|
||||||
|
export default async function PaymentCallbackPage({
|
||||||
|
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) {
|
||||||
|
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}`
|
||||||
|
|
||||||
|
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,33 @@
|
|||||||
|
import { BOOKING_CONFIRMATION_NUMBER } from "@/constants/booking"
|
||||||
|
import { bookingConfirmation } from "@/constants/routes/hotelReservation"
|
||||||
|
|
||||||
|
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,
|
||||||
|
{
|
||||||
|
confirmationNumber: string
|
||||||
|
}
|
||||||
|
>) {
|
||||||
|
console.log(`[payment-callback] success callback started`)
|
||||||
|
const lang = params.lang
|
||||||
|
|
||||||
|
const confirmationNumber = searchParams.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}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -285,11 +285,6 @@ const nextConfig = {
|
|||||||
source: `${myPages.sv}/:path*`,
|
source: `${myPages.sv}/:path*`,
|
||||||
destination: `/sv/my-pages/:path*`,
|
destination: `/sv/my-pages/:path*`,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
source: "/:lang/hotelreservation/payment-callback/:status",
|
|
||||||
destination:
|
|
||||||
"/:lang/hotelreservation/payment-callback?status=:status",
|
|
||||||
},
|
|
||||||
// Find my booking
|
// Find my booking
|
||||||
{
|
{
|
||||||
source: findMyBooking.en,
|
source: findMyBooking.en,
|
||||||
|
|||||||
Reference in New Issue
Block a user