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

12.0 KB
Raw Blame
import * as fixtures from "../../../fixtures/imports";
import State from "../../../utils/State";
import getConnectorDetails, * as utils from "../../configs/Payment/Utils";

let globalState;
let originalCustomerId;

describe("Card - SingleUse Mandates flow test", () => {
  before("seed global state", function () {
    let skip = false;

    cy.task("getGlobalState")
      .then((state) => {
        globalState = new State(state);
        originalCustomerId = globalState.get("customerId");

        // Skip running test against a connector that is added in the exclude list
        if (
          utils.shouldExcludeConnector(
            globalState.get("connectorId"),
            utils.CONNECTOR_LISTS.EXCLUDE.MANDATE_ID_TEST
          )
        ) {
          skip = true;
        }
      })
      .then(() => {
        if (skip) {
          this.skip();
        }
      });
  });

  after("flush global state", () => {
    // This spec's contexts create their own customers for local mandate/PMID
    // testing, overwriting globalState.customerId along the way. Restore the
    // original customer before flushing so later specs (which just read
    // globalState.customerId) don't inherit a customer scoped to this spec's
    // own mandate tests.
    globalState.set("customerId", originalCustomerId);
    cy.task("setGlobalState", globalState.data);
  });

  context("Card - Zero Auth Payment", () => {
    let shouldContinue = true; // variable that will be used to skip tests if a previous test fails

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

    it("Create Customer", () => {
      cy.createCustomerCallTest(fixtures.customerCreateBody, globalState);
    });

    it("Create No 3DS Payment Intent", () => {
      const data = getConnectorDetails(globalState.get("connectorId"))[
        "card_pm"
      ]["ZeroAuthPaymentIntent"];

      cy.createPaymentIntentTest(
        fixtures.createPaymentBody,
        data,
        "no_three_ds",
        "automatic",
        globalState
      );

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

    it("Confirm No 3DS payment", () => {
      const data = getConnectorDetails(globalState.get("connectorId"))[
        "card_pm"
      ]["ZeroAuthConfirmPayment"];

      cy.confirmCallTest(fixtures.confirmBody, data, true, globalState);

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

    it("Retrieve Payment Call Test", () => {
      const data = getConnectorDetails(globalState.get("connectorId"))[
        "card_pm"
      ]["ZeroAuthConfirmPayment"];

      cy.retrievePaymentCallTest({ globalState, data });
    });

    it("Retrieve CustomerPM Call Test", () => {
      cy.listCustomerPMCallTest(globalState);
    });

    it("Create Recurring Payment Intent", () => {
      const data = getConnectorDetails(globalState.get("connectorId"))[
        "card_pm"
      ]["PaymentIntentOffSession"];

      cy.createPaymentIntentTest(
        fixtures.createPaymentBody,
        data,
        "no_three_ds",
        "automatic",
        globalState
      );

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

    it("Confirm Recurring Payment", () => {
      const data = getConnectorDetails(globalState.get("connectorId"))[
        "card_pm"
      ]["SaveCardConfirmAutoCaptureOffSession"];

      cy.saveCardConfirmCallTest(
        fixtures.saveCardConfirmBody,
        data,
        globalState
      );

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

    it("retrieve-payment-call-test", () => {
      const data = getConnectorDetails(globalState.get("connectorId"))[
        "card_pm"
      ]["SaveCardConfirmAutoCaptureOffSession"];

      cy.retrievePaymentCallTest({ globalState, data });
    });

    it("Customer delete call", () => {
      cy.customerDeleteCall(globalState);
    });
  });

  context(
    "Card - Zero auth Mandate flow Using PMID (create and confirm)",
    () => {
      let shouldContinue = true; // variable that will be used to skip tests if a previous test fails

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

      it("Create Customer", () => {
        cy.createCustomerCallTest(fixtures.customerCreateBody, globalState);
      });

      it("Create No 3DS Payment Intent", () => {
        const data = getConnectorDetails(globalState.get("connectorId"))[
          "card_pm"
        ]["ZeroAuthPaymentIntent"];

        cy.createPaymentIntentTest(
          fixtures.createPaymentBody,
          data,
          "no_three_ds",
          "automatic",
          globalState
        );

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

      it("Confirm No 3DS payment", () => {
        const data = getConnectorDetails(globalState.get("connectorId"))[
          "card_pm"
        ]["ZeroAuthConfirmPayment"];

        cy.confirmCallTest(fixtures.confirmBody, data, true, globalState);

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

      it("retrieve-payment-call-test", () => {
        const data = getConnectorDetails(globalState.get("connectorId"))[
          "card_pm"
        ]["ZeroAuthMandate"];

        cy.retrievePaymentCallTest({ globalState, data });
      });

      it("Confirm No 3DS MIT", () => {
        const data = getConnectorDetails(globalState.get("connectorId"))[
          "card_pm"
        ]["MITAutoCapture"];

        cy.mitUsingPMId(
          fixtures.pmIdConfirmBody,
          data,
          true,
          "automatic",
          globalState
        );
      });

      it("retrieve-payment-call-test", () => {
        const data = getConnectorDetails(globalState.get("connectorId"))[
          "card_pm"
        ]["MITAutoCapture"];

        cy.retrievePaymentCallTest({ globalState, data });
      });

      it("Confirm No 3DS MIT", () => {
        const data = getConnectorDetails(globalState.get("connectorId"))[
          "card_pm"
        ]["MITAutoCapture"];

        cy.mitUsingPMId(
          fixtures.pmIdConfirmBody,
          data,
          true,
          "automatic",
          globalState
        );
      });

      it("retrieve-payment-call-test", () => {
        const data = getConnectorDetails(globalState.get("connectorId"))[
          "card_pm"
        ]["MITAutoCapture"];

        cy.retrievePaymentCallTest({ globalState, data });
      });

      it("Customer delete call", () => {
        cy.customerDeleteCall(globalState);
      });
    }
  );

  context("Card - Zero auth Mandate flow Using PMID (create + confirm)", () => {
    let shouldContinue = true; // variable that will be used to skip tests if a previous test fails

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

    it("Create Customer", () => {
      cy.createCustomerCallTest(fixtures.customerCreateBody, globalState);
    });

    it("Confirm No 3DS CIT", () => {
      const data = getConnectorDetails(globalState.get("connectorId"))[
        "card_pm"
      ]["ZeroAuthConfirmPayment"];

      cy.citForMandatesCallTest(
        fixtures.citConfirmBody,
        data,
        true,
        "automatic",
        "setup_mandate",
        globalState
      );

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

    it("retrieve-payment-call-test", () => {
      const data = getConnectorDetails(globalState.get("connectorId"))[
        "card_pm"
      ]["ZeroAuthMandate"];

      cy.retrievePaymentCallTest({ globalState, data });
    });

    it("Confirm No 3DS MIT", () => {
      const data = getConnectorDetails(globalState.get("connectorId"))[
        "card_pm"
      ]["MITAutoCapture"];

      cy.mitUsingPMId(
        fixtures.pmIdConfirmBody,
        data,
        true,
        "automatic",
        globalState
      );
    });

    it("retrieve-payment-call-test", () => {
      const data = getConnectorDetails(globalState.get("connectorId"))[
        "card_pm"
      ]["MITAutoCapture"];

      cy.retrievePaymentCallTest({ globalState, data });
    });

    // No "Customer delete call" here: the CIT above uses payment_type
    // "setup_mandate", which creates a Mandate record that stays Active.
    // delete_customer refuses to delete a customer with an active mandate
    // (crates/router/src/core/customers.rs), so this customer can't be
    // cleaned up this way.
  });

  context(
    "Card - Zero auth Mandate flow with Manual Capture Using NTID and Card Details (create + confirm)",
    () => {
      let shouldContinue = true;

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

      it("Create Customer", function () {
        if (
          utils.shouldIncludeConnector(
            globalState.get("connectorId"),
            utils.CONNECTOR_LISTS.INCLUDE.ZERO_AUTH_MANDATE
          )
        ) {
          this.skip();
        }

        cy.createCustomerCallTest(fixtures.customerCreateBody, globalState);
      });

      it("Confirm No 3DS CIT", function () {
        if (
          utils.shouldIncludeConnector(
            globalState.get("connectorId"),
            utils.CONNECTOR_LISTS.INCLUDE.ZERO_AUTH_MANDATE
          )
        ) {
          this.skip();
        }

        const data = getConnectorDetails(globalState.get("connectorId"))[
          "card_pm"
        ]["ZeroAuthConfirmPaymentManual"];

        cy.citForMandatesCallTest(
          fixtures.citConfirmBody,
          data,
          true,
          "manual",
          "setup_mandate",
          globalState
        );

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

      it("retrieve-payment-call-test", function () {
        if (
          utils.shouldIncludeConnector(
            globalState.get("connectorId"),
            utils.CONNECTOR_LISTS.INCLUDE.ZERO_AUTH_MANDATE
          )
        ) {
          this.skip();
        }

        const data = getConnectorDetails(globalState.get("connectorId"))[
          "card_pm"
        ]["ZeroAuthMandate"];

        cy.retrievePaymentCallTest({ globalState, data });
      });

      it("Confirm No 3DS MIT", function () {
        if (
          utils.shouldIncludeConnector(
            globalState.get("connectorId"),
            utils.CONNECTOR_LISTS.INCLUDE.ZERO_AUTH_MANDATE
          )
        ) {
          this.skip();
        }

        const data = getConnectorDetails(globalState.get("connectorId"))[
          "card_pm"
        ]["MITManualCapture"];

        cy.mitUsingNTID(
          fixtures.ntidConfirmBody,
          data,
          true,
          "manual",
          globalState
        );

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

      it("mit-capture-call-test", function () {
        if (
          utils.shouldIncludeConnector(
            globalState.get("connectorId"),
            utils.CONNECTOR_LISTS.INCLUDE.ZERO_AUTH_MANDATE
          )
        ) {
          this.skip();
        }

        const data = getConnectorDetails(globalState.get("connectorId"))[
          "card_pm"
        ]["Capture"];

        cy.captureCallTest(fixtures.captureBody, data, globalState);
      });

      it("retrieve-payment-call-test", function () {
        if (
          utils.shouldIncludeConnector(
            globalState.get("connectorId"),
            utils.CONNECTOR_LISTS.INCLUDE.ZERO_AUTH_MANDATE
          )
        ) {
          this.skip();
        }

        const data = getConnectorDetails(globalState.get("connectorId"))[
          "card_pm"
        ]["Capture"];

        cy.retrievePaymentCallTest({ globalState, data });
      });

      // No "Customer delete call" here: the CIT above uses payment_type
      // "setup_mandate", which creates a Mandate record that stays Active.
      // delete_customer refuses to delete a customer with an active mandate
      // (crates/router/src/core/customers.rs), so this customer can't be
      // cleaned up this way.
    }
  );
});