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

test(cypress): add delayed session response coverage for trustpay (#12519)

HS-QUALIBOT9bdbb3d91eef
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Trustpay.js b/cypress-tests/cypress/e2e/configs/Payment/Trustpay.js
index 0c6a8efa70..0bae60d84a 100644
--- a/cypress-tests/cypress/e2e/configs/Payment/Trustpay.js
+++ b/cypress-tests/cypress/e2e/configs/Payment/Trustpay.js
@@ -542,18 +542,15 @@ export const connectorDetails = {
},
},
SessionToken: {
+ Request: {
+ wallets: ["apple_pay", "google_pay"],
+ },
Response: {
status: 200,
body: {
session_token: [
- {
- wallet_name: "apple_pay",
- connector: "trustpay",
- },
- {
- wallet_name: "google_pay",
- connector: "trustpay",
- },
+ { wallet_name: "apple_pay", connector: "trustpay" },
+ { wallet_name: "google_pay", connector: "trustpay" },
],
},
},
@@ -908,4 +905,82 @@ export const connectorDetails = {
source: "paymentAttemptID",
},
},
+ wallet_pm: {
+ PaymentIntent: getCustomExchange({
+ Request: {
+ currency: "USD",
+ amount: 6000,
+ setup_future_usage: "on_session",
+ },
+ Response: {
+ status: 200,
+ body: {
+ status: "requires_payment_method",
+ },
+ },
+ }),
+ DelayedSessionToken: {
+ Request: {
+ wallets: ["apple_pay", "google_pay"],
+ },
+ Response: {
+ status: 200,
+ body: {
+ session_token: [
+ {
+ wallet_name: "apple_pay",
+ connector: "trustpay",
+ delayed_session_token: true,
+ sdk_next_action: {
+ next_action: "confirm",
+ should_block_confirm: null,
+ },
+ },
+ {
+ wallet_name: "google_pay",
+ connector: "trustpay",
+ delayed_session_token: true,
+ sdk_next_action: {
+ next_action: "confirm",
+ should_block_confirm: null,
+ },
+ },
+ ],
+ },
+ },
+ },
+ DelayedSessionTokenMissingClientSecret: {
+ Request: {
+ wallets: ["apple_pay", "google_pay"],
+ client_secret: null,
+ },
+ Response: {
+ status: 400,
+ body: {
+ error: {
+ type: "invalid_request",
+ code: "IR_04",
+ message: "Missing required param: client_secret",
+ },
+ },
+ },
+ },
+ DelayedSessionTokenInvalidPaymentId: {
+ Request: {
+ wallets: ["apple_pay", "google_pay"],
+ payment_id: "pay_nonexistent12345",
+ client_secret: "pay_nonexistent12345_secret_xyz",
+ },
+ Response: {
+ status: 404,
+ body: {
+ error: {
+ type: "invalid_request",
+ code: "HE_02",
+ message: "Payment does not exist in our records",
+ },
+ },
+ },
+ },
+ },
};
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Utils.js b/cypress-tests/cypress/e2e/configs/Payment/Utils.js
index 0363ed4883..6ad6362b40 100644
--- a/cypress-tests/cypress/e2e/configs/Payment/Utils.js
+++ b/cypress-tests/cypress/e2e/configs/Payment/Utils.js
@@ -673,6 +673,7 @@ export const CONNECTOR_LISTS = {
"worldpayvantiv",
],
POLL_CONFIG: ["stripe"],
+ DELAYED_SESSION_TOKEN: ["trustpay", "payme"],
CLIENT_SESSION_VALIDATION: ["stripe"],
// Add more inclusion lists
},
diff --git a/cypress-tests/cypress/e2e/spec/Payment/26-SessionCall.cy.js b/cypress-tests/cypress/e2e/spec/Payment/26-SessionCall.cy.js
index 5a62f5f1a6..451447c3f1 100644
--- a/cypress-tests/cypress/e2e/spec/Payment/26-SessionCall.cy.js
+++ b/cypress-tests/cypress/e2e/spec/Payment/26-SessionCall.cy.js
@@ -4,47 +4,52 @@ import getConnectorDetails, * as utils from "../../configs/Payment/Utils";
let globalState;
-describe("Customer Create flow test", () => {
+describe("Session Call flow test", () => {
before("seed global state", () => {
cy.task("getGlobalState").then((state) => {
globalState = new State(state);
});
});
- after("flush global state", () => {
+ afterEach("flush global state", () => {
cy.task("setGlobalState", globalState.data);
});
- const shouldContinue = true; // variable that will be used to skip tests if a previous test fails
-
- beforeEach(function () {
- if (!shouldContinue) {
- this.skip();
- }
- });
- it("create-payment-call-test", () => {
- let shouldContinue = true; // variable that will be used to skip tests if a previous test fails
-
- const data = getConnectorDetails(globalState.get("connectorId"))["card_pm"][
- "PaymentIntent"
- ];
-
- cy.createPaymentIntentTest(
- fixtures.createPaymentBody,
- data,
- "no_three_ds",
- "automatic",
- globalState
- );
-
- if (shouldContinue) shouldContinue = utils.should_continue_further(data);
- });
-
- it("session-call-test", () => {
- const data = getConnectorDetails(globalState.get("connectorId"))["card_pm"][
- "SessionToken"
- ];
-
- cy.sessionTokenCall(fixtures.sessionTokenBody, data, globalState);
+ context("Session token retrieval flow", () => {
+ it("session-call-flow", () => {
+ let shouldContinue = true;
+
+ cy.step("Step 1: Create payment intent", () => {
+ const data = getConnectorDetails(globalState.get("connectorId"))[
+ "card_pm"
+ ]["PaymentIntent"];
+
+ cy.createPaymentIntentTest(
+ fixtures.createPaymentBody,
+ data,
+ "no_three_ds",
+ "automatic",
+ globalState
+ );
+
+ if (shouldContinue)
+ shouldContinue = utils.should_continue_further(data);
+ });
+
+ cy.step("Step 2: Get session token", () => {
+ if (!shouldContinue) {
+ cy.log(
+ "⏭️ Skipping step due to previous failure - should_continue_further returned false"
+ );
+ return;
+ }
+
+ const data = getConnectorDetails(globalState.get("connectorId"))[
+ "card_pm"
+ ]["SessionToken"];
+
+ cy.sessionTokenCall(fixtures.sessionTokenBody, data, globalState);
+ });
+ });
});
});
diff --git a/cypress-tests/cypress/e2e/spec/Payment/53-DelayedSessionToken.cy.js b/cypress-tests/cypress/e2e/spec/Payment/53-DelayedSessionToken.cy.js
new file mode 100644
index 0000000000..0510386620
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Payment/53-DelayedSessionToken.cy.js
@@ -0,0 +1,126 @@
+import * as fixtures from "../../../fixtures/imports";
+import State from "../../../utils/State";
+import getConnectorDetails, {
+ CONNECTOR_LISTS,
+ shouldIncludeConnector,
+} from "../../configs/Payment/Utils";
+import * as utils from "../../configs/Payment/Utils";
+
+let globalState;
+let connector;
+
+describe("Delayed Session Token flow test", () => {
+ before("seed global state", function () {
+ let skip = false;
+
+ cy.task("getGlobalState")
+ .then((state) => {
+ globalState = new State(state);
+ connector = globalState.get("connectorId");
+
+ if (
+ shouldIncludeConnector(
+ connector,
+ CONNECTOR_LISTS.INCLUDE.DELAYED_SESSION_TOKEN
+ )
+ ) {
+ skip = true;
+ return;
+ }
+ })
+ .then(() => {
+ if (skip) {
+ this.skip();
+ }
+ });
+ });
+
+ afterEach("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ context("Delayed session token - Apple Pay and Google Pay", () => {
+ it("Create Payment Intent -> Get Delayed Session Token", () => {
+ let shouldContinue = true;
+
+ cy.step("Create Payment Intent", () => {
+ const data = getConnectorDetails(globalState.get("connectorId"))[
+ "wallet_pm"
+ ]["PaymentIntent"];
+
+ cy.createPaymentIntentTest(
+ fixtures.createPaymentBody,
+ data,
+ "no_three_ds",
+ "automatic",
+ globalState
+ );
+
+ if (!utils.should_continue_further(data)) {
+ shouldContinue = false;
+ }
+ });
+
+ cy.step("Get Delayed Session Token", () => {
+ if (!shouldContinue) {
+ cy.task("cli_log", "Skipping step: Get Delayed Session Token");
+ return;
+ }
+ const data = getConnectorDetails(globalState.get("connectorId"))[
+ "wallet_pm"
+ ]["DelayedSessionToken"];
+
+ cy.sessionTokenCall(fixtures.sessionTokenBody, data, globalState);
+ });
+ });
+ });
+
+ context("Error case - Missing client_secret", () => {
+ it("Create Payment Intent -> Session Token without client_secret", () => {
+ let shouldContinue = true;
+
+ cy.step("Create Payment Intent", () => {
+ const data = getConnectorDetails(globalState.get("connectorId"))[
+ "wallet_pm"
+ ]["PaymentIntent"];
+
+ cy.createPaymentIntentTest(
+ fixtures.createPaymentBody,
+ data,
+ "no_three_ds",
+ "automatic",
+ globalState
+ );
+
+ if (!utils.should_continue_further(data)) {
+ shouldContinue = false;
+ }
+ });
+
+ cy.step("Session Token without client_secret", () => {
+ if (!shouldContinue) {
+ cy.task(
+ "cli_log",
+ "Skipping step: Session Token without client_secret"
+ );
+ return;
+ }
+ const data = getConnectorDetails(globalState.get("connectorId"))[
+ "wallet_pm"
+ ]["DelayedSessionTokenMissingClientSecret"];
+
+ cy.sessionTokenCall(fixtures.sessionTokenBody, data, globalState);
+ });
+ });
+ });
+
+ context("Error case - Invalid payment_id", () => {
+ it("Session Token with invalid payment_id", () => {
+ const data = getConnectorDetails(globalState.get("connectorId"))[
+ "wallet_pm"
+ ]["DelayedSessionTokenInvalidPaymentId"];
+
+ cy.sessionTokenCall(fixtures.sessionTokenBody, data, globalState);
+ });
+ });
+});
diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js
index d34279f34d..60ab6291e8 100644
--- a/cypress-tests/cypress/support/commands.js
+++ b/cypress-tests/cypress/support/commands.js
@@ -2287,10 +2287,19 @@ Cypress.Commands.add(
Cypress.Commands.add(
"sessionTokenCall",
(sessionTokenBody, data, globalState) => {
- const { Response: resData } = data || {};
+ const { Request: reqData = {}, Response: resData } = data || {};
- sessionTokenBody.payment_id = globalState.get("paymentID");
- sessionTokenBody.client_secret = globalState.get("clientSecret");
+ sessionTokenBody.wallets = reqData.wallets || [];
+ if ("payment_id" in reqData) {
+ sessionTokenBody.payment_id = reqData.payment_id;
+ } else {
+ sessionTokenBody.payment_id = globalState.get("paymentID");
+ }
+ if ("client_secret" in reqData) {
+ sessionTokenBody.client_secret = reqData.client_secret;
+ } else {
+ sessionTokenBody.client_secret = globalState.get("clientSecret");
+ }
cy.request({
method: "POST",
@@ -2317,17 +2326,12 @@ Cypress.Commands.add(
expectedTokens.length
);
- // Verify specific fields in each session_token object
+ // Verify all keys in each session_token object
expectedTokens.forEach((expectedToken, index) => {
const actualToken = actualTokens[index];
-
- // Check specific fields only
- expect(actualToken.wallet_name, "wallet_name").to.equal(
- expectedToken.wallet_name
- );
- expect(actualToken.connector, "connector").to.equal(
- expectedToken.connector
- );
+ for (const key in expectedToken) {
+ expect(actualToken[key], key).to.deep.equal(expectedToken[key]);
+ }
});
} else {
defaultErrorHandler(response, resData);