Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cypress): verify payment status after payment redirection #6187

Conversation

Ankesh2004
Copy link
Contributor

@Ankesh2004 Ankesh2004 commented Oct 1, 2024

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

This pull request Resolve #5915

Description

This PR refactors the verifyReturnUrl function to validate the redirection_url and ensure that the payment status is either succeeded or processing. If the status is invalid, the test will now fail, preventing false positives in redirection tests like 3DS or bank redirects.

###Key Changes:

  • Parse the redirection_url query string to extract the status parameter.
  • Validate the status against the allowed values (succeeded or processing).
  • Fail the test if the status is not one of the expected values.
  • Maintain the existing redirection validation process (e.g., origin matching).

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

This change improves the reliability of Cypress redirection tests by ensuring that the final redirection URL reflects a valid payment status, preventing false positives and ensuring tests behave as expected for flows like 3DS and bank redirects.

How did you test it?

Ran against Integ environment for Stripe:

image

when the validation fails, below is the kind of error we get:

image

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@Ankesh2004 Ankesh2004 requested a review from a team as a code owner October 1, 2024 10:33
Copy link

semanticdiff-com bot commented Oct 1, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  cypress-tests/cypress/support/redirectionHandler.js  6% smaller

Copy link
Member

@pixincreate pixincreate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other than that, looks good to me!

cypress-tests/cypress/support/redirectionHandler.js Outdated Show resolved Hide resolved
cypress-tests/cypress/support/redirectionHandler.js Outdated Show resolved Hide resolved
@pixincreate pixincreate added A-CI-CD Area: Continuous Integration/Deployment S-waiting-on-review Status: This PR has been implemented and needs to be reviewed labels Oct 1, 2024
@pixincreate pixincreate changed the title fix[refactor]: verifyurl in redirection handler refactor(cypress): verify payment status after payment redirection Oct 1, 2024
@Ankesh2004
Copy link
Contributor Author

@pixincreate I have made all the suggested changes.

Copy link
Member

@pixincreate pixincreate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other than that, looks good to me!

cypress-tests/cypress/support/redirectionHandler.js Outdated Show resolved Hide resolved
@Ankesh2004 Ankesh2004 requested a review from pixincreate October 2, 2024 04:58
pixincreate
pixincreate previously approved these changes Oct 2, 2024
@gorakhnathy7 gorakhnathy7 requested review from SanchithHegde, Sakilmostak and Gnanasundari24 and removed request for SanchithHegde October 2, 2024 09:05
Gnanasundari24
Gnanasundari24 previously approved these changes Oct 3, 2024
@Gnanasundari24 Gnanasundari24 self-requested a review October 3, 2024 07:35
@Ankesh2004 Ankesh2004 dismissed stale reviews from Gnanasundari24 and pixincreate via bd3174d October 3, 2024 13:11
likhinbopanna
likhinbopanna previously approved these changes Jan 2, 2025
pixincreate
pixincreate previously approved these changes Jan 3, 2025
Gnanasundari24
Gnanasundari24 previously approved these changes Jan 6, 2025
if (
payment_status !== "succeeded" &&
payment_status !== "processing" &&
payment_status !== "partially_captured" &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to include failed status and have to remove partially_captured state as we shouldn't get this status in authorize call

Copy link
Member

@pixincreate pixincreate Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed this.

we'll now check only for terminal statuses. if we get anything other than that, then we throw the error. and take a screenshot.

image

tested with:


  context.only("[Payment - 3DS] Capture greater amount", () => {
    let shouldContinue = true; // variable that will be used to skip tests if a previous test fails

    before("seed global state", () => {
      cy.task("getGlobalState").then((state) => {
        globalState = new State(state);
      });
    });

    after("flush global state", () => {
      cy.task("setGlobalState", globalState.data);
    });

    beforeEach(function () {
      if (!shouldContinue) {
        this.skip();
      }
    });

    it("Create payment intent and confirm", () => {
      const data = getConnectorDetails(globalState.get("connectorId"))[
        "card_pm"
      ]["No3DSFailPayment"];

      cy.createConfirmPaymentTest(
        paymentCreateConfirmBody,
        data,
        "three_ds",
        "manual",
        globalState
      );

      if (shouldContinue) shouldContinue = utils.should_continue_further(data);
    });

    it("Handle redirection", () => {
      const expected_redirection = fixtures.confirmBody["return_url"];
      cy.handleRedirection(globalState, expected_redirection);
    });

    it("Capture call", () => {
      const data = getConnectorDetails(globalState.get("commons"))["card_pm"][
        "CaptureGreaterAmount"
      ];

      cy.retrievePaymentCallTest(globalState, data);
      cy.captureCallTest(fixtures.captureBody, data, 65000, globalState);

      if (shouldContinue) shouldContinue = utils.should_continue_further(data);
    });
  });

@Gnanasundari24 Gnanasundari24 self-requested a review January 6, 2025 10:17
…tiple smaller functions and also handle for failed case
@pixincreate pixincreate dismissed stale reviews from Gnanasundari24, likhinbopanna, and themself via c74aa11 January 6, 2025 12:11
Gnanasundari24
Gnanasundari24 previously approved these changes Jan 9, 2025
likhinbopanna
likhinbopanna previously approved these changes Jan 9, 2025
@likhinbopanna likhinbopanna added this pull request to the merge queue Jan 9, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 9, 2025
…r-verifyurl-in-redirection-handler

* 'main' of github.com:juspay/hyperswitch: (30 commits)
  test(cypress): add test for In Memory Cache (juspay#6961)
  chore(version): 2025.01.09.1
  fix(dummyconnector): add tenant id in dummyconnector requests (juspay#7008)
  chore(version): 2025.01.09.0
  fix(cypress): backup and restore sessions when using user apis (juspay#6978)
  feat(users): handle edge features for users in tenancy (juspay#6990)
  chore(dynamic-fields): [Worldpay] update dynamic fields for payments (juspay#7002)
  chore(version): 2025.01.08.0
  fix: consider status of payment method before filtering wallets in list pm (juspay#7004)
  feat(core): add columns unified error code and error message in refund table (juspay#6933)
  feat(connector): [Fiuu] Consume transaction id for error cases for Fiuu (juspay#6998)
  docs(cypress): update cypress documentation (juspay#6956)
  chore(version): 2025.01.07.0
  chore(keymanager): add tenant-id to keymanager requests (juspay#6968)
  ci(cypress): Add Session Token Testcases (juspay#6683)
  Ci(Cypress): Add PML test and Dynamic Fields Test for Novalnet (juspay#6544)
  chore(version): 2025.01.06.0
  ci(cypress): fix adyen sofort in cypress (juspay#6984)
  chore: add migrations for Currency type in DB (juspay#6980)
  chore(version): 2025.01.03.0
  ...
…into multiple smaller functions and also handle for failed case"

This reverts commit c74aa11.
@pixincreate
Copy link
Member

UI:

image

CI:

image

@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Jan 13, 2025
Merged via the queue into juspay:main with commit 1d99305 Jan 13, 2025
21 of 23 checks passed
@pixincreate pixincreate removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Jan 13, 2025
pixincreate added a commit that referenced this pull request Jan 13, 2025
…itch into refactor-add-memory-cache

* 'refactor-add-memory-cache' of github.com:juspay/hyperswitch:
  docs(cypress): update file structure (#7016)
  refactor(cypress): verify payment status after payment redirection (#6187)
  chore(version): 2025.01.13.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CI-CD Area: Continuous Integration/Deployment hacktoberfest Issues that are up for grabs for Hacktoberfest participants hacktoberfest-accepted Pull requests accepted as Hacktoberfest contributions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CYPRESS_FRAMEWORK] Verify URL after redirection
5 participants