Fixing routing for status callbacks

This commit is contained in:
Mitchell Magro 2026-01-13 12:54:40 +01:00
parent adf892c0af
commit 08918c6c10

View File

@ -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}`;
}