Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

refactor(cypress): fix adyen ideal bank redirect and refactor `handleFlow` (#7848)

Pa1NarK919f8b4674b7
diff --git a/cypress-tests/cypress/support/redirectionHandler.js b/cypress-tests/cypress/support/redirectionHandler.js
index 56647fcf4e..21ef784c56 100644
--- a/cypress-tests/cypress/support/redirectionHandler.js
+++ b/cypress-tests/cypress/support/redirectionHandler.js
@@ -136,134 +136,186 @@ function bankRedirectRedirection(
let verifyUrl = false;
cy.visit(redirectionUrl.href);
- waitForRedirect(redirectionUrl.href);
+ waitForRedirect(redirectionUrl.href); // Wait for the first redirect
- handleFlow(
- redirectionUrl,
- expectedUrl,
- connectorId,
- ({ connectorId, constants, paymentMethodType }) => {
- switch (connectorId) {
- case "adyen":
- switch (paymentMethodType) {
- case "eps":
- cy.get("h1").should("contain.text", "Acquirer Simulator");
- cy.get('[value="authorised"]').click();
- break;
- case "ideal":
- cy.wait(constants.TIMEOUT / 10); // 2 seconds
- cy.get("button[data-testid=payment-action-button]").click();
- cy.wait(constants.TIMEOUT / 10); // 2 seconds
- cy.get("button[id=bank-item-TESTNL2A]").click();
- cy.wait(constants.TIMEOUT / 10); // 2 seconds
- cy.location("host").then(() => {
- cy.url().then((currentUrl) => {
- cy.origin(new URL(currentUrl).origin, () => {
- cy.url().then(() => {
- cy.get("button.shared-styles_button__cNu+v")
- .contains("Success")
- .click();
- cy.url().should("include", "/loading/SUCCESS");
- });
- });
+ // adyen ideal has been kept outside the handleFlow function just because cypress does not support nested `cy.origin` yet
+ // ref: https://github.com/cypress-io/cypress/issues/20718
+ // the work around is to use `cy.origin` in sequential manner
+ if (connectorId === "adyen" && paymentMethodType === "ideal") {
+ const adyenIdealOrigin1 = "https://ext.pay.ideal.nl";
+ const adyenIdealOrigin2 = "https://handler.ext.idealtesttool.nl";
+
+ cy.origin(
+ adyenIdealOrigin1,
+ { args: { constants: CONSTANTS } },
+ ({ constants }) => {
+ cy.log(
+ "Executing on Adyen iDEAL Origin 1:",
+ cy.state("window").location.origin
+ );
+ cy.wait(constants.TIMEOUT / 10); // 2 seconds
+ cy.get("button[data-testid=payment-action-button]").click();
+ cy.wait(constants.TIMEOUT / 10); // 2 seconds
+ cy.get("button[id=bank-item-TESTNL2A]").click();
+ }
+ );
+
+ cy.log(`Waiting for redirection to ${adyenIdealOrigin2}`);
+ cy.location("origin", { timeout: CONSTANTS.TIMEOUT }).should(
+ "eq",
+ adyenIdealOrigin2
+ );
+
+ cy.origin(
+ adyenIdealOrigin2,
+ { args: { constants: CONSTANTS } },
+ ({ constants }) => {
+ cy.log(
+ "Executing on Adyen iDEAL Origin 2:",
+ cy.state("window").location.origin
+ );
+
+ cy.get(".btn.btn-primary.btn-lg")
+ .contains("Success")
+ .should("be.visible")
+ .click();
+
+ cy.url({ timeout: constants.WAIT_TIME }).should(
+ "include",
+ "/loading/SUCCESS"
+ );
+ }
+ );
+
+ // we get `An error occurred with the WebSocket` after clicking the `success` button
+ // and it does not redirect to the expected url
+ // so, we need cannot verify the return url for adyen ideal bank redirect
+ verifyUrl = false;
+ } else {
+ handleFlow(
+ redirectionUrl,
+ expectedUrl,
+ connectorId,
+ ({ connectorId, paymentMethodType }) => {
+ // Renamed expectedUrl arg for clarity
+ // This callback now runs either in cy.origin (if redirected) or directly (if iframe)
+ switch (connectorId) {
+ case "adyen":
+ switch (paymentMethodType) {
+ case "eps":
+ cy.get("h1").should("contain.text", "Acquirer Simulator");
+ cy.get('[value="authorised"]').click();
+ verifyUrl = true;
+ break;
+ // The 'ideal' case is handled outside handleFlow
+ default:
+ throw new Error(
+ `Unsupported Adyen payment method type in handleFlow: ${paymentMethodType}`
+ );
+ }
+ break;
+
+ case "paypal":
+ if (["eps", "ideal", "giropay"].includes(paymentMethodType)) {
+ cy.get('button[name="Successful"][value="SUCCEEDED"]').click();
+ verifyUrl = true;
+ } else {
+ throw new Error(
+ `Unsupported Paypal payment method type: ${paymentMethodType}`
+ );
+ }
+
+ break;
+
+ case "stripe":
+ if (
+ ["eps", "ideal", "giropay", "sofort", "przelewy24"].includes(
+ paymentMethodType
+ )
+ ) {
+ // scroll down and click on the authorize test payment button
+ cy.get("body").then(($body) => {
+ cy.get("#frame-warning-container").then(($el) => {
+ if ($el.is(":visible")) {
+ // Frame warning is visible — use test payment button
+ cy.get("#authorize-test-payment")
+ .scrollIntoView()
+ .should("be.visible")
+ .click();
+ } else {
+ // Frame warning is hidden — use the success link
+ cy.contains(
+ 'a.common-Button[name="success"]',
+ "Authorize Test Payment"
+ )
+ .scrollIntoView()
+ .should("be.visible")
+ .click();
+ }
});
});
- break;
- default:
+ verifyUrl = true;
+ } else {
throw new Error(
- `Unsupported payment method type: ${paymentMethodType}`
+ `Unsupported Stripe payment method type: ${paymentMethodType}`
);
- }
- verifyUrl = true;
- break;
- case "paypal":
- if (["eps", "ideal", "giropay"].includes(paymentMethodType)) {
- cy.get('button[name="Successful"][value="SUCCEEDED"]').click();
- verifyUrl = true;
- } else {
- throw new Error(
- `Unsupported payment method type: ${paymentMethodType}`
- );
- }
- verifyUrl = true;
- break;
- case "stripe":
- if (
- ["eps", "ideal", "giropay", "sofort", "przelewy24"].includes(
- paymentMethodType
- )
- ) {
- // scroll down and click on the authorize test payment button
- cy.get("body").then(($body) => {
- cy.get("#frame-warning-container").then(($el) => {
- if ($el.is(":visible")) {
- // Frame warning is visible — use test payment button
- cy.get("#authorize-test-payment")
- .scrollIntoView()
- .should("be.visible")
- .click();
- } else {
- // Frame warning is hidden — use the success link
- cy.contains(
- 'a.common-Button[name="success"]',
- "Authorize Test Payment"
- )
- .scrollIntoView()
- .should("be.visible")
- .click();
- }
- });
- });
- verifyUrl = true;
- } else {
+ }
+
+ break;
+
+ case "trustpay":
+ // Trustpay bank redirects never reach the terminal state
+ switch (paymentMethodType) {
+ case "eps":
+ cy.get("#bankname").type(
+ "Allgemeine Sparkasse Oberösterreich Bank AG (ASPKAT2LXXX / 20320)"
+ );
+ cy.get("#selectionSubmit").click();
+ break;
+ case "ideal":
+ cy.contains("button", "Select your bank").click();
+ cy.get(
+ 'button[data-testid="bank-item"][id="bank-item-INGBNL2A"]'
+ ).click();
+ break;
+ case "giropay":
+ cy.get("._transactionId__header__iXVd_").should(
+ "contain.text",
+ "Bank suchen ‑ mit giropay zahlen."
+ );
+ cy.get(".BankSearch_searchInput__uX_9l").type(
+ "Volksbank Hildesheim{enter}"
+ );
+ cy.get(".BankSearch_searchIcon__EcVO7").click();
+ cy.get(".BankSearch_bankWrapper__R5fUK").click();
+ cy.get("._transactionId__primaryButton__nCa0r").click();
+ cy.get(".normal-3").should("contain.text", "Kontoauswahl");
+ break;
+ default:
+ throw new Error(
+ `Unsupported Trustpay payment method type: ${paymentMethodType}`
+ );
+ }
+ verifyUrl = false;
+ break;
+
+ default:
throw new Error(
- `Unsupported payment method type: ${paymentMethodType}`
+ `Unsupported connector in handleFlow: ${connectorId}`
);
- }
- verifyUrl = true;
- break;
- case "trustpay":
- switch (paymentMethodType) {
- case "eps":
- cy.get("#bankname").type(
- "Allgemeine Sparkasse Oberösterreich Bank AG (ASPKAT2LXXX / 20320)"
- );
- cy.get("#selectionSubmit").click();
- break;
- case "ideal":
- cy.contains("button", "Select your bank").click();
- cy.get(
- 'button[data-testid="bank-item"][id="bank-item-INGBNL2A"]'
- ).click();
- break;
- case "giropay":
- cy.get("._transactionId__header__iXVd_").should(
- "contain.text",
- "Bank suchen ‑ mit giropay zahlen."
- );
- cy.get(".BankSearch_searchInput__uX_9l").type(
- "Volksbank Hildesheim{enter}"
- );
- cy.get(".BankSearch_searchIcon__EcVO7").click();
- cy.get(".BankSearch_bankWrapper__R5fUK").click();
- cy.get("._transactionId__primaryButton__nCa0r").click();
- cy.get(".normal-3").should("contain.text", "Kontoauswahl");
- break;
- default:
- throw new Error(
- `Unsupported payment method type: ${paymentMethodType}`
- );
- }
- verifyUrl = false;
- break;
- default:
- throw new Error(`Unsupported connector: ${connectorId}`);
- }
- },
- { paymentMethodType }
- );
+ }
+ },
+ { paymentMethodType } // Pass options to handleFlow
+ );
+ // extract the verifyUrl decision from within the handleFlow callback
+ // since the callback runs asynchronously within cy.origin or directly,
+ // we need a way to signal back if verification is needed.
+ // we use a closure variable `verifyUrl` which is modified inside the callback.
+ // this relies on cypress command queue ensuring the callback completes before cy.then runs.
+ }
cy.then(() => {
+ // The value of verifyUrl determined by the specific flow (Adyen iDEAL or handleFlow callback)
verifyReturnUrl(redirectionUrl, expectedUrl, verifyUrl);
});
}
@@ -473,13 +525,18 @@ function upiRedirection(
}
function verifyReturnUrl(redirectionUrl, expectedUrl, forwardFlow) {
- if (!forwardFlow) return;
+ if (!forwardFlow) {
+ cy.log("Skipping return URL verification as forwardFlow is false.");
+ return;
+ }
+ cy.log(`Verifying return URL. Expecting host: ${expectedUrl.host}`);
cy.location("host", { timeout: CONSTANTS.TIMEOUT }).should((currentHost) => {
expect(currentHost).to.equal(expectedUrl.host);
});
cy.url().then((url) => {
+ cy.log(`Current URL for verification: ${url}`);
cy.origin(
new URL(url).origin,
{
@@ -494,6 +551,10 @@ function verifyReturnUrl(redirectionUrl, expectedUrl, forwardFlow) {
const redirectionHost = new URL(redirectionUrl).host;
const expectedHost = new URL(expectedUrl).host;
+ cy.log(
+ `Running verification checks within origin: ${location.origin}`
+ );
+
cy.window()
.its("location")
.then((location) => {
@@ -501,6 +562,9 @@ function verifyReturnUrl(redirectionUrl, expectedUrl, forwardFlow) {
const urlParams = new URLSearchParams(location.search);
const paymentId = urlParams.get("payment_id");
+ cy.log(`URL Params: ${location.search}`);
+ cy.log(`Payment ID: ${paymentId}`);
+
if (!paymentId) {
// eslint-disable-next-line cypress/assertion-before-screenshot
cy.screenshot("missing-payment-id-error");
@@ -514,9 +578,15 @@ function verifyReturnUrl(redirectionUrl, expectedUrl, forwardFlow) {
// Check page state before taking screenshots
cy.document().then((doc) => {
const pageText = doc.body.innerText.toLowerCase();
+
+ cy.log(
+ `Page text for error check: ${pageText.substring(0, 200)}...`
+ );
+
if (!pageText) {
// eslint-disable-next-line cypress/assertion-before-screenshot
cy.screenshot("blank-page-error");
+ cy.log("Warning: Page appears blank.");
} else {
// Check if any error pattern exists in the text
const hasError = constants.ERROR_PATTERNS.some((pattern) =>
@@ -678,6 +748,7 @@ function handleFlow(
) {
// Extract the host from the redirection URL
const originalHost = new URL(redirectionUrl.href).host;
+
cy.location("host", { timeout: CONSTANTS.TIMEOUT }).then((currentHost) => {
const callbackArgs = {
connectorId,
@@ -687,20 +758,35 @@ function handleFlow(
};
if (currentHost !== originalHost) {
+ cy.log(
+ `Redirect detected: ${originalHost} -> ${currentHost}. Using cy.origin.`
+ );
+
// For a regular redirection flow: host changed, use cy.origin
cy.url().then((currentUrl) => {
cy.origin(new URL(currentUrl).origin, { args: callbackArgs }, callback);
});
} else {
+ cy.log(
+ `No host change detected or potential iframe. Executing callback directly/targeting iframe.`
+ );
+
// For embedded flows using an iframe:
cy.get("iframe", { timeout: CONSTANTS.TIMEOUT })
.should("be.visible")
.should("exist")
.then((iframes) => {
if (iframes.length === 0) {
+ cy.log(
+ "No host change and no iframe detected, executing callback directly."
+ );
+
throw new Error("No iframe found for embedded flow.");
}
// Execute the callback directly for the embedded flow
+ cy.log(
+ "Iframe detected, executing callback targeting iframe context (implicitly)."
+ );
callback(callbackArgs);
});
}