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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
ci(cypress): add payment method blocking tests for business profile (#11652)
likhinbopannad8f3806c906b
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Commons.js b/cypress-tests/cypress/e2e/configs/Payment/Commons.jsindex 951d6197bf..8d310217f8 100644--- a/cypress-tests/cypress/e2e/configs/Payment/Commons.js+++ b/cypress-tests/cypress/e2e/configs/Payment/Commons.js@@ -1,6 +1,19 @@// This file is the default. To override, add to connector.jsimport { getCurrency, getCustomExchange } from "./Modifiers";+export const blockedPaymentErrorBody = {+ status: 200,+ expectBlockedPayment: true,+ body: {+ error: {+ type: "blocked",+ message: "This payment method is blocked",+ code: "HE_03",+ reason: "Blocked",+ },+ },+};+export const customerAcceptance = {acceptance_type: "offline",accepted_at: "1963-05-03T04:07:52.723Z",@@ -2348,4 +2361,70 @@ export const connectorDetails = {},},}),+ payment_method_blocking_pm: {+ BlockIssuingCountry: getCustomExchange({+ Request: {+ payment_method: "card",+ payment_method_data: {+ card: {+ card_number: "4000000000000002",+ card_exp_month: "03",+ card_exp_year: "30",+ card_holder_name: "joseph Doeeee",+ card_cvc: "737",+ card_network: "Visa",+ },+ },+ },+ Response: blockedPaymentErrorBody,+ }),+ BlockCardType: getCustomExchange({+ Request: {+ payment_method: "card",+ payment_method_data: {+ card: {+ card_number: "4111111111111111",+ card_exp_month: "03",+ card_exp_year: "30",+ card_holder_name: "joseph Doeeee",+ card_cvc: "737",+ card_network: "Visa",+ },+ },+ },+ Response: blockedPaymentErrorBody,+ }),+ BlockCardSubtype: getCustomExchange({+ Request: {+ payment_method: "card",+ payment_method_data: {+ card: {+ card_number: "378282246310005",+ card_exp_month: "03",+ card_exp_year: "30",+ card_holder_name: "joseph Doeeee",+ card_cvc: "737",+ card_network: "Visa",+ },+ },+ },+ Response: blockedPaymentErrorBody,+ }),+ BlockIfBinInfoUnavailable: getCustomExchange({+ Request: {+ payment_method: "card",+ payment_method_data: {+ card: {+ card_number: "6304000000000000",+ card_exp_month: "03",+ card_exp_year: "30",+ card_holder_name: "joseph Doeeee",+ card_cvc: "737",+ card_network: "Visa",+ },+ },+ },+ Response: blockedPaymentErrorBody,+ }),+ },};diff --git a/cypress-tests/cypress/e2e/spec/Payment/41-CardPaymentBlocking.cy.js b/cypress-tests/cypress/e2e/spec/Payment/41-CardPaymentBlocking.cy.jsnew file mode 100644index 0000000000..be411ac87b--- /dev/null+++ b/cypress-tests/cypress/e2e/spec/Payment/41-CardPaymentBlocking.cy.js@@ -0,0 +1,275 @@+import * as fixtures from "../../../fixtures/imports";+import State from "../../../utils/State";+import getConnectorDetails, * as utils from "../../configs/Payment/Utils";++let globalState;++describe("Business Profile Payment Method Blocking", () => {+ before("seed global state", () => {+ cy.task("getGlobalState").then((state) => {+ globalState = new State(state);+ });+ });++ after("flush global state", () => {+ 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("Enable blocklist", () => {+ cy.blocklistToggle("true", globalState);+ });++ 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("Card Type 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: ["smallcorporate"],+ },+ },+ };+ 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+ );+ }+ );++ cy.step("Disable blocklist", () => {+ cy.blocklistToggle("false", globalState);+ });+ });+ });+});diff --git a/cypress-tests/cypress/e2e/spec/Payment/41-DynamicFields.cy.js b/cypress-tests/cypress/e2e/spec/Payment/42-DynamicFields.cy.jssimilarity index 100%rename from cypress-tests/cypress/e2e/spec/Payment/41-DynamicFields.cy.jsrename to cypress-tests/cypress/e2e/spec/Payment/42-DynamicFields.cy.jsdiff --git a/cypress-tests/cypress/e2e/spec/Payment/42-PaymentWebhook.cy.js b/cypress-tests/cypress/e2e/spec/Payment/43-PaymentWebhook.cy.jssimilarity index 100%rename from cypress-tests/cypress/e2e/spec/Payment/42-PaymentWebhook.cy.jsrename to cypress-tests/cypress/e2e/spec/Payment/43-PaymentWebhook.cy.jsdiff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.jsindex 0a06abe9f1..7634bd24ab 100644--- a/cypress-tests/cypress/support/commands.js+++ b/cypress-tests/cypress/support/commands.js@@ -2264,7 +2264,18 @@ Cypress.Commands.add(cy.wrap(response).then(() => {expect(response.headers["content-type"]).to.include("application/json");- if (response.status === 200) {++ // Check if this is a blocklist / payment method blocking case+ const expectBlockedPayment = resData?.expectBlockedPayment || false;++ if (expectBlockedPayment && response.status === 200) {+ // Blocklist case: HTTP 200 with an error body instead of a success body+ expect(response.status, "status_code").to.equal(200);+ // Validate response body against expected values from config (Commons.js)+ for (const key in resData.body) {+ expect(resData.body[key], [key]).to.deep.equal(response.body[key]);+ }+ } else if (response.status === 200) {globalState.set("paymentID", paymentIntentID);updateConnectorState(globalState, response.body.connector);globalState.set(@@ -6162,3 +6173,31 @@ Cypress.Commands.add(});});++Cypress.Commands.add("blocklistToggle", (status, globalState) => {+ const apiKey = globalState.get("apiKey");+ const baseUrl = globalState.get("baseUrl");+ const url = `${baseUrl}/blocklist/toggle?status=${status}`;++ cy.request({+ method: "POST",+ url: url,+ headers: {+ "Content-Type": "application/json",+ "api-key": apiKey,+ },+ failOnStatusCode: false,+ }).then((response) => {+ logRequestId(response.headers["x-request-id"]);++ cy.wrap(response).then(() => {+ if (response.status === 200) {+ cy.log(`Blocklist toggled successfully to status: ${status}`);+ } else {+ throw new Error(+ `Blocklist toggle failed with status: ${response.status} and message: ${response.body?.error?.message}`+ );+ }+ });+ });+});