Merged in fix/STAY-67-redirect-to-webview-after-gla (pull request #2795)

fix(STAY-67): redirect to webview after guarantee on my stay

* fix(STAY-67): redirect to webview after guarantee on my stay

* fix(STAY-67): add callback page for guarantee on webview


Approved-by: Linus Flood
This commit is contained in:
Bianca Widstam
2025-09-15 07:18:58 +00:00
parent 98816b27ce
commit 800948bb94
6 changed files with 173 additions and 81 deletions

View File

@@ -1,15 +1,11 @@
import { notFound } from "next/navigation"
import { PaymentCallbackStatusEnum } from "@scandic-hotels/common/constants/paymentCallbackStatusEnum"
import { myStay } from "@scandic-hotels/common/constants/routes/myStay"
import { logger } from "@scandic-hotels/common/logger"
import { LoadingSpinner } from "@scandic-hotels/design-system/LoadingSpinner"
import { BookingErrorCodeEnum } from "@scandic-hotels/trpc/enums/bookingErrorCode"
import { serverClient } from "@/lib/trpc/server"
import GuaranteeCallbackPage from "@/components/GuaranteeCallback"
import GuaranteeCallback from "@/components/HotelReservation/MyStay/Ancillaries/GuaranteeCallback"
import TrackGuarantee from "@/components/HotelReservation/MyStay/TrackGuarantee"
import type { PaymentCallbackStatusEnum } from "@scandic-hotels/common/constants/paymentCallbackStatusEnum"
import type { LangParams, PageArgs } from "@/types/params"
@@ -34,77 +30,16 @@ export default async function GuaranteePaymentCallbackPage(
if (!status || !confirmationNumber || !refId) {
notFound()
}
const isAncillaryFlow = searchParams.ancillary
const myStayUrl = `${myStay[lang]}?RefId=${encodeURIComponent(refId)}`
const searchObject = new URLSearchParams()
if (status === PaymentCallbackStatusEnum.Success && confirmationNumber) {
if (isAncillaryFlow) {
return (
<GuaranteeCallback
returnUrl={myStayUrl}
refId={refId}
confirmationNumber={confirmationNumber}
lang={lang}
/>
)
}
logger.debug(`[gla-payment-callback] redirecting to: ${myStayUrl}`)
return <TrackGuarantee status={status} redirectUrl={myStayUrl} />
}
let errorMessage = undefined
if (refId) {
try {
const caller = await serverClient()
const bookingStatus = await caller.booking.status({
refId,
})
const { booking } = bookingStatus
const error = booking.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 {
logger.error(
`[gla-payment-callback] failed to get booking status for ${confirmationNumber}, status: ${status}`
)
if (status === PaymentCallbackStatusEnum.Cancel) {
searchObject.set("errorCode", BookingErrorCodeEnum.TransactionCancelled)
} else if (status === PaymentCallbackStatusEnum.Error) {
searchObject.set("errorCode", BookingErrorCodeEnum.TransactionFailed)
errorMessage = `Failed to get booking status for ${confirmationNumber}, status: ${status}`
}
}
if (errorMessage) {
logger.error(errorMessage)
}
if (isAncillaryFlow) {
searchObject.set("ancillary", "ancillary")
}
return (
<TrackGuarantee
status={status}
isAncillaryFlow={!!isAncillaryFlow}
redirectUrl={`${myStayUrl}&${searchObject.toString()}`}
errorMessage={errorMessage}
/>
)
}
return <LoadingSpinner />
return (
<GuaranteeCallbackPage
status={status}
confirmationNumber={confirmationNumber}
refId={refId}
myStayUrl={myStayUrl}
lang={lang}
isAncillaryFlow={!!searchParams.ancillary}
/>
)
}