Skip to content

Commit

Permalink
fix: handle ecommerce-fe redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
petretiandrea committed May 22, 2024
1 parent e0511c2 commit e724c15
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/routes/PaymentCheckPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { Bundle } from "../../generated/definitions/payment-ecommerce/Bundle";
import { CalculateFeeResponse } from "../../generated/definitions/payment-ecommerce/CalculateFeeResponse";
import { SessionPaymentMethodResponse } from "../../generated/definitions/payment-ecommerce/SessionPaymentMethodResponse";
import { ImageComponent } from "../features/payment/components/PaymentChoice/PaymentMethodImage";
import { isEcommerceFrontendRedirection } from "../utils/regex/urlUtilities";
import { CheckoutRoutes } from "./models/routeModel";

const defaultStyle = {
Expand Down Expand Up @@ -154,7 +155,10 @@ export default function PaymentCheckPage() {
try {
window.removeEventListener("beforeunload", onBrowserUnload);
const url = new URL(authorizationUrl);
if (url.origin === window.location.origin) {
if (
url.origin === window.location.origin &&
!isEcommerceFrontendRedirection(url)
) {
navigate(`${url.pathname}${url.hash}`);
setPayLoading(false);
} else {
Expand Down
19 changes: 18 additions & 1 deletion src/utils/__tests__/urlUtili.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ROUTE_FRAGMENT } from "../../routes/models/routeModel";
import { getFragmentParameter } from "../../utils/regex/urlUtilities";
import {
getFragmentParameter,
isEcommerceFrontendRedirection,
} from "../../utils/regex/urlUtilities";

describe("getFragmentParameter function utility", () => {
it("Should return the param value correctly", () => {
Expand Down Expand Up @@ -31,4 +34,18 @@ describe("getFragmentParameter function utility", () => {
""
);
});

it("Should return true if the URL require ecommerce-fe redirection", () => {
expect(
isEcommerceFrontendRedirection(
new URL("http://localhost:1234/ecommerce-fe/gdi-check#iframe=0")
)
).toEqual(true);

expect(
isEcommerceFrontendRedirection(
new URL("http://localhost:1234/v2/esito#outcome=0")
)
).toEqual(false);
});
});
4 changes: 4 additions & 0 deletions src/utils/regex/urlUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ export function getFragmentParameter(
return "";
}
}

const eCommerceFrontendPathNameRegex = /^\/ecommerce-fe/;
export const isEcommerceFrontendRedirection = (url: URL) =>
eCommerceFrontendPathNameRegex.test(url.pathname);

0 comments on commit e724c15

Please sign in to comment.