Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
ci(cypress): add cashtocode connector (#10736)
likhinbopannaa3f2b6ce6f67
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Cashtocode.js b/cypress-tests/cypress/e2e/configs/Payment/Cashtocode.jsnew file mode 100644index 0000000000..d9fd5ea262--- /dev/null+++ b/cypress-tests/cypress/e2e/configs/Payment/Cashtocode.js@@ -0,0 +1,142 @@+const successfulNo3DSCardDetails = {+ card_number: "4111111111111111",+ card_exp_month: "03",+ card_exp_year: "30",+ card_holder_name: "John Doe",+ card_cvc: "737",+};++const billingAddress = {+ address: {+ line1: "1467",+ line2: "Harrison Street",+ line3: "Harrison Street",+ city: "San Fransico",+ state: "CA",+ zip: "94122",+ country: "US",+ first_name: "John",+ last_name: "Doe",+ },+ phone: {+ number: "9123456789",+ country_code: "+91",+ },+};++export const connectorDetails = {+ reward_pm: {+ PaymentIntentUSD: {+ Request: {+ currency: "USD",+ amount: 6000,+ customer_acceptance: null,+ setup_future_usage: "on_session",+ billing: billingAddress,+ },+ Response: {+ status: 200,+ body: {+ status: "requires_payment_method",+ },+ },+ },+ PaymentIntentEUR: {+ Request: {+ currency: "EUR",+ amount: 6000,+ customer_acceptance: null,+ setup_future_usage: "on_session",+ billing: billingAddress,+ },+ Response: {+ status: 200,+ body: {+ status: "requires_payment_method",+ },+ },+ },+ Evoucher: {+ Request: {+ payment_method: "reward",+ payment_method_type: "evoucher",+ payment_method_data: "reward",+ billing: billingAddress,+ },+ Response: {+ status: 200,+ body: {+ status: "requires_customer_action",+ payment_method: "reward",+ payment_method_type: "evoucher",+ amount: 6000,+ },+ },+ },+ Classic: {+ Request: {+ payment_method: "reward",+ payment_method_type: "classic",+ payment_method_data: "reward",+ billing: billingAddress,+ },+ Response: {+ status: 200,+ body: {+ status: "requires_customer_action",+ payment_method: "reward",+ payment_method_type: "classic",+ amount: 6000,+ },+ },+ },+ },+ card_pm: {+ ZeroAuthMandate: {+ Response: {+ status: 501,+ body: {+ error: {+ type: "invalid_request",+ message: "Setup Mandate flow for Cashtocode is not implemented",+ code: "IR_00",+ },+ },+ },+ },+ ZeroAuthPaymentIntent: {+ Request: {+ amount: 0,+ setup_future_usage: "off_session",+ currency: "USD",+ },+ Response: {+ status: 200,+ body: {+ status: "requires_payment_method",+ setup_future_usage: "off_session",+ },+ },+ },+ ZeroAuthConfirmPayment: {+ Request: {+ payment_type: "setup_mandate",+ payment_method: "card",+ payment_method_type: "credit",+ payment_method_data: {+ card: successfulNo3DSCardDetails,+ },+ },+ Response: {+ status: 501,+ body: {+ error: {+ type: "invalid_request",+ message: "Setup Mandate flow for Cashtocode is not implemented",+ code: "IR_00",+ },+ },+ },+ },+ },+};diff --git a/cypress-tests/cypress/e2e/configs/Payment/Commons.js b/cypress-tests/cypress/e2e/configs/Payment/Commons.jsindex f085d173b8..0ec397477e 100644--- a/cypress-tests/cypress/e2e/configs/Payment/Commons.js+++ b/cypress-tests/cypress/e2e/configs/Payment/Commons.js@@ -405,6 +405,33 @@ export const payment_methods_enabled = [},],},+ {+ payment_method: "reward",+ payment_method_types: [+ {+ payment_method_type: "evoucher",+ payment_experience: "redirect_to_url",+ card_networks: null,+ accepted_currencies: null,+ accepted_countries: null,+ minimum_amount: 0,+ maximum_amount: 68607706,+ recurring_enabled: true,+ installment_payment_enabled: false,+ },+ {+ payment_method_type: "classic",+ payment_experience: "redirect_to_url",+ card_networks: null,+ accepted_currencies: null,+ accepted_countries: null,+ minimum_amount: 0,+ maximum_amount: 68607706,+ recurring_enabled: true,+ installment_payment_enabled: false,+ },+ ],+ },];export const connectorDetails = {@@ -1883,6 +1910,54 @@ export const connectorDetails = {},}),},+ reward_pm: {+ PaymentIntentUSD: getCustomExchange({+ Request: {+ currency: "USD",+ amount: 6000,+ customer_acceptance: null,+ setup_future_usage: "on_session",+ billing: standardBillingAddress,+ },+ Response: {+ status: 200,+ body: {+ status: "requires_payment_method",+ },+ },+ }),+ PaymentIntentEUR: getCustomExchange({+ Request: {+ currency: "EUR",+ amount: 6000,+ customer_acceptance: null,+ setup_future_usage: "on_session",+ billing: standardBillingAddress,+ },+ Response: {+ status: 200,+ body: {+ status: "requires_payment_method",+ },+ },+ }),+ Evoucher: getCustomExchange({+ Request: {+ payment_method: "reward",+ payment_method_type: "evoucher",+ payment_method_data: "reward",+ billing: standardBillingAddress,+ },+ }),+ Classic: getCustomExchange({+ Request: {+ payment_method: "reward",+ payment_method_type: "classic",+ payment_method_data: "reward",+ billing: standardBillingAddress,+ },+ }),+ },pm_list: {PmListResponse: {PmListNull: {diff --git a/cypress-tests/cypress/e2e/configs/Payment/Redsys.js b/cypress-tests/cypress/e2e/configs/Payment/Redsys.jsindex fcc8a6394e..5b3ecec03a 100644--- a/cypress-tests/cypress/e2e/configs/Payment/Redsys.js+++ b/cypress-tests/cypress/e2e/configs/Payment/Redsys.js@@ -317,7 +317,7 @@ export const connectorDetails = {body: {error: {type: "invalid_request",- message: "Setup Mandate flow for redsys is not implemented",+ message: "Setup Mandate flow for Redsys is not implemented",code: "IR_00",},},diff --git a/cypress-tests/cypress/e2e/configs/Payment/Utils.js b/cypress-tests/cypress/e2e/configs/Payment/Utils.jsindex 6712e56f4e..6ade114a27 100644--- a/cypress-tests/cypress/e2e/configs/Payment/Utils.js+++ b/cypress-tests/cypress/e2e/configs/Payment/Utils.js@@ -15,6 +15,7 @@ import { connectorDetails as barclaycardConnectorDetails } from "./Barclaycard.jimport { connectorDetails as billwerkConnectorDetails } from "./Billwerk.js";import { connectorDetails as bluesnapConnectorDetails } from "./Bluesnap.js";import { connectorDetails as braintreeConnectorDetails } from "./Braintree.js";+import { connectorDetails as cashtocodeConnectorDetails } from "./Cashtocode.js";import { connectorDetails as celeroConnectorDetails } from "./Celero.js";import { connectorDetails as checkbookConnectorDetails } from "./Checkbook.js";import { connectorDetails as checkoutConnectorDetails } from "./Checkout.js";@@ -80,6 +81,7 @@ const connectorDetails = {billwerk: billwerkConnectorDetails,bluesnap: bluesnapConnectorDetails,braintree: braintreeConnectorDetails,+ cashtocode: cashtocodeConnectorDetails,celero: celeroConnectorDetails,checkout: checkoutConnectorDetails,checkbook: checkbookConnectorDetails,diff --git a/cypress-tests/cypress/e2e/spec/Payment/00036-RewardPayment.cy.js b/cypress-tests/cypress/e2e/spec/Payment/00036-RewardPayment.cy.jsnew file mode 100644index 0000000000..4bc761e92f--- /dev/null+++ b/cypress-tests/cypress/e2e/spec/Payment/00036-RewardPayment.cy.js@@ -0,0 +1,137 @@+import * as fixtures from "../../../fixtures/imports";+import State from "../../../utils/State";+import getConnectorDetails, * as utils from "../../configs/Payment/Utils";++let globalState;++describe("Reward Payment - Cashtocode", () => {+ before("seed global state", () => {+ cy.task("getGlobalState").then((state) => {+ globalState = new State(state);+ });+ });++ after("flush global state", () => {+ cy.task("setGlobalState", globalState.data);+ });++ afterEach("flush global state", () => {+ cy.task("setGlobalState", globalState.data);+ });++ context("Evoucher payment method flow", () => {+ let shouldContinue = true; // variable that will be used to skip tests if a previous test fails++ beforeEach(function () {+ if (!shouldContinue) {+ this.skip();+ }+ });++ it("Create Payment Intent for Evoucher", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "reward_pm"+ ]["PaymentIntentUSD"];++ cy.createPaymentIntentTest(+ fixtures.createPaymentBody,+ data,+ "no_three_ds",+ "automatic",+ globalState+ );++ if (shouldContinue) shouldContinue = utils.should_continue_further(data);+ });++ it("Payment Methods Call Test", () => {+ cy.paymentMethodsCallTest(globalState);+ });++ it("Confirm Evoucher Payment", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "reward_pm"+ ]["Evoucher"];++ cy.confirmRewardCallTest(fixtures.confirmBody, data, true, globalState);++ if (shouldContinue) shouldContinue = utils.should_continue_further(data);+ });++ it("Handle redirection", () => {+ const expected_redirection = fixtures.confirmBody["return_url"];+ const payment_method_type = globalState.get("paymentMethodType");+ cy.handleRewardRedirection(+ globalState,+ payment_method_type,+ expected_redirection+ );+ });++ it("Retrieve Payment Call Test", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "reward_pm"+ ]["Evoucher"];++ cy.retrievePaymentCallTest(globalState, data);+ });+ });++ context("Classic payment method flow", () => {+ let shouldContinue = true;++ beforeEach(function () {+ if (!shouldContinue) {+ this.skip();+ }+ });++ it("Create Payment Intent for Classic", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "reward_pm"+ ]["PaymentIntentEUR"];++ cy.createPaymentIntentTest(+ fixtures.createPaymentBody,+ data,+ "no_three_ds",+ "automatic",+ globalState+ );++ if (shouldContinue) shouldContinue = utils.should_continue_further(data);+ });++ it("Payment Methods Call Test", () => {+ cy.paymentMethodsCallTest(globalState);+ });++ it("Confirm Classic Payment", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "reward_pm"+ ]["Classic"];++ cy.confirmRewardCallTest(fixtures.confirmBody, data, true, globalState);++ if (shouldContinue) shouldContinue = utils.should_continue_further(data);+ });++ it("Handle Redirection for Classic", () => {+ const expected_redirection = fixtures.confirmBody["return_url"];+ const payment_method_type = globalState.get("paymentMethodType");+ cy.handleRewardRedirection(+ globalState,+ payment_method_type,+ expected_redirection+ );+ });++ it("Retrieve Payment Call Test", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "reward_pm"+ ]["Classic"];++ cy.retrievePaymentCallTest(globalState, data);+ });+ });+});diff --git a/cypress-tests/cypress/e2e/spec/Payment/00035-DynamicFields.cy.js b/cypress-tests/cypress/e2e/spec/Payment/00037-DynamicFields.cy.jssimilarity index 100%rename from cypress-tests/cypress/e2e/spec/Payment/00035-DynamicFields.cy.jsrename to cypress-tests/cypress/e2e/spec/Payment/00037-DynamicFields.cy.jsdiff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.jsindex 25ee162f33..338dfa93a4 100644--- a/cypress-tests/cypress/support/commands.js+++ b/cypress-tests/cypress/support/commands.js@@ -3704,6 +3704,24 @@ Cypress.Commands.add(});+Cypress.Commands.add(+ "handleRewardRedirection",+ (globalState, paymentMethodType, expectedRedirection) => {+ const connectorId = globalState.get("connectorId");+ const nextActionUrl = globalState.get("nextActionUrl");++ const expectedUrl = new URL(expectedRedirection);+ const redirectionUrl = new URL(nextActionUrl);++ handleRedirection(+ "reward",+ { redirectionUrl, expectedUrl },+ connectorId,+ paymentMethodType+ );+ }+);+Cypress.Commands.add("confirmRealTimePaymentCallTest",(confirmBody, data, confirm, globalState) => {@@ -3790,6 +3808,78 @@ Cypress.Commands.add(});+Cypress.Commands.add(+ "confirmRewardCallTest",+ (confirmBody, data, confirm, globalState) => {+ const {+ Configs: configs = {},+ Request: reqData,+ Response: resData,+ } = data || {};++ const configInfo = execConfig(validateConfig(configs));+ const paymentIntentID = globalState.get("paymentID");+ const profile_id = globalState.get(`${configInfo.profilePrefix}Id`);++ for (const key in reqData) {+ confirmBody[key] = reqData[key];+ }+ confirmBody.client_secret = globalState.get("clientSecret");+ confirmBody.confirm = confirm;+ confirmBody.profile_id = profile_id;++ 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"]);++ cy.wrap(response).then(() => {+ expect(response.headers["content-type"]).to.include("application/json");+ if (response.status === 200) {+ globalState.set("paymentID", paymentIntentID);++ validateErrorMessage(response, resData);++ 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+ );+ globalState.set("nextActionType", "redirect_to_url");++ for (const key in resData.body) {+ expect(resData.body[key], [key]).to.deep.equal(+ response.body[key]+ );+ }+ } else {+ throw new Error(+ `Invalid capture method ${response.body.capture_method}`+ );+ }+ } else {+ defaultErrorHandler(response, resData);+ }+ });+ });+ }+);+Cypress.Commands.add("handleUpiRedirection",(globalState, paymentMethodType, expected_redirection) => {diff --git a/cypress-tests/cypress/support/redirectionHandler.js b/cypress-tests/cypress/support/redirectionHandler.jsindex 3f5a4494cf..cf4ba5ae9d 100644--- a/cypress-tests/cypress/support/redirectionHandler.js+++ b/cypress-tests/cypress/support/redirectionHandler.js@@ -62,6 +62,14 @@ export function handleRedirection(paymentMethodType);break;+ case "reward":+ rewardRedirection(+ urls.redirectionUrl,+ urls.expectedUrl,+ connectorId,+ paymentMethodType+ );+ break;default:throw new Error(`Unknown redirection type: ${redirectionType}`);}@@ -1253,6 +1261,58 @@ function upiRedirection(});}+function rewardRedirection(+ redirectionUrl,+ expectedUrl,+ connectorId,+ paymentMethodType+) {+ let verifyUrl = false;++ // Skip if redirectionUrl is null (happens when nextActionUrl is invalid)+ if (redirectionUrl && redirectionUrl.href) {+ cy.visit(redirectionUrl.href);+ waitForRedirect(redirectionUrl.href);++ handleFlow(+ redirectionUrl,+ expectedUrl,+ connectorId,+ ({ connectorId, paymentMethodType }) => {+ switch (connectorId) {+ case "cashtocode":+ // Cashtocode reward payment redirects+ switch (paymentMethodType) {+ case "evoucher":+ case "classic":+ cy.log(`Handling Cashtocode ${paymentMethodType} payment`);+ // Cashtocode reward payments don't reach terminal state+ // Skip return URL verification+ verifyUrl = false;+ break;+ default:+ throw new Error(+ `Unsupported Cashtocode payment method type: ${paymentMethodType}`+ );+ }+ break;+ default:+ // Default handling for other connectors that may support reward payments+ cy.log(`Handling reward payment for connector: ${connectorId}`);+ verifyUrl = false;+ }+ },+ { paymentMethodType }+ );+ } else {+ cy.log("Skipping reward redirection - no valid redirect URL provided");+ }++ cy.then(() => {+ verifyReturnUrl(redirectionUrl, expectedUrl, verifyUrl);+ });+}+function verifyReturnUrl(redirectionUrl, expectedUrl, forwardFlow) {if (!forwardFlow) {cy.log("Skipping return URL verification as forwardFlow is false.");