From 1e049e029565e3a9b892cbcb3f7a0784ff3078e8 Mon Sep 17 00:00:00 2001 From: gnanasundarig Date: Mon, 30 Sep 2024 04:00:50 +0530 Subject: [PATCH 1/6] ci(cypress): Add field level verification --- .../cypress/e2e/PaymentUtils/Stripe.js | 87 +- cypress-tests/cypress/support/commands.js | 2536 +++++++---------- 2 files changed, 1187 insertions(+), 1436 deletions(-) diff --git a/cypress-tests/cypress/e2e/PaymentUtils/Stripe.js b/cypress-tests/cypress/e2e/PaymentUtils/Stripe.js index d34ae2a8254..826f65d1aa7 100644 --- a/cypress-tests/cypress/e2e/PaymentUtils/Stripe.js +++ b/cypress-tests/cypress/e2e/PaymentUtils/Stripe.js @@ -62,6 +62,7 @@ export const connectorDetails = { status: 200, body: { status: "requires_payment_method", + setup_future_usage: "on_session", }, }, }, @@ -75,6 +76,7 @@ export const connectorDetails = { status: 200, body: { status: "requires_payment_method", + setup_future_usage: "off_session", }, }, }, @@ -91,10 +93,29 @@ export const connectorDetails = { Response: { status: 200, body: { - status: "requires_capture", + status: "requires_customer_action", + setup_future_usage: "on_session", + payment_method_data: { + card: { + last4: "3155", + card_type: "CREDIT", + card_network: null, + card_issuer: "INTL HDQTRS-CENTER OWNED", + card_issuing_country: "UNITEDSTATES", + card_isin: "400000", + card_extended_bin: null, + card_exp_month: "10", + card_exp_year: "25", + card_holder_name: null, + payment_checks: null, + authentication_data: null, + }, + billing: null, + }, }, }, }, + "3DSAutoCapture": { Request: { payment_method: "card", @@ -109,6 +130,24 @@ export const connectorDetails = { status: 200, body: { status: "requires_customer_action", + setup_future_usage: "on_session", + payment_method_data: { + card: { + last4: "3155", + card_type: "CREDIT", + card_network: null, + card_issuer: "INTL HDQTRS-CENTER OWNED", + card_issuing_country: "UNITEDSTATES", + card_isin: "400000", + card_extended_bin: null, + card_exp_month: "10", + card_exp_year: "25", + card_holder_name: null, + payment_checks: null, + authentication_data: null, + }, + billing: null, + }, }, }, }, @@ -126,6 +165,29 @@ export const connectorDetails = { status: 200, body: { status: "requires_capture", + payment_method: "card", + attempt_count: 1, + payment_method_data: { + card: { + last4: "4242", + card_type: "CREDIT", + card_network: null, + card_issuer: "STRIPE PAYMENTS UK LIMITED", + card_issuing_country: "UNITEDKINGDOM", + card_isin: "424242", + card_extended_bin: null, + card_exp_month: "10", + card_exp_year: "25", + card_holder_name: null, + payment_checks: { + cvc_check: "pass", + address_line1_check: "pass", + address_postal_code_check: "pass", + }, + authentication_data: null, + }, + billing: null, + }, }, }, }, @@ -143,6 +205,29 @@ export const connectorDetails = { status: 200, body: { status: "succeeded", + payment_method: "card", + attempt_count: 1, + payment_method_data: { + card: { + last4: "4242", + card_type: "CREDIT", + card_network: null, + card_issuer: "STRIPE PAYMENTS UK LIMITED", + card_issuing_country: "UNITEDKINGDOM", + card_isin: "424242", + card_extended_bin: null, + card_exp_month: "10", + card_exp_year: "25", + card_holder_name: null, + payment_checks: { + cvc_check: "pass", + address_line1_check: "pass", + address_postal_code_check: "pass", + }, + authentication_data: null, + }, + billing: null, + }, }, }, }, diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js index 396be8e59f4..63d7c54b5a6 100644 --- a/cypress-tests/cypress/support/commands.js +++ b/cypress-tests/cypress/support/commands.js @@ -37,31 +37,28 @@ function logRequestId(xRequestId) { } } -Cypress.Commands.add( - "merchantCreateCallTest", - (merchantCreateBody, globalState) => { - const randomMerchantId = RequestBodyUtils.generateRandomString(); - RequestBodyUtils.setMerchantId(merchantCreateBody, randomMerchantId); - globalState.set("merchantId", randomMerchantId); +Cypress.Commands.add("merchantCreateCallTest", (merchantCreateBody, globalState) => { + const randomMerchantId = RequestBodyUtils.generateRandomString(); + RequestBodyUtils.setMerchantId(merchantCreateBody, randomMerchantId); + globalState.set("merchantId", randomMerchantId); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/accounts`, - headers: { - Accept: "application/json", - "Content-Type": "application/json", - "api-key": globalState.get("adminApiKey"), - }, - body: merchantCreateBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/accounts`, + headers: { + Accept: "application/json", + "Content-Type": "application/json", + "api-key": globalState.get("adminApiKey"), + }, + body: merchantCreateBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); - // Handle the response as needed - globalState.set("publishableKey", response.body.publishable_key); - globalState.set("merchantDetails", response.body.merchant_details); - }); - } -); + // Handle the response as needed + globalState.set("publishableKey", response.body.publishable_key); + globalState.set("merchantDetails", response.body.merchant_details); + }); +}); Cypress.Commands.add("merchantRetrieveCall", (globalState) => { const merchant_id = globalState.get("merchantId"); @@ -125,43 +122,38 @@ Cypress.Commands.add("merchantListCall", (globalState) => { expect(response.headers["content-type"]).to.include("application/json"); for (const key in response.body) { expect(response.body[key]).to.have.property("merchant_id").and.not.empty; - expect(response.body[key]).to.have.property("organization_id").and.not - .empty; - expect(response.body[key]).to.have.property("default_profile").and.not - .empty; + expect(response.body[key]).to.have.property("organization_id").and.not.empty; + expect(response.body[key]).to.have.property("default_profile").and.not.empty; } }); }); -Cypress.Commands.add( - "merchantUpdateCall", - (merchantUpdateBody, globalState) => { - const merchant_id = globalState.get("merchantId"); - const organization_id = globalState.get("organizationId"); - const publishable_key = globalState.get("publishableKey"); - const merchant_details = globalState.get("merchantDetails"); - - merchantUpdateBody.merchant_id = merchant_id; - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/accounts/${merchant_id}`, - headers: { - Accept: "application/json", - "Content-Type": "application/json", - "api-key": globalState.get("adminApiKey"), - }, - body: merchantUpdateBody, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - expect(response.body.merchant_id).to.equal(merchant_id); - expect(response.body.publishable_key).to.equal(publishable_key); - expect(response.body.organization_id).to.equal(organization_id); - expect(response.body.merchant_details).to.not.equal(merchant_details); - }); - } -); +Cypress.Commands.add("merchantUpdateCall", (merchantUpdateBody, globalState) => { + const merchant_id = globalState.get("merchantId"); + const organization_id = globalState.get("organizationId"); + const publishable_key = globalState.get("publishableKey"); + const merchant_details = globalState.get("merchantDetails"); + + merchantUpdateBody.merchant_id = merchant_id; + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/accounts/${merchant_id}`, + headers: { + Accept: "application/json", + "Content-Type": "application/json", + "api-key": globalState.get("adminApiKey"), + }, + body: merchantUpdateBody, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + expect(response.body.merchant_id).to.equal(merchant_id); + expect(response.body.publishable_key).to.equal(publishable_key); + expect(response.body.organization_id).to.equal(organization_id); + expect(response.body.merchant_details).to.not.equal(merchant_details); + }); +}); Cypress.Commands.add("apiKeyCreateTest", (apiKeyCreateBody, globalState) => { cy.request({ @@ -249,11 +241,9 @@ Cypress.Commands.add("apiKeyListCall", (globalState) => { for (const key in response.body) { expect(response.body[key]).to.have.property("name").and.not.empty; if (base_url.includes("sandbox") || base_url.includes("integ")) { - expect(response.body[key]).to.have.property("key_id").include("snd_") - .and.not.empty; + expect(response.body[key]).to.have.property("key_id").include("snd_").and.not.empty; } else if (base_url.includes("localhost")) { - expect(response.body[key]).to.have.property("key_id").include("dev_") - .and.not.empty; + expect(response.body[key]).to.have.property("key_id").include("dev_").and.not.empty; } expect(response.body[key].merchant_id).to.equal(merchant_id); } @@ -285,14 +275,7 @@ Cypress.Commands.add("apiKeyDeleteCall", (globalState) => { Cypress.Commands.add( "createNamedConnectorCallTest", - ( - connectorType, - createConnectorBody, - payment_methods_enabled, - globalState, - connectorName, - connectorLabel - ) => { + (connectorType, createConnectorBody, payment_methods_enabled, globalState, connectorName, connectorLabel) => { const merchantId = globalState.get("merchantId"); createConnectorBody.connector_type = connectorType; createConnectorBody.connector_name = connectorName; @@ -300,187 +283,133 @@ Cypress.Commands.add( createConnectorBody.payment_methods_enabled = payment_methods_enabled; // readFile is used to read the contents of the file and it always returns a promise ([Object Object]) due to its asynchronous nature // it is best to use then() to handle the response within the same block of code - cy.readFile(globalState.get("connectorAuthFilePath")).then( - (jsonContent) => { - const authDetails = getValueByKey( - JSON.stringify(jsonContent), - connectorName - ); - createConnectorBody.connector_account_details = - authDetails.connector_account_details; - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`, - headers: { - "Content-Type": "application/json", - Accept: "application/json", - "api-key": globalState.get("adminApiKey"), - }, - body: createConnectorBody, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - - if (response.status === 200) { - expect(connectorName).to.equal(response.body.connector_name); - globalState.set( - "merchantConnectorId", - response.body.merchant_connector_id - ); - } else { - cy.task( - "cli_log", - "response status -> " + JSON.stringify(response.status) - ); - - throw new Error( - `Connector Create Call Failed ${response.body.error.message}` - ); - } - }); - } - ); + cy.readFile(globalState.get("connectorAuthFilePath")).then((jsonContent) => { + const authDetails = getValueByKey(JSON.stringify(jsonContent), connectorName); + createConnectorBody.connector_account_details = authDetails.connector_account_details; + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`, + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "api-key": globalState.get("adminApiKey"), + }, + body: createConnectorBody, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + + if (response.status === 200) { + expect(connectorName).to.equal(response.body.connector_name); + globalState.set("merchantConnectorId", response.body.merchant_connector_id); + } else { + cy.task("cli_log", "response status -> " + JSON.stringify(response.status)); + + throw new Error(`Connector Create Call Failed ${response.body.error.message}`); + } + }); + }); } ); Cypress.Commands.add( "createConnectorCallTest", - ( - connectorType, - createConnectorBody, - payment_methods_enabled, - globalState - ) => { + (connectorType, createConnectorBody, payment_methods_enabled, globalState) => { const merchantId = globalState.get("merchantId"); createConnectorBody.connector_type = connectorType; createConnectorBody.connector_name = globalState.get("connectorId"); createConnectorBody.payment_methods_enabled = payment_methods_enabled; // readFile is used to read the contents of the file and it always returns a promise ([Object Object]) due to its asynchronous nature // it is best to use then() to handle the response within the same block of code - cy.readFile(globalState.get("connectorAuthFilePath")).then( - (jsonContent) => { - const authDetails = getValueByKey( - JSON.stringify(jsonContent), - globalState.get("connectorId") - ); - createConnectorBody.connector_account_details = - authDetails.connector_account_details; - - if (authDetails && authDetails.metadata) { - createConnectorBody.metadata = { - ...createConnectorBody.metadata, // Preserve existing metadata fields - ...authDetails.metadata, // Merge with authDetails.metadata - }; - } - - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`, - headers: { - "Content-Type": "application/json", - Accept: "application/json", - "api-key": globalState.get("adminApiKey"), - }, - body: createConnectorBody, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - - if (response.status === 200) { - expect(globalState.get("connectorId")).to.equal( - response.body.connector_name - ); - globalState.set( - "merchantConnectorId", - response.body.merchant_connector_id - ); - } else { - cy.task( - "cli_log", - "response status -> " + JSON.stringify(response.status) - ); - - throw new Error( - `Connector Create Call Failed ${response.body.error.message}` - ); - } - }); + cy.readFile(globalState.get("connectorAuthFilePath")).then((jsonContent) => { + const authDetails = getValueByKey(JSON.stringify(jsonContent), globalState.get("connectorId")); + createConnectorBody.connector_account_details = authDetails.connector_account_details; + + if (authDetails && authDetails.metadata) { + createConnectorBody.metadata = { + ...createConnectorBody.metadata, // Preserve existing metadata fields + ...authDetails.metadata, // Merge with authDetails.metadata + }; } - ); + + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`, + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "api-key": globalState.get("adminApiKey"), + }, + body: createConnectorBody, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + + if (response.status === 200) { + expect(globalState.get("connectorId")).to.equal(response.body.connector_name); + globalState.set("merchantConnectorId", response.body.merchant_connector_id); + } else { + cy.task("cli_log", "response status -> " + JSON.stringify(response.status)); + + throw new Error(`Connector Create Call Failed ${response.body.error.message}`); + } + }); + }); } ); -Cypress.Commands.add( - "createPayoutConnectorCallTest", - (connectorType, createConnectorBody, globalState) => { - const merchantId = globalState.get("merchantId"); - let connectorName = globalState.get("connectorId"); - createConnectorBody.connector_type = connectorType; - createConnectorBody.connector_name = connectorName; - createConnectorBody.connector_type = "payout_processor"; - // readFile is used to read the contents of the file and it always returns a promise ([Object Object]) due to its asynchronous nature - // it is best to use then() to handle the response within the same block of code - cy.readFile(globalState.get("connectorAuthFilePath")).then( - (jsonContent) => { - let authDetails = getValueByKey( - JSON.stringify(jsonContent), - `${connectorName}_payout` - ); +Cypress.Commands.add("createPayoutConnectorCallTest", (connectorType, createConnectorBody, globalState) => { + const merchantId = globalState.get("merchantId"); + let connectorName = globalState.get("connectorId"); + createConnectorBody.connector_type = connectorType; + createConnectorBody.connector_name = connectorName; + createConnectorBody.connector_type = "payout_processor"; + // readFile is used to read the contents of the file and it always returns a promise ([Object Object]) due to its asynchronous nature + // it is best to use then() to handle the response within the same block of code + cy.readFile(globalState.get("connectorAuthFilePath")).then((jsonContent) => { + let authDetails = getValueByKey(JSON.stringify(jsonContent), `${connectorName}_payout`); + + // If the connector does not have payout connector creds in creds file, set payoutsExecution to false + if (authDetails === null) { + globalState.set("payoutsExecution", false); + return false; + } else { + globalState.set("payoutsExecution", true); + } - // If the connector does not have payout connector creds in creds file, set payoutsExecution to false - if (authDetails === null) { - globalState.set("payoutsExecution", false); - return false; - } else { - globalState.set("payoutsExecution", true); - } + createConnectorBody.connector_account_details = authDetails.connector_account_details; - createConnectorBody.connector_account_details = - authDetails.connector_account_details; + if (authDetails && authDetails.metadata) { + createConnectorBody.metadata = { + ...createConnectorBody.metadata, // Preserve existing metadata fields + ...authDetails.metadata, // Merge with authDetails.metadata + }; + } - if (authDetails && authDetails.metadata) { - createConnectorBody.metadata = { - ...createConnectorBody.metadata, // Preserve existing metadata fields - ...authDetails.metadata, // Merge with authDetails.metadata - }; - } + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`, + headers: { + Accept: "application/json", + "Content-Type": "application/json", + "api-key": globalState.get("adminApiKey"), + }, + body: createConnectorBody, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`, - headers: { - Accept: "application/json", - "Content-Type": "application/json", - "api-key": globalState.get("adminApiKey"), - }, - body: createConnectorBody, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - - if (response.status === 200) { - expect(globalState.get("connectorId")).to.equal( - response.body.connector_name - ); - globalState.set( - "merchantConnectorId", - response.body.merchant_connector_id - ); - } else { - cy.task( - "cli_log", - "response status -> " + JSON.stringify(response.status) - ); - - throw new Error( - `Connector Create Call Failed ${response.body.error.message}` - ); - } - }); + if (response.status === 200) { + expect(globalState.get("connectorId")).to.equal(response.body.connector_name); + globalState.set("merchantConnectorId", response.body.merchant_connector_id); + } else { + cy.task("cli_log", "response status -> " + JSON.stringify(response.status)); + + throw new Error(`Connector Create Call Failed ${response.body.error.message}`); } - ); - } -); + }); + }); +}); Cypress.Commands.add("connectorRetrieveCall", (globalState) => { const merchant_id = globalState.get("merchantId"); @@ -526,36 +455,31 @@ Cypress.Commands.add("connectorDeleteCall", (globalState) => { }); }); -Cypress.Commands.add( - "connectorUpdateCall", - (connectorType, updateConnectorBody, globalState) => { - const merchant_id = globalState.get("merchantId"); - const connector_id = globalState.get("connectorId"); - const merchant_connector_id = globalState.get("merchantConnectorId"); - updateConnectorBody.connector_type = connectorType; +Cypress.Commands.add("connectorUpdateCall", (connectorType, updateConnectorBody, globalState) => { + const merchant_id = globalState.get("merchantId"); + const connector_id = globalState.get("connectorId"); + const merchant_connector_id = globalState.get("merchantConnectorId"); + updateConnectorBody.connector_type = connectorType; - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/account/${merchant_id}/connectors/${merchant_connector_id}`, - headers: { - Accept: "application/json", - "Content-Type": "application/json", - "api-key": globalState.get("adminApiKey"), - "x-merchant-id": merchant_id, - }, - body: updateConnectorBody, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - expect(response.body.connector_name).to.equal(connector_id); - expect(response.body.merchant_connector_id).to.equal( - merchant_connector_id - ); - expect(response.body.connector_label).to.equal("updated_connector_label"); - }); - } -); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/account/${merchant_id}/connectors/${merchant_connector_id}`, + headers: { + Accept: "application/json", + "Content-Type": "application/json", + "api-key": globalState.get("adminApiKey"), + "x-merchant-id": merchant_id, + }, + body: updateConnectorBody, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + expect(response.body.connector_name).to.equal(connector_id); + expect(response.body.merchant_connector_id).to.equal(merchant_connector_id); + expect(response.body.connector_label).to.equal("updated_connector_label"); + }); +}); // Generic function to list all connectors Cypress.Commands.add("connectorListByMid", (globalState) => { @@ -576,24 +500,21 @@ Cypress.Commands.add("connectorListByMid", (globalState) => { }); }); -Cypress.Commands.add( - "createCustomerCallTest", - (customerCreateBody, globalState) => { - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/customers`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - body: customerCreateBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.body.customer_id).to.not.be.empty; - globalState.set("customerId", response.body.customer_id); - }); - } -); +Cypress.Commands.add("createCustomerCallTest", (customerCreateBody, globalState) => { + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/customers`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + body: customerCreateBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.body.customer_id).to.not.be.empty; + globalState.set("customerId", response.body.customer_id); + }); +}); Cypress.Commands.add("customerListCall", (globalState) => { cy.request({ @@ -629,26 +550,23 @@ Cypress.Commands.add("customerRetrieveCall", (globalState) => { }); }); -Cypress.Commands.add( - "customerUpdateCall", - (customerUpdateBody, globalState) => { - const customer_id = globalState.get("customerId"); +Cypress.Commands.add("customerUpdateCall", (customerUpdateBody, globalState) => { + const customer_id = globalState.get("customerId"); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/customers/${customer_id}`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - body: customerUpdateBody, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.body.customer_id).to.equal(customer_id); - }); - } -); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/customers/${customer_id}`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + body: customerUpdateBody, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.body.customer_id).to.equal(customer_id); + }); +}); Cypress.Commands.add("ephemeralGenerateCall", (globalState) => { const customer_id = globalState.get("customerId"); @@ -692,127 +610,98 @@ Cypress.Commands.add("customerDeleteCall", (globalState) => { }); }); +Cypress.Commands.add("paymentMethodListTestLessThanEqualToOnePaymentMethod", (res_data, globalState) => { + cy.request({ + method: "GET", + url: `${globalState.get("baseUrl")}/account/payment_methods?client_secret=${globalState.get("clientSecret")}`, + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "api-key": globalState.get("publishableKey"), + }, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + expect(response.body).to.have.property("currency"); + if (res_data["payment_methods"].length == 1) { + function getPaymentMethodType(obj) { + return obj["payment_methods"][0]["payment_method_types"][0]["payment_method_type"]; + } + expect(getPaymentMethodType(res_data)).to.equal(getPaymentMethodType(response.body)); + } else { + expect(0).to.equal(response.body["payment_methods"].length); + } + } else { + defaultErrorHandler(response, res_data); + } + }); +}); + +Cypress.Commands.add("paymentMethodListTestTwoConnectorsForOnePaymentMethodCredit", (res_data, globalState) => { + cy.request({ + method: "GET", + url: `${globalState.get("baseUrl")}/account/payment_methods?client_secret=${globalState.get("clientSecret")}`, + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "api-key": globalState.get("publishableKey"), + }, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + expect(response.body).to.have.property("currency"); + if (res_data["payment_methods"].length > 0) { + function getPaymentMethodType(obj) { + return obj["payment_methods"][0]["payment_method_types"][0]["card_networks"][0]["eligible_connectors"] + .slice() + .sort(); + } + let config_payment_method_type = getPaymentMethodType(res_data); + let response_payment_method_type = getPaymentMethodType(response.body); + for (let i = 0; i < response_payment_method_type.length; i++) { + expect(config_payment_method_type[i]).to.equal(response_payment_method_type[i]); + } + } else { + expect(0).to.equal(response.body["payment_methods"].length); + } + } else { + defaultErrorHandler(response, res_data); + } + }); +}); + Cypress.Commands.add( - "paymentMethodListTestLessThanEqualToOnePaymentMethod", - (res_data, globalState) => { + "createPaymentIntentTest", + (createPaymentBody, req_data, res_data, authentication_type, capture_method, globalState) => { + if (!createPaymentBody || typeof createPaymentBody !== "object" || !req_data.currency) { + throw new Error("Invalid parameters provided to createPaymentIntentTest command"); + } + + for (const key in req_data) { + createPaymentBody[key] = req_data[key]; + } + createPaymentBody.authentication_type = authentication_type; + + createPaymentBody.capture_method = capture_method; + createPaymentBody.customer_id = globalState.get("customerId"); + globalState.set("paymentAmount", createPaymentBody.amount); cy.request({ - method: "GET", - url: `${globalState.get("baseUrl")}/account/payment_methods?client_secret=${globalState.get("clientSecret")}`, + method: "POST", + url: `${globalState.get("baseUrl")}/payments`, headers: { "Content-Type": "application/json", Accept: "application/json", - "api-key": globalState.get("publishableKey"), + "api-key": globalState.get("apiKey"), }, failOnStatusCode: false, + body: createPaymentBody, }).then((response) => { logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - expect(response.body).to.have.property("currency"); - if (res_data["payment_methods"].length == 1) { - function getPaymentMethodType(obj) { - return obj["payment_methods"][0]["payment_method_types"][0][ - "payment_method_type" - ]; - } - expect(getPaymentMethodType(res_data)).to.equal( - getPaymentMethodType(response.body) - ); - } else { - expect(0).to.equal(response.body["payment_methods"].length); - } - } else { - defaultErrorHandler(response, res_data); - } - }); - } -); - -Cypress.Commands.add( - "paymentMethodListTestTwoConnectorsForOnePaymentMethodCredit", - (res_data, globalState) => { - cy.request({ - method: "GET", - url: `${globalState.get("baseUrl")}/account/payment_methods?client_secret=${globalState.get("clientSecret")}`, - headers: { - "Content-Type": "application/json", - Accept: "application/json", - "api-key": globalState.get("publishableKey"), - }, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - expect(response.body).to.have.property("currency"); - if (res_data["payment_methods"].length > 0) { - function getPaymentMethodType(obj) { - return obj["payment_methods"][0]["payment_method_types"][0][ - "card_networks" - ][0]["eligible_connectors"] - .slice() - .sort(); - } - let config_payment_method_type = getPaymentMethodType(res_data); - let response_payment_method_type = getPaymentMethodType( - response.body - ); - for (let i = 0; i < response_payment_method_type.length; i++) { - expect(config_payment_method_type[i]).to.equal( - response_payment_method_type[i] - ); - } - } else { - expect(0).to.equal(response.body["payment_methods"].length); - } - } else { - defaultErrorHandler(response, res_data); - } - }); - } -); - -Cypress.Commands.add( - "createPaymentIntentTest", - ( - createPaymentBody, - req_data, - res_data, - authentication_type, - capture_method, - globalState - ) => { - if ( - !createPaymentBody || - typeof createPaymentBody !== "object" || - !req_data.currency - ) { - throw new Error( - "Invalid parameters provided to createPaymentIntentTest command" - ); - } - - for (const key in req_data) { - createPaymentBody[key] = req_data[key]; - } - createPaymentBody.authentication_type = authentication_type; - - createPaymentBody.capture_method = capture_method; - createPaymentBody.customer_id = globalState.get("customerId"); - globalState.set("paymentAmount", createPaymentBody.amount); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments`, - headers: { - "Content-Type": "application/json", - Accept: "application/json", - "api-key": globalState.get("apiKey"), - }, - failOnStatusCode: false, - body: createPaymentBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - + expect(response.headers["content-type"]).to.include("application/json"); if (res_data.status === 200) { @@ -822,13 +711,35 @@ Cypress.Commands.add( globalState.set("paymentID", response.body.payment_id); cy.log(clientSecret); for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); + expect(res_data.body[key]).to.equal( + response.body[key], + `Expected ${res_data.body[key]} but got ${response.body[key]}` + ); } - expect(createPaymentBody.amount).to.equal(response.body.amount); - expect(null).to.equal(response.body.amount_received); - expect(createPaymentBody.amount).to.equal( - response.body.amount_capturable + expect(createPaymentBody.amount, "amount").to.equal(response.body.amount); + expect(createPaymentBody.currency, "currency").to.equal(response.body.currency); + expect(createPaymentBody.capture_method, "capture_method").to.equal(response.body.capture_method); + expect(createPaymentBody.authentication_type, "authentication_type").to.equal( + response.body.authentication_type ); + expect(createPaymentBody.description, "description").to.equal(response.body.description); + expect(createPaymentBody.email, "email").to.equal(response.body.email); + expect(createPaymentBody.email, "customer.email").to.equal(response.body.customer.email); + expect(createPaymentBody.customer_id, "customer.id").to.equal(response.body.customer.id); + expect(createPaymentBody.metadata, "metadata").to.deep.equal(response.body.metadata); + expect(createPaymentBody.setup_future_usage, "setup_future_usage").to.equal(response.body.setup_future_usage); + expect(createPaymentBody.amount, "amount_capturable").to.equal(response.body.amount_capturable); + expect(response.body.amount_received, "amount_received").to.be.oneOf([0, null]); + expect(response.body.connector, "connector").to.be.null; + expect(createPaymentBody.capture_method, "capture_method").to.equal(response.body.capture_method); + expect(response.body.payment_method, "payment_method").to.be.null; + expect(response.body.payment_method_data, "payment_method_data").to.be.null; + expect(response.body.merchant_connector_id, "merchant_connector_id").to.be.null; + expect(response.body.payment_method_id, "payment_method_id").to.be.null; + expect(response.body.payment_method_id, "payment_method_status").to.be.null; + expect(response.body.profile_id, "profile_id").to.not.be.null; + expect(response.body.merchant_order_reference_id, "merchant_order_reference_id").to.be.null; + expect(response.body.connector_mandate_id, "connector_mandate_id").to.be.null; } else { defaultErrorHandler(response, res_data); } @@ -858,341 +769,260 @@ Cypress.Commands.add("paymentMethodsCallTest", (globalState) => { }); }); -Cypress.Commands.add( - "createPaymentMethodTest", - (globalState, req_data, res_data) => { - req_data.customer_id = globalState.get("customerId"); +Cypress.Commands.add("createPaymentMethodTest", (globalState, req_data, res_data) => { + req_data.customer_id = globalState.get("customerId"); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payment_methods`, - body: req_data, - headers: { - "Content-Type": "application/json", - Accept: "application/json", - "api-key": globalState.get("apiKey"), - }, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payment_methods`, + body: req_data, + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "api-key": globalState.get("apiKey"), + }, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - expect(response.body).to.have.property("payment_method_id"); - expect(response.body).to.have.property("client_secret"); - globalState.set("paymentMethodId", response.body.payment_method_id); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + expect(response.body).to.have.property("payment_method_id"); + expect(response.body).to.have.property("client_secret"); + globalState.set("paymentMethodId", response.body.payment_method_id); + } else { + defaultErrorHandler(response, res_data); + } + }); +}); + +Cypress.Commands.add("confirmCallTest", (confirmBody, req_data, res_data, confirm, globalState) => { + const paymentIntentID = globalState.get("paymentID"); + confirmBody.confirm = confirm; + confirmBody.client_secret = globalState.get("clientSecret"); + for (const key in req_data) { + confirmBody[key] = req_data[key]; + } + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payments/${paymentIntentID}/confirm`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("publishableKey"), + }, + failOnStatusCode: false, + body: confirmBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + globalState.set("paymentID", paymentIntentID); + globalState.set("connectorId", response.body.connector); + expect(response.body.connector, "connector").to.equal(globalState.get("connectorId")); + expect(response.body.payment_id, "payment_id").to.equal(paymentIntentID); + expect(response.body.payment_method_data, "payment_method_data").to.not.be.empty; + expect(response.body.merchant_connector_id, "connectorId").to.equal(globalState.get("merchantConnectorId")); + expect(response.body.customer, "customer").to.not.be.empty; + expect(response.body.billing, "billingAddress").to.not.be.empty; + expect(response.body.profile_id, "profile_id").to.not.be.null; + expect(response.body.connector_transaction_id, "connector_transaction_id").to.not.be.null; + if (response.body.capture_method === "automatic") { + if (response.body.authentication_type === "three_ds") { + expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); + globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); + for (const key in res_data.body) { + expect(res_data.body[key], [key]).to.deep.equal(response.body[key]); + } + } else if (response.body.authentication_type === "no_three_ds") { + for (const key in res_data.body) { + expect(res_data.body[key], [key]).to.deep.equal(response.body[key]); + } + } else { + throw new Error(`Invalid authentication type ${response.body.authentication_type}`); + } + } else if (response.body.capture_method === "manual") { + if (response.body.authentication_type === "three_ds") { + expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); + globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); + for (const key in res_data.body) { + expect(res_data.body[key], [key]).to.deep.equal(response.body[key]); + } + } else if (response.body.authentication_type === "no_three_ds") { + for (const key in res_data.body) { + expect(res_data.body[key], [key]).to.deep.equal(response.body[key]); + } + } else { + throw new Error(`Invalid authentication type ${response.body.authentication_type}`); + } } else { - defaultErrorHandler(response, res_data); + throw new Error(`Invalid capture method ${response.body.capture_method}`); } - }); + } else { + defaultErrorHandler(response, res_data); + } + }); +}); + +Cypress.Commands.add("confirmBankRedirectCallTest", (confirmBody, req_data, res_data, confirm, globalState) => { + const paymentIntentId = globalState.get("paymentID"); + const connectorId = globalState.get("connectorId"); + for (const key in req_data) { + confirmBody[key] = req_data[key]; } -); + confirmBody.confirm = confirm; + confirmBody.client_secret = globalState.get("clientSecret"); -Cypress.Commands.add( - "confirmCallTest", - (confirmBody, req_data, res_data, confirm, globalState) => { - const paymentIntentID = globalState.get("paymentID"); - confirmBody.confirm = confirm; - confirmBody.client_secret = globalState.get("clientSecret"); - for (const key in req_data) { - confirmBody[key] = req_data[key]; - } - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments/${paymentIntentID}/confirm`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("publishableKey"), - }, - failOnStatusCode: false, - body: confirmBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payments/${paymentIntentId}/confirm`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("publishableKey"), + }, + failOnStatusCode: false, + body: confirmBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + if (response.status === 200) { expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - globalState.set("paymentID", paymentIntentID); - globalState.set("connectorId", response.body.connector); - if (response.body.capture_method === "automatic") { - if (response.body.authentication_type === "three_ds") { - expect(response.body) - .to.have.property("next_action") - .to.have.property("redirect_to_url"); - globalState.set( - "nextActionUrl", - response.body.next_action.redirect_to_url - ); - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); - } - } else if (response.body.authentication_type === "no_three_ds") { - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); + globalState.set("paymentID", paymentIntentId); + globalState.set("connectorId", response.body.connector); + globalState.set("paymentMethodType", confirmBody.payment_method_type); + + switch (response.body.authentication_type) { + case "three_ds": + if (response.body.capture_method === "automatic" || response.body.capture_method === "manual") { + if (response.body.status !== "failed") { + // we get many statuses here, hence this verification + if (connectorId === "adyen" && response.body.payment_method_type === "blik") { + expect(response.body) + .to.have.property("next_action") + .to.have.property("type") + .to.equal("wait_screen_information"); + } else { + expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); + globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); + } + } else if (response.body.status === "failed") { + expect(response.body.error_code).to.equal(res_data.body.error_code); } } else { - throw new Error( - `Invalid authentication type ${response.body.authentication_type}` - ); + throw new Error(`Invalid capture method ${response.body.capture_method}`); } - } else if (response.body.capture_method === "manual") { - if (response.body.authentication_type === "three_ds") { - expect(response.body) - .to.have.property("next_action") - .to.have.property("redirect_to_url"); - globalState.set( - "nextActionUrl", - response.body.next_action.redirect_to_url - ); - } else if (response.body.authentication_type === "no_three_ds") { - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); - } + break; + case "no_three_ds": + if (response.body.capture_method === "automatic" || response.body.capture_method === "manual") { + expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); + globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); } else { - throw new Error( - `Invalid authentication type ${response.body.authentication_type}` - ); + throw new Error(`Invalid capture method ${response.body.capture_method}`); } - } else { - throw new Error( - `Invalid capture method ${response.body.capture_method}` - ); - } - } else { - defaultErrorHandler(response, res_data); + break; + default: + throw new Error(`Invalid authentication type ${response.body.authentication_type}`); } - }); - } -); - -Cypress.Commands.add( - "confirmBankRedirectCallTest", - (confirmBody, req_data, res_data, confirm, globalState) => { - const paymentIntentId = globalState.get("paymentID"); - const connectorId = globalState.get("connectorId"); - for (const key in req_data) { - confirmBody[key] = req_data[key]; + } else { + defaultErrorHandler(response, res_data); } - confirmBody.confirm = confirm; - confirmBody.client_secret = globalState.get("clientSecret"); + }); +}); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments/${paymentIntentId}/confirm`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("publishableKey"), - }, - failOnStatusCode: false, - body: confirmBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - if (response.status === 200) { - expect(response.headers["content-type"]).to.include("application/json"); - globalState.set("paymentID", paymentIntentId); - globalState.set("connectorId", response.body.connector); - globalState.set("paymentMethodType", confirmBody.payment_method_type); - - switch (response.body.authentication_type) { - case "three_ds": - if ( - response.body.capture_method === "automatic" || - response.body.capture_method === "manual" - ) { - if (response.body.status !== "failed") { - // we get many statuses here, hence this verification - if ( - connectorId === "adyen" && - response.body.payment_method_type === "blik" - ) { - expect(response.body) - .to.have.property("next_action") - .to.have.property("type") - .to.equal("wait_screen_information"); - } else { - expect(response.body) - .to.have.property("next_action") - .to.have.property("redirect_to_url"); - globalState.set( - "nextActionUrl", - response.body.next_action.redirect_to_url - ); - } - } else if (response.body.status === "failed") { - expect(response.body.error_code).to.equal( - res_data.body.error_code - ); - } - } else { - throw new Error( - `Invalid capture method ${response.body.capture_method}` - ); - } - break; - case "no_three_ds": - if ( - response.body.capture_method === "automatic" || - response.body.capture_method === "manual" - ) { - expect(response.body) - .to.have.property("next_action") - .to.have.property("redirect_to_url"); +Cypress.Commands.add("confirmBankTransferCallTest", (confirmBody, req_data, res_data, confirm, globalState) => { + const paymentIntentID = globalState.get("paymentID"); + for (const key in req_data) { + confirmBody[key] = req_data[key]; + } + confirmBody.confirm = confirm; + confirmBody.client_secret = globalState.get("clientSecret"); + globalState.set("paymentMethodType", confirmBody.payment_method_type); + + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payments/${paymentIntentID}/confirm`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("publishableKey"), + }, + failOnStatusCode: false, + body: confirmBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + globalState.set("paymentID", paymentIntentID); + if (response.body.capture_method === "automatic" || response.body.capture_method === "manual") { + switch (response.body.payment_method_type) { + case "pix": + expect(response.body).to.have.property("next_action").to.have.property("qr_code_url"); + if (response.body.next_action.qr_code_url !== null) { globalState.set( - "nextActionUrl", - response.body.next_action.redirect_to_url + "nextActionUrl", // This is intentionally kept as nextActionUrl to avoid issues during handleRedirection call, + response.body.next_action.qr_code_url ); + globalState.set("nextActionType", "qr_code_url"); } else { - throw new Error( - `Invalid capture method ${response.body.capture_method}` + globalState.set( + "nextActionUrl", // This is intentionally kept as nextActionUrl to avoid issues during handleRedirection call, + response.body.next_action.image_data_url ); + globalState.set("nextActionType", "image_data_url"); } break; default: - throw new Error( - `Invalid authentication type ${response.body.authentication_type}` - ); + expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); + globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); + break; } } else { - defaultErrorHandler(response, res_data); + throw new Error(`Invalid capture method ${response.body.capture_method}`); } - }); - } -); - -Cypress.Commands.add( - "confirmBankTransferCallTest", - (confirmBody, req_data, res_data, confirm, globalState) => { - const paymentIntentID = globalState.get("paymentID"); - for (const key in req_data) { - confirmBody[key] = req_data[key]; + } else { + defaultErrorHandler(response, res_data); } - confirmBody.confirm = confirm; - confirmBody.client_secret = globalState.get("clientSecret"); - globalState.set("paymentMethodType", confirmBody.payment_method_type); + }); +}); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments/${paymentIntentID}/confirm`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("publishableKey"), - }, - failOnStatusCode: false, - body: confirmBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - globalState.set("paymentID", paymentIntentID); - if ( - response.body.capture_method === "automatic" || - response.body.capture_method === "manual" - ) { - switch (response.body.payment_method_type) { - case "pix": - expect(response.body) - .to.have.property("next_action") - .to.have.property("qr_code_url"); - if (response.body.next_action.qr_code_url !== null) { - globalState.set( - "nextActionUrl", // This is intentionally kept as nextActionUrl to avoid issues during handleRedirection call, - response.body.next_action.qr_code_url - ); - globalState.set("nextActionType", "qr_code_url"); - } else { - globalState.set( - "nextActionUrl", // This is intentionally kept as nextActionUrl to avoid issues during handleRedirection call, - response.body.next_action.image_data_url - ); - globalState.set("nextActionType", "image_data_url"); - } - break; - default: - expect(response.body) - .to.have.property("next_action") - .to.have.property("redirect_to_url"); - globalState.set( - "nextActionUrl", - response.body.next_action.redirect_to_url - ); - break; - } - } else { - throw new Error( - `Invalid capture method ${response.body.capture_method}` - ); - } - } else { - defaultErrorHandler(response, res_data); - } - }); +Cypress.Commands.add("confirmUpiCall", (confirmBody, req_data, res_data, confirm, globalState) => { + const paymentId = globalState.get("paymentID"); + for (const key in req_data) { + confirmBody[key] = req_data[key]; } -); + confirmBody.confirm = confirm; + confirmBody.client_secret = globalState.get("clientSecret"); + globalState.set("paymentMethodType", confirmBody.payment_method_type); -Cypress.Commands.add( - "confirmUpiCall", - (confirmBody, req_data, res_data, confirm, globalState) => { - const paymentId = globalState.get("paymentID"); - for (const key in req_data) { - confirmBody[key] = req_data[key]; - } - confirmBody.confirm = confirm; - confirmBody.client_secret = globalState.get("clientSecret"); - globalState.set("paymentMethodType", confirmBody.payment_method_type); - - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments/${paymentId}/confirm`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("publishableKey"), - }, - failOnStatusCode: false, - body: confirmBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - if ( - response.body.capture_method === "automatic" || - response.body.capture_method === "manual" - ) { - if (response.body.payment_method_type === "upi_collect") { - expect(response.body) - .to.have.property("next_action") - .to.have.property("redirect_to_url"); - globalState.set( - "nextActionUrl", - response.body.next_action.redirect_to_url - ); - } else if (response.body.payment_method_type === "upi_intent") { - expect(response.body) - .to.have.property("next_action") - .to.have.property("qr_code_fetch_url"); - globalState.set( - "nextActionUrl", - response.body.next_action.qr_code_fetch_url - ); - } - } else { - throw new Error( - `Invalid capture method ${response.body.capture_method}` - ); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payments/${paymentId}/confirm`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("publishableKey"), + }, + failOnStatusCode: false, + body: confirmBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + if (response.body.capture_method === "automatic" || response.body.capture_method === "manual") { + if (response.body.payment_method_type === "upi_collect") { + expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); + globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); + } else if (response.body.payment_method_type === "upi_intent") { + expect(response.body).to.have.property("next_action").to.have.property("qr_code_fetch_url"); + globalState.set("nextActionUrl", response.body.next_action.qr_code_fetch_url); } } else { - defaultErrorHandler(response, res_data); + throw new Error(`Invalid capture method ${response.body.capture_method}`); } - }); - } -); + } else { + defaultErrorHandler(response, res_data); + } + }); +}); Cypress.Commands.add( "createConfirmPaymentTest", - ( - createConfirmPaymentBody, - req_data, - res_data, - authentication_type, - capture_method, - globalState - ) => { + (createConfirmPaymentBody, req_data, res_data, authentication_type, capture_method, globalState) => { createConfirmPaymentBody.authentication_type = authentication_type; createConfirmPaymentBody.capture_method = capture_method; createConfirmPaymentBody.customer_id = globalState.get("customerId"); @@ -1212,47 +1042,44 @@ Cypress.Commands.add( logRequestId(response.headers["x-request-id"]); expect(response.headers["content-type"]).to.include("application/json"); if (response.status === 200) { + globalState.set("paymentAmount", createConfirmPaymentBody.amount); + globalState.set("paymentID", response.body.payment_id); + expect(response.body.connector, "connector").to.equal(globalState.get("connectorId")); + expect(response.body.payment_id, "payment_id").to.equal(globalState.get("paymentID")); + expect(response.body.payment_method_data, "payment_method_data").to.not.be.empty; + expect(response.body.merchant_connector_id, "connectorId").to.equal(globalState.get("merchantConnectorId")); + expect(response.body.customer, "customer").to.not.be.empty; + expect(response.body.billing, "billingAddress").to.not.be.empty; + expect(response.body.profile_id, "profile_id").to.not.be.null; + expect(response.body.connector_transaction_id, "connector_transaction_id").to.not.be.null; + expect(response.body).to.have.property("status"); if (response.body.capture_method === "automatic") { - expect(response.body).to.have.property("status"); - globalState.set("paymentAmount", createConfirmPaymentBody.amount); - globalState.set("paymentID", response.body.payment_id); if (response.body.authentication_type === "three_ds") { - expect(response.body) - .to.have.property("next_action") - .to.have.property("redirect_to_url"); - globalState.set( - "nextActionUrl", - response.body.next_action.redirect_to_url - ); + expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); + globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); + for (const key in res_data.body) { + expect(res_data.body[key], [key]).to.deep.equal(response.body[key]); + } } else if (response.body.authentication_type === "no_three_ds") { for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); + expect(res_data.body[key], [key]).to.deep.equal(response.body[key]); } } else { - throw new Error( - `Invalid authentication type: ${response.body.authentication_type}` - ); + throw new Error(`Invalid authentication type: ${response.body.authentication_type}`); } } else if (response.body.capture_method === "manual") { - expect(response.body).to.have.property("status"); - globalState.set("paymentAmount", createConfirmPaymentBody.amount); - globalState.set("paymentID", response.body.payment_id); if (response.body.authentication_type === "three_ds") { - expect(response.body) - .to.have.property("next_action") - .to.have.property("redirect_to_url"); - globalState.set( - "nextActionUrl", - response.body.next_action.redirect_to_url - ); + expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); + globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); + for (const key in res_data.body) { + expect(res_data.body[key], [key]).to.deep.equal(response.body[key]); + } } else if (response.body.authentication_type === "no_three_ds") { for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); + expect(res_data.body[key], [key]).to.deep.equal(response.body[key]); } } else { - throw new Error( - `Invalid authentication type: ${response.body.authentication_type}` - ); + throw new Error(`Invalid authentication type: ${response.body.authentication_type}`); } } } else { @@ -1263,256 +1090,219 @@ Cypress.Commands.add( ); // This is consequent saved card payment confirm call test(Using payment token) -Cypress.Commands.add( - "saveCardConfirmCallTest", - (saveCardConfirmBody, req_data, res_data, globalState) => { - const paymentIntentID = globalState.get("paymentID"); - if (req_data.setup_future_usage === "on_session") { - saveCardConfirmBody.card_cvc = req_data.payment_method_data.card.card_cvc; - } - saveCardConfirmBody.payment_token = globalState.get("paymentToken"); - saveCardConfirmBody.client_secret = globalState.get("clientSecret"); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments/${paymentIntentID}/confirm`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("publishableKey"), - }, - failOnStatusCode: false, - body: saveCardConfirmBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); +Cypress.Commands.add("saveCardConfirmCallTest", (saveCardConfirmBody, req_data, res_data, globalState) => { + const paymentIntentID = globalState.get("paymentID"); + if (req_data.setup_future_usage === "on_session") { + saveCardConfirmBody.card_cvc = req_data.payment_method_data.card.card_cvc; + } + saveCardConfirmBody.payment_token = globalState.get("paymentToken"); + saveCardConfirmBody.client_secret = globalState.get("clientSecret"); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payments/${paymentIntentID}/confirm`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("publishableKey"), + }, + failOnStatusCode: false, + body: saveCardConfirmBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - globalState.set("paymentID", paymentIntentID); - if (response.body.capture_method === "automatic") { - if (response.body.authentication_type === "three_ds") { - expect(response.body) - .to.have.property("next_action") - .to.have.property("redirect_to_url"); - const nextActionUrl = response.body.next_action.redirect_to_url; - } else if (response.body.authentication_type === "no_three_ds") { - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); - } - expect(response.body.customer_id).to.equal( - globalState.get("customerId") - ); - } else { - // Handle other authentication types as needed - throw new Error( - `Invalid authentication type: ${response.body.authentication_type}` - ); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + globalState.set("paymentID", paymentIntentID); + if (response.body.capture_method === "automatic") { + if (response.body.authentication_type === "three_ds") { + expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); + const nextActionUrl = response.body.next_action.redirect_to_url; + } else if (response.body.authentication_type === "no_three_ds") { + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); } - } else if (response.body.capture_method === "manual") { - if (response.body.authentication_type === "three_ds") { - expect(response.body) - .to.have.property("next_action") - .to.have.property("redirect_to_url"); - } else if (response.body.authentication_type === "no_three_ds") { - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); - } - expect(response.body.customer_id).to.equal( - globalState.get("customerId") - ); - } else { - // Handle other authentication types as needed - throw new Error( - `Invalid authentication type: ${response.body.authentication_type}` - ); + expect(response.body.customer_id).to.equal(globalState.get("customerId")); + } else { + // Handle other authentication types as needed + throw new Error(`Invalid authentication type: ${response.body.authentication_type}`); + } + } else if (response.body.capture_method === "manual") { + if (response.body.authentication_type === "three_ds") { + expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); + } else if (response.body.authentication_type === "no_three_ds") { + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); } + expect(response.body.customer_id).to.equal(globalState.get("customerId")); } else { - // Handle other capture methods as needed - throw new Error( - `Invalid capture method: ${response.body.capture_method}` - ); + // Handle other authentication types as needed + throw new Error(`Invalid authentication type: ${response.body.authentication_type}`); } } else { - defaultErrorHandler(response, res_data); + // Handle other capture methods as needed + throw new Error(`Invalid capture method: ${response.body.capture_method}`); } - }); - } -); + } else { + defaultErrorHandler(response, res_data); + } + }); +}); -Cypress.Commands.add( - "captureCallTest", - (requestBody, req_data, res_data, amount_to_capture, globalState) => { - const payment_id = globalState.get("paymentID"); - requestBody.amount_to_capture = amount_to_capture; - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments/${payment_id}/capture`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - failOnStatusCode: false, - body: requestBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); +Cypress.Commands.add("captureCallTest", (requestBody, req_data, res_data, amount_to_capture, globalState) => { + const payment_id = globalState.get("paymentID"); + requestBody.amount_to_capture = amount_to_capture; + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payments/${payment_id}/capture`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + failOnStatusCode: false, + body: requestBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.body.capture_method !== undefined) { - expect(response.body.payment_id).to.equal(payment_id); - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); - } - } else { - defaultErrorHandler(response, res_data); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.body.capture_method !== undefined) { + expect(response.body.payment_id).to.equal(payment_id); + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); } - }); - } -); + } else { + defaultErrorHandler(response, res_data); + } + }); +}); -Cypress.Commands.add( - "voidCallTest", - (requestBody, req_data, res_data, globalState) => { - const payment_id = globalState.get("paymentID"); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments/${payment_id}/cancel`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - failOnStatusCode: false, - body: requestBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); +Cypress.Commands.add("voidCallTest", (requestBody, req_data, res_data, globalState) => { + const payment_id = globalState.get("paymentID"); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payments/${payment_id}/cancel`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + failOnStatusCode: false, + body: requestBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); - } - } else { - defaultErrorHandler(response, res_data); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); } - }); - } -); - -Cypress.Commands.add( - "retrievePaymentCallTest", - (globalState, autoretries = false, attempt = 1) => { - const payment_id = globalState.get("paymentID"); - cy.request({ - method: "GET", - url: `${globalState.get("baseUrl")}/payments/${payment_id}?force_sync=true&expand_attempts=true`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - - expect(response.headers["content-type"]).to.include("application/json"); - expect(response.body.payment_id).to.equal(payment_id); - expect(response.body.amount).to.equal(globalState.get("paymentAmount")); - globalState.set("paymentID", response.body.payment_id); + } else { + defaultErrorHandler(response, res_data); + } + }); +}); - if (autoretries) { - expect(response.body).to.have.property("attempts"); - expect(response.body.attempts).to.be.an("array").and.not.empty; - expect(response.body.attempts.length).to.equal(attempt); - expect(response.body.attempts[0].attempt_id).to.include( - `${payment_id}_` - ); - for (const key in response.body.attempts) { - if ( - response.body.attempts[key].attempt_id === - `${payment_id}_${attempt}` && - response.body.status === "succeeded" - ) { - expect(response.body.attempts[key].status).to.equal("charged"); - } else if ( - response.body.attempts[key].attempt_id === - `${payment_id}_${attempt}` && - response.body.status === "requires_customer_action" - ) { - expect(response.body.attempts[key].status).to.equal( - "authentication_pending" - ); - } else { - expect(response.body.attempts[key].status).to.equal("failure"); - } - } - } - }); - } -); +Cypress.Commands.add("retrievePaymentCallTest", (globalState, autoretries = false, attempt = 1) => { + const payment_id = globalState.get("paymentID"); + cy.request({ + method: "GET", + url: `${globalState.get("baseUrl")}/payments/${payment_id}?force_sync=true&expand_attempts=true`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + globalState.set("paymentID", response.body.payment_id); -Cypress.Commands.add( - "refundCallTest", - (requestBody, req_data, res_data, refund_amount, globalState) => { - const payment_id = globalState.get("paymentID"); - requestBody.payment_id = payment_id; - requestBody.amount = refund_amount; - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/refunds`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - failOnStatusCode: false, - body: requestBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); + expect(response.headers["content-type"]).to.include("application/json"); + expect(response.body.payment_id).to.equal(payment_id); + expect(response.body.amount).to.equal(globalState.get("paymentAmount")); + expect(response.body.profile_id, "profile_id").to.not.be.null; + expect(response.body.billing, "billingAddress").to.not.be.empty; + expect(response.body.customer, "customer").to.not.be.empty; + if (["succeeded", "processing", "requires_customer_action"].includes(response.body.status)) { + expect(response.body.connector, "connector").to.equal(globalState.get("connectorId")); + expect(response.body.payment_method_data, "payment_method_data").to.not.be.empty; + expect(response.body.payment_method, "payment_method").to.not.be.null; + expect(response.body.merchant_connector_id, "connectorId").to.equal(globalState.get("merchantConnectorId")); + expect(response.body.connector_transaction_id, "connector_transaction_id").to.not.be.null; + } - if (response.status === 200) { - globalState.set("refundId", response.body.refund_id); - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); + if (autoretries) { + expect(response.body).to.have.property("attempts"); + expect(response.body.attempts).to.be.an("array").and.not.empty; + expect(response.body.attempts.length).to.equal(attempt); + expect(response.body.attempts[0].attempt_id).to.include(`${payment_id}_`); + for (const key in response.body.attempts) { + if ( + response.body.attempts[key].attempt_id === `${payment_id}_${attempt}` && + response.body.status === "succeeded" + ) { + expect(response.body.attempts[key].status).to.equal("charged"); + } else if ( + response.body.attempts[key].attempt_id === `${payment_id}_${attempt}` && + response.body.status === "requires_customer_action" + ) { + expect(response.body.attempts[key].status).to.equal("authentication_pending"); + } else { + expect(response.body.attempts[key].status).to.equal("failure"); } - expect(response.body.payment_id).to.equal(payment_id); - } else { - defaultErrorHandler(response, res_data); } - }); - } -); + } + }); +}); -Cypress.Commands.add( - "syncRefundCallTest", - (req_data, res_data, globalState) => { - const refundId = globalState.get("refundId"); - cy.request({ - method: "GET", - url: `${globalState.get("baseUrl")}/refunds/${refundId}`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); +Cypress.Commands.add("refundCallTest", (requestBody, req_data, res_data, refund_amount, globalState) => { + const payment_id = globalState.get("paymentID"); + requestBody.payment_id = payment_id; + requestBody.amount = refund_amount; + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/refunds`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + failOnStatusCode: false, + body: requestBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); - expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + globalState.set("refundId", response.body.refund_id); for (const key in res_data.body) { expect(res_data.body[key]).to.equal(response.body[key]); } - }); - } -); + expect(response.body.payment_id).to.equal(payment_id); + } else { + defaultErrorHandler(response, res_data); + } + }); +}); + +Cypress.Commands.add("syncRefundCallTest", (req_data, res_data, globalState) => { + const refundId = globalState.get("refundId"); + cy.request({ + method: "GET", + url: `${globalState.get("baseUrl")}/refunds/${refundId}`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + + expect(response.headers["content-type"]).to.include("application/json"); + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); + } + }); +}); Cypress.Commands.add( "citForMandatesCallTest", - ( - requestBody, - req_data, - res_data, - amount, - confirm, - capture_method, - payment_type, - globalState - ) => { + (requestBody, req_data, res_data, amount, confirm, capture_method, payment_type, globalState) => { for (const key in req_data) { requestBody[key] = req_data[key]; } @@ -1548,14 +1338,9 @@ Cypress.Commands.add( if (response.body.capture_method === "automatic") { expect(response.body).to.have.property("mandate_id"); if (response.body.authentication_type === "three_ds") { - expect(response.body) - .to.have.property("next_action") - .to.have.property("redirect_to_url"); + expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); const nextActionUrl = response.body.next_action.redirect_to_url; - globalState.set( - "nextActionUrl", - response.body.next_action.redirect_to_url - ); + globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); cy.log(nextActionUrl); for (const key in res_data.body) { expect(res_data.body[key]).to.equal(response.body[key]); @@ -1565,20 +1350,13 @@ Cypress.Commands.add( expect(res_data.body[key]).to.equal(response.body[key]); } } else { - throw new Error( - `Invalid authentication type ${response.body.authentication_type}` - ); + throw new Error(`Invalid authentication type ${response.body.authentication_type}`); } } else if (response.body.capture_method === "manual") { if (response.body.authentication_type === "three_ds") { - expect(response.body) - .to.have.property("next_action") - .to.have.property("redirect_to_url"); + expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); const nextActionUrl = response.body.next_action.redirect_to_url; - globalState.set( - "nextActionUrl", - response.body.next_action.redirect_to_url - ); + globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); cy.log(nextActionUrl); for (const key in res_data.body) { expect(res_data.body[key]).to.equal(response.body[key]); @@ -1588,14 +1366,10 @@ Cypress.Commands.add( expect(res_data.body[key]).to.equal(response.body[key]); } } else { - throw new Error( - `Invalid authentication type ${response.body.authentication_type}` - ); + throw new Error(`Invalid authentication type ${response.body.authentication_type}`); } } else { - throw new Error( - `Invalid capture method ${response.body.capture_method}` - ); + throw new Error(`Invalid capture method ${response.body.capture_method}`); } } else { defaultErrorHandler(response, res_data); @@ -1604,144 +1378,114 @@ Cypress.Commands.add( } ); -Cypress.Commands.add( - "mitForMandatesCallTest", - (requestBody, amount, confirm, capture_method, globalState) => { - requestBody.amount = amount; - requestBody.confirm = confirm; - requestBody.capture_method = capture_method; - requestBody.mandate_id = globalState.get("mandateId"); - requestBody.customer_id = globalState.get("customerId"); - globalState.set("paymentAmount", requestBody.amount); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - failOnStatusCode: false, - body: requestBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - globalState.set("paymentID", response.body.payment_id); - if (response.body.capture_method === "automatic") { - if (response.body.authentication_type === "three_ds") { - expect(response.body) - .to.have.property("next_action") - .to.have.property("redirect_to_url"); - const nextActionUrl = response.body.next_action.redirect_to_url; - cy.log(nextActionUrl); - } else if (response.body.authentication_type === "no_three_ds") { - expect(response.body.status).to.equal("succeeded"); - } else { - throw new Error( - `Invalid authentication type ${response.body.authentication_type}` - ); - } - } else if (response.body.capture_method === "manual") { - if (response.body.authentication_type === "three_ds") { - expect(response.body) - .to.have.property("next_action") - .to.have.property("redirect_to_url"); - const nextActionUrl = response.body.next_action.redirect_to_url; - cy.log(nextActionUrl); - } else if (response.body.authentication_type === "no_three_ds") { - expect(response.body.status).to.equal("requires_capture"); - } else { - throw new Error( - `Invalid authentication type ${response.body.authentication_type}` - ); - } +Cypress.Commands.add("mitForMandatesCallTest", (requestBody, amount, confirm, capture_method, globalState) => { + requestBody.amount = amount; + requestBody.confirm = confirm; + requestBody.capture_method = capture_method; + requestBody.mandate_id = globalState.get("mandateId"); + requestBody.customer_id = globalState.get("customerId"); + globalState.set("paymentAmount", requestBody.amount); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payments`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + failOnStatusCode: false, + body: requestBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + globalState.set("paymentID", response.body.payment_id); + if (response.body.capture_method === "automatic") { + if (response.body.authentication_type === "three_ds") { + expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); + const nextActionUrl = response.body.next_action.redirect_to_url; + cy.log(nextActionUrl); + } else if (response.body.authentication_type === "no_three_ds") { + expect(response.body.status).to.equal("succeeded"); } else { - throw new Error( - `Invalid capture method ${response.body.capture_method}` - ); + throw new Error(`Invalid authentication type ${response.body.authentication_type}`); } - } else if (response.status === 400) { - if (response.body.error.message === "Mandate Validation Failed") { - expect(response.body.error.code).to.equal("HE_03"); - expect(response.body.error.message).to.equal( - "Mandate Validation Failed" - ); - expect(response.body.error.reason).to.equal( - "request amount is greater than mandate amount" - ); + } else if (response.body.capture_method === "manual") { + if (response.body.authentication_type === "three_ds") { + expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); + const nextActionUrl = response.body.next_action.redirect_to_url; + cy.log(nextActionUrl); + } else if (response.body.authentication_type === "no_three_ds") { + expect(response.body.status).to.equal("requires_capture"); + } else { + throw new Error(`Invalid authentication type ${response.body.authentication_type}`); } } else { - throw new Error( - `Error Response: ${response.status}\n${response.body.error.message}\n${response.body.error.code}` - ); + throw new Error(`Invalid capture method ${response.body.capture_method}`); } - }); - } -); + } else if (response.status === 400) { + if (response.body.error.message === "Mandate Validation Failed") { + expect(response.body.error.code).to.equal("HE_03"); + expect(response.body.error.message).to.equal("Mandate Validation Failed"); + expect(response.body.error.reason).to.equal("request amount is greater than mandate amount"); + } + } else { + throw new Error( + `Error Response: ${response.status}\n${response.body.error.message}\n${response.body.error.code}` + ); + } + }); +}); -Cypress.Commands.add( - "mitUsingPMId", - (requestBody, amount, confirm, capture_method, globalState) => { - requestBody.amount = amount; - requestBody.confirm = confirm; - requestBody.capture_method = capture_method; - requestBody.recurring_details.data = globalState.get("paymentMethodId"); - requestBody.customer_id = globalState.get("customerId"); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - failOnStatusCode: false, - body: requestBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - globalState.set("paymentID", response.body.payment_id); - if (response.body.capture_method === "automatic") { - if (response.body.authentication_type === "three_ds") { - expect(response.body) - .to.have.property("next_action") - .to.have.property("redirect_to_url"); - const nextActionUrl = response.body.next_action.redirect_to_url; - cy.log(nextActionUrl); - } else if (response.body.authentication_type === "no_three_ds") { - expect(response.body.status).to.equal("succeeded"); - } else { - throw new Error( - `Invalid authentication type ${response.body.authentication_type}` - ); - } - } else if (response.body.capture_method === "manual") { - if (response.body.authentication_type === "three_ds") { - expect(response.body) - .to.have.property("next_action") - .to.have.property("redirect_to_url"); - const nextActionUrl = response.body.next_action.redirect_to_url; - cy.log(nextActionUrl); - } else if (response.body.authentication_type === "no_three_ds") { - expect(response.body.status).to.equal("requires_capture"); - } else { - throw new Error( - `Invalid authentication type ${response.body.authentication_type}` - ); - } +Cypress.Commands.add("mitUsingPMId", (requestBody, amount, confirm, capture_method, globalState) => { + requestBody.amount = amount; + requestBody.confirm = confirm; + requestBody.capture_method = capture_method; + requestBody.recurring_details.data = globalState.get("paymentMethodId"); + requestBody.customer_id = globalState.get("customerId"); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payments`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + failOnStatusCode: false, + body: requestBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + globalState.set("paymentID", response.body.payment_id); + if (response.body.capture_method === "automatic") { + if (response.body.authentication_type === "three_ds") { + expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); + const nextActionUrl = response.body.next_action.redirect_to_url; + cy.log(nextActionUrl); + } else if (response.body.authentication_type === "no_three_ds") { + expect(response.body.status).to.equal("succeeded"); } else { - throw new Error( - `Invalid capture method ${response.body.capture_method}` - ); + throw new Error(`Invalid authentication type ${response.body.authentication_type}`); + } + } else if (response.body.capture_method === "manual") { + if (response.body.authentication_type === "three_ds") { + expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); + const nextActionUrl = response.body.next_action.redirect_to_url; + cy.log(nextActionUrl); + } else if (response.body.authentication_type === "no_three_ds") { + expect(response.body.status).to.equal("requires_capture"); + } else { + throw new Error(`Invalid authentication type ${response.body.authentication_type}`); } } else { - throw new Error( - `Error Response: ${response.status}\n${response.body.error.message}\n${response.body.error.code}` - ); + throw new Error(`Invalid capture method ${response.body.capture_method}`); } - }); - } -); + } else { + throw new Error( + `Error Response: ${response.status}\n${response.body.error.message}\n${response.body.error.code}` + ); + } + }); +}); Cypress.Commands.add("listMandateCallTest", (globalState) => { const customerId = globalState.get("customerId"); @@ -1788,72 +1532,41 @@ Cypress.Commands.add("revokeMandateCallTest", (globalState) => { }); }); -Cypress.Commands.add( - "handleRedirection", - (globalState, expected_redirection) => { - let connectorId = globalState.get("connectorId"); - let expected_url = new URL(expected_redirection); - let redirection_url = new URL(globalState.get("nextActionUrl")); - handleRedirection( - "three_ds", - { redirection_url, expected_url }, - connectorId, - null - ); - } -); +Cypress.Commands.add("handleRedirection", (globalState, expected_redirection) => { + let connectorId = globalState.get("connectorId"); + let expected_url = new URL(expected_redirection); + let redirection_url = new URL(globalState.get("nextActionUrl")); + handleRedirection("three_ds", { redirection_url, expected_url }, connectorId, null); +}); -Cypress.Commands.add( - "handleBankRedirectRedirection", - (globalState, payment_method_type, expected_redirection) => { - let connectorId = globalState.get("connectorId"); - let expected_url = new URL(expected_redirection); - let redirection_url = new URL(globalState.get("nextActionUrl")); - // explicitly restricting `sofort` payment method by adyen from running as it stops other tests from running - // trying to handle that specific case results in stripe 3ds tests to fail - if (!(connectorId == "adyen" && payment_method_type == "sofort")) { - handleRedirection( - "bank_redirect", - { redirection_url, expected_url }, - connectorId, - payment_method_type - ); - } +Cypress.Commands.add("handleBankRedirectRedirection", (globalState, payment_method_type, expected_redirection) => { + let connectorId = globalState.get("connectorId"); + let expected_url = new URL(expected_redirection); + let redirection_url = new URL(globalState.get("nextActionUrl")); + // explicitly restricting `sofort` payment method by adyen from running as it stops other tests from running + // trying to handle that specific case results in stripe 3ds tests to fail + if (!(connectorId == "adyen" && payment_method_type == "sofort")) { + handleRedirection("bank_redirect", { redirection_url, expected_url }, connectorId, payment_method_type); } -); +}); -Cypress.Commands.add( - "handleBankTransferRedirection", - (globalState, payment_method_type, expected_redirection) => { - let connectorId = globalState.get("connectorId"); - let expected_url = new URL(expected_redirection); - let redirection_url = new URL(globalState.get("nextActionUrl")); - let next_action_type = globalState.get("nextActionType"); - cy.log(payment_method_type); - handleRedirection( - "bank_transfer", - { redirection_url, expected_url }, - connectorId, - payment_method_type, - { next_action_type } - ); - } -); +Cypress.Commands.add("handleBankTransferRedirection", (globalState, payment_method_type, expected_redirection) => { + let connectorId = globalState.get("connectorId"); + let expected_url = new URL(expected_redirection); + let redirection_url = new URL(globalState.get("nextActionUrl")); + let next_action_type = globalState.get("nextActionType"); + cy.log(payment_method_type); + handleRedirection("bank_transfer", { redirection_url, expected_url }, connectorId, payment_method_type, { + next_action_type, + }); +}); -Cypress.Commands.add( - "handleUpiRedirection", - (globalState, payment_method_type, expected_redirection) => { - let connectorId = globalState.get("connectorId"); - let expected_url = new URL(expected_redirection); - let redirection_url = new URL(globalState.get("nextActionUrl")); - handleRedirection( - "upi", - { redirection_url, expected_url }, - connectorId, - payment_method_type - ); - } -); +Cypress.Commands.add("handleUpiRedirection", (globalState, payment_method_type, expected_redirection) => { + let connectorId = globalState.get("connectorId"); + let expected_url = new URL(expected_redirection); + let redirection_url = new URL(globalState.get("nextActionUrl")); + handleRedirection("upi", { redirection_url, expected_url }, connectorId, payment_method_type); +}); Cypress.Commands.add("listCustomerPMCallTest", (globalState) => { const customerId = globalState.get("customerId"); @@ -1868,14 +1581,11 @@ Cypress.Commands.add("listCustomerPMCallTest", (globalState) => { logRequestId(response.headers["x-request-id"]); expect(response.headers["content-type"]).to.include("application/json"); if (response.body.customer_payment_methods[0]?.payment_token) { - const paymentToken = - response.body.customer_payment_methods[0].payment_token; + const paymentToken = response.body.customer_payment_methods[0].payment_token; globalState.set("paymentToken", paymentToken); // Set paymentToken in globalState } else { // We only get an empty array if something's wrong. One exception is a 4xx when no customer exist but it is handled in the test - expect(response.body) - .to.have.property("customer_payment_methods") - .to.be.an("array").and.empty; + expect(response.body).to.have.property("customer_payment_methods").to.be.an("array").and.empty; } }); }); @@ -1898,14 +1608,7 @@ Cypress.Commands.add("listRefundCallTest", (requestBody, globalState) => { Cypress.Commands.add( "createConfirmPayoutTest", - ( - createConfirmPayoutBody, - req_data, - res_data, - confirm, - auto_fulfill, - globalState - ) => { + (createConfirmPayoutBody, req_data, res_data, confirm, auto_fulfill, globalState) => { for (const key in req_data) { createConfirmPayoutBody[key] = req_data[key]; } @@ -1941,97 +1644,31 @@ Cypress.Commands.add( Cypress.Commands.add( "createConfirmWithTokenPayoutTest", - ( - createConfirmPayoutBody, - req_data, - res_data, - confirm, - auto_fulfill, - globalState - ) => { - for (const key in req_data) { - createConfirmPayoutBody[key] = req_data[key]; - } - createConfirmPayoutBody.customer_id = globalState.get("customerId"); - createConfirmPayoutBody.payout_token = globalState.get("paymentToken"); - createConfirmPayoutBody.auto_fulfill = auto_fulfill; - createConfirmPayoutBody.confirm = confirm; - - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payouts/create`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - failOnStatusCode: false, - body: createConfirmPayoutBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - - if (response.status === 200) { - globalState.set("payoutAmount", createConfirmPayoutBody.amount); - globalState.set("payoutID", response.body.payout_id); - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); - } - } else { - defaultErrorHandler(response, res_data); - } - }); - } -); - -Cypress.Commands.add( - "fulfillPayoutCallTest", - (payoutFulfillBody, req_data, res_data, globalState) => { - payoutFulfillBody.payout_id = globalState.get("payoutID"); - - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payouts/${globalState.get("payoutID")}/fulfill`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - failOnStatusCode: false, - body: payoutFulfillBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - - if (response.status === 200) { - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); - } - } else { - defaultErrorHandler(response, res_data); - } - }); - } -); - -Cypress.Commands.add( - "updatePayoutCallTest", - (payoutConfirmBody, req_data, res_data, auto_fulfill, globalState) => { - payoutConfirmBody.confirm = true; - payoutConfirmBody.auto_fulfill = auto_fulfill; + (createConfirmPayoutBody, req_data, res_data, confirm, auto_fulfill, globalState) => { + for (const key in req_data) { + createConfirmPayoutBody[key] = req_data[key]; + } + createConfirmPayoutBody.customer_id = globalState.get("customerId"); + createConfirmPayoutBody.payout_token = globalState.get("paymentToken"); + createConfirmPayoutBody.auto_fulfill = auto_fulfill; + createConfirmPayoutBody.confirm = confirm; cy.request({ - method: "PUT", - url: `${globalState.get("baseUrl")}/payouts/${globalState.get("payoutID")}`, + method: "POST", + url: `${globalState.get("baseUrl")}/payouts/create`, headers: { "Content-Type": "application/json", "api-key": globalState.get("apiKey"), }, failOnStatusCode: false, - body: payoutConfirmBody, + body: createConfirmPayoutBody, }).then((response) => { logRequestId(response.headers["x-request-id"]); expect(response.headers["content-type"]).to.include("application/json"); if (response.status === 200) { + globalState.set("payoutAmount", createConfirmPayoutBody.amount); + globalState.set("payoutID", response.body.payout_id); for (const key in res_data.body) { expect(res_data.body[key]).to.equal(response.body[key]); } @@ -2042,6 +1679,59 @@ Cypress.Commands.add( } ); +Cypress.Commands.add("fulfillPayoutCallTest", (payoutFulfillBody, req_data, res_data, globalState) => { + payoutFulfillBody.payout_id = globalState.get("payoutID"); + + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payouts/${globalState.get("payoutID")}/fulfill`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + failOnStatusCode: false, + body: payoutFulfillBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + + if (response.status === 200) { + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); + } + } else { + defaultErrorHandler(response, res_data); + } + }); +}); + +Cypress.Commands.add("updatePayoutCallTest", (payoutConfirmBody, req_data, res_data, auto_fulfill, globalState) => { + payoutConfirmBody.confirm = true; + payoutConfirmBody.auto_fulfill = auto_fulfill; + + cy.request({ + method: "PUT", + url: `${globalState.get("baseUrl")}/payouts/${globalState.get("payoutID")}`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + failOnStatusCode: false, + body: payoutConfirmBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + + if (response.status === 200) { + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); + } + } else { + defaultErrorHandler(response, res_data); + } + }); +}); + Cypress.Commands.add("retrievePayoutCallTest", (globalState) => { const payout_id = globalState.get("payoutID"); cy.request({ @@ -2124,9 +1814,7 @@ Cypress.Commands.add("terminate2Fa", (globalState) => { cy.task("setGlobalState", globalState.data); } } else { - throw new Error( - `2FA terminate call failed with status ${response.status} and message ${response.body.message}` - ); + throw new Error(`2FA terminate call failed with status ${response.status} and message ${response.body.message}`); } }); }); @@ -2186,184 +1874,162 @@ Cypress.Commands.add("ListMcaByMid", (globalState) => { }); }); -Cypress.Commands.add( - "addRoutingConfig", - (routingBody, req_data, res_data, type, data, globalState) => { - for (const key in req_data) { - routingBody[key] = req_data[key]; - } - // set profile id from env - routingBody.profile_id = globalState.get("profileId"); - routingBody.algorithm.type = type; - routingBody.algorithm.data = data; +Cypress.Commands.add("addRoutingConfig", (routingBody, req_data, res_data, type, data, globalState) => { + for (const key in req_data) { + routingBody[key] = req_data[key]; + } + // set profile id from env + routingBody.profile_id = globalState.get("profileId"); + routingBody.algorithm.type = type; + routingBody.algorithm.data = data; - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/routing`, - headers: { - Authorization: `Bearer ${globalState.get("userInfoToken")}`, - "Content-Type": "application/json", - Cookie: `${globalState.get("cookie")}`, - }, - failOnStatusCode: false, - body: routingBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/routing`, + headers: { + Authorization: `Bearer ${globalState.get("userInfoToken")}`, + "Content-Type": "application/json", + Cookie: `${globalState.get("cookie")}`, + }, + failOnStatusCode: false, + body: routingBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - expect(response.body).to.have.property("id"); - globalState.set("routingConfigId", response.body.id); - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); - } - } else { - defaultErrorHandler(response, res_data); + if (response.status === 200) { + expect(response.body).to.have.property("id"); + globalState.set("routingConfigId", response.body.id); + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); } - }); - } -); + } else { + defaultErrorHandler(response, res_data); + } + }); +}); -Cypress.Commands.add( - "activateRoutingConfig", - (req_data, res_data, globalState) => { - let routing_config_id = globalState.get("routingConfigId"); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/routing/${routing_config_id}/activate`, - headers: { - Authorization: `Bearer ${globalState.get("userInfoToken")}`, - "Content-Type": "application/json", - Cookie: `${globalState.get("cookie")}`, - }, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); +Cypress.Commands.add("activateRoutingConfig", (req_data, res_data, globalState) => { + let routing_config_id = globalState.get("routingConfigId"); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/routing/${routing_config_id}/activate`, + headers: { + Authorization: `Bearer ${globalState.get("userInfoToken")}`, + "Content-Type": "application/json", + Cookie: `${globalState.get("cookie")}`, + }, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - expect(response.body.id).to.equal(routing_config_id); - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); - } - } else { - defaultErrorHandler(response, res_data); + if (response.status === 200) { + expect(response.body.id).to.equal(routing_config_id); + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); } - }); - } -); + } else { + defaultErrorHandler(response, res_data); + } + }); +}); -Cypress.Commands.add( - "retrieveRoutingConfig", - (req_data, res_data, globalState) => { - let routing_config_id = globalState.get("routingConfigId"); - cy.request({ - method: "GET", - url: `${globalState.get("baseUrl")}/routing/${routing_config_id}`, - headers: { - Authorization: `Bearer ${globalState.get("userInfoToken")}`, - "Content-Type": "application/json", - Cookie: `${globalState.get("cookie")}`, - }, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); +Cypress.Commands.add("retrieveRoutingConfig", (req_data, res_data, globalState) => { + let routing_config_id = globalState.get("routingConfigId"); + cy.request({ + method: "GET", + url: `${globalState.get("baseUrl")}/routing/${routing_config_id}`, + headers: { + Authorization: `Bearer ${globalState.get("userInfoToken")}`, + "Content-Type": "application/json", + Cookie: `${globalState.get("cookie")}`, + }, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - expect(response.body.id).to.equal(routing_config_id); - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); - } - } else { - defaultErrorHandler(response, res_data); + if (response.status === 200) { + expect(response.body.id).to.equal(routing_config_id); + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); } - }); - } -); + } else { + defaultErrorHandler(response, res_data); + } + }); +}); -Cypress.Commands.add( - "autoRetryConfig", - (autoRetryGsmBody, globalState, value) => { - const key = `should_call_gsm_${globalState.get("merchantId")}`; - autoRetryGsmBody.key = key; - autoRetryGsmBody.value = value; +Cypress.Commands.add("autoRetryConfig", (autoRetryGsmBody, globalState, value) => { + const key = `should_call_gsm_${globalState.get("merchantId")}`; + autoRetryGsmBody.key = key; + autoRetryGsmBody.value = value; - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/configs/${key}`, - headers: { - Accept: "application/json", - "Content-Type": "application/json", - "api-key": globalState.get("adminApiKey"), - }, - body: autoRetryGsmBody, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/configs/${key}`, + headers: { + Accept: "application/json", + "Content-Type": "application/json", + "api-key": globalState.get("adminApiKey"), + }, + body: autoRetryGsmBody, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); - if (response.status === 200) { - expect(response.body).to.have.property("key").to.equal(key); - expect(response.body).to.have.property("value").to.equal(value); - } - }); - } -); + if (response.status === 200) { + expect(response.body).to.have.property("key").to.equal(key); + expect(response.body).to.have.property("value").to.equal(value); + } + }); +}); -Cypress.Commands.add( - "setMaxAutoRetries", - (maxAutoRetryBody, globalState, value) => { - const key = `max_auto_retries_enabled_${globalState.get("merchantId")}`; - maxAutoRetryBody.key = key; - maxAutoRetryBody.value = value; +Cypress.Commands.add("setMaxAutoRetries", (maxAutoRetryBody, globalState, value) => { + const key = `max_auto_retries_enabled_${globalState.get("merchantId")}`; + maxAutoRetryBody.key = key; + maxAutoRetryBody.value = value; - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/configs/${key}`, - headers: { - Accept: "application/json", - "Content-Type": "application/json", - "api-key": globalState.get("adminApiKey"), - }, - body: maxAutoRetryBody, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - if (response.status === 200) { - expect(response.body).to.have.property("key").to.equal(key); - expect(response.body).to.have.property("value").to.equal(value); - } - }); - } -); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/configs/${key}`, + headers: { + Accept: "application/json", + "Content-Type": "application/json", + "api-key": globalState.get("adminApiKey"), + }, + body: maxAutoRetryBody, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + if (response.status === 200) { + expect(response.body).to.have.property("key").to.equal(key); + expect(response.body).to.have.property("value").to.equal(value); + } + }); +}); -Cypress.Commands.add( - "updateGsmConfig", - (gsmBody, globalState, step_up_possible) => { - gsmBody.step_up_possible = step_up_possible; - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/gsm/update`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("adminApiKey"), - }, - body: gsmBody, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - if (response.status === 200) { - expect(response.body) - .to.have.property("message") - .to.equal("card_declined"); - expect(response.body).to.have.property("connector").to.equal("stripe"); - expect(response.body) - .to.have.property("step_up_possible") - .to.equal(step_up_possible); - } - }); - } -); +Cypress.Commands.add("updateGsmConfig", (gsmBody, globalState, step_up_possible) => { + gsmBody.step_up_possible = step_up_possible; + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/gsm/update`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("adminApiKey"), + }, + body: gsmBody, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + if (response.status === 200) { + expect(response.body).to.have.property("message").to.equal("card_declined"); + expect(response.body).to.have.property("connector").to.equal("stripe"); + expect(response.body).to.have.property("step_up_possible").to.equal(step_up_possible); + } + }); +}); Cypress.Commands.add("stepUp", (stepUpBody, globalState, value) => { const key = `step_up_enabled_${globalState.get("merchantId")}`; From 81bbd0535ae762e914b0cca121ae6121cc1f7e97 Mon Sep 17 00:00:00 2001 From: gnanasundarig Date: Tue, 1 Oct 2024 13:13:54 +0530 Subject: [PATCH 2/6] Updated the card network --- cypress-tests/cypress/e2e/PaymentUtils/Stripe.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cypress-tests/cypress/e2e/PaymentUtils/Stripe.js b/cypress-tests/cypress/e2e/PaymentUtils/Stripe.js index 826f65d1aa7..3099e65b2fa 100644 --- a/cypress-tests/cypress/e2e/PaymentUtils/Stripe.js +++ b/cypress-tests/cypress/e2e/PaymentUtils/Stripe.js @@ -99,7 +99,7 @@ export const connectorDetails = { card: { last4: "3155", card_type: "CREDIT", - card_network: null, + card_network: "Visa", card_issuer: "INTL HDQTRS-CENTER OWNED", card_issuing_country: "UNITEDSTATES", card_isin: "400000", @@ -135,7 +135,7 @@ export const connectorDetails = { card: { last4: "3155", card_type: "CREDIT", - card_network: null, + card_network: "Visa", card_issuer: "INTL HDQTRS-CENTER OWNED", card_issuing_country: "UNITEDSTATES", card_isin: "400000", @@ -171,7 +171,7 @@ export const connectorDetails = { card: { last4: "4242", card_type: "CREDIT", - card_network: null, + card_network: "Visa", card_issuer: "STRIPE PAYMENTS UK LIMITED", card_issuing_country: "UNITEDKINGDOM", card_isin: "424242", @@ -211,7 +211,7 @@ export const connectorDetails = { card: { last4: "4242", card_type: "CREDIT", - card_network: null, + card_network: "Visa", card_issuer: "STRIPE PAYMENTS UK LIMITED", card_issuing_country: "UNITEDKINGDOM", card_isin: "424242", From 5796d1e42b142e3471de88a27e9587f455974e03 Mon Sep 17 00:00:00 2001 From: gnanasundarig Date: Thu, 3 Oct 2024 17:11:26 +0530 Subject: [PATCH 3/6] chore: remove print width from prettier --- cypress-tests/.prettierrc.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cypress-tests/.prettierrc.json b/cypress-tests/.prettierrc.json index 479993c1334..f0eb61e0f7c 100644 --- a/cypress-tests/.prettierrc.json +++ b/cypress-tests/.prettierrc.json @@ -2,6 +2,5 @@ "trailingComma": "es5", "tabWidth": 2, "semi": true, - "singleQuote": false, - "printWidth": 120 + "singleQuote": false } From 95eba5d7173d663dc835e5f686af77b1a9e5ef98 Mon Sep 17 00:00:00 2001 From: gnanasundarig Date: Thu, 3 Oct 2024 17:13:37 +0530 Subject: [PATCH 4/6] chore: linted command.js file --- cypress-tests/cypress/support/commands.js | 2626 ++++++++++++--------- 1 file changed, 1548 insertions(+), 1078 deletions(-) diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js index 63d7c54b5a6..940b395fedb 100644 --- a/cypress-tests/cypress/support/commands.js +++ b/cypress-tests/cypress/support/commands.js @@ -37,28 +37,31 @@ function logRequestId(xRequestId) { } } -Cypress.Commands.add("merchantCreateCallTest", (merchantCreateBody, globalState) => { - const randomMerchantId = RequestBodyUtils.generateRandomString(); - RequestBodyUtils.setMerchantId(merchantCreateBody, randomMerchantId); - globalState.set("merchantId", randomMerchantId); +Cypress.Commands.add( + "merchantCreateCallTest", + (merchantCreateBody, globalState) => { + const randomMerchantId = RequestBodyUtils.generateRandomString(); + RequestBodyUtils.setMerchantId(merchantCreateBody, randomMerchantId); + globalState.set("merchantId", randomMerchantId); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/accounts`, - headers: { - Accept: "application/json", - "Content-Type": "application/json", - "api-key": globalState.get("adminApiKey"), - }, - body: merchantCreateBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/accounts`, + headers: { + Accept: "application/json", + "Content-Type": "application/json", + "api-key": globalState.get("adminApiKey"), + }, + body: merchantCreateBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); - // Handle the response as needed - globalState.set("publishableKey", response.body.publishable_key); - globalState.set("merchantDetails", response.body.merchant_details); - }); -}); + // Handle the response as needed + globalState.set("publishableKey", response.body.publishable_key); + globalState.set("merchantDetails", response.body.merchant_details); + }); + } +); Cypress.Commands.add("merchantRetrieveCall", (globalState) => { const merchant_id = globalState.get("merchantId"); @@ -122,38 +125,43 @@ Cypress.Commands.add("merchantListCall", (globalState) => { expect(response.headers["content-type"]).to.include("application/json"); for (const key in response.body) { expect(response.body[key]).to.have.property("merchant_id").and.not.empty; - expect(response.body[key]).to.have.property("organization_id").and.not.empty; - expect(response.body[key]).to.have.property("default_profile").and.not.empty; + expect(response.body[key]).to.have.property("organization_id").and.not + .empty; + expect(response.body[key]).to.have.property("default_profile").and.not + .empty; } }); }); -Cypress.Commands.add("merchantUpdateCall", (merchantUpdateBody, globalState) => { - const merchant_id = globalState.get("merchantId"); - const organization_id = globalState.get("organizationId"); - const publishable_key = globalState.get("publishableKey"); - const merchant_details = globalState.get("merchantDetails"); - - merchantUpdateBody.merchant_id = merchant_id; - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/accounts/${merchant_id}`, - headers: { - Accept: "application/json", - "Content-Type": "application/json", - "api-key": globalState.get("adminApiKey"), - }, - body: merchantUpdateBody, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - expect(response.body.merchant_id).to.equal(merchant_id); - expect(response.body.publishable_key).to.equal(publishable_key); - expect(response.body.organization_id).to.equal(organization_id); - expect(response.body.merchant_details).to.not.equal(merchant_details); - }); -}); +Cypress.Commands.add( + "merchantUpdateCall", + (merchantUpdateBody, globalState) => { + const merchant_id = globalState.get("merchantId"); + const organization_id = globalState.get("organizationId"); + const publishable_key = globalState.get("publishableKey"); + const merchant_details = globalState.get("merchantDetails"); + + merchantUpdateBody.merchant_id = merchant_id; + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/accounts/${merchant_id}`, + headers: { + Accept: "application/json", + "Content-Type": "application/json", + "api-key": globalState.get("adminApiKey"), + }, + body: merchantUpdateBody, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + expect(response.body.merchant_id).to.equal(merchant_id); + expect(response.body.publishable_key).to.equal(publishable_key); + expect(response.body.organization_id).to.equal(organization_id); + expect(response.body.merchant_details).to.not.equal(merchant_details); + }); + } +); Cypress.Commands.add("apiKeyCreateTest", (apiKeyCreateBody, globalState) => { cy.request({ @@ -241,9 +249,11 @@ Cypress.Commands.add("apiKeyListCall", (globalState) => { for (const key in response.body) { expect(response.body[key]).to.have.property("name").and.not.empty; if (base_url.includes("sandbox") || base_url.includes("integ")) { - expect(response.body[key]).to.have.property("key_id").include("snd_").and.not.empty; + expect(response.body[key]).to.have.property("key_id").include("snd_") + .and.not.empty; } else if (base_url.includes("localhost")) { - expect(response.body[key]).to.have.property("key_id").include("dev_").and.not.empty; + expect(response.body[key]).to.have.property("key_id").include("dev_") + .and.not.empty; } expect(response.body[key].merchant_id).to.equal(merchant_id); } @@ -275,7 +285,14 @@ Cypress.Commands.add("apiKeyDeleteCall", (globalState) => { Cypress.Commands.add( "createNamedConnectorCallTest", - (connectorType, createConnectorBody, payment_methods_enabled, globalState, connectorName, connectorLabel) => { + ( + connectorType, + createConnectorBody, + payment_methods_enabled, + globalState, + connectorName, + connectorLabel + ) => { const merchantId = globalState.get("merchantId"); createConnectorBody.connector_type = connectorType; createConnectorBody.connector_name = connectorName; @@ -283,133 +300,187 @@ Cypress.Commands.add( createConnectorBody.payment_methods_enabled = payment_methods_enabled; // readFile is used to read the contents of the file and it always returns a promise ([Object Object]) due to its asynchronous nature // it is best to use then() to handle the response within the same block of code - cy.readFile(globalState.get("connectorAuthFilePath")).then((jsonContent) => { - const authDetails = getValueByKey(JSON.stringify(jsonContent), connectorName); - createConnectorBody.connector_account_details = authDetails.connector_account_details; - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`, - headers: { - "Content-Type": "application/json", - Accept: "application/json", - "api-key": globalState.get("adminApiKey"), - }, - body: createConnectorBody, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - - if (response.status === 200) { - expect(connectorName).to.equal(response.body.connector_name); - globalState.set("merchantConnectorId", response.body.merchant_connector_id); - } else { - cy.task("cli_log", "response status -> " + JSON.stringify(response.status)); - - throw new Error(`Connector Create Call Failed ${response.body.error.message}`); - } - }); - }); + cy.readFile(globalState.get("connectorAuthFilePath")).then( + (jsonContent) => { + const authDetails = getValueByKey( + JSON.stringify(jsonContent), + connectorName + ); + createConnectorBody.connector_account_details = + authDetails.connector_account_details; + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`, + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "api-key": globalState.get("adminApiKey"), + }, + body: createConnectorBody, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + + if (response.status === 200) { + expect(connectorName).to.equal(response.body.connector_name); + globalState.set( + "merchantConnectorId", + response.body.merchant_connector_id + ); + } else { + cy.task( + "cli_log", + "response status -> " + JSON.stringify(response.status) + ); + + throw new Error( + `Connector Create Call Failed ${response.body.error.message}` + ); + } + }); + } + ); } ); Cypress.Commands.add( "createConnectorCallTest", - (connectorType, createConnectorBody, payment_methods_enabled, globalState) => { + ( + connectorType, + createConnectorBody, + payment_methods_enabled, + globalState + ) => { const merchantId = globalState.get("merchantId"); createConnectorBody.connector_type = connectorType; createConnectorBody.connector_name = globalState.get("connectorId"); createConnectorBody.payment_methods_enabled = payment_methods_enabled; // readFile is used to read the contents of the file and it always returns a promise ([Object Object]) due to its asynchronous nature // it is best to use then() to handle the response within the same block of code - cy.readFile(globalState.get("connectorAuthFilePath")).then((jsonContent) => { - const authDetails = getValueByKey(JSON.stringify(jsonContent), globalState.get("connectorId")); - createConnectorBody.connector_account_details = authDetails.connector_account_details; - - if (authDetails && authDetails.metadata) { - createConnectorBody.metadata = { - ...createConnectorBody.metadata, // Preserve existing metadata fields - ...authDetails.metadata, // Merge with authDetails.metadata - }; - } - - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`, - headers: { - "Content-Type": "application/json", - Accept: "application/json", - "api-key": globalState.get("adminApiKey"), - }, - body: createConnectorBody, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - - if (response.status === 200) { - expect(globalState.get("connectorId")).to.equal(response.body.connector_name); - globalState.set("merchantConnectorId", response.body.merchant_connector_id); - } else { - cy.task("cli_log", "response status -> " + JSON.stringify(response.status)); - - throw new Error(`Connector Create Call Failed ${response.body.error.message}`); + cy.readFile(globalState.get("connectorAuthFilePath")).then( + (jsonContent) => { + const authDetails = getValueByKey( + JSON.stringify(jsonContent), + globalState.get("connectorId") + ); + createConnectorBody.connector_account_details = + authDetails.connector_account_details; + + if (authDetails && authDetails.metadata) { + createConnectorBody.metadata = { + ...createConnectorBody.metadata, // Preserve existing metadata fields + ...authDetails.metadata, // Merge with authDetails.metadata + }; } - }); - }); + + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`, + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "api-key": globalState.get("adminApiKey"), + }, + body: createConnectorBody, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + + if (response.status === 200) { + expect(globalState.get("connectorId")).to.equal( + response.body.connector_name + ); + globalState.set( + "merchantConnectorId", + response.body.merchant_connector_id + ); + } else { + cy.task( + "cli_log", + "response status -> " + JSON.stringify(response.status) + ); + + throw new Error( + `Connector Create Call Failed ${response.body.error.message}` + ); + } + }); + } + ); } ); -Cypress.Commands.add("createPayoutConnectorCallTest", (connectorType, createConnectorBody, globalState) => { - const merchantId = globalState.get("merchantId"); - let connectorName = globalState.get("connectorId"); - createConnectorBody.connector_type = connectorType; - createConnectorBody.connector_name = connectorName; - createConnectorBody.connector_type = "payout_processor"; - // readFile is used to read the contents of the file and it always returns a promise ([Object Object]) due to its asynchronous nature - // it is best to use then() to handle the response within the same block of code - cy.readFile(globalState.get("connectorAuthFilePath")).then((jsonContent) => { - let authDetails = getValueByKey(JSON.stringify(jsonContent), `${connectorName}_payout`); - - // If the connector does not have payout connector creds in creds file, set payoutsExecution to false - if (authDetails === null) { - globalState.set("payoutsExecution", false); - return false; - } else { - globalState.set("payoutsExecution", true); - } - - createConnectorBody.connector_account_details = authDetails.connector_account_details; +Cypress.Commands.add( + "createPayoutConnectorCallTest", + (connectorType, createConnectorBody, globalState) => { + const merchantId = globalState.get("merchantId"); + let connectorName = globalState.get("connectorId"); + createConnectorBody.connector_type = connectorType; + createConnectorBody.connector_name = connectorName; + createConnectorBody.connector_type = "payout_processor"; + // readFile is used to read the contents of the file and it always returns a promise ([Object Object]) due to its asynchronous nature + // it is best to use then() to handle the response within the same block of code + cy.readFile(globalState.get("connectorAuthFilePath")).then( + (jsonContent) => { + let authDetails = getValueByKey( + JSON.stringify(jsonContent), + `${connectorName}_payout` + ); - if (authDetails && authDetails.metadata) { - createConnectorBody.metadata = { - ...createConnectorBody.metadata, // Preserve existing metadata fields - ...authDetails.metadata, // Merge with authDetails.metadata - }; - } + // If the connector does not have payout connector creds in creds file, set payoutsExecution to false + if (authDetails === null) { + globalState.set("payoutsExecution", false); + return false; + } else { + globalState.set("payoutsExecution", true); + } - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`, - headers: { - Accept: "application/json", - "Content-Type": "application/json", - "api-key": globalState.get("adminApiKey"), - }, - body: createConnectorBody, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); + createConnectorBody.connector_account_details = + authDetails.connector_account_details; - if (response.status === 200) { - expect(globalState.get("connectorId")).to.equal(response.body.connector_name); - globalState.set("merchantConnectorId", response.body.merchant_connector_id); - } else { - cy.task("cli_log", "response status -> " + JSON.stringify(response.status)); + if (authDetails && authDetails.metadata) { + createConnectorBody.metadata = { + ...createConnectorBody.metadata, // Preserve existing metadata fields + ...authDetails.metadata, // Merge with authDetails.metadata + }; + } - throw new Error(`Connector Create Call Failed ${response.body.error.message}`); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`, + headers: { + Accept: "application/json", + "Content-Type": "application/json", + "api-key": globalState.get("adminApiKey"), + }, + body: createConnectorBody, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + + if (response.status === 200) { + expect(globalState.get("connectorId")).to.equal( + response.body.connector_name + ); + globalState.set( + "merchantConnectorId", + response.body.merchant_connector_id + ); + } else { + cy.task( + "cli_log", + "response status -> " + JSON.stringify(response.status) + ); + + throw new Error( + `Connector Create Call Failed ${response.body.error.message}` + ); + } + }); } - }); - }); -}); + ); + } +); Cypress.Commands.add("connectorRetrieveCall", (globalState) => { const merchant_id = globalState.get("merchantId"); @@ -455,31 +526,36 @@ Cypress.Commands.add("connectorDeleteCall", (globalState) => { }); }); -Cypress.Commands.add("connectorUpdateCall", (connectorType, updateConnectorBody, globalState) => { - const merchant_id = globalState.get("merchantId"); - const connector_id = globalState.get("connectorId"); - const merchant_connector_id = globalState.get("merchantConnectorId"); - updateConnectorBody.connector_type = connectorType; +Cypress.Commands.add( + "connectorUpdateCall", + (connectorType, updateConnectorBody, globalState) => { + const merchant_id = globalState.get("merchantId"); + const connector_id = globalState.get("connectorId"); + const merchant_connector_id = globalState.get("merchantConnectorId"); + updateConnectorBody.connector_type = connectorType; - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/account/${merchant_id}/connectors/${merchant_connector_id}`, - headers: { - Accept: "application/json", - "Content-Type": "application/json", - "api-key": globalState.get("adminApiKey"), - "x-merchant-id": merchant_id, - }, - body: updateConnectorBody, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - expect(response.body.connector_name).to.equal(connector_id); - expect(response.body.merchant_connector_id).to.equal(merchant_connector_id); - expect(response.body.connector_label).to.equal("updated_connector_label"); - }); -}); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/account/${merchant_id}/connectors/${merchant_connector_id}`, + headers: { + Accept: "application/json", + "Content-Type": "application/json", + "api-key": globalState.get("adminApiKey"), + "x-merchant-id": merchant_id, + }, + body: updateConnectorBody, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + expect(response.body.connector_name).to.equal(connector_id); + expect(response.body.merchant_connector_id).to.equal( + merchant_connector_id + ); + expect(response.body.connector_label).to.equal("updated_connector_label"); + }); + } +); // Generic function to list all connectors Cypress.Commands.add("connectorListByMid", (globalState) => { @@ -500,21 +576,24 @@ Cypress.Commands.add("connectorListByMid", (globalState) => { }); }); -Cypress.Commands.add("createCustomerCallTest", (customerCreateBody, globalState) => { - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/customers`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - body: customerCreateBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.body.customer_id).to.not.be.empty; - globalState.set("customerId", response.body.customer_id); - }); -}); +Cypress.Commands.add( + "createCustomerCallTest", + (customerCreateBody, globalState) => { + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/customers`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + body: customerCreateBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.body.customer_id).to.not.be.empty; + globalState.set("customerId", response.body.customer_id); + }); + } +); Cypress.Commands.add("customerListCall", (globalState) => { cy.request({ @@ -550,23 +629,26 @@ Cypress.Commands.add("customerRetrieveCall", (globalState) => { }); }); -Cypress.Commands.add("customerUpdateCall", (customerUpdateBody, globalState) => { - const customer_id = globalState.get("customerId"); +Cypress.Commands.add( + "customerUpdateCall", + (customerUpdateBody, globalState) => { + const customer_id = globalState.get("customerId"); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/customers/${customer_id}`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - body: customerUpdateBody, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.body.customer_id).to.equal(customer_id); - }); -}); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/customers/${customer_id}`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + body: customerUpdateBody, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.body.customer_id).to.equal(customer_id); + }); + } +); Cypress.Commands.add("ephemeralGenerateCall", (globalState) => { const customer_id = globalState.get("customerId"); @@ -610,102 +692,131 @@ Cypress.Commands.add("customerDeleteCall", (globalState) => { }); }); -Cypress.Commands.add("paymentMethodListTestLessThanEqualToOnePaymentMethod", (res_data, globalState) => { - cy.request({ - method: "GET", - url: `${globalState.get("baseUrl")}/account/payment_methods?client_secret=${globalState.get("clientSecret")}`, - headers: { - "Content-Type": "application/json", - Accept: "application/json", - "api-key": globalState.get("publishableKey"), - }, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - expect(response.body).to.have.property("currency"); - if (res_data["payment_methods"].length == 1) { - function getPaymentMethodType(obj) { - return obj["payment_methods"][0]["payment_method_types"][0]["payment_method_type"]; - } - expect(getPaymentMethodType(res_data)).to.equal(getPaymentMethodType(response.body)); - } else { - expect(0).to.equal(response.body["payment_methods"].length); - } - } else { - defaultErrorHandler(response, res_data); - } - }); -}); - -Cypress.Commands.add("paymentMethodListTestTwoConnectorsForOnePaymentMethodCredit", (res_data, globalState) => { - cy.request({ - method: "GET", - url: `${globalState.get("baseUrl")}/account/payment_methods?client_secret=${globalState.get("clientSecret")}`, - headers: { - "Content-Type": "application/json", - Accept: "application/json", - "api-key": globalState.get("publishableKey"), - }, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - expect(response.body).to.have.property("currency"); - if (res_data["payment_methods"].length > 0) { - function getPaymentMethodType(obj) { - return obj["payment_methods"][0]["payment_method_types"][0]["card_networks"][0]["eligible_connectors"] - .slice() - .sort(); - } - let config_payment_method_type = getPaymentMethodType(res_data); - let response_payment_method_type = getPaymentMethodType(response.body); - for (let i = 0; i < response_payment_method_type.length; i++) { - expect(config_payment_method_type[i]).to.equal(response_payment_method_type[i]); - } - } else { - expect(0).to.equal(response.body["payment_methods"].length); - } - } else { - defaultErrorHandler(response, res_data); - } - }); -}); - Cypress.Commands.add( - "createPaymentIntentTest", - (createPaymentBody, req_data, res_data, authentication_type, capture_method, globalState) => { - if (!createPaymentBody || typeof createPaymentBody !== "object" || !req_data.currency) { - throw new Error("Invalid parameters provided to createPaymentIntentTest command"); - } - - for (const key in req_data) { - createPaymentBody[key] = req_data[key]; - } - createPaymentBody.authentication_type = authentication_type; - - createPaymentBody.capture_method = capture_method; - createPaymentBody.customer_id = globalState.get("customerId"); - globalState.set("paymentAmount", createPaymentBody.amount); + "paymentMethodListTestLessThanEqualToOnePaymentMethod", + (res_data, globalState) => { cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments`, + method: "GET", + url: `${globalState.get("baseUrl")}/account/payment_methods?client_secret=${globalState.get("clientSecret")}`, headers: { "Content-Type": "application/json", Accept: "application/json", - "api-key": globalState.get("apiKey"), + "api-key": globalState.get("publishableKey"), }, failOnStatusCode: false, - body: createPaymentBody, }).then((response) => { logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - - if (res_data.status === 200) { - expect(response.body).to.have.property("client_secret"); + if (response.status === 200) { + expect(response.body).to.have.property("currency"); + if (res_data["payment_methods"].length == 1) { + function getPaymentMethodType(obj) { + return obj["payment_methods"][0]["payment_method_types"][0][ + "payment_method_type" + ]; + } + expect(getPaymentMethodType(res_data)).to.equal( + getPaymentMethodType(response.body) + ); + } else { + expect(0).to.equal(response.body["payment_methods"].length); + } + } else { + defaultErrorHandler(response, res_data); + } + }); + } +); + +Cypress.Commands.add( + "paymentMethodListTestTwoConnectorsForOnePaymentMethodCredit", + (res_data, globalState) => { + cy.request({ + method: "GET", + url: `${globalState.get("baseUrl")}/account/payment_methods?client_secret=${globalState.get("clientSecret")}`, + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "api-key": globalState.get("publishableKey"), + }, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + expect(response.body).to.have.property("currency"); + if (res_data["payment_methods"].length > 0) { + function getPaymentMethodType(obj) { + return obj["payment_methods"][0]["payment_method_types"][0][ + "card_networks" + ][0]["eligible_connectors"] + .slice() + .sort(); + } + let config_payment_method_type = getPaymentMethodType(res_data); + let response_payment_method_type = getPaymentMethodType( + response.body + ); + for (let i = 0; i < response_payment_method_type.length; i++) { + expect(config_payment_method_type[i]).to.equal( + response_payment_method_type[i] + ); + } + } else { + expect(0).to.equal(response.body["payment_methods"].length); + } + } else { + defaultErrorHandler(response, res_data); + } + }); + } +); + +Cypress.Commands.add( + "createPaymentIntentTest", + ( + createPaymentBody, + req_data, + res_data, + authentication_type, + capture_method, + globalState + ) => { + if ( + !createPaymentBody || + typeof createPaymentBody !== "object" || + !req_data.currency + ) { + throw new Error( + "Invalid parameters provided to createPaymentIntentTest command" + ); + } + + for (const key in req_data) { + createPaymentBody[key] = req_data[key]; + } + createPaymentBody.authentication_type = authentication_type; + + createPaymentBody.capture_method = capture_method; + createPaymentBody.customer_id = globalState.get("customerId"); + globalState.set("paymentAmount", createPaymentBody.amount); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payments`, + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "api-key": globalState.get("apiKey"), + }, + failOnStatusCode: false, + body: createPaymentBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + + expect(response.headers["content-type"]).to.include("application/json"); + + if (res_data.status === 200) { + expect(response.body).to.have.property("client_secret"); const clientSecret = response.body.client_secret; globalState.set("clientSecret", clientSecret); globalState.set("paymentID", response.body.payment_id); @@ -716,30 +827,62 @@ Cypress.Commands.add( `Expected ${res_data.body[key]} but got ${response.body[key]}` ); } - expect(createPaymentBody.amount, "amount").to.equal(response.body.amount); - expect(createPaymentBody.currency, "currency").to.equal(response.body.currency); - expect(createPaymentBody.capture_method, "capture_method").to.equal(response.body.capture_method); - expect(createPaymentBody.authentication_type, "authentication_type").to.equal( - response.body.authentication_type + expect(createPaymentBody.amount, "amount").to.equal( + response.body.amount + ); + expect(createPaymentBody.currency, "currency").to.equal( + response.body.currency + ); + expect(createPaymentBody.capture_method, "capture_method").to.equal( + response.body.capture_method + ); + expect( + createPaymentBody.authentication_type, + "authentication_type" + ).to.equal(response.body.authentication_type); + expect(createPaymentBody.description, "description").to.equal( + response.body.description ); - expect(createPaymentBody.description, "description").to.equal(response.body.description); expect(createPaymentBody.email, "email").to.equal(response.body.email); - expect(createPaymentBody.email, "customer.email").to.equal(response.body.customer.email); - expect(createPaymentBody.customer_id, "customer.id").to.equal(response.body.customer.id); - expect(createPaymentBody.metadata, "metadata").to.deep.equal(response.body.metadata); - expect(createPaymentBody.setup_future_usage, "setup_future_usage").to.equal(response.body.setup_future_usage); - expect(createPaymentBody.amount, "amount_capturable").to.equal(response.body.amount_capturable); - expect(response.body.amount_received, "amount_received").to.be.oneOf([0, null]); + expect(createPaymentBody.email, "customer.email").to.equal( + response.body.customer.email + ); + expect(createPaymentBody.customer_id, "customer.id").to.equal( + response.body.customer.id + ); + expect(createPaymentBody.metadata, "metadata").to.deep.equal( + response.body.metadata + ); + expect( + createPaymentBody.setup_future_usage, + "setup_future_usage" + ).to.equal(response.body.setup_future_usage); + expect(createPaymentBody.amount, "amount_capturable").to.equal( + response.body.amount_capturable + ); + expect(response.body.amount_received, "amount_received").to.be.oneOf([ + 0, + null, + ]); expect(response.body.connector, "connector").to.be.null; - expect(createPaymentBody.capture_method, "capture_method").to.equal(response.body.capture_method); + expect(createPaymentBody.capture_method, "capture_method").to.equal( + response.body.capture_method + ); expect(response.body.payment_method, "payment_method").to.be.null; - expect(response.body.payment_method_data, "payment_method_data").to.be.null; - expect(response.body.merchant_connector_id, "merchant_connector_id").to.be.null; + expect(response.body.payment_method_data, "payment_method_data").to.be + .null; + expect(response.body.merchant_connector_id, "merchant_connector_id").to + .be.null; expect(response.body.payment_method_id, "payment_method_id").to.be.null; - expect(response.body.payment_method_id, "payment_method_status").to.be.null; + expect(response.body.payment_method_id, "payment_method_status").to.be + .null; expect(response.body.profile_id, "profile_id").to.not.be.null; - expect(response.body.merchant_order_reference_id, "merchant_order_reference_id").to.be.null; - expect(response.body.connector_mandate_id, "connector_mandate_id").to.be.null; + expect( + response.body.merchant_order_reference_id, + "merchant_order_reference_id" + ).to.be.null; + expect(response.body.connector_mandate_id, "connector_mandate_id").to.be + .null; } else { defaultErrorHandler(response, res_data); } @@ -769,260 +912,370 @@ Cypress.Commands.add("paymentMethodsCallTest", (globalState) => { }); }); -Cypress.Commands.add("createPaymentMethodTest", (globalState, req_data, res_data) => { - req_data.customer_id = globalState.get("customerId"); - - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payment_methods`, - body: req_data, - headers: { - "Content-Type": "application/json", - Accept: "application/json", - "api-key": globalState.get("apiKey"), - }, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); +Cypress.Commands.add( + "createPaymentMethodTest", + (globalState, req_data, res_data) => { + req_data.customer_id = globalState.get("customerId"); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - expect(response.body).to.have.property("payment_method_id"); - expect(response.body).to.have.property("client_secret"); - globalState.set("paymentMethodId", response.body.payment_method_id); - } else { - defaultErrorHandler(response, res_data); - } - }); -}); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payment_methods`, + body: req_data, + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "api-key": globalState.get("apiKey"), + }, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); -Cypress.Commands.add("confirmCallTest", (confirmBody, req_data, res_data, confirm, globalState) => { - const paymentIntentID = globalState.get("paymentID"); - confirmBody.confirm = confirm; - confirmBody.client_secret = globalState.get("clientSecret"); - for (const key in req_data) { - confirmBody[key] = req_data[key]; - } - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments/${paymentIntentID}/confirm`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("publishableKey"), - }, - failOnStatusCode: false, - body: confirmBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - globalState.set("paymentID", paymentIntentID); - globalState.set("connectorId", response.body.connector); - expect(response.body.connector, "connector").to.equal(globalState.get("connectorId")); - expect(response.body.payment_id, "payment_id").to.equal(paymentIntentID); - expect(response.body.payment_method_data, "payment_method_data").to.not.be.empty; - expect(response.body.merchant_connector_id, "connectorId").to.equal(globalState.get("merchantConnectorId")); - expect(response.body.customer, "customer").to.not.be.empty; - expect(response.body.billing, "billingAddress").to.not.be.empty; - expect(response.body.profile_id, "profile_id").to.not.be.null; - expect(response.body.connector_transaction_id, "connector_transaction_id").to.not.be.null; - if (response.body.capture_method === "automatic") { - if (response.body.authentication_type === "three_ds") { - expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); - globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); - for (const key in res_data.body) { - expect(res_data.body[key], [key]).to.deep.equal(response.body[key]); - } - } else if (response.body.authentication_type === "no_three_ds") { - for (const key in res_data.body) { - expect(res_data.body[key], [key]).to.deep.equal(response.body[key]); - } - } else { - throw new Error(`Invalid authentication type ${response.body.authentication_type}`); - } - } else if (response.body.capture_method === "manual") { - if (response.body.authentication_type === "three_ds") { - expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); - globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); - for (const key in res_data.body) { - expect(res_data.body[key], [key]).to.deep.equal(response.body[key]); - } - } else if (response.body.authentication_type === "no_three_ds") { - for (const key in res_data.body) { - expect(res_data.body[key], [key]).to.deep.equal(response.body[key]); - } - } else { - throw new Error(`Invalid authentication type ${response.body.authentication_type}`); - } + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + expect(response.body).to.have.property("payment_method_id"); + expect(response.body).to.have.property("client_secret"); + globalState.set("paymentMethodId", response.body.payment_method_id); } else { - throw new Error(`Invalid capture method ${response.body.capture_method}`); + defaultErrorHandler(response, res_data); } - } else { - defaultErrorHandler(response, res_data); - } - }); -}); - -Cypress.Commands.add("confirmBankRedirectCallTest", (confirmBody, req_data, res_data, confirm, globalState) => { - const paymentIntentId = globalState.get("paymentID"); - const connectorId = globalState.get("connectorId"); - for (const key in req_data) { - confirmBody[key] = req_data[key]; + }); } - confirmBody.confirm = confirm; - confirmBody.client_secret = globalState.get("clientSecret"); +); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments/${paymentIntentId}/confirm`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("publishableKey"), - }, - failOnStatusCode: false, - body: confirmBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - if (response.status === 200) { +Cypress.Commands.add( + "confirmCallTest", + (confirmBody, req_data, res_data, confirm, globalState) => { + const paymentIntentID = globalState.get("paymentID"); + confirmBody.confirm = confirm; + confirmBody.client_secret = globalState.get("clientSecret"); + for (const key in req_data) { + confirmBody[key] = req_data[key]; + } + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payments/${paymentIntentID}/confirm`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("publishableKey"), + }, + failOnStatusCode: false, + body: confirmBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); expect(response.headers["content-type"]).to.include("application/json"); - globalState.set("paymentID", paymentIntentId); - globalState.set("connectorId", response.body.connector); - globalState.set("paymentMethodType", confirmBody.payment_method_type); - - switch (response.body.authentication_type) { - case "three_ds": - if (response.body.capture_method === "automatic" || response.body.capture_method === "manual") { - if (response.body.status !== "failed") { - // we get many statuses here, hence this verification - if (connectorId === "adyen" && response.body.payment_method_type === "blik") { - expect(response.body) - .to.have.property("next_action") - .to.have.property("type") - .to.equal("wait_screen_information"); - } else { - expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); - globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); - } - } else if (response.body.status === "failed") { - expect(response.body.error_code).to.equal(res_data.body.error_code); + if (response.status === 200) { + globalState.set("paymentID", paymentIntentID); + globalState.set("connectorId", response.body.connector); + expect(response.body.connector, "connector").to.equal( + globalState.get("connectorId") + ); + expect(response.body.payment_id, "payment_id").to.equal( + paymentIntentID + ); + expect(response.body.payment_method_data, "payment_method_data").to.not + .be.empty; + expect(response.body.merchant_connector_id, "connectorId").to.equal( + globalState.get("merchantConnectorId") + ); + expect(response.body.customer, "customer").to.not.be.empty; + expect(response.body.billing, "billingAddress").to.not.be.empty; + expect(response.body.profile_id, "profile_id").to.not.be.null; + expect( + response.body.connector_transaction_id, + "connector_transaction_id" + ).to.not.be.null; + if (response.body.capture_method === "automatic") { + if (response.body.authentication_type === "three_ds") { + expect(response.body) + .to.have.property("next_action") + .to.have.property("redirect_to_url"); + globalState.set( + "nextActionUrl", + response.body.next_action.redirect_to_url + ); + for (const key in res_data.body) { + expect(res_data.body[key], [key]).to.deep.equal( + response.body[key] + ); + } + } else if (response.body.authentication_type === "no_three_ds") { + for (const key in res_data.body) { + expect(res_data.body[key], [key]).to.deep.equal( + response.body[key] + ); } } else { - throw new Error(`Invalid capture method ${response.body.capture_method}`); + throw new Error( + `Invalid authentication type ${response.body.authentication_type}` + ); } - break; - case "no_three_ds": - if (response.body.capture_method === "automatic" || response.body.capture_method === "manual") { - expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); - globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); + } else if (response.body.capture_method === "manual") { + if (response.body.authentication_type === "three_ds") { + expect(response.body) + .to.have.property("next_action") + .to.have.property("redirect_to_url"); + globalState.set( + "nextActionUrl", + response.body.next_action.redirect_to_url + ); + for (const key in res_data.body) { + expect(res_data.body[key], [key]).to.deep.equal( + response.body[key] + ); + } + } else if (response.body.authentication_type === "no_three_ds") { + for (const key in res_data.body) { + expect(res_data.body[key], [key]).to.deep.equal( + response.body[key] + ); + } } else { - throw new Error(`Invalid capture method ${response.body.capture_method}`); + throw new Error( + `Invalid authentication type ${response.body.authentication_type}` + ); } - break; - default: - throw new Error(`Invalid authentication type ${response.body.authentication_type}`); + } else { + throw new Error( + `Invalid capture method ${response.body.capture_method}` + ); + } + } else { + defaultErrorHandler(response, res_data); } - } else { - defaultErrorHandler(response, res_data); - } - }); -}); - -Cypress.Commands.add("confirmBankTransferCallTest", (confirmBody, req_data, res_data, confirm, globalState) => { - const paymentIntentID = globalState.get("paymentID"); - for (const key in req_data) { - confirmBody[key] = req_data[key]; + }); } - confirmBody.confirm = confirm; - confirmBody.client_secret = globalState.get("clientSecret"); - globalState.set("paymentMethodType", confirmBody.payment_method_type); +); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments/${paymentIntentID}/confirm`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("publishableKey"), - }, - failOnStatusCode: false, - body: confirmBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - globalState.set("paymentID", paymentIntentID); - if (response.body.capture_method === "automatic" || response.body.capture_method === "manual") { - switch (response.body.payment_method_type) { - case "pix": - expect(response.body).to.have.property("next_action").to.have.property("qr_code_url"); - if (response.body.next_action.qr_code_url !== null) { +Cypress.Commands.add( + "confirmBankRedirectCallTest", + (confirmBody, req_data, res_data, confirm, globalState) => { + const paymentIntentId = globalState.get("paymentID"); + const connectorId = globalState.get("connectorId"); + for (const key in req_data) { + confirmBody[key] = req_data[key]; + } + confirmBody.confirm = confirm; + confirmBody.client_secret = globalState.get("clientSecret"); + + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payments/${paymentIntentId}/confirm`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("publishableKey"), + }, + failOnStatusCode: false, + body: confirmBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + if (response.status === 200) { + expect(response.headers["content-type"]).to.include("application/json"); + globalState.set("paymentID", paymentIntentId); + globalState.set("connectorId", response.body.connector); + globalState.set("paymentMethodType", confirmBody.payment_method_type); + + switch (response.body.authentication_type) { + case "three_ds": + if ( + response.body.capture_method === "automatic" || + response.body.capture_method === "manual" + ) { + if (response.body.status !== "failed") { + // we get many statuses here, hence this verification + if ( + connectorId === "adyen" && + response.body.payment_method_type === "blik" + ) { + expect(response.body) + .to.have.property("next_action") + .to.have.property("type") + .to.equal("wait_screen_information"); + } else { + expect(response.body) + .to.have.property("next_action") + .to.have.property("redirect_to_url"); + globalState.set( + "nextActionUrl", + response.body.next_action.redirect_to_url + ); + } + } else if (response.body.status === "failed") { + expect(response.body.error_code).to.equal( + res_data.body.error_code + ); + } + } else { + throw new Error( + `Invalid capture method ${response.body.capture_method}` + ); + } + break; + case "no_three_ds": + if ( + response.body.capture_method === "automatic" || + response.body.capture_method === "manual" + ) { + expect(response.body) + .to.have.property("next_action") + .to.have.property("redirect_to_url"); globalState.set( - "nextActionUrl", // This is intentionally kept as nextActionUrl to avoid issues during handleRedirection call, - response.body.next_action.qr_code_url + "nextActionUrl", + response.body.next_action.redirect_to_url ); - globalState.set("nextActionType", "qr_code_url"); } else { - globalState.set( - "nextActionUrl", // This is intentionally kept as nextActionUrl to avoid issues during handleRedirection call, - response.body.next_action.image_data_url + throw new Error( + `Invalid capture method ${response.body.capture_method}` ); - globalState.set("nextActionType", "image_data_url"); } break; default: - expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); - globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); - break; + throw new Error( + `Invalid authentication type ${response.body.authentication_type}` + ); } } else { - throw new Error(`Invalid capture method ${response.body.capture_method}`); + defaultErrorHandler(response, res_data); } - } else { - defaultErrorHandler(response, res_data); + }); + } +); + +Cypress.Commands.add( + "confirmBankTransferCallTest", + (confirmBody, req_data, res_data, confirm, globalState) => { + const paymentIntentID = globalState.get("paymentID"); + for (const key in req_data) { + confirmBody[key] = req_data[key]; } - }); -}); + confirmBody.confirm = confirm; + confirmBody.client_secret = globalState.get("clientSecret"); + globalState.set("paymentMethodType", confirmBody.payment_method_type); -Cypress.Commands.add("confirmUpiCall", (confirmBody, req_data, res_data, confirm, globalState) => { - const paymentId = globalState.get("paymentID"); - for (const key in req_data) { - confirmBody[key] = req_data[key]; + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payments/${paymentIntentID}/confirm`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("publishableKey"), + }, + failOnStatusCode: false, + body: confirmBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + globalState.set("paymentID", paymentIntentID); + if ( + response.body.capture_method === "automatic" || + response.body.capture_method === "manual" + ) { + switch (response.body.payment_method_type) { + case "pix": + expect(response.body) + .to.have.property("next_action") + .to.have.property("qr_code_url"); + if (response.body.next_action.qr_code_url !== null) { + globalState.set( + "nextActionUrl", // This is intentionally kept as nextActionUrl to avoid issues during handleRedirection call, + response.body.next_action.qr_code_url + ); + globalState.set("nextActionType", "qr_code_url"); + } else { + globalState.set( + "nextActionUrl", // This is intentionally kept as nextActionUrl to avoid issues during handleRedirection call, + response.body.next_action.image_data_url + ); + globalState.set("nextActionType", "image_data_url"); + } + break; + default: + expect(response.body) + .to.have.property("next_action") + .to.have.property("redirect_to_url"); + globalState.set( + "nextActionUrl", + response.body.next_action.redirect_to_url + ); + break; + } + } else { + throw new Error( + `Invalid capture method ${response.body.capture_method}` + ); + } + } else { + defaultErrorHandler(response, res_data); + } + }); } - confirmBody.confirm = confirm; - confirmBody.client_secret = globalState.get("clientSecret"); - globalState.set("paymentMethodType", confirmBody.payment_method_type); +); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments/${paymentId}/confirm`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("publishableKey"), - }, - failOnStatusCode: false, - body: confirmBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - if (response.body.capture_method === "automatic" || response.body.capture_method === "manual") { - if (response.body.payment_method_type === "upi_collect") { - expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); - globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); - } else if (response.body.payment_method_type === "upi_intent") { - expect(response.body).to.have.property("next_action").to.have.property("qr_code_fetch_url"); - globalState.set("nextActionUrl", response.body.next_action.qr_code_fetch_url); +Cypress.Commands.add( + "confirmUpiCall", + (confirmBody, req_data, res_data, confirm, globalState) => { + const paymentId = globalState.get("paymentID"); + for (const key in req_data) { + confirmBody[key] = req_data[key]; + } + confirmBody.confirm = confirm; + confirmBody.client_secret = globalState.get("clientSecret"); + globalState.set("paymentMethodType", confirmBody.payment_method_type); + + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payments/${paymentId}/confirm`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("publishableKey"), + }, + failOnStatusCode: false, + body: confirmBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + if ( + response.body.capture_method === "automatic" || + response.body.capture_method === "manual" + ) { + if (response.body.payment_method_type === "upi_collect") { + expect(response.body) + .to.have.property("next_action") + .to.have.property("redirect_to_url"); + globalState.set( + "nextActionUrl", + response.body.next_action.redirect_to_url + ); + } else if (response.body.payment_method_type === "upi_intent") { + expect(response.body) + .to.have.property("next_action") + .to.have.property("qr_code_fetch_url"); + globalState.set( + "nextActionUrl", + response.body.next_action.qr_code_fetch_url + ); + } + } else { + throw new Error( + `Invalid capture method ${response.body.capture_method}` + ); } } else { - throw new Error(`Invalid capture method ${response.body.capture_method}`); + defaultErrorHandler(response, res_data); } - } else { - defaultErrorHandler(response, res_data); - } - }); -}); + }); + } +); Cypress.Commands.add( "createConfirmPaymentTest", - (createConfirmPaymentBody, req_data, res_data, authentication_type, capture_method, globalState) => { + ( + createConfirmPaymentBody, + req_data, + res_data, + authentication_type, + capture_method, + globalState + ) => { createConfirmPaymentBody.authentication_type = authentication_type; createConfirmPaymentBody.capture_method = capture_method; createConfirmPaymentBody.customer_id = globalState.get("customerId"); @@ -1044,42 +1297,74 @@ Cypress.Commands.add( if (response.status === 200) { globalState.set("paymentAmount", createConfirmPaymentBody.amount); globalState.set("paymentID", response.body.payment_id); - expect(response.body.connector, "connector").to.equal(globalState.get("connectorId")); - expect(response.body.payment_id, "payment_id").to.equal(globalState.get("paymentID")); - expect(response.body.payment_method_data, "payment_method_data").to.not.be.empty; - expect(response.body.merchant_connector_id, "connectorId").to.equal(globalState.get("merchantConnectorId")); + expect(response.body.connector, "connector").to.equal( + globalState.get("connectorId") + ); + expect(response.body.payment_id, "payment_id").to.equal( + globalState.get("paymentID") + ); + expect(response.body.payment_method_data, "payment_method_data").to.not + .be.empty; + expect(response.body.merchant_connector_id, "connectorId").to.equal( + globalState.get("merchantConnectorId") + ); expect(response.body.customer, "customer").to.not.be.empty; expect(response.body.billing, "billingAddress").to.not.be.empty; expect(response.body.profile_id, "profile_id").to.not.be.null; - expect(response.body.connector_transaction_id, "connector_transaction_id").to.not.be.null; + expect( + response.body.connector_transaction_id, + "connector_transaction_id" + ).to.not.be.null; expect(response.body).to.have.property("status"); if (response.body.capture_method === "automatic") { if (response.body.authentication_type === "three_ds") { - expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); - globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); + expect(response.body) + .to.have.property("next_action") + .to.have.property("redirect_to_url"); + globalState.set( + "nextActionUrl", + response.body.next_action.redirect_to_url + ); for (const key in res_data.body) { - expect(res_data.body[key], [key]).to.deep.equal(response.body[key]); + expect(res_data.body[key], [key]).to.deep.equal( + response.body[key] + ); } } else if (response.body.authentication_type === "no_three_ds") { for (const key in res_data.body) { - expect(res_data.body[key], [key]).to.deep.equal(response.body[key]); + expect(res_data.body[key], [key]).to.deep.equal( + response.body[key] + ); } } else { - throw new Error(`Invalid authentication type: ${response.body.authentication_type}`); + throw new Error( + `Invalid authentication type: ${response.body.authentication_type}` + ); } } else if (response.body.capture_method === "manual") { if (response.body.authentication_type === "three_ds") { - expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); - globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); + expect(response.body) + .to.have.property("next_action") + .to.have.property("redirect_to_url"); + globalState.set( + "nextActionUrl", + response.body.next_action.redirect_to_url + ); for (const key in res_data.body) { - expect(res_data.body[key], [key]).to.deep.equal(response.body[key]); + expect(res_data.body[key], [key]).to.deep.equal( + response.body[key] + ); } } else if (response.body.authentication_type === "no_three_ds") { for (const key in res_data.body) { - expect(res_data.body[key], [key]).to.deep.equal(response.body[key]); + expect(res_data.body[key], [key]).to.deep.equal( + response.body[key] + ); } } else { - throw new Error(`Invalid authentication type: ${response.body.authentication_type}`); + throw new Error( + `Invalid authentication type: ${response.body.authentication_type}` + ); } } } else { @@ -1090,219 +1375,278 @@ Cypress.Commands.add( ); // This is consequent saved card payment confirm call test(Using payment token) -Cypress.Commands.add("saveCardConfirmCallTest", (saveCardConfirmBody, req_data, res_data, globalState) => { - const paymentIntentID = globalState.get("paymentID"); - if (req_data.setup_future_usage === "on_session") { - saveCardConfirmBody.card_cvc = req_data.payment_method_data.card.card_cvc; - } - saveCardConfirmBody.payment_token = globalState.get("paymentToken"); - saveCardConfirmBody.client_secret = globalState.get("clientSecret"); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments/${paymentIntentID}/confirm`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("publishableKey"), - }, - failOnStatusCode: false, - body: saveCardConfirmBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); +Cypress.Commands.add( + "saveCardConfirmCallTest", + (saveCardConfirmBody, req_data, res_data, globalState) => { + const paymentIntentID = globalState.get("paymentID"); + if (req_data.setup_future_usage === "on_session") { + saveCardConfirmBody.card_cvc = req_data.payment_method_data.card.card_cvc; + } + saveCardConfirmBody.payment_token = globalState.get("paymentToken"); + saveCardConfirmBody.client_secret = globalState.get("clientSecret"); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payments/${paymentIntentID}/confirm`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("publishableKey"), + }, + failOnStatusCode: false, + body: saveCardConfirmBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - globalState.set("paymentID", paymentIntentID); - if (response.body.capture_method === "automatic") { - if (response.body.authentication_type === "three_ds") { - expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); - const nextActionUrl = response.body.next_action.redirect_to_url; - } else if (response.body.authentication_type === "no_three_ds") { - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + globalState.set("paymentID", paymentIntentID); + if (response.body.capture_method === "automatic") { + if (response.body.authentication_type === "three_ds") { + expect(response.body) + .to.have.property("next_action") + .to.have.property("redirect_to_url"); + const nextActionUrl = response.body.next_action.redirect_to_url; + } else if (response.body.authentication_type === "no_three_ds") { + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); + } + expect(response.body.customer_id).to.equal( + globalState.get("customerId") + ); + } else { + // Handle other authentication types as needed + throw new Error( + `Invalid authentication type: ${response.body.authentication_type}` + ); } - expect(response.body.customer_id).to.equal(globalState.get("customerId")); - } else { - // Handle other authentication types as needed - throw new Error(`Invalid authentication type: ${response.body.authentication_type}`); - } - } else if (response.body.capture_method === "manual") { - if (response.body.authentication_type === "three_ds") { - expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); - } else if (response.body.authentication_type === "no_three_ds") { - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); + } else if (response.body.capture_method === "manual") { + if (response.body.authentication_type === "three_ds") { + expect(response.body) + .to.have.property("next_action") + .to.have.property("redirect_to_url"); + } else if (response.body.authentication_type === "no_three_ds") { + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); + } + expect(response.body.customer_id).to.equal( + globalState.get("customerId") + ); + } else { + // Handle other authentication types as needed + throw new Error( + `Invalid authentication type: ${response.body.authentication_type}` + ); } - expect(response.body.customer_id).to.equal(globalState.get("customerId")); } else { - // Handle other authentication types as needed - throw new Error(`Invalid authentication type: ${response.body.authentication_type}`); + // Handle other capture methods as needed + throw new Error( + `Invalid capture method: ${response.body.capture_method}` + ); } } else { - // Handle other capture methods as needed - throw new Error(`Invalid capture method: ${response.body.capture_method}`); + defaultErrorHandler(response, res_data); } - } else { - defaultErrorHandler(response, res_data); - } - }); -}); + }); + } +); -Cypress.Commands.add("captureCallTest", (requestBody, req_data, res_data, amount_to_capture, globalState) => { - const payment_id = globalState.get("paymentID"); - requestBody.amount_to_capture = amount_to_capture; - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments/${payment_id}/capture`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - failOnStatusCode: false, - body: requestBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); +Cypress.Commands.add( + "captureCallTest", + (requestBody, req_data, res_data, amount_to_capture, globalState) => { + const payment_id = globalState.get("paymentID"); + requestBody.amount_to_capture = amount_to_capture; + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payments/${payment_id}/capture`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + failOnStatusCode: false, + body: requestBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.body.capture_method !== undefined) { - expect(response.body.payment_id).to.equal(payment_id); - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.body.capture_method !== undefined) { + expect(response.body.payment_id).to.equal(payment_id); + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); + } + } else { + defaultErrorHandler(response, res_data); } - } else { - defaultErrorHandler(response, res_data); - } - }); -}); + }); + } +); -Cypress.Commands.add("voidCallTest", (requestBody, req_data, res_data, globalState) => { - const payment_id = globalState.get("paymentID"); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments/${payment_id}/cancel`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - failOnStatusCode: false, - body: requestBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); +Cypress.Commands.add( + "voidCallTest", + (requestBody, req_data, res_data, globalState) => { + const payment_id = globalState.get("paymentID"); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payments/${payment_id}/cancel`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + failOnStatusCode: false, + body: requestBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); + } + } else { + defaultErrorHandler(response, res_data); } - } else { - defaultErrorHandler(response, res_data); - } - }); -}); + }); + } +); -Cypress.Commands.add("retrievePaymentCallTest", (globalState, autoretries = false, attempt = 1) => { - const payment_id = globalState.get("paymentID"); - cy.request({ - method: "GET", - url: `${globalState.get("baseUrl")}/payments/${payment_id}?force_sync=true&expand_attempts=true`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - globalState.set("paymentID", response.body.payment_id); +Cypress.Commands.add( + "retrievePaymentCallTest", + (globalState, autoretries = false, attempt = 1) => { + const payment_id = globalState.get("paymentID"); + cy.request({ + method: "GET", + url: `${globalState.get("baseUrl")}/payments/${payment_id}?force_sync=true&expand_attempts=true`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + globalState.set("paymentID", response.body.payment_id); - expect(response.headers["content-type"]).to.include("application/json"); - expect(response.body.payment_id).to.equal(payment_id); - expect(response.body.amount).to.equal(globalState.get("paymentAmount")); - expect(response.body.profile_id, "profile_id").to.not.be.null; - expect(response.body.billing, "billingAddress").to.not.be.empty; - expect(response.body.customer, "customer").to.not.be.empty; - if (["succeeded", "processing", "requires_customer_action"].includes(response.body.status)) { - expect(response.body.connector, "connector").to.equal(globalState.get("connectorId")); - expect(response.body.payment_method_data, "payment_method_data").to.not.be.empty; - expect(response.body.payment_method, "payment_method").to.not.be.null; - expect(response.body.merchant_connector_id, "connectorId").to.equal(globalState.get("merchantConnectorId")); - expect(response.body.connector_transaction_id, "connector_transaction_id").to.not.be.null; - } + expect(response.headers["content-type"]).to.include("application/json"); + expect(response.body.payment_id).to.equal(payment_id); + expect(response.body.amount).to.equal(globalState.get("paymentAmount")); + expect(response.body.profile_id, "profile_id").to.not.be.null; + expect(response.body.billing, "billingAddress").to.not.be.empty; + expect(response.body.customer, "customer").to.not.be.empty; + if ( + ["succeeded", "processing", "requires_customer_action"].includes( + response.body.status + ) + ) { + expect(response.body.connector, "connector").to.equal( + globalState.get("connectorId") + ); + expect(response.body.payment_method_data, "payment_method_data").to.not + .be.empty; + expect(response.body.payment_method, "payment_method").to.not.be.null; + expect(response.body.merchant_connector_id, "connectorId").to.equal( + globalState.get("merchantConnectorId") + ); + expect( + response.body.connector_transaction_id, + "connector_transaction_id" + ).to.not.be.null; + } + + if (autoretries) { + expect(response.body).to.have.property("attempts"); + expect(response.body.attempts).to.be.an("array").and.not.empty; + expect(response.body.attempts.length).to.equal(attempt); + expect(response.body.attempts[0].attempt_id).to.include( + `${payment_id}_` + ); + for (const key in response.body.attempts) { + if ( + response.body.attempts[key].attempt_id === + `${payment_id}_${attempt}` && + response.body.status === "succeeded" + ) { + expect(response.body.attempts[key].status).to.equal("charged"); + } else if ( + response.body.attempts[key].attempt_id === + `${payment_id}_${attempt}` && + response.body.status === "requires_customer_action" + ) { + expect(response.body.attempts[key].status).to.equal( + "authentication_pending" + ); + } else { + expect(response.body.attempts[key].status).to.equal("failure"); + } + } + } + }); + } +); + +Cypress.Commands.add( + "refundCallTest", + (requestBody, req_data, res_data, refund_amount, globalState) => { + const payment_id = globalState.get("paymentID"); + requestBody.payment_id = payment_id; + requestBody.amount = refund_amount; + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/refunds`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + failOnStatusCode: false, + body: requestBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); - if (autoretries) { - expect(response.body).to.have.property("attempts"); - expect(response.body.attempts).to.be.an("array").and.not.empty; - expect(response.body.attempts.length).to.equal(attempt); - expect(response.body.attempts[0].attempt_id).to.include(`${payment_id}_`); - for (const key in response.body.attempts) { - if ( - response.body.attempts[key].attempt_id === `${payment_id}_${attempt}` && - response.body.status === "succeeded" - ) { - expect(response.body.attempts[key].status).to.equal("charged"); - } else if ( - response.body.attempts[key].attempt_id === `${payment_id}_${attempt}` && - response.body.status === "requires_customer_action" - ) { - expect(response.body.attempts[key].status).to.equal("authentication_pending"); - } else { - expect(response.body.attempts[key].status).to.equal("failure"); + if (response.status === 200) { + globalState.set("refundId", response.body.refund_id); + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); } + expect(response.body.payment_id).to.equal(payment_id); + } else { + defaultErrorHandler(response, res_data); } - } - }); -}); + }); + } +); -Cypress.Commands.add("refundCallTest", (requestBody, req_data, res_data, refund_amount, globalState) => { - const payment_id = globalState.get("paymentID"); - requestBody.payment_id = payment_id; - requestBody.amount = refund_amount; - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/refunds`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - failOnStatusCode: false, - body: requestBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); +Cypress.Commands.add( + "syncRefundCallTest", + (req_data, res_data, globalState) => { + const refundId = globalState.get("refundId"); + cy.request({ + method: "GET", + url: `${globalState.get("baseUrl")}/refunds/${refundId}`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); - if (response.status === 200) { - globalState.set("refundId", response.body.refund_id); + expect(response.headers["content-type"]).to.include("application/json"); for (const key in res_data.body) { expect(res_data.body[key]).to.equal(response.body[key]); } - expect(response.body.payment_id).to.equal(payment_id); - } else { - defaultErrorHandler(response, res_data); - } - }); -}); - -Cypress.Commands.add("syncRefundCallTest", (req_data, res_data, globalState) => { - const refundId = globalState.get("refundId"); - cy.request({ - method: "GET", - url: `${globalState.get("baseUrl")}/refunds/${refundId}`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - - expect(response.headers["content-type"]).to.include("application/json"); - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); - } - }); -}); + }); + } +); Cypress.Commands.add( "citForMandatesCallTest", - (requestBody, req_data, res_data, amount, confirm, capture_method, payment_type, globalState) => { + ( + requestBody, + req_data, + res_data, + amount, + confirm, + capture_method, + payment_type, + globalState + ) => { for (const key in req_data) { requestBody[key] = req_data[key]; } @@ -1338,9 +1682,14 @@ Cypress.Commands.add( if (response.body.capture_method === "automatic") { expect(response.body).to.have.property("mandate_id"); if (response.body.authentication_type === "three_ds") { - expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); + expect(response.body) + .to.have.property("next_action") + .to.have.property("redirect_to_url"); const nextActionUrl = response.body.next_action.redirect_to_url; - globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); + globalState.set( + "nextActionUrl", + response.body.next_action.redirect_to_url + ); cy.log(nextActionUrl); for (const key in res_data.body) { expect(res_data.body[key]).to.equal(response.body[key]); @@ -1350,13 +1699,20 @@ Cypress.Commands.add( expect(res_data.body[key]).to.equal(response.body[key]); } } else { - throw new Error(`Invalid authentication type ${response.body.authentication_type}`); + throw new Error( + `Invalid authentication type ${response.body.authentication_type}` + ); } } else if (response.body.capture_method === "manual") { if (response.body.authentication_type === "three_ds") { - expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); + expect(response.body) + .to.have.property("next_action") + .to.have.property("redirect_to_url"); const nextActionUrl = response.body.next_action.redirect_to_url; - globalState.set("nextActionUrl", response.body.next_action.redirect_to_url); + globalState.set( + "nextActionUrl", + response.body.next_action.redirect_to_url + ); cy.log(nextActionUrl); for (const key in res_data.body) { expect(res_data.body[key]).to.equal(response.body[key]); @@ -1366,10 +1722,14 @@ Cypress.Commands.add( expect(res_data.body[key]).to.equal(response.body[key]); } } else { - throw new Error(`Invalid authentication type ${response.body.authentication_type}`); + throw new Error( + `Invalid authentication type ${response.body.authentication_type}` + ); } } else { - throw new Error(`Invalid capture method ${response.body.capture_method}`); + throw new Error( + `Invalid capture method ${response.body.capture_method}` + ); } } else { defaultErrorHandler(response, res_data); @@ -1378,114 +1738,144 @@ Cypress.Commands.add( } ); -Cypress.Commands.add("mitForMandatesCallTest", (requestBody, amount, confirm, capture_method, globalState) => { - requestBody.amount = amount; - requestBody.confirm = confirm; - requestBody.capture_method = capture_method; - requestBody.mandate_id = globalState.get("mandateId"); - requestBody.customer_id = globalState.get("customerId"); - globalState.set("paymentAmount", requestBody.amount); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - failOnStatusCode: false, - body: requestBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - globalState.set("paymentID", response.body.payment_id); - if (response.body.capture_method === "automatic") { - if (response.body.authentication_type === "three_ds") { - expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); - const nextActionUrl = response.body.next_action.redirect_to_url; - cy.log(nextActionUrl); - } else if (response.body.authentication_type === "no_three_ds") { - expect(response.body.status).to.equal("succeeded"); +Cypress.Commands.add( + "mitForMandatesCallTest", + (requestBody, amount, confirm, capture_method, globalState) => { + requestBody.amount = amount; + requestBody.confirm = confirm; + requestBody.capture_method = capture_method; + requestBody.mandate_id = globalState.get("mandateId"); + requestBody.customer_id = globalState.get("customerId"); + globalState.set("paymentAmount", requestBody.amount); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payments`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + failOnStatusCode: false, + body: requestBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + globalState.set("paymentID", response.body.payment_id); + if (response.body.capture_method === "automatic") { + if (response.body.authentication_type === "three_ds") { + expect(response.body) + .to.have.property("next_action") + .to.have.property("redirect_to_url"); + const nextActionUrl = response.body.next_action.redirect_to_url; + cy.log(nextActionUrl); + } else if (response.body.authentication_type === "no_three_ds") { + expect(response.body.status).to.equal("succeeded"); + } else { + throw new Error( + `Invalid authentication type ${response.body.authentication_type}` + ); + } + } else if (response.body.capture_method === "manual") { + if (response.body.authentication_type === "three_ds") { + expect(response.body) + .to.have.property("next_action") + .to.have.property("redirect_to_url"); + const nextActionUrl = response.body.next_action.redirect_to_url; + cy.log(nextActionUrl); + } else if (response.body.authentication_type === "no_three_ds") { + expect(response.body.status).to.equal("requires_capture"); + } else { + throw new Error( + `Invalid authentication type ${response.body.authentication_type}` + ); + } } else { - throw new Error(`Invalid authentication type ${response.body.authentication_type}`); + throw new Error( + `Invalid capture method ${response.body.capture_method}` + ); } - } else if (response.body.capture_method === "manual") { - if (response.body.authentication_type === "three_ds") { - expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); - const nextActionUrl = response.body.next_action.redirect_to_url; - cy.log(nextActionUrl); - } else if (response.body.authentication_type === "no_three_ds") { - expect(response.body.status).to.equal("requires_capture"); - } else { - throw new Error(`Invalid authentication type ${response.body.authentication_type}`); + } else if (response.status === 400) { + if (response.body.error.message === "Mandate Validation Failed") { + expect(response.body.error.code).to.equal("HE_03"); + expect(response.body.error.message).to.equal( + "Mandate Validation Failed" + ); + expect(response.body.error.reason).to.equal( + "request amount is greater than mandate amount" + ); } } else { - throw new Error(`Invalid capture method ${response.body.capture_method}`); - } - } else if (response.status === 400) { - if (response.body.error.message === "Mandate Validation Failed") { - expect(response.body.error.code).to.equal("HE_03"); - expect(response.body.error.message).to.equal("Mandate Validation Failed"); - expect(response.body.error.reason).to.equal("request amount is greater than mandate amount"); + throw new Error( + `Error Response: ${response.status}\n${response.body.error.message}\n${response.body.error.code}` + ); } - } else { - throw new Error( - `Error Response: ${response.status}\n${response.body.error.message}\n${response.body.error.code}` - ); - } - }); -}); + }); + } +); -Cypress.Commands.add("mitUsingPMId", (requestBody, amount, confirm, capture_method, globalState) => { - requestBody.amount = amount; - requestBody.confirm = confirm; - requestBody.capture_method = capture_method; - requestBody.recurring_details.data = globalState.get("paymentMethodId"); - requestBody.customer_id = globalState.get("customerId"); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payments`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - failOnStatusCode: false, - body: requestBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - globalState.set("paymentID", response.body.payment_id); - if (response.body.capture_method === "automatic") { - if (response.body.authentication_type === "three_ds") { - expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); - const nextActionUrl = response.body.next_action.redirect_to_url; - cy.log(nextActionUrl); - } else if (response.body.authentication_type === "no_three_ds") { - expect(response.body.status).to.equal("succeeded"); - } else { - throw new Error(`Invalid authentication type ${response.body.authentication_type}`); - } - } else if (response.body.capture_method === "manual") { - if (response.body.authentication_type === "three_ds") { - expect(response.body).to.have.property("next_action").to.have.property("redirect_to_url"); - const nextActionUrl = response.body.next_action.redirect_to_url; - cy.log(nextActionUrl); - } else if (response.body.authentication_type === "no_three_ds") { - expect(response.body.status).to.equal("requires_capture"); +Cypress.Commands.add( + "mitUsingPMId", + (requestBody, amount, confirm, capture_method, globalState) => { + requestBody.amount = amount; + requestBody.confirm = confirm; + requestBody.capture_method = capture_method; + requestBody.recurring_details.data = globalState.get("paymentMethodId"); + requestBody.customer_id = globalState.get("customerId"); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payments`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + failOnStatusCode: false, + body: requestBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + globalState.set("paymentID", response.body.payment_id); + if (response.body.capture_method === "automatic") { + if (response.body.authentication_type === "three_ds") { + expect(response.body) + .to.have.property("next_action") + .to.have.property("redirect_to_url"); + const nextActionUrl = response.body.next_action.redirect_to_url; + cy.log(nextActionUrl); + } else if (response.body.authentication_type === "no_three_ds") { + expect(response.body.status).to.equal("succeeded"); + } else { + throw new Error( + `Invalid authentication type ${response.body.authentication_type}` + ); + } + } else if (response.body.capture_method === "manual") { + if (response.body.authentication_type === "three_ds") { + expect(response.body) + .to.have.property("next_action") + .to.have.property("redirect_to_url"); + const nextActionUrl = response.body.next_action.redirect_to_url; + cy.log(nextActionUrl); + } else if (response.body.authentication_type === "no_three_ds") { + expect(response.body.status).to.equal("requires_capture"); + } else { + throw new Error( + `Invalid authentication type ${response.body.authentication_type}` + ); + } } else { - throw new Error(`Invalid authentication type ${response.body.authentication_type}`); + throw new Error( + `Invalid capture method ${response.body.capture_method}` + ); } } else { - throw new Error(`Invalid capture method ${response.body.capture_method}`); + throw new Error( + `Error Response: ${response.status}\n${response.body.error.message}\n${response.body.error.code}` + ); } - } else { - throw new Error( - `Error Response: ${response.status}\n${response.body.error.message}\n${response.body.error.code}` - ); - } - }); -}); + }); + } +); Cypress.Commands.add("listMandateCallTest", (globalState) => { const customerId = globalState.get("customerId"); @@ -1532,41 +1922,74 @@ Cypress.Commands.add("revokeMandateCallTest", (globalState) => { }); }); -Cypress.Commands.add("handleRedirection", (globalState, expected_redirection) => { - let connectorId = globalState.get("connectorId"); - let expected_url = new URL(expected_redirection); - let redirection_url = new URL(globalState.get("nextActionUrl")); - handleRedirection("three_ds", { redirection_url, expected_url }, connectorId, null); -}); +Cypress.Commands.add( + "handleRedirection", + (globalState, expected_redirection) => { + let connectorId = globalState.get("connectorId"); + let expected_url = new URL(expected_redirection); + let redirection_url = new URL(globalState.get("nextActionUrl")); + handleRedirection( + "three_ds", + { redirection_url, expected_url }, + connectorId, + null + ); + } +); -Cypress.Commands.add("handleBankRedirectRedirection", (globalState, payment_method_type, expected_redirection) => { - let connectorId = globalState.get("connectorId"); - let expected_url = new URL(expected_redirection); - let redirection_url = new URL(globalState.get("nextActionUrl")); - // explicitly restricting `sofort` payment method by adyen from running as it stops other tests from running - // trying to handle that specific case results in stripe 3ds tests to fail - if (!(connectorId == "adyen" && payment_method_type == "sofort")) { - handleRedirection("bank_redirect", { redirection_url, expected_url }, connectorId, payment_method_type); +Cypress.Commands.add( + "handleBankRedirectRedirection", + (globalState, payment_method_type, expected_redirection) => { + let connectorId = globalState.get("connectorId"); + let expected_url = new URL(expected_redirection); + let redirection_url = new URL(globalState.get("nextActionUrl")); + // explicitly restricting `sofort` payment method by adyen from running as it stops other tests from running + // trying to handle that specific case results in stripe 3ds tests to fail + if (!(connectorId == "adyen" && payment_method_type == "sofort")) { + handleRedirection( + "bank_redirect", + { redirection_url, expected_url }, + connectorId, + payment_method_type + ); + } } -}); +); -Cypress.Commands.add("handleBankTransferRedirection", (globalState, payment_method_type, expected_redirection) => { - let connectorId = globalState.get("connectorId"); - let expected_url = new URL(expected_redirection); - let redirection_url = new URL(globalState.get("nextActionUrl")); - let next_action_type = globalState.get("nextActionType"); - cy.log(payment_method_type); - handleRedirection("bank_transfer", { redirection_url, expected_url }, connectorId, payment_method_type, { - next_action_type, - }); -}); +Cypress.Commands.add( + "handleBankTransferRedirection", + (globalState, payment_method_type, expected_redirection) => { + let connectorId = globalState.get("connectorId"); + let expected_url = new URL(expected_redirection); + let redirection_url = new URL(globalState.get("nextActionUrl")); + let next_action_type = globalState.get("nextActionType"); + cy.log(payment_method_type); + handleRedirection( + "bank_transfer", + { redirection_url, expected_url }, + connectorId, + payment_method_type, + { + next_action_type, + } + ); + } +); -Cypress.Commands.add("handleUpiRedirection", (globalState, payment_method_type, expected_redirection) => { - let connectorId = globalState.get("connectorId"); - let expected_url = new URL(expected_redirection); - let redirection_url = new URL(globalState.get("nextActionUrl")); - handleRedirection("upi", { redirection_url, expected_url }, connectorId, payment_method_type); -}); +Cypress.Commands.add( + "handleUpiRedirection", + (globalState, payment_method_type, expected_redirection) => { + let connectorId = globalState.get("connectorId"); + let expected_url = new URL(expected_redirection); + let redirection_url = new URL(globalState.get("nextActionUrl")); + handleRedirection( + "upi", + { redirection_url, expected_url }, + connectorId, + payment_method_type + ); + } +); Cypress.Commands.add("listCustomerPMCallTest", (globalState) => { const customerId = globalState.get("customerId"); @@ -1581,11 +2004,14 @@ Cypress.Commands.add("listCustomerPMCallTest", (globalState) => { logRequestId(response.headers["x-request-id"]); expect(response.headers["content-type"]).to.include("application/json"); if (response.body.customer_payment_methods[0]?.payment_token) { - const paymentToken = response.body.customer_payment_methods[0].payment_token; + const paymentToken = + response.body.customer_payment_methods[0].payment_token; globalState.set("paymentToken", paymentToken); // Set paymentToken in globalState } else { // We only get an empty array if something's wrong. One exception is a 4xx when no customer exist but it is handled in the test - expect(response.body).to.have.property("customer_payment_methods").to.be.an("array").and.empty; + expect(response.body) + .to.have.property("customer_payment_methods") + .to.be.an("array").and.empty; } }); }); @@ -1608,7 +2034,14 @@ Cypress.Commands.add("listRefundCallTest", (requestBody, globalState) => { Cypress.Commands.add( "createConfirmPayoutTest", - (createConfirmPayoutBody, req_data, res_data, confirm, auto_fulfill, globalState) => { + ( + createConfirmPayoutBody, + req_data, + res_data, + confirm, + auto_fulfill, + globalState + ) => { for (const key in req_data) { createConfirmPayoutBody[key] = req_data[key]; } @@ -1644,7 +2077,14 @@ Cypress.Commands.add( Cypress.Commands.add( "createConfirmWithTokenPayoutTest", - (createConfirmPayoutBody, req_data, res_data, confirm, auto_fulfill, globalState) => { + ( + createConfirmPayoutBody, + req_data, + res_data, + confirm, + auto_fulfill, + globalState + ) => { for (const key in req_data) { createConfirmPayoutBody[key] = req_data[key]; } @@ -1654,21 +2094,80 @@ Cypress.Commands.add( createConfirmPayoutBody.confirm = confirm; cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payouts/create`, + method: "POST", + url: `${globalState.get("baseUrl")}/payouts/create`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + failOnStatusCode: false, + body: createConfirmPayoutBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + + if (response.status === 200) { + globalState.set("payoutAmount", createConfirmPayoutBody.amount); + globalState.set("payoutID", response.body.payout_id); + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); + } + } else { + defaultErrorHandler(response, res_data); + } + }); + } +); + +Cypress.Commands.add( + "fulfillPayoutCallTest", + (payoutFulfillBody, req_data, res_data, globalState) => { + payoutFulfillBody.payout_id = globalState.get("payoutID"); + + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/payouts/${globalState.get("payoutID")}/fulfill`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("apiKey"), + }, + failOnStatusCode: false, + body: payoutFulfillBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + + if (response.status === 200) { + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); + } + } else { + defaultErrorHandler(response, res_data); + } + }); + } +); + +Cypress.Commands.add( + "updatePayoutCallTest", + (payoutConfirmBody, req_data, res_data, auto_fulfill, globalState) => { + payoutConfirmBody.confirm = true; + payoutConfirmBody.auto_fulfill = auto_fulfill; + + cy.request({ + method: "PUT", + url: `${globalState.get("baseUrl")}/payouts/${globalState.get("payoutID")}`, headers: { "Content-Type": "application/json", "api-key": globalState.get("apiKey"), }, failOnStatusCode: false, - body: createConfirmPayoutBody, + body: payoutConfirmBody, }).then((response) => { logRequestId(response.headers["x-request-id"]); expect(response.headers["content-type"]).to.include("application/json"); if (response.status === 200) { - globalState.set("payoutAmount", createConfirmPayoutBody.amount); - globalState.set("payoutID", response.body.payout_id); for (const key in res_data.body) { expect(res_data.body[key]).to.equal(response.body[key]); } @@ -1679,59 +2178,6 @@ Cypress.Commands.add( } ); -Cypress.Commands.add("fulfillPayoutCallTest", (payoutFulfillBody, req_data, res_data, globalState) => { - payoutFulfillBody.payout_id = globalState.get("payoutID"); - - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/payouts/${globalState.get("payoutID")}/fulfill`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - failOnStatusCode: false, - body: payoutFulfillBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - - if (response.status === 200) { - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); - } - } else { - defaultErrorHandler(response, res_data); - } - }); -}); - -Cypress.Commands.add("updatePayoutCallTest", (payoutConfirmBody, req_data, res_data, auto_fulfill, globalState) => { - payoutConfirmBody.confirm = true; - payoutConfirmBody.auto_fulfill = auto_fulfill; - - cy.request({ - method: "PUT", - url: `${globalState.get("baseUrl")}/payouts/${globalState.get("payoutID")}`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("apiKey"), - }, - failOnStatusCode: false, - body: payoutConfirmBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); - - if (response.status === 200) { - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); - } - } else { - defaultErrorHandler(response, res_data); - } - }); -}); - Cypress.Commands.add("retrievePayoutCallTest", (globalState) => { const payout_id = globalState.get("payoutID"); cy.request({ @@ -1814,7 +2260,9 @@ Cypress.Commands.add("terminate2Fa", (globalState) => { cy.task("setGlobalState", globalState.data); } } else { - throw new Error(`2FA terminate call failed with status ${response.status} and message ${response.body.message}`); + throw new Error( + `2FA terminate call failed with status ${response.status} and message ${response.body.message}` + ); } }); }); @@ -1874,162 +2322,184 @@ Cypress.Commands.add("ListMcaByMid", (globalState) => { }); }); -Cypress.Commands.add("addRoutingConfig", (routingBody, req_data, res_data, type, data, globalState) => { - for (const key in req_data) { - routingBody[key] = req_data[key]; - } - // set profile id from env - routingBody.profile_id = globalState.get("profileId"); - routingBody.algorithm.type = type; - routingBody.algorithm.data = data; +Cypress.Commands.add( + "addRoutingConfig", + (routingBody, req_data, res_data, type, data, globalState) => { + for (const key in req_data) { + routingBody[key] = req_data[key]; + } + // set profile id from env + routingBody.profile_id = globalState.get("profileId"); + routingBody.algorithm.type = type; + routingBody.algorithm.data = data; - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/routing`, - headers: { - Authorization: `Bearer ${globalState.get("userInfoToken")}`, - "Content-Type": "application/json", - Cookie: `${globalState.get("cookie")}`, - }, - failOnStatusCode: false, - body: routingBody, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/routing`, + headers: { + Authorization: `Bearer ${globalState.get("userInfoToken")}`, + "Content-Type": "application/json", + Cookie: `${globalState.get("cookie")}`, + }, + failOnStatusCode: false, + body: routingBody, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - expect(response.body).to.have.property("id"); - globalState.set("routingConfigId", response.body.id); - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); + if (response.status === 200) { + expect(response.body).to.have.property("id"); + globalState.set("routingConfigId", response.body.id); + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); + } + } else { + defaultErrorHandler(response, res_data); } - } else { - defaultErrorHandler(response, res_data); - } - }); -}); + }); + } +); -Cypress.Commands.add("activateRoutingConfig", (req_data, res_data, globalState) => { - let routing_config_id = globalState.get("routingConfigId"); - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/routing/${routing_config_id}/activate`, - headers: { - Authorization: `Bearer ${globalState.get("userInfoToken")}`, - "Content-Type": "application/json", - Cookie: `${globalState.get("cookie")}`, - }, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); +Cypress.Commands.add( + "activateRoutingConfig", + (req_data, res_data, globalState) => { + let routing_config_id = globalState.get("routingConfigId"); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/routing/${routing_config_id}/activate`, + headers: { + Authorization: `Bearer ${globalState.get("userInfoToken")}`, + "Content-Type": "application/json", + Cookie: `${globalState.get("cookie")}`, + }, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - expect(response.body.id).to.equal(routing_config_id); - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); + if (response.status === 200) { + expect(response.body.id).to.equal(routing_config_id); + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); + } + } else { + defaultErrorHandler(response, res_data); } - } else { - defaultErrorHandler(response, res_data); - } - }); -}); + }); + } +); -Cypress.Commands.add("retrieveRoutingConfig", (req_data, res_data, globalState) => { - let routing_config_id = globalState.get("routingConfigId"); - cy.request({ - method: "GET", - url: `${globalState.get("baseUrl")}/routing/${routing_config_id}`, - headers: { - Authorization: `Bearer ${globalState.get("userInfoToken")}`, - "Content-Type": "application/json", - Cookie: `${globalState.get("cookie")}`, - }, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - expect(response.headers["content-type"]).to.include("application/json"); +Cypress.Commands.add( + "retrieveRoutingConfig", + (req_data, res_data, globalState) => { + let routing_config_id = globalState.get("routingConfigId"); + cy.request({ + method: "GET", + url: `${globalState.get("baseUrl")}/routing/${routing_config_id}`, + headers: { + Authorization: `Bearer ${globalState.get("userInfoToken")}`, + "Content-Type": "application/json", + Cookie: `${globalState.get("cookie")}`, + }, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); - if (response.status === 200) { - expect(response.body.id).to.equal(routing_config_id); - for (const key in res_data.body) { - expect(res_data.body[key]).to.equal(response.body[key]); + if (response.status === 200) { + expect(response.body.id).to.equal(routing_config_id); + for (const key in res_data.body) { + expect(res_data.body[key]).to.equal(response.body[key]); + } + } else { + defaultErrorHandler(response, res_data); } - } else { - defaultErrorHandler(response, res_data); - } - }); -}); + }); + } +); -Cypress.Commands.add("autoRetryConfig", (autoRetryGsmBody, globalState, value) => { - const key = `should_call_gsm_${globalState.get("merchantId")}`; - autoRetryGsmBody.key = key; - autoRetryGsmBody.value = value; +Cypress.Commands.add( + "autoRetryConfig", + (autoRetryGsmBody, globalState, value) => { + const key = `should_call_gsm_${globalState.get("merchantId")}`; + autoRetryGsmBody.key = key; + autoRetryGsmBody.value = value; - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/configs/${key}`, - headers: { - Accept: "application/json", - "Content-Type": "application/json", - "api-key": globalState.get("adminApiKey"), - }, - body: autoRetryGsmBody, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/configs/${key}`, + headers: { + Accept: "application/json", + "Content-Type": "application/json", + "api-key": globalState.get("adminApiKey"), + }, + body: autoRetryGsmBody, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); - if (response.status === 200) { - expect(response.body).to.have.property("key").to.equal(key); - expect(response.body).to.have.property("value").to.equal(value); - } - }); -}); + if (response.status === 200) { + expect(response.body).to.have.property("key").to.equal(key); + expect(response.body).to.have.property("value").to.equal(value); + } + }); + } +); -Cypress.Commands.add("setMaxAutoRetries", (maxAutoRetryBody, globalState, value) => { - const key = `max_auto_retries_enabled_${globalState.get("merchantId")}`; - maxAutoRetryBody.key = key; - maxAutoRetryBody.value = value; +Cypress.Commands.add( + "setMaxAutoRetries", + (maxAutoRetryBody, globalState, value) => { + const key = `max_auto_retries_enabled_${globalState.get("merchantId")}`; + maxAutoRetryBody.key = key; + maxAutoRetryBody.value = value; - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/configs/${key}`, - headers: { - Accept: "application/json", - "Content-Type": "application/json", - "api-key": globalState.get("adminApiKey"), - }, - body: maxAutoRetryBody, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - if (response.status === 200) { - expect(response.body).to.have.property("key").to.equal(key); - expect(response.body).to.have.property("value").to.equal(value); - } - }); -}); + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/configs/${key}`, + headers: { + Accept: "application/json", + "Content-Type": "application/json", + "api-key": globalState.get("adminApiKey"), + }, + body: maxAutoRetryBody, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + if (response.status === 200) { + expect(response.body).to.have.property("key").to.equal(key); + expect(response.body).to.have.property("value").to.equal(value); + } + }); + } +); -Cypress.Commands.add("updateGsmConfig", (gsmBody, globalState, step_up_possible) => { - gsmBody.step_up_possible = step_up_possible; - cy.request({ - method: "POST", - url: `${globalState.get("baseUrl")}/gsm/update`, - headers: { - "Content-Type": "application/json", - "api-key": globalState.get("adminApiKey"), - }, - body: gsmBody, - failOnStatusCode: false, - }).then((response) => { - logRequestId(response.headers["x-request-id"]); - if (response.status === 200) { - expect(response.body).to.have.property("message").to.equal("card_declined"); - expect(response.body).to.have.property("connector").to.equal("stripe"); - expect(response.body).to.have.property("step_up_possible").to.equal(step_up_possible); - } - }); -}); +Cypress.Commands.add( + "updateGsmConfig", + (gsmBody, globalState, step_up_possible) => { + gsmBody.step_up_possible = step_up_possible; + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/gsm/update`, + headers: { + "Content-Type": "application/json", + "api-key": globalState.get("adminApiKey"), + }, + body: gsmBody, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + if (response.status === 200) { + expect(response.body) + .to.have.property("message") + .to.equal("card_declined"); + expect(response.body).to.have.property("connector").to.equal("stripe"); + expect(response.body) + .to.have.property("step_up_possible") + .to.equal(step_up_possible); + } + }); + } +); Cypress.Commands.add("stepUp", (stepUpBody, globalState, value) => { const key = `step_up_enabled_${globalState.get("merchantId")}`; From 955acb89c4053eae481ec97e460cd3fef359ceed Mon Sep 17 00:00:00 2001 From: gnanasundarig Date: Thu, 3 Oct 2024 17:16:02 +0530 Subject: [PATCH 5/6] Added const for payment method data details --- .../cypress/e2e/PaymentUtils/Nexixpay.js | 58 ++++----- .../cypress/e2e/PaymentUtils/Stripe.js | 120 +++++++----------- 2 files changed, 73 insertions(+), 105 deletions(-) diff --git a/cypress-tests/cypress/e2e/PaymentUtils/Nexixpay.js b/cypress-tests/cypress/e2e/PaymentUtils/Nexixpay.js index ab9edc62c9f..954a4475b7b 100644 --- a/cypress-tests/cypress/e2e/PaymentUtils/Nexixpay.js +++ b/cypress-tests/cypress/e2e/PaymentUtils/Nexixpay.js @@ -9,11 +9,11 @@ const successfulNo3DSCardDetails = { }; const successfulThreeDSTestCardDetails = { - card_number: "4349940199004549", - card_exp_month: "12", - card_exp_year: "30", - card_holder_name: "joseph Doe", - card_cvc: "396", + card_number: "4349940199004549", + card_exp_month: "12", + card_exp_year: "30", + card_holder_name: "joseph Doe", + card_cvc: "396", }; export const connectorDetails = { @@ -37,21 +37,21 @@ export const connectorDetails = { payment_method: "card", billing: { address: { - line1: "1467", - line2: "CA", - line3: "CA", - city: "Florence", - state: "Tuscany", - zip: "12345", - country: "IT", - first_name: "Max", - last_name: "Mustermann" + line1: "1467", + line2: "CA", + line3: "CA", + city: "Florence", + state: "Tuscany", + zip: "12345", + country: "IT", + first_name: "Max", + last_name: "Mustermann", }, email: "mauro.morandi@nexi.it", phone: { - number: "9123456789", - country_code: "+91" - } + number: "9123456789", + country_code: "+91", + }, }, payment_method_data: { card: successfulThreeDSTestCardDetails, @@ -71,21 +71,21 @@ export const connectorDetails = { payment_method: "card", billing: { address: { - line1: "1467", - line2: "CA", - line3: "CA", - city: "Florence", - state: "Tuscany", - zip: "12345", - country: "IT", - first_name: "Max", - last_name: "Mustermann" + line1: "1467", + line2: "CA", + line3: "CA", + city: "Florence", + state: "Tuscany", + zip: "12345", + country: "IT", + first_name: "Max", + last_name: "Mustermann", }, email: "mauro.morandi@nexi.it", phone: { - number: "9123456789", - country_code: "+91" - } + number: "9123456789", + country_code: "+91", + }, }, payment_method_data: { card: successfulThreeDSTestCardDetails, diff --git a/cypress-tests/cypress/e2e/PaymentUtils/Stripe.js b/cypress-tests/cypress/e2e/PaymentUtils/Stripe.js index 3099e65b2fa..3b44f0e4e1e 100644 --- a/cypress-tests/cypress/e2e/PaymentUtils/Stripe.js +++ b/cypress-tests/cypress/e2e/PaymentUtils/Stripe.js @@ -50,6 +50,46 @@ const multiUseMandateData = { }, }; +const payment_method_data_3ds = { + card: { + last4: "3155", + card_type: "CREDIT", + card_network: "Visa", + card_issuer: "INTL HDQTRS-CENTER OWNED", + card_issuing_country: "UNITEDSTATES", + card_isin: "400000", + card_extended_bin: null, + card_exp_month: "10", + card_exp_year: "25", + card_holder_name: null, + payment_checks: null, + authentication_data: null, + }, + billing: null, +}; + +const payment_method_data_no3ds = { + card: { + last4: "4242", + card_type: "CREDIT", + card_network: "Visa", + card_issuer: "STRIPE PAYMENTS UK LIMITED", + card_issuing_country: "UNITEDKINGDOM", + card_isin: "424242", + card_extended_bin: null, + card_exp_month: "10", + card_exp_year: "25", + card_holder_name: null, + payment_checks: { + cvc_check: "pass", + address_line1_check: "pass", + address_postal_code_check: "pass", + }, + authentication_data: null, + }, + billing: null, +}; + export const connectorDetails = { card_pm: { PaymentIntent: { @@ -95,23 +135,7 @@ export const connectorDetails = { body: { status: "requires_customer_action", setup_future_usage: "on_session", - payment_method_data: { - card: { - last4: "3155", - card_type: "CREDIT", - card_network: "Visa", - card_issuer: "INTL HDQTRS-CENTER OWNED", - card_issuing_country: "UNITEDSTATES", - card_isin: "400000", - card_extended_bin: null, - card_exp_month: "10", - card_exp_year: "25", - card_holder_name: null, - payment_checks: null, - authentication_data: null, - }, - billing: null, - }, + payment_method_data: payment_method_data_3ds, }, }, }, @@ -131,23 +155,7 @@ export const connectorDetails = { body: { status: "requires_customer_action", setup_future_usage: "on_session", - payment_method_data: { - card: { - last4: "3155", - card_type: "CREDIT", - card_network: "Visa", - card_issuer: "INTL HDQTRS-CENTER OWNED", - card_issuing_country: "UNITEDSTATES", - card_isin: "400000", - card_extended_bin: null, - card_exp_month: "10", - card_exp_year: "25", - card_holder_name: null, - payment_checks: null, - authentication_data: null, - }, - billing: null, - }, + payment_method_data: payment_method_data_3ds, }, }, }, @@ -167,27 +175,7 @@ export const connectorDetails = { status: "requires_capture", payment_method: "card", attempt_count: 1, - payment_method_data: { - card: { - last4: "4242", - card_type: "CREDIT", - card_network: "Visa", - card_issuer: "STRIPE PAYMENTS UK LIMITED", - card_issuing_country: "UNITEDKINGDOM", - card_isin: "424242", - card_extended_bin: null, - card_exp_month: "10", - card_exp_year: "25", - card_holder_name: null, - payment_checks: { - cvc_check: "pass", - address_line1_check: "pass", - address_postal_code_check: "pass", - }, - authentication_data: null, - }, - billing: null, - }, + payment_method_data: payment_method_data_no3ds, }, }, }, @@ -207,27 +195,7 @@ export const connectorDetails = { status: "succeeded", payment_method: "card", attempt_count: 1, - payment_method_data: { - card: { - last4: "4242", - card_type: "CREDIT", - card_network: "Visa", - card_issuer: "STRIPE PAYMENTS UK LIMITED", - card_issuing_country: "UNITEDKINGDOM", - card_isin: "424242", - card_extended_bin: null, - card_exp_month: "10", - card_exp_year: "25", - card_holder_name: null, - payment_checks: { - cvc_check: "pass", - address_line1_check: "pass", - address_postal_code_check: "pass", - }, - authentication_data: null, - }, - billing: null, - }, + payment_method_data: payment_method_data_no3ds, }, }, }, From 162fc1c2bdab7a0e5dd488891b860aa2fc857b5b Mon Sep 17 00:00:00 2001 From: gnanasundarig Date: Mon, 7 Oct 2024 12:59:48 +0530 Subject: [PATCH 6/6] Renamed custom names --- cypress-tests/cypress/support/commands.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js index 940b395fedb..17d3d2e9727 100644 --- a/cypress-tests/cypress/support/commands.js +++ b/cypress-tests/cypress/support/commands.js @@ -973,11 +973,11 @@ Cypress.Commands.add( ); expect(response.body.payment_method_data, "payment_method_data").to.not .be.empty; - expect(response.body.merchant_connector_id, "connectorId").to.equal( + expect(response.body.merchant_connector_id, "connector_id").to.equal( globalState.get("merchantConnectorId") ); expect(response.body.customer, "customer").to.not.be.empty; - expect(response.body.billing, "billingAddress").to.not.be.empty; + expect(response.body.billing, "billing_address").to.not.be.empty; expect(response.body.profile_id, "profile_id").to.not.be.null; expect( response.body.connector_transaction_id, @@ -1305,11 +1305,11 @@ Cypress.Commands.add( ); expect(response.body.payment_method_data, "payment_method_data").to.not .be.empty; - expect(response.body.merchant_connector_id, "connectorId").to.equal( + expect(response.body.merchant_connector_id, "connector_id").to.equal( globalState.get("merchantConnectorId") ); expect(response.body.customer, "customer").to.not.be.empty; - expect(response.body.billing, "billingAddress").to.not.be.empty; + expect(response.body.billing, "billing_address").to.not.be.empty; expect(response.body.profile_id, "profile_id").to.not.be.null; expect( response.body.connector_transaction_id, @@ -1527,7 +1527,7 @@ Cypress.Commands.add( expect(response.body.payment_id).to.equal(payment_id); expect(response.body.amount).to.equal(globalState.get("paymentAmount")); expect(response.body.profile_id, "profile_id").to.not.be.null; - expect(response.body.billing, "billingAddress").to.not.be.empty; + expect(response.body.billing, "billing_address").to.not.be.empty; expect(response.body.customer, "customer").to.not.be.empty; if ( ["succeeded", "processing", "requires_customer_action"].includes( @@ -1540,7 +1540,7 @@ Cypress.Commands.add( expect(response.body.payment_method_data, "payment_method_data").to.not .be.empty; expect(response.body.payment_method, "payment_method").to.not.be.null; - expect(response.body.merchant_connector_id, "connectorId").to.equal( + expect(response.body.merchant_connector_id, "connector_id").to.equal( globalState.get("merchantConnectorId") ); expect(