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

ci(cypress): fix modular payment method service spec (#14745)

likhinbopanna22e239adc0da
diff --git a/cypress-tests/cypress/e2e/spec/ModularPmService/0000-CoreFlows.cy.js b/cypress-tests/cypress/e2e/spec/ModularPmService/0000-CoreFlows.cy.js
index 20505369ad..9c5d6cf5d5 100644
--- a/cypress-tests/cypress/e2e/spec/ModularPmService/0000-CoreFlows.cy.js
+++ b/cypress-tests/cypress/e2e/spec/ModularPmService/0000-CoreFlows.cy.js
@@ -1,21 +1,37 @@
import * as fixtures from "../../../fixtures/imports";
import State from "../../../utils/State";
import { payment_methods_enabled } from "../../configs/Payment/Commons";
+import getConnectorDetails from "../../configs/Payment/Utils";
let globalState;
-describe("Core flows", () => {
- context("Modular Payment Method core flows", () => {
- before("seed global state", () => {
- cy.task("getGlobalState").then((state) => {
- globalState = new State(state);
- });
- });
+describe("Modular Payment Method Service - Core Flows", () => {
+ let specShouldSkip = false;
+
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
- after("flush global state", () => {
- cy.task("setGlobalState", globalState.data);
+ // The whole spec depends on the modular payment method service
+ if (!globalState.get("pmServiceUrl")) {
+ cy.task("cli_log", "PM_SERVICE_URL not set — skipping the spec");
+ specShouldSkip = true;
+ return;
+ }
});
+ });
+ beforeEach(function () {
+ if (specShouldSkip) {
+ this.skip();
+ }
+ });
+
+ afterEach("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ context("Setup - merchant, api key and connector account", () => {
it("merchant create call", () => {
cy.merchantCreateCallTest(fixtures.merchantCreateBody, globalState);
});
@@ -32,81 +48,169 @@ describe("Core flows", () => {
globalState
);
});
+ });
- it("Modular PM Service - Customer create call", () => {
- cy.customerCreateCall(globalState, fixtures.customerCreate);
+ // Both configs stay in place after the run — the merchant (and with it the
+ // org and merchant ids they are scoped by) is created fresh on every run
+ context("Setup - superposition configs", () => {
+ it("org - enable the modular payment method service", () => {
+ cy.setSuperpositionConfigs(
+ globalState,
+ { "system.should_call_pm_modular_service": true },
+ // DimensionsWithProviderMerchantIdAndOrgId; the org scoped context
+ // is what 54-ConnectorAgnosticMandates uses for the same config
+ { organization_id: globalState.get("organizationId") }
+ );
});
- it("Modular PM Service - Merchant Config create call", () => {
- const key = `should_return_raw_payment_method_details_${globalState.get("merchantId")}`;
-
- cy.setConfigs(globalState, key, "true", "CREATE");
+ it("merchant - enable raw payment method details", () => {
+ cy.setSuperpositionConfigs(
+ globalState,
+ { "payments.should_return_raw_payment_method_details": true },
+ // DimensionsWithProviderMerchantId — this config only resolves
+ // against a merchant scoped context
+ { provider_merchant_id: globalState.get("merchantId") }
+ );
});
+ });
- it("Modular PM Service - Organization Config create call", () => {
- const key = `should_call_pm_modular_service_${globalState.get("organizationId")}`;
-
- cy.setConfigs(globalState, key, "true", "CREATE");
- });
- it("Modular PM Service - Payment Method Create call", () => {
- cy.paymentMethodCreateCall(globalState, fixtures.paymentMethodCreate);
+ context("Customer and payment method core flows", () => {
+ it("Customer create call", () => {
+ cy.customerCreateCall(globalState, fixtures.customerCreate);
});
- it("Modular PM Service - Get Raw Payment Method Details call", () => {
- cy.getRawPaymentMethodDetailsCall(globalState);
+ it("Payment Method Create call", () => {
+ cy.paymentMethodCreateCall(globalState, fixtures.paymentMethodCreate);
});
- it("Modular PM Service - Payments call with pm_id", () => {
- cy.paymentWithSavedPMCall(
+ it("Get Raw Payment Method Details call", () => {
+ cy.getRawPaymentMethodDetailsCall(
globalState,
- fixtures.modularPmServicePaymentsCall
+ fixtures.paymentMethodCreate
);
});
- it("Modular PM Service - Update Payment Method call", () => {
+ it("Payments call with pm_id -> Retrieve Payment", () => {
+ cy.step("Payments call with pm_id", () => {
+ // `retrievePaymentCallTest` asserts the retrieved amount against
+ // `paymentAmount`, which `paymentWithSavedPMCall` does not set
+ globalState.set(
+ "paymentAmount",
+ fixtures.modularPmServicePaymentsCall.amount
+ );
+
+ cy.paymentWithSavedPMCall(globalState, {
+ ...fixtures.modularPmServicePaymentsCall,
+ confirm: false,
+ });
+
+ cy.confirmWithSavedPMCall(globalState, {
+ ...fixtures.modularPmServicePaymentsCall,
+ payment_method_data: {
+ card_token: {
+ card_cvc:
+ fixtures.paymentMethodCreate.payment_method_data.card.card_cvc,
+ },
+ },
+ });
+ });
+
+ cy.step("Retrieve Payment", () => {
+ const data = getConnectorDetails(globalState.get("connectorId"))[
+ "card_pm"
+ ]["No3DSAutoCapture"];
+
+ cy.retrievePaymentCallTest({
+ globalState,
+ data,
+ expectedIntentStatus: "succeeded",
+ });
+ });
+ });
+
+ it("Update Payment Method call", () => {
cy.updateSavedPMCall(globalState, fixtures.paymentMethodUpdate);
});
- it("Modular PM Service - Payment Method List call", () => {
+ it("Payment Method List call", () => {
cy.listSavedPMCall(globalState);
});
+ });
- it("Modular PM Service - Payment Method Session Create call", () => {
+ context("Payment method session core flows", () => {
+ it("Payment Method Session Create call", () => {
cy.pmSessionCreateCall(globalState, fixtures.paymentMethodSessionCreate);
});
- it("Modular PM Service - Payment Method Session Retrieve call", () => {
+ it("Payment Method Session Retrieve call", () => {
cy.pmSessionRetrieveCall(globalState);
});
- it("Modular PM Service - Payment Method Session List call", () => {
+ it("Payment Method Session List call", () => {
cy.pmSessionListPMCall(globalState);
});
- it("Modular PM Service - Payment Method Session Update call", () => {
+ it("Payment Method Session Update call", () => {
cy.pmSessionUpdatePMCall(
globalState,
fixtures.paymentMethodSessionUpdate
);
});
- it("Modular PM Service - Payment Method Session Confirm call", () => {
+ it("Payment Method Session Confirm call", () => {
cy.pmSessionConfirmCall(
globalState,
fixtures.paymentMethodSessionConfirm
);
});
- it("Modular PM Service - Get Payment Method from session token call", () => {
+ it("Get Payment Method from session token call", () => {
cy.getPMFromTokenCall(globalState);
});
- it("Modular PM Service - Payments call with pm_token", () => {
- cy.paymentWithSavedPMCall(
- globalState,
- fixtures.modularPmServicePaymentsCall,
- true
- );
+ it("Payments call with pm_token -> Retrieve Payment", () => {
+ cy.step("Payments call with pm_token", () => {
+ globalState.set(
+ "paymentAmount",
+ fixtures.modularPmServicePaymentsCall.amount
+ );
+
+ cy.paymentWithSavedPMCall(
+ globalState,
+ {
+ ...fixtures.modularPmServicePaymentsCall,
+ confirm: false,
+ },
+ true
+ );
+
+ cy.confirmWithSavedPMCall(
+ globalState,
+ {
+ ...fixtures.modularPmServicePaymentsCall,
+ payment_method_data: {
+ card_token: {
+ card_cvc:
+ fixtures.paymentMethodSessionConfirm.payment_method_data.card
+ .card_cvc,
+ },
+ },
+ },
+ true
+ );
+ });
+
+ cy.step("Retrieve Payment", () => {
+ const data = getConnectorDetails(globalState.get("connectorId"))[
+ "card_pm"
+ ]["No3DSAutoCapture"];
+
+ cy.retrievePaymentCallTest({
+ globalState,
+ data,
+ expectedIntentStatus: "succeeded",
+ });
+ });
});
});
});
diff --git a/cypress-tests/cypress/fixtures/modularPmService/modular-pm-service-pm-create.json b/cypress-tests/cypress/fixtures/modularPmService/modular-pm-service-pm-create.json
index f95bad8b5b..034c812718 100644
--- a/cypress-tests/cypress/fixtures/modularPmService/modular-pm-service-pm-create.json
+++ b/cypress-tests/cypress/fixtures/modularPmService/modular-pm-service-pm-create.json
@@ -3,7 +3,7 @@
"payment_method_subtype": "credit",
"payment_method_data": {
"card": {
- "card_number": "4761360080000093",
+ "card_number": "5555555555554444",
"card_exp_month": "07",
"card_exp_year": "2030",
"card_holder_name": "Gaurav rawat",
diff --git a/cypress-tests/cypress/fixtures/modularPmService/modular-pm-service-pm-update.json b/cypress-tests/cypress/fixtures/modularPmService/modular-pm-service-pm-update.json
index 2524087b20..e69423f9ab 100644
--- a/cypress-tests/cypress/fixtures/modularPmService/modular-pm-service-pm-update.json
+++ b/cypress-tests/cypress/fixtures/modularPmService/modular-pm-service-pm-update.json
@@ -1,7 +1,8 @@
{
"payment_method_data": {
"card": {
- "card_cvc": "123"
+ "card_holder_name": "Gaurav Rawat",
+ "nick_name": "Primary Card"
}
}
}
diff --git a/cypress-tests/cypress/fixtures/modularPmService/modular-pm-service-pms-confirm.json b/cypress-tests/cypress/fixtures/modularPmService/modular-pm-service-pms-confirm.json
index eaa86926cb..639a71f45c 100644
--- a/cypress-tests/cypress/fixtures/modularPmService/modular-pm-service-pms-confirm.json
+++ b/cypress-tests/cypress/fixtures/modularPmService/modular-pm-service-pms-confirm.json
@@ -9,5 +9,13 @@
}
},
"payment_method_type": "card",
- "payment_method_subtype": "credit"
+ "payment_method_subtype": "credit",
+ "customer_acceptance": {
+ "acceptance_type": "offline",
+ "accepted_at": "1963-05-03T04:07:52.723Z",
+ "online": {
+ "ip_address": "in sit",
+ "user_agent": "amet irure esse"
+ }
+ }
}
diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js
index 37b32ac9d9..0e04556ddc 100644
--- a/cypress-tests/cypress/support/commands.js
+++ b/cypress-tests/cypress/support/commands.js
@@ -10083,42 +10083,70 @@ Cypress.Commands.add("paymentMethodCreateCall", (globalState, pmData) => {
});
});
-Cypress.Commands.add("getRawPaymentMethodDetailsCall", (globalState) => {
- const apiKey = globalState.get("apiKey");
- const profileId = globalState.get("profileId");
- const paymentMethodId = globalState.get("paymentMethodId");
+Cypress.Commands.add(
+ "getRawPaymentMethodDetailsCall",
+ (globalState, pmData) => {
+ const apiKey = globalState.get("apiKey");
+ const profileId = globalState.get("profileId");
+ const paymentMethodId = globalState.get("paymentMethodId");
- cy.request({
- method: "GET",
- url: `${globalState.get("pmServiceUrl")}/v1/payment-methods/${paymentMethodId}?fetch_raw_detail=true`,
- headers: {
- "Content-Type": "application/json",
- Accept: "application/json",
- "X-Profile-Id": profileId,
- Authorization: `api-key=${apiKey}`,
- },
- failOnStatusCode: false,
- }).then((response) => {
- if (response.status === 200) {
- expect(response.body).to.have.property("id");
- expect(response.body.id).to.equal(paymentMethodId);
- expect(response.body).to.have.property("payment_method_type");
- expect(response.body).to.have.property("payment_method_subtype");
- expect(response.body).to.have.property("payment_method_data");
- const card = response.body.payment_method_data.card;
- expect(card).to.have.property("last4_digits");
- expect(card).to.have.property("expiry_month");
- expect(card).to.have.property("expiry_year");
- expect(card).to.have.property("card_holder_name");
- expect(card).to.have.property("saved_to_locker");
- expect(card.saved_to_locker).to.be.true;
- } else {
- throw new Error(
- `Get raw payment method details failed with status ${response.status}: ${JSON.stringify(response.body)}`
- );
- }
- });
-});
+ cy.request({
+ method: "GET",
+ url: `${globalState.get("pmServiceUrl")}/v1/payment-methods/${paymentMethodId}?fetch_raw_detail=true`,
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ "X-Profile-Id": profileId,
+ Authorization: `api-key=${apiKey}`,
+ },
+ failOnStatusCode: false,
+ }).then((response) => {
+ if (response.status === 200) {
+ expect(response.body).to.have.property("id");
+ expect(response.body.id).to.equal(paymentMethodId);
+ expect(response.body).to.have.property("payment_method_type");
+ expect(response.body).to.have.property("payment_method_subtype");
+ expect(response.body).to.have.property("payment_method_data");
+ const card = response.body.payment_method_data.card;
+ expect(card).to.have.property("last4_digits");
+ expect(card).to.have.property("expiry_month");
+ expect(card).to.have.property("expiry_year");
+ expect(card).to.have.property("card_holder_name");
+ expect(card).to.have.property("saved_to_locker");
+ expect(card.saved_to_locker).to.be.true;
+
+ // `fetch_raw_detail=true` only includes raw_payment_method_data when
+ // the merchant-scoped
+ // `payments.should_return_raw_payment_method_details` superposition
+ // config allows it for external api keys — a denied fetch silently
+ // omits the field, so asserting it here verifies that config too
+ const expectedCard = pmData?.payment_method_data?.card;
+ if (expectedCard) {
+ const rawCard = response.body.raw_payment_method_data?.card;
+ expect(rawCard, "raw_payment_method_data.card").to.not.be.undefined;
+ expect(rawCard.card_number, "raw card_number").to.equal(
+ expectedCard.card_number
+ );
+ expect(rawCard.card_exp_month, "raw card_exp_month").to.equal(
+ expectedCard.card_exp_month
+ );
+ expect(rawCard.card_exp_year, "raw card_exp_year").to.equal(
+ expectedCard.card_exp_year
+ );
+ if (expectedCard.card_holder_name) {
+ expect(rawCard.card_holder_name, "raw card_holder_name").to.equal(
+ expectedCard.card_holder_name
+ );
+ }
+ }
+ } else {
+ throw new Error(
+ `Get raw payment method details failed with status ${response.status}: ${JSON.stringify(response.body)}`
+ );
+ }
+ });
+ }
+);
Cypress.Commands.add("updateSavedPMCall", (globalState, updateData) => {
const apiKey = globalState.get("apiKey");
@@ -10428,6 +10456,67 @@ Cypress.Commands.add(
}
);
+Cypress.Commands.add(
+ "confirmWithSavedPMCall",
+ (globalState, confirmData, useToken = false) => {
+ const baseUrl = globalState.get("baseUrl");
+ const apiKey = globalState.get("apiKey");
+ const customerId = globalState.get("customerId");
+ const profileId = globalState.get("profileId");
+ const paymentIntentId = globalState.get("paymentID");
+
+ // Same token resolution as paymentWithSavedPMCall — the payment being
+ // confirmed was created against this token.
+ const paymentToken = useToken
+ ? globalState.get("paymentMethodToken") || globalState.get("paymentToken")
+ : globalState.get("paymentMethodId");
+
+ if (!paymentIntentId) {
+ throw new Error(
+ "confirmWithSavedPMCall: no `paymentID` found; create the payment with paymentWithSavedPMCall first"
+ );
+ }
+
+ if (!paymentToken) {
+ throw new Error(
+ "confirmWithSavedPMCall: no payment token found. Set `paymentMethodId` via a payment method create, or `paymentMethodToken` via the payment method session flow, before calling this command"
+ );
+ }
+
+ const requestBody = {
+ ...confirmData,
+ confirm: true,
+ customer_id: customerId,
+ profile_id: profileId,
+ payment_token: paymentToken,
+ };
+
+ cy.request({
+ method: "POST",
+ url: `${baseUrl}/payments/${paymentIntentId}/confirm`,
+ headers: {
+ "Content-Type": "application/json",
+ "api-key": apiKey,
+ },
+ body: requestBody,
+ failOnStatusCode: false,
+ }).then((response) => {
+ if (response.status === 200) {
+ globalState.set("paymentId", response.body.payment_id);
+ globalState.set("paymentID", response.body.payment_id);
+ expect(response.body).to.have.property("payment_id");
+ expect(response.body).to.have.property("status");
+ expect(response.body.amount).to.equal(confirmData.amount);
+ expect(response.body.currency).to.equal(confirmData.currency);
+ } else {
+ throw new Error(
+ `Confirm with saved PM failed with status ${response.status}: ${JSON.stringify(response.body)}`
+ );
+ }
+ });
+ }
+);
+
Cypress.Commands.add("step", (stepName, fn) => {
cy.task("cli_log", `\nSTEP: ${stepName}`);