Fixing routing for status callbacks
This commit is contained in:
parent
adf892c0af
commit
08918c6c10
@ -198,31 +198,37 @@ export function getCashierConfig(): ICashierConfig {
|
|||||||
|
|
||||||
// Default redirect URLs (fallback if not provided)
|
// Default redirect URLs (fallback if not provided)
|
||||||
// Convert relative paths to absolute URLs for payment provider redirects
|
// Convert relative paths to absolute URLs for payment provider redirects
|
||||||
|
// Uses hash-based routing for iframe compatibility
|
||||||
export function getDefaultRedirectUrls(): IRedirect {
|
export function getDefaultRedirectUrls(): IRedirect {
|
||||||
const currentOrigin = window.location.origin;
|
const currentOrigin = window.location.origin;
|
||||||
const currentPath = window.location.pathname.replace(/\/[^/]*$/, ''); // Remove last path segment if any
|
const currentPath = window.location.pathname.replace(/\/[^/]*$/, ''); // Remove last path segment if any
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: `${currentOrigin}${currentPath}/result?status=success`,
|
success: `${currentOrigin}${currentPath}#/result?status=success`,
|
||||||
cancel: `${currentOrigin}${currentPath}/result?status=cancel`,
|
cancel: `${currentOrigin}${currentPath}#/result?status=cancel`,
|
||||||
error: `${currentOrigin}${currentPath}/result?status=error`,
|
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 {
|
export function normalizeRedirectUrl(url: string): string {
|
||||||
// If it's already an absolute URL, return as-is
|
// If it's already an absolute URL, return as-is
|
||||||
if (url.startsWith('http://') || url.startsWith('https://')) {
|
if (url.startsWith('http://') || url.startsWith('https://')) {
|
||||||
return url;
|
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 currentOrigin = window.location.origin;
|
||||||
const currentPath = window.location.pathname.replace(/\/[^/]*$/, '');
|
const currentPath = window.location.pathname.replace(/\/[^/]*$/, '');
|
||||||
|
|
||||||
// Handle query parameters - if URL already has query params, preserve them
|
// Handle hash-based routing - if URL starts with /, convert to #/
|
||||||
// Otherwise, ensure it starts with /
|
// Preserve query parameters
|
||||||
const cleanPath = url.startsWith('/') ? url : `/${url}`;
|
let hashPath = url;
|
||||||
|
if (hashPath.startsWith('/')) {
|
||||||
|
hashPath = `#${hashPath}`;
|
||||||
|
} else if (!hashPath.startsWith('#')) {
|
||||||
|
hashPath = `#/${hashPath}`;
|
||||||
|
}
|
||||||
|
|
||||||
return `${currentOrigin}${currentPath}${cleanPath}`;
|
return `${currentOrigin}${currentPath}${hashPath}`;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user