diff --git a/apps/scandic-web/components/HotelReservation/BookingConfirmation/Tracking/index.tsx b/apps/scandic-web/components/HotelReservation/BookingConfirmation/Tracking/index.tsx index 2f372bd5a..6a4c4e548 100644 --- a/apps/scandic-web/components/HotelReservation/BookingConfirmation/Tracking/index.tsx +++ b/apps/scandic-web/components/HotelReservation/BookingConfirmation/Tracking/index.tsx @@ -8,6 +8,7 @@ import TrackingSDK from "@/components/TrackingSDK" import useLang from "@/hooks/useLang" import { useSearchHistory } from "@/hooks/useSearchHistory" +import { clearPaymentInfoSessionStorage } from "../../EnterDetails/Payment/helpers" import { getTracking } from "./tracking" import type { Room } from "@/types/stores/booking-confirmation" @@ -37,20 +38,31 @@ export default function Tracking({ const searchHistory = useSearchHistory() const searchTerm = searchHistory.searchHistory[0]?.name - if (!bookingRooms.every(Boolean)) { - return null - } + let trackingData = null - const rooms = bookingRooms.filter((room): room is Room => !!room) - - const { hotelsTrackingData, pageTrackingData, paymentInfo, ancillaries } = - getTracking( + if (bookingRooms.every(Boolean)) { + const rooms = bookingRooms.filter((room): room is Room => !!room) + trackingData = getTracking( lang, bookingConfirmation.booking, bookingConfirmation.hotel, rooms, searchTerm ) + } + + useEffect(() => { + if (trackingData?.paymentInfo) { + clearPaymentInfoSessionStorage() + } + }, [trackingData]) + + if (!trackingData) { + return null + } + + const { hotelsTrackingData, pageTrackingData, paymentInfo, ancillaries } = + trackingData return ( 0) { router.replace(`${returnUrl}?${searchParams.toString()}`) diff --git a/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentCallback/HandleSuccessCallback.tsx b/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentCallback/HandleSuccessCallback.tsx index f563f1856..f2273abac 100644 --- a/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentCallback/HandleSuccessCallback.tsx +++ b/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentCallback/HandleSuccessCallback.tsx @@ -66,6 +66,11 @@ export default function HandleSuccessCallback({ hotelId: glaSessionData.hotelId, guaranteedProduct: "room", }, + paymentInfo: { + hotelId: glaSessionData.hotelId, + type: glaSessionData.paymentMethod, + isSavedCreditCard: glaSessionData.isSavedCreditCard, + }, }) clearGlaSessionStorage() } diff --git a/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentCallback/helpers.ts b/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentCallback/helpers.ts index 445bedd6b..dc7bd85ed 100644 --- a/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentCallback/helpers.ts +++ b/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentCallback/helpers.ts @@ -5,6 +5,8 @@ export const glaStorageName = "gla-storage" type GlaSessionData = { lateArrivalGuarantee: string hotelId: string + paymentMethod?: string + isSavedCreditCard?: boolean } export function readGlaFromSessionStorage(): GlaSessionData | null { @@ -20,12 +22,19 @@ export function readGlaFromSessionStorage(): GlaSessionData | null { export function writeGlaToSessionStorage( lateArrivalGuarantee: string, - hotelId: string + hotelId: string, + paymentMethod: string, + isSavedCreditCard: boolean ) { try { sessionStorage.setItem( glaStorageName, - JSON.stringify({ lateArrivalGuarantee, hotelId }) + JSON.stringify({ + lateArrivalGuarantee, + hotelId, + paymentMethod, + isSavedCreditCard, + }) ) } catch (error) { console.error("Error writing to session storage:", error) diff --git a/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentClient.tsx b/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentClient.tsx index fa25c2793..43b681963 100644 --- a/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentClient.tsx +++ b/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentClient.tsx @@ -43,7 +43,12 @@ import PriceChangeDialog from "../PriceChangeDialog" import { writeGlaToSessionStorage } from "./PaymentCallback/helpers" import BookingAlert from "./BookingAlert" import GuaranteeDetails from "./GuaranteeDetails" -import { hasFlexibleRate, hasPrepaidRate, isPaymentMethodEnum } from "./helpers" +import { + hasFlexibleRate, + hasPrepaidRate, + isPaymentMethodEnum, + writePaymentInfoToSessionStorage, +} from "./helpers" import MixedRatePaymentBreakdown from "./MixedRatePaymentBreakdown" import PaymentOptionsGroup from "./PaymentOptionsGroup" import { type PaymentFormData, paymentSchema } from "./schema" @@ -216,10 +221,12 @@ export default function PaymentClient({ const currentPaymentMethod = methods.getValues("paymentMethod") const smsEnable = methods.getValues("smsConfirmation") const guarantee = methods.getValues("guarantee") - const isSavedCreditCard = savedCreditCards?.some( + const savedCreditCard = savedCreditCards?.find( (card) => card.id === currentPaymentMethod ) + const isSavedCreditCard = !!savedCreditCard + if (guarantee || (bookingMustBeGuaranteed && hasOnlyFlexRates)) { const lateArrivalGuarantee = guarantee ? "yes" : "mandatory" trackEvent({ @@ -233,13 +240,14 @@ export default function PaymentClient({ isSavedCreditCard, hotelId, status: "glacardsavefailed", + type: savedCreditCard ? savedCreditCard.type : currentPaymentMethod, }, }) } else { trackPaymentEvent({ event: "paymentFail", hotelId, - method: currentPaymentMethod, + method: savedCreditCard ? savedCreditCard.type : currentPaymentMethod, isSavedCreditCard, smsEnable, errorMessage, @@ -355,21 +363,29 @@ export default function PaymentClient({ cancel: `${paymentRedirectUrl}/cancel`, } : undefined - + const paymentMethodType = savedCreditCard + ? savedCreditCard.type + : paymentMethod if (guarantee || (bookingMustBeGuaranteed && hasOnlyFlexRates)) { const lateArrivalGuarantee = guarantee ? "yes" : "mandatory" - writeGlaToSessionStorage(lateArrivalGuarantee, hotelId) + writeGlaToSessionStorage( + lateArrivalGuarantee, + hotelId, + paymentMethodType, + !!savedCreditCard + ) trackGlaSaveCardAttempt(hotelId, savedCreditCard, lateArrivalGuarantee) } else if (!hasOnlyFlexRates) { trackPaymentEvent({ event: "paymentAttemptStart", hotelId, - method: savedCreditCard ? savedCreditCard.type : paymentMethod, + method: paymentMethodType, isSavedCreditCard: !!savedCreditCard, smsEnable: data.smsConfirmation, status: "attempt", }) } + writePaymentInfoToSessionStorage(paymentMethodType, !!savedCreditCard) const payload = { checkInDate: fromDate, diff --git a/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/helpers.ts b/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/helpers.ts index 383f36c09..36cf6308c 100644 --- a/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/helpers.ts +++ b/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/helpers.ts @@ -45,3 +45,46 @@ export function calculateTotalRoomPrice( comparisonPrice, } } + +export const paymentInfoStorageName = "payment-info-storage" + +type PaymentInfoSessionData = { + paymentMethod: string + isSavedCreditCard: boolean +} + +export function readPaymentInfoFromSessionStorage(): + | PaymentInfoSessionData + | undefined { + try { + const paymentInfoSessionData = sessionStorage.getItem( + paymentInfoStorageName + ) + if (!paymentInfoSessionData) return undefined + return JSON.parse(paymentInfoSessionData) + } catch (error) { + console.error("Error reading from session storage:", error) + return undefined + } +} + +export function writePaymentInfoToSessionStorage( + paymentMethod: string, + isSavedCreditCard: boolean +) { + try { + sessionStorage.setItem( + paymentInfoStorageName, + JSON.stringify({ + paymentMethod, + isSavedCreditCard, + }) + ) + } catch (error) { + console.error("Error writing to session storage:", error) + } +} + +export function clearPaymentInfoSessionStorage() { + sessionStorage.removeItem(paymentInfoStorageName) +} diff --git a/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/NotCancelled/ManageStay/Actions/GuaranteeLateArrival/Form/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/NotCancelled/ManageStay/Actions/GuaranteeLateArrival/Form/index.tsx index 720e00655..a1cd01a1d 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/NotCancelled/ManageStay/Actions/GuaranteeLateArrival/Form/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/NotCancelled/ManageStay/Actions/GuaranteeLateArrival/Form/index.tsx @@ -80,7 +80,13 @@ export default function Form() { cardType: savedCreditCard.cardType, } : undefined - writeGlaToSessionStorage("yes", hotelId) + const lateArrivalGuarantee = "yes" + writeGlaToSessionStorage( + lateArrivalGuarantee, + hotelId, + savedCreditCard ? savedCreditCard.type : PaymentMethodEnum.card, + !!savedCreditCard + ) guaranteeBooking.mutate({ refId, language: lang, diff --git a/apps/scandic-web/components/HotelReservation/MyStay/TrackGuarantee.tsx b/apps/scandic-web/components/HotelReservation/MyStay/TrackGuarantee.tsx index cef37bda9..8e5949330 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/TrackGuarantee.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/TrackGuarantee.tsx @@ -57,16 +57,18 @@ export default function TrackGuarantee({ } const trackGuaranteePaymentEvent = (event: string, status: string) => { - const glaHotelInfo = readGlaFromSessionStorage() + const glaSessionData = readGlaFromSessionStorage() trackEvent({ event, hotelInfo: { - hotelId: glaHotelInfo?.hotelId, + hotelId: glaSessionData?.hotelId, lateArrivalGuarantee: "yes", guaranteedProduct: "room", }, paymentInfo: { status, + type: glaSessionData?.paymentMethod, + isSavedCreditCard: glaSessionData?.isSavedCreditCard, ...(errorMessage && { errorMessage }), }, }) @@ -75,14 +77,19 @@ export default function TrackGuarantee({ switch (status) { case PaymentCallbackStatusEnum.Success: - const glaHotelInfo = readGlaFromSessionStorage() + const glaSessionData = readGlaFromSessionStorage() trackEvent({ event: "guaranteeBookingSuccess", hotelInfo: { - hotelId: glaHotelInfo?.hotelId, + hotelId: glaSessionData?.hotelId, lateArrivalGuarantee: "yes", guaranteedProduct: "room", }, + paymentInfo: { + type: glaSessionData?.paymentMethod, + hotelId: glaSessionData?.hotelId, + isSavedCreditCard: glaSessionData?.isSavedCreditCard, + }, }) clearGlaSessionStorage() break diff --git a/apps/scandic-web/utils/tracking/myStay.ts b/apps/scandic-web/utils/tracking/myStay.ts index 9278c749e..443500c0b 100644 --- a/apps/scandic-web/utils/tracking/myStay.ts +++ b/apps/scandic-web/utils/tracking/myStay.ts @@ -43,6 +43,7 @@ export function trackGlaSaveCardAttempt( }, paymentInfo: { status: "glacardsaveattempt", + isSavedCreditCard: !!savedCreditCard, type: savedCreditCard?.cardType, }, })