Merged in feat/SW-910-membershipnumber-non-happy-path (pull request #1358)

fix(SW-910): handle MembershipFailedError

* fix(SW-910): handle MembershipFailedError


Approved-by: Tobias Johansson
This commit is contained in:
Arvid Norlin
2025-02-24 15:55:31 +00:00
parent c0cfa342cc
commit cf3268bda3
3 changed files with 34 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ import { redirect } from "next/navigation"
import {
BOOKING_CONFIRMATION_NUMBER,
MEMBERSHIP_FAILED_ERROR,
PaymentErrorCodeEnum,
} from "@/constants/booking"
import {
@@ -31,7 +32,17 @@ export default async function PaymentCallbackPage({
const confirmationNumber = searchParams.confirmationNumber
if (status === "success" && confirmationNumber) {
const confirmationUrl = `${bookingConfirmation(lang)}?${BOOKING_CONFIRMATION_NUMBER}=${confirmationNumber}`
const bookingStatus = await serverClient().booking.status({
confirmationNumber,
})
const membershipFailedError = bookingStatus.errors.find(
(e) => e.errorCode === MEMBERSHIP_FAILED_ERROR
)
const errorParam = membershipFailedError
? `&errorCode=${membershipFailedError.errorCode}`
: ""
const confirmationUrl = `${bookingConfirmation(lang)}?${BOOKING_CONFIRMATION_NUMBER}=${confirmationNumber}${errorParam}`
console.log(`[payment-callback] redirecting to: ${confirmationUrl}`)
redirect(confirmationUrl)

View File

@@ -1,7 +1,10 @@
"use client"
import { useSearchParams } from "next/navigation"
import { useRef } from "react"
import { useIntl } from "react-intl"
import { MEMBERSHIP_FAILED_ERROR } from "@/constants/booking"
import Header from "@/components/HotelReservation/BookingConfirmation/Header"
import HotelDetails from "@/components/HotelReservation/BookingConfirmation/HotelDetails"
import PaymentDetails from "@/components/HotelReservation/BookingConfirmation/PaymentDetails"
@@ -22,9 +25,11 @@ export default function Confirmation({
hotel,
room,
}: ConfirmationProps) {
const searchParams = useSearchParams()
const intl = useIntl()
const mainRef = useRef<HTMLElement | null>(null)
const membershipFailedError =
searchParams.get("errorCode") === MEMBERSHIP_FAILED_ERROR
const failedToVerifyMembership =
booking.rateDefinition.isMemberRate && !booking.guest.membershipNumber
@@ -32,7 +37,20 @@ export default function Confirmation({
<main className={styles.main} ref={mainRef}>
<Header booking={booking} hotel={hotel} mainRef={mainRef} />
<div className={styles.booking}>
{failedToVerifyMembership && (
{/* Customer has manually entered a membership number for which verification failed */}
{membershipFailedError && (
<Alert
type={AlertTypeEnum.Info}
heading={intl.formatMessage({
id: "Failed to verify membership",
})}
text={intl.formatMessage({
id: "The first or last name doesn't match the membership number you provided. Your booking(s) is confirmed but to get the membership attached you'll need to present your existing membership number upon check-in. If you have booked with a member discount, you'll either need to present your existing membership number upon check-in, become a member or pay the price difference at the hotel. Signing up is preferably done online before the stay, or we can assist upon arrival.",
})}
/>
)}
{/* For some other reason membership could not be verified */}
{!membershipFailedError && failedToVerifyMembership && (
<Alert
type={AlertTypeEnum.Info}
heading={intl.formatMessage({

View File

@@ -37,6 +37,8 @@ export enum ChildBedTypeEnum {
export const BOOKING_CONFIRMATION_NUMBER = "confirmationNumber"
export const MEMBERSHIP_FAILED_ERROR = "MembershipFailedError"
export enum PaymentMethodEnum {
card = "card",
swish = "swish",