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

chore(tests): add cypress tests for payments eligibility flow (#10221)

Sai Harsha Vardhan748f88d5e81b
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Commons.js b/cypress-tests/cypress/e2e/configs/Payment/Commons.js
index b7c4cc26c6..20971eee7c 100644
--- a/cypress-tests/cypress/e2e/configs/Payment/Commons.js
+++ b/cypress-tests/cypress/e2e/configs/Payment/Commons.js
@@ -19,6 +19,15 @@ const successfulNo3DSCardDetails = {
card_cvc: "999",
};
+const blocklistedCardDetails = {
+ card_number: "4242424242424242",
+ card_exp_month: "01",
+ card_exp_year: "2050",
+ card_holder_name: "John Smith",
+ card_cvc: "349",
+ card_network: "Visa",
+};
+
const successfulThreeDSTestCardDetails = {
card_number: "4111111111111111",
card_exp_month: "10",
@@ -54,6 +63,24 @@ export const multiUseMandateData = {
},
};
+export const standardBillingAddress = {
+ address: {
+ line1: "1467",
+ line2: "Harrison Street",
+ line3: "Harrison Street",
+ city: "San Fransico",
+ state: "CA",
+ zip: "94122",
+ country: "US",
+ first_name: "John",
+ last_name: "Doe",
+ },
+ phone: {
+ number: "8056594427",
+ country_code: "+91",
+ },
+};
+
export const cardRequiredField = {
"payment_method_data.card.card_number": {
required_field: "payment_method_data.card.card_number",
@@ -1873,6 +1900,56 @@ export const connectorDetails = {
},
}),
},
+ eligibility_api: {
+ PaymentIntentForBlocklist: getCustomExchange({
+ Request: {
+ currency: "USD",
+ amount: 6500,
+ },
+ Response: {
+ status: 200,
+ body: {
+ status: "requires_payment_method",
+ },
+ },
+ }),
+ BlocklistedCardDenied: getCustomExchange({
+ Request: {
+ payment_method_type: "card",
+ payment_method_data: {
+ card: blocklistedCardDetails,
+ billing: standardBillingAddress,
+ },
+ },
+ Response: {
+ status: 200,
+ body: {
+ sdk_next_action: {
+ next_action: {
+ deny: {
+ message: "Card number is blocklisted",
+ },
+ },
+ },
+ },
+ },
+ }),
+ NonBlocklistedCardAllowed: getCustomExchange({
+ Request: {
+ payment_method_type: "card",
+ payment_method_data: {
+ card: successfulNo3DSCardDetails,
+ billing: standardBillingAddress,
+ },
+ },
+ Response: {
+ status: 200,
+ body: {
+ // Should not have deny action for non-blocklisted cards
+ },
+ },
+ }),
+ },
mandate_id_too_long: getCustomExchange({
Request: {
mandate_id: "mnd_" + "a".repeat(63),
diff --git a/cypress-tests/cypress/e2e/spec/Payment/00033-PaymentsEligibilityAPI.cy.js b/cypress-tests/cypress/e2e/spec/Payment/00033-PaymentsEligibilityAPI.cy.js
new file mode 100644
index 0000000000..ed962081ef
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Payment/00033-PaymentsEligibilityAPI.cy.js
@@ -0,0 +1,79 @@
+import * as fixtures from "../../../fixtures/imports";
+import State from "../../../utils/State";
+import { connectorDetails } from "../../../e2e/configs/Payment/Commons";
+
+let globalState;
+
+describe("Payments Eligibility API with Blocklist", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ context("Setup Phase", () => {
+ it("payment intent create call", () => {
+ cy.createPaymentIntentTest(
+ fixtures.createPaymentBody,
+ connectorDetails.eligibility_api.PaymentIntentForBlocklist,
+ "no_three_ds",
+ "automatic",
+ globalState
+ );
+ });
+ });
+
+ context("Blocklist Configuration", () => {
+ it("should create blocklist rule for card_bin 424242", () => {
+ cy.blocklistCreateRule(
+ fixtures.blocklistCreateBody,
+ "424242",
+ globalState
+ );
+ });
+
+ it("should enable blocklist functionality using configs API", () => {
+ const merchantId = globalState.get("merchantId");
+ const key = `guard_blocklist_for_${merchantId}`;
+ const value = "true";
+
+ cy.setConfigs(globalState, key, value, "CREATE");
+ });
+ });
+
+ context("Eligibility API Tests", () => {
+ it("should deny payment for blocklisted card_bin 424242", () => {
+ cy.paymentsEligibilityCheck(
+ fixtures.eligibilityCheckBody,
+ connectorDetails.eligibility_api.BlocklistedCardDenied,
+ globalState
+ );
+ });
+
+ it("should allow payment for non-blocklisted card", () => {
+ cy.paymentsEligibilityCheck(
+ fixtures.eligibilityCheckBody,
+ connectorDetails.eligibility_api.NonBlocklistedCardAllowed,
+ globalState
+ );
+ });
+ });
+
+ context("Cleanup", () => {
+ it("should delete blocklist rule", () => {
+ cy.blocklistDeleteRule("card_bin", "424242", globalState);
+ });
+
+ it("should disable blocklist functionality using configs API", () => {
+ const merchantId = globalState.get("merchantId");
+ const key = `guard_blocklist_for_${merchantId}`;
+ const value = "true";
+
+ cy.setConfigs(globalState, key, value, "DELETE");
+ });
+ });
+});
diff --git a/cypress-tests/cypress/fixtures/blocklist-create-body.json b/cypress-tests/cypress/fixtures/blocklist-create-body.json
new file mode 100644
index 0000000000..0a8c55525d
--- /dev/null
+++ b/cypress-tests/cypress/fixtures/blocklist-create-body.json
@@ -0,0 +1,4 @@
+{
+ "type": "card_bin",
+ "data": ""
+}
diff --git a/cypress-tests/cypress/fixtures/eligibility-check-body.json b/cypress-tests/cypress/fixtures/eligibility-check-body.json
new file mode 100644
index 0000000000..785d41ca6e
--- /dev/null
+++ b/cypress-tests/cypress/fixtures/eligibility-check-body.json
@@ -0,0 +1,31 @@
+{
+ "client_secret": "",
+ "payment_method_type": "card",
+ "payment_method_data": {
+ "card": {
+ "card_number": "",
+ "card_exp_month": "",
+ "card_exp_year": "",
+ "card_holder_name": "",
+ "card_cvc": "",
+ "card_network": ""
+ },
+ "billing": {
+ "address": {
+ "line1": "",
+ "line2": "",
+ "line3": "",
+ "city": "",
+ "state": "",
+ "zip": "",
+ "country": "",
+ "first_name": "",
+ "last_name": ""
+ },
+ "phone": {
+ "number": "",
+ "country_code": ""
+ }
+ }
+ }
+}
diff --git a/cypress-tests/cypress/fixtures/imports.js b/cypress-tests/cypress/fixtures/imports.js
index 58768394cb..fa46991646 100644
--- a/cypress-tests/cypress/fixtures/imports.js
+++ b/cypress-tests/cypress/fixtures/imports.js
@@ -24,10 +24,13 @@ import updateConnectorBody from "./update-connector-body.json";
import customerUpdateBody from "./update-customer-body.json";
import voidBody from "./void-payment-body.json";
import ntidConfirmBody from "./create-ntid-mit.json";
+import blocklistCreateBody from "./blocklist-create-body.json";
+import eligibilityCheckBody from "./eligibility-check-body.json";
export {
apiKeyCreateBody,
apiKeyUpdateBody,
+ blocklistCreateBody,
businessProfile,
captureBody,
citConfirmBody,
@@ -39,6 +42,7 @@ export {
createPayoutBody,
customerCreateBody,
customerUpdateBody,
+ eligibilityCheckBody,
gsmBody,
listRefundCall,
merchantCreateBody,
diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js
index 334df1f292..985d5be415 100644
--- a/cypress-tests/cypress/support/commands.js
+++ b/cypress-tests/cypress/support/commands.js
@@ -4182,6 +4182,153 @@ Cypress.Commands.add("cleanupUCSConfigs", (globalState, connector) => {
cy.setConfigs(globalState, "ucs_enabled", "true", "DELETE");
});
+// Blocklist and Eligibility API Commands
+Cypress.Commands.add(
+ "blocklistCreateRule",
+ (requestBody, cardBin, globalState) => {
+ const apiKey = globalState.get("apiKey");
+ const baseUrl = globalState.get("baseUrl");
+ const url = `${baseUrl}/blocklist`;
+
+ const body = {
+ ...requestBody,
+ type: "card_bin",
+ data: cardBin,
+ };
+
+ cy.request({
+ method: "POST",
+ url: url,
+ headers: {
+ "Content-Type": "application/json",
+ "api-key": apiKey,
+ },
+ body: body,
+ failOnStatusCode: false,
+ }).then((response) => {
+ logRequestId(response.headers["x-request-id"]);
+
+ cy.wrap(response).then(() => {
+ if (response.status === 200) {
+ expect(response.body)
+ .to.have.property("fingerprint_id")
+ .to.equal(cardBin);
+ expect(response.body)
+ .to.have.property("data_kind")
+ .to.equal("card_bin");
+ expect(response.body).to.have.property("created_at").to.not.be.null;
+ globalState.set("blocklistRuleId", response.body.fingerprint_id);
+ } else {
+ throw new Error(
+ `Blocklist create rule failed with status: ${response.status} and message: ${response.body?.error?.message}`
+ );
+ }
+ });
+ });
+ }
+);
+
+Cypress.Commands.add("blocklistDeleteRule", (type, data, globalState) => {
+ const apiKey = globalState.get("apiKey");
+ const baseUrl = globalState.get("baseUrl");
+ const url = `${baseUrl}/blocklist`;
+
+ const body = {
+ type: type,
+ data: data,
+ };
+
+ cy.request({
+ method: "DELETE",
+ url: url,
+ headers: {
+ "Content-Type": "application/json",
+ "api-key": apiKey,
+ },
+ body: body,
+ failOnStatusCode: false,
+ }).then((response) => {
+ logRequestId(response.headers["x-request-id"]);
+
+ cy.wrap(response).then(() => {
+ if (response.status === 200) {
+ cy.log(`Blocklist rule deleted for ${type}: ${data}`);
+ } else {
+ throw new Error(
+ `Blocklist delete failed with status: ${response.status} and message: ${response.body?.error?.message}`
+ );
+ }
+ });
+ });
+});
+
+Cypress.Commands.add(
+ "paymentsEligibilityCheck",
+ (requestBody, data, globalState) => {
+ const { Request: reqData, Response: resData } = data || {};
+
+ const publishableKey = globalState.get("publishableKey");
+ const baseUrl = globalState.get("baseUrl");
+ const paymentId = globalState.get("paymentID");
+ const clientSecret = globalState.get("clientSecret");
+ const url = `${baseUrl}/payments/${paymentId}/eligibility`;
+
+ const body = {
+ ...requestBody,
+ client_secret: clientSecret,
+ ...reqData,
+ };
+
+ cy.request({
+ method: "POST",
+ url: url,
+ headers: {
+ "Content-Type": "application/json",
+ "api-key": publishableKey,
+ },
+ body: body,
+ failOnStatusCode: false,
+ }).then((response) => {
+ logRequestId(response.headers["x-request-id"]);
+
+ cy.wrap(response).then(() => {
+ expect(response.headers["content-type"]).to.include("application/json");
+
+ if (response.status === 200) {
+ expect(response.body)
+ .to.have.property("payment_id")
+ .to.equal(paymentId);
+
+ // Check for expected response structure based on test case
+ if (resData.body.sdk_next_action?.next_action?.deny) {
+ expect(response.body).to.have.property("sdk_next_action");
+ expect(response.body.sdk_next_action).to.have.property(
+ "next_action"
+ );
+ expect(response.body.sdk_next_action.next_action).to.have.property(
+ "deny"
+ );
+ expect(response.body.sdk_next_action.next_action.deny)
+ .to.have.property("message")
+ .to.equal(resData.body.sdk_next_action.next_action.deny.message);
+ } else {
+ // For non-blocklisted cards, we expect no deny action
+ if (response.body.sdk_next_action?.next_action?.deny) {
+ throw new Error(
+ "Expected no deny action for non-blocklisted card"
+ );
+ }
+ }
+ } else {
+ throw new Error(
+ `Eligibility check failed with status: ${response.status} and message: ${response.body?.error?.message}`
+ );
+ }
+ });
+ });
+ }
+);
+
// DDC Race Condition Test Commands
Cypress.Commands.add(
"ddcServerSideRaceConditionTest",