From 08918c6c1063309b567af333eb7edba7c60ed8eb Mon Sep 17 00:00:00 2001 From: Mitchell Magro Date: Tue, 13 Jan 2026 12:54:40 +0100 Subject: [PATCH] Fixing routing for status callbacks --- src/config/cashierConfig.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/config/cashierConfig.ts b/src/config/cashierConfig.ts index 30b1613..6aa9633 100644 --- a/src/config/cashierConfig.ts +++ b/src/config/cashierConfig.ts @@ -198,31 +198,37 @@ export function getCashierConfig(): ICashierConfig { // Default redirect URLs (fallback if not provided) // Convert relative paths to absolute URLs for payment provider redirects +// Uses hash-based routing for iframe compatibility export function getDefaultRedirectUrls(): IRedirect { const currentOrigin = window.location.origin; const currentPath = window.location.pathname.replace(/\/[^/]*$/, ''); // Remove last path segment if any return { - success: `${currentOrigin}${currentPath}/result?status=success`, - cancel: `${currentOrigin}${currentPath}/result?status=cancel`, - error: `${currentOrigin}${currentPath}/result?status=error`, + success: `${currentOrigin}${currentPath}#/result?status=success`, + cancel: `${currentOrigin}${currentPath}#/result?status=cancel`, + error: `${currentOrigin}${currentPath}#/result?status=error`, }; } -// Convert relative URLs to absolute URLs +// Convert relative URLs to absolute URLs with hash-based routing export function normalizeRedirectUrl(url: string): string { // If it's already an absolute URL, return as-is if (url.startsWith('http://') || url.startsWith('https://')) { return url; } - // If it's a relative path, convert to absolute + // If it's a relative path, convert to absolute with hash routing const currentOrigin = window.location.origin; const currentPath = window.location.pathname.replace(/\/[^/]*$/, ''); - // Handle query parameters - if URL already has query params, preserve them - // Otherwise, ensure it starts with / - const cleanPath = url.startsWith('/') ? url : `/${url}`; + // Handle hash-based routing - if URL starts with /, convert to #/ + // Preserve query parameters + let hashPath = url; + if (hashPath.startsWith('/')) { + hashPath = `#${hashPath}`; + } else if (!hashPath.startsWith('#')) { + hashPath = `#/${hashPath}`; + } - return `${currentOrigin}${currentPath}${cleanPath}`; + return `${currentOrigin}${currentPath}${hashPath}`; }