From 6bf7462ac7d4f7b4938e8d58ff5f4d7e305ded2d Mon Sep 17 00:00:00 2001 From: Linus Flood Date: Wed, 11 Jun 2025 17:49:27 +0000 Subject: [PATCH] Merged in fix/payment-error (pull request #2342) Fix/payment error * fix: dont show not found page when payment fails * Show error message when payment fails Approved-by: Anton Gunnarsson --- .../payment-callback/page.tsx | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/(payment-callback)/payment-callback/page.tsx b/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/(payment-callback)/payment-callback/page.tsx index 411340050..4327d8410 100644 --- a/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/(payment-callback)/payment-callback/page.tsx +++ b/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/(payment-callback)/payment-callback/page.tsx @@ -38,6 +38,9 @@ export default async function PaymentCallbackPage( const confirmationNumber = searchParams.confirmationNumber if (!status || !confirmationNumber) { + console.error( + `[payment-callback] missing status or confirmationNumber in search params` + ) notFound() } @@ -69,17 +72,21 @@ export default async function PaymentCallbackPage( } if (!token) { + console.error( + `[payment-callback] no token found for user, cannot fetch booking` + ) notFound() } const booking = await getBooking(confirmationNumber, params.lang, token) - if (!booking) { - notFound() - } - const { refId } = booking + const refId = booking?.refId - if (status === PaymentCallbackStatusEnum.Success && confirmationNumber) { + if ( + status === PaymentCallbackStatusEnum.Success && + confirmationNumber && + refId + ) { const expire = Math.floor(Date.now() / 1000) + 60 const sig = encrypt(expire.toString()) const confirmationUrl = `${bookingConfirmation(lang)}?RefId=${encodeURIComponent(refId)}` @@ -127,6 +134,14 @@ export default async function PaymentCallbackPage( } } + if (status === PaymentCallbackStatusEnum.Error) { + console.error( + `[payment-callback] error status received for ${confirmationNumber}, status: ${status}` + ) + searchObject.set("errorCode", BookingErrorCodeEnum.TransactionFailed) + errorMessage = `Failed to get booking status for ${confirmationNumber}, status: ${status}` + } + return (