Merged in feat/SW-1149-handle-status-polling (pull request #1562)
Feat/SW-1149 handle status polling * feat(SW-1149): move terms and conditions sections to separate component and added copy * feat(SW-1149): Added client component to handle success callback for payment flow * fix: check for bookingCompleted status as well * feat(SW-1587): use alert instead of toast for showing payment errors * fix: added enum for payment callback status * fix: proper way of checking for multiple statuses * fix: update schema type * fix: use localised link to customer service * fix: update to use enum for status strings Approved-by: Arvid Norlin
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { redirect } from "next/navigation"
|
||||
|
||||
import { BookingErrorCodeEnum } from "@/constants/booking"
|
||||
import {
|
||||
BookingErrorCodeEnum,
|
||||
PaymentCallbackStatusEnum,
|
||||
} from "@/constants/booking"
|
||||
import { hotelreservation } from "@/constants/routes/hotelReservation"
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
|
||||
@@ -14,7 +17,7 @@ export default async function GuaranteePaymentCallbackPage({
|
||||
}: PageArgs<
|
||||
LangParams,
|
||||
{
|
||||
status: "error" | "success" | "cancel"
|
||||
status: PaymentCallbackStatusEnum
|
||||
refId: string
|
||||
confirmationNumber?: string
|
||||
}
|
||||
@@ -26,7 +29,11 @@ export default async function GuaranteePaymentCallbackPage({
|
||||
const refId = searchParams.refId
|
||||
const myStayUrl = `${hotelreservation(lang)}/my-stay?RefId=${refId}`
|
||||
|
||||
if (status === "success" && confirmationNumber && refId) {
|
||||
if (
|
||||
status === PaymentCallbackStatusEnum.Success &&
|
||||
confirmationNumber &&
|
||||
refId
|
||||
) {
|
||||
console.log(`[gla-payment-callback] redirecting to: ${myStayUrl}`)
|
||||
redirect(myStayUrl)
|
||||
}
|
||||
@@ -58,10 +65,10 @@ export default async function GuaranteePaymentCallbackPage({
|
||||
console.error(
|
||||
`[gla-payment-callback] failed to get booking status for ${confirmationNumber}, status: ${status}`
|
||||
)
|
||||
if (status === "cancel") {
|
||||
if (status === PaymentCallbackStatusEnum.Cancel) {
|
||||
searchObject.set("errorCode", BookingErrorCodeEnum.TransactionCancelled)
|
||||
}
|
||||
if (status === "error") {
|
||||
if (status === PaymentCallbackStatusEnum.Error) {
|
||||
searchObject.set(
|
||||
"errorCode",
|
||||
BookingErrorCodeEnum.TransactionFailed.toString()
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { redirect } from "next/navigation"
|
||||
|
||||
import {
|
||||
BOOKING_CONFIRMATION_NUMBER,
|
||||
BookingErrorCodeEnum,
|
||||
MEMBERSHIP_FAILED_ERROR,
|
||||
PaymentCallbackStatusEnum,
|
||||
} from "@/constants/booking"
|
||||
import {
|
||||
bookingConfirmation,
|
||||
@@ -11,7 +9,8 @@ import {
|
||||
} from "@/constants/routes/hotelReservation"
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
|
||||
import PaymentCallback from "@/components/HotelReservation/EnterDetails/Payment/PaymentCallback"
|
||||
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"
|
||||
|
||||
@@ -21,7 +20,7 @@ export default async function PaymentCallbackPage({
|
||||
}: PageArgs<
|
||||
LangParams,
|
||||
{
|
||||
status: "error" | "success" | "cancel"
|
||||
status: PaymentCallbackStatusEnum
|
||||
confirmationNumber?: string
|
||||
hotel?: string
|
||||
}
|
||||
@@ -31,21 +30,18 @@ export default async function PaymentCallbackPage({
|
||||
const status = searchParams.status
|
||||
const confirmationNumber = searchParams.confirmationNumber
|
||||
|
||||
if (status === "success" && confirmationNumber) {
|
||||
const bookingStatus = await serverClient().booking.status({
|
||||
confirmationNumber,
|
||||
})
|
||||
const membershipFailedError = bookingStatus.errors.find(
|
||||
(e) => e.errorCode === MEMBERSHIP_FAILED_ERROR
|
||||
if (status === PaymentCallbackStatusEnum.Success && confirmationNumber) {
|
||||
const confirmationUrl = `${bookingConfirmation(lang)}?${BOOKING_CONFIRMATION_NUMBER}=${confirmationNumber}`
|
||||
console.log(
|
||||
`[payment-callback] rendering success callback with confirmation number: ${confirmationNumber}`
|
||||
)
|
||||
|
||||
const errorParam = membershipFailedError
|
||||
? `&errorCode=${membershipFailedError.errorCode}`
|
||||
: ""
|
||||
const confirmationUrl = `${bookingConfirmation(lang)}?${BOOKING_CONFIRMATION_NUMBER}=${confirmationNumber}${errorParam}`
|
||||
|
||||
console.log(`[payment-callback] redirecting to: ${confirmationUrl}`)
|
||||
redirect(confirmationUrl)
|
||||
return (
|
||||
<HandleSuccessCallback
|
||||
confirmationNumber={confirmationNumber}
|
||||
successRedirectUrl={confirmationUrl}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const returnUrl = details(lang)
|
||||
@@ -76,10 +72,10 @@ export default async function PaymentCallbackPage({
|
||||
console.error(
|
||||
`[payment-callback] failed to get booking status for ${confirmationNumber}, status: ${status}`
|
||||
)
|
||||
if (status === "cancel") {
|
||||
if (status === PaymentCallbackStatusEnum.Cancel) {
|
||||
searchObject.set("errorCode", BookingErrorCodeEnum.TransactionCancelled)
|
||||
}
|
||||
if (status === "error") {
|
||||
if (status === PaymentCallbackStatusEnum.Error) {
|
||||
searchObject.set("errorCode", BookingErrorCodeEnum.TransactionFailed)
|
||||
errorMessage = `Failed to get booking status for ${confirmationNumber}, status: ${status}`
|
||||
}
|
||||
@@ -87,7 +83,7 @@ export default async function PaymentCallbackPage({
|
||||
}
|
||||
|
||||
return (
|
||||
<PaymentCallback
|
||||
<HandleErrorCallback
|
||||
returnUrl={returnUrl.toString()}
|
||||
searchObject={searchObject}
|
||||
status={status}
|
||||
|
||||
Reference in New Issue
Block a user