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

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

let globalState;

const blocklistContext = () => ({
  processor_merchant_id: globalState.get("merchantId"),
  provider_merchant_id: globalState.get("merchantId"),
  profile_id: globalState.get("profileId"),
});

describe("Business Profile Payment Method Blocking", () => {
  let specShouldSkip = false;

  before("seed global state", () => {
    cy.task("getGlobalState").then((state) => {
      globalState = new State(state);
      if (
        !globalState.get("superpositionBaseUrl") ||
        !globalState.get("superpositionSecret") ||
        !globalState.get("superpositionAuthToken")
      ) {
        cy.task(
          "cli_log",
          "Superposition credentials not set — skipping blocklist spec"
        );
        specShouldSkip = true;
        return;
      }
      expect(globalState.get("merchantId"), "merchant ID").to.be.a("string").and
        .not.be.empty;
      cy.setSuperpositionConfig(
        globalState,
        "payments.payment_blocklist_guard",
        true,
        blocklistContext()
      );
    });
  });

  beforeEach(function () {
    if (specShouldSkip) {
      this.skip();
    }
  });

  after("cleanup superposition config + flush global state", () => {
    if (!specShouldSkip && globalState?.get("merchantId")) {
      cy.setSuperpositionConfig(
        globalState,
        "payments.payment_blocklist_guard",
        false,
        blocklistContext()
      );
    }
    cy.task("setGlobalState", globalState.data);
  });

  context("Card Issuing Country Blocking", () => {
    it("should block payment when card issuing country is blocked", () => {
      let shouldContinue = true;

      cy.step("Update business profile to block issuing country", () => {
        const updateBusinessProfileBody = {
          payment_method_blocking: {
            card: {
              issuing_country: ["US"],
            },
          },
        };
        cy.UpdateBusinessProfileTest(
          updateBusinessProfileBody,
          false, // is_connector_agnostic_enabled
          false, // collect_billing_address_from_wallet_connector
          false, // collect_shipping_address_from_wallet_connector
          false, // always_collect_billing_address_from_wallet_connector
          false, // always_collect_shipping_address_from_wallet_connector
          globalState
        );
      });

      cy.step("Create Payment Intent", () => {
        const data = getConnectorDetails(globalState.get("connectorId"))[
          "card_pm"
        ]["PaymentIntent"];

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

        if (!utils.should_continue_further(data)) {
          shouldContinue = false;
        }
      });

      cy.step("Confirm Payment Intent - should be blocked", () => {
        if (!shouldContinue) {
          cy.task("cli_log", "Skipping step: Confirm Payment Intent");
          return;
        }

        const confirmData = getConnectorDetails(globalState.get("connectorId"))[
          "payment_method_blocking_pm"
        ]["BlockIssuingCountry"];

        cy.confirmCallTest(
          fixtures.confirmBody,
          confirmData,
          true,
          globalState
        );
      });
    });
  });

  context("Debit Card Blocking", () => {
    it("should block payment when debit cards are blocked", () => {
      let shouldContinue = true;

      cy.step("Update business profile to block debit cards", () => {
        const updateBusinessProfileBody = {
          payment_method_blocking: {
            card: {
              card_types: ["debit"],
            },
          },
        };
        cy.UpdateBusinessProfileTest(
          updateBusinessProfileBody,
          false, // is_connector_agnostic_enabled
          false, // collect_billing_address_from_wallet_connector
          false, // collect_shipping_address_from_wallet_connector
          false, // always_collect_billing_address_from_wallet_connector
          false, // always_collect_shipping_address_from_wallet_connector
          globalState
        );
      });

      cy.step("Create Payment Intent", () => {
        const data = getConnectorDetails(globalState.get("connectorId"))[
          "card_pm"
        ]["PaymentIntent"];

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

        if (!utils.should_continue_further(data)) {
          shouldContinue = false;
        }
      });

      cy.step("Confirm Payment Intent - should be blocked", () => {
        if (!shouldContinue) {
          cy.task("cli_log", "Skipping step: Confirm Payment Intent");
          return;
        }

        const confirmData = getConnectorDetails(globalState.get("connectorId"))[
          "payment_method_blocking_pm"
        ]["BlockCardType"];

        cy.confirmCallTest(
          fixtures.confirmBody,
          confirmData,
          true,
          globalState
        );
      });
    });
  });

  context("Card Subtype Blocking", () => {
    it("should block payment when card subtype is blocked", () => {
      let shouldContinue = true;

      cy.step("Update business profile to block specific card subtype", () => {
        const updateBusinessProfileBody = {
          payment_method_blocking: {
            card: {
              card_subtypes: ["CORPORATE"],
            },
          },
        };
        cy.UpdateBusinessProfileTest(
          updateBusinessProfileBody,
          false, // is_connector_agnostic_enabled
          false, // collect_billing_address_from_wallet_connector
          false, // collect_shipping_address_from_wallet_connector
          false, // always_collect_billing_address_from_wallet_connector
          false, // always_collect_shipping_address_from_wallet_connector
          globalState
        );
      });

      cy.step("Create Payment Intent", () => {
        const data = getConnectorDetails(globalState.get("connectorId"))[
          "card_pm"
        ]["PaymentIntent"];

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

        if (!utils.should_continue_further(data)) {
          shouldContinue = false;
        }
      });

      cy.step("Confirm Payment Intent - should be blocked", () => {
        if (!shouldContinue) {
          cy.task("cli_log", "Skipping step: Confirm Payment Intent");
          return;
        }

        const confirmData = getConnectorDetails(globalState.get("connectorId"))[
          "payment_method_blocking_pm"
        ]["BlockCardSubtype"];

        cy.confirmCallTest(
          fixtures.confirmBody,
          confirmData,
          true,
          globalState
        );
      });
    });
  });

  context("Block If BIN Info Unavailable", () => {
    it("should block payment when BIN info is unavailable and block_if_bin_info_unavailable is true", () => {
      let shouldContinue = true;

      cy.step(
        "Update business profile to block when BIN info unavailable",
        () => {
          const updateBusinessProfileBody = {
            payment_method_blocking: {
              card: {
                block_if_bin_info_unavailable: true,
              },
            },
          };
          cy.UpdateBusinessProfileTest(
            updateBusinessProfileBody,
            false, // is_connector_agnostic_enabled
            false, // collect_billing_address_from_wallet_connector
            false, // collect_shipping_address_from_wallet_connector
            false, // always_collect_billing_address_from_wallet_connector
            false, // always_collect_shipping_address_from_wallet_connector
            globalState
          );
        }
      );

      cy.step("Create Payment Intent", () => {
        const data = getConnectorDetails(globalState.get("connectorId"))[
          "card_pm"
        ]["PaymentIntent"];

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

        if (!utils.should_continue_further(data)) {
          shouldContinue = false;
        }
      });

      cy.step(
        "Confirm Payment Intent - should be blocked when BIN unavailable",
        () => {
          if (!shouldContinue) {
            cy.task("cli_log", "Skipping step: Confirm Payment Intent");
            return;
          }

          const confirmData = getConnectorDetails(
            globalState.get("connectorId")
          )["payment_method_blocking_pm"]["BlockIfBinInfoUnavailable"];

          cy.confirmCallTest(
            fixtures.confirmBody,
            confirmData,
            true,
            globalState
          );
        }
      );
    });
  });
});