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
test(cypress): Add Affirm PayLater payment test for Stripe connector (#12308)
HS-QUALIBOT6222a25e813d
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Commons.js b/cypress-tests/cypress/e2e/configs/Payment/Commons.jsindex 7285c7d133..89ad040063 100644--- a/cypress-tests/cypress/e2e/configs/Payment/Commons.js+++ b/cypress-tests/cypress/e2e/configs/Payment/Commons.js@@ -655,6 +655,17 @@ export const payment_methods_enabled = [recurring_enabled: false,installment_payment_enabled: false,},+ {+ payment_method_type: "affirm",+ payment_experience: "redirect_to_url",+ card_networks: null,+ accepted_currencies: null,+ accepted_countries: null,+ minimum_amount: 1,+ maximum_amount: 68607706,+ recurring_enabled: false,+ installment_payment_enabled: false,+ },],},];@@ -1319,6 +1330,39 @@ export const connectorDetails = {],},}),+ Affirm: getCustomExchange({+ Request: {+ payment_method: "pay_later",+ payment_method_type: "affirm",+ payment_experience: "redirect_to_url",+ payment_method_data: {+ pay_later: {+ affirm_redirect: {},+ },+ },+ billing: {+ email: "[email protected]",+ address: {+ line1: "1467",+ line2: "Harrison Street",+ line3: "Harrison Street",+ city: "San Fransico",+ state: "California",+ zip: "94122",+ country: "US",+ first_name: "joseph",+ last_name: "Doe",+ },+ },+ order_details: [+ {+ product_name: "Test Product",+ quantity: 1,+ amount: 6000,+ },+ ],+ },+ }),AutoCapture: getCustomExchange({Request: {currency: "EUR",diff --git a/cypress-tests/cypress/e2e/configs/Payment/Modifiers.js b/cypress-tests/cypress/e2e/configs/Payment/Modifiers.jsindex dd5679be93..c2b588a337 100644--- a/cypress-tests/cypress/e2e/configs/Payment/Modifiers.js+++ b/cypress-tests/cypress/e2e/configs/Payment/Modifiers.js@@ -197,6 +197,7 @@ const CURRENCY_MAP = {OnlineBankingFpx: "MYR", // Malaysian payment methodsInterac: "CAD", // Canadian payment methodAliPayHk: "HKD", // Hong Kong payment method+ Affirm: "USD", // US BNPL payment methodMifinity: "EUR", // Mifinity wallet payment methodSkrill: "USD", // Skrill wallet payment methodPaySafeCard: "USD", // PaySafeCard gift card payment methoddiff --git a/cypress-tests/cypress/e2e/configs/Payment/Stripe.js b/cypress-tests/cypress/e2e/configs/Payment/Stripe.jsindex c4dfbe8a7e..20070e5a3b 100644--- a/cypress-tests/cypress/e2e/configs/Payment/Stripe.js+++ b/cypress-tests/cypress/e2e/configs/Payment/Stripe.js@@ -1345,6 +1345,43 @@ export const connectorDetails = {},},}),+ Affirm: getCustomExchange({+ Request: {+ payment_method: "pay_later",+ payment_method_type: "affirm",+ payment_experience: "redirect_to_url",+ payment_method_data: {+ pay_later: {+ affirm_redirect: {},+ },+ },+ billing: {+ email: "[email protected]",+ address: {+ line1: "1467 Harrison Street",+ city: "San Francisco",+ state: "California",+ zip: "94122",+ country: "US",+ first_name: "Mock",+ last_name: "Mock",+ },+ },+ order_details: [+ {+ product_name: "Test Product",+ quantity: 1,+ amount: 6000,+ },+ ],+ },+ Response: {+ status: 200,+ body: {+ status: "requires_customer_action",+ },+ },+ }),Capture: getCustomExchange({Request: {amount_to_capture: 6000,diff --git a/cypress-tests/cypress/e2e/configs/Payment/Utils.js b/cypress-tests/cypress/e2e/configs/Payment/Utils.jsindex 379a80e0ba..4838564a81 100644--- a/cypress-tests/cypress/e2e/configs/Payment/Utils.js+++ b/cypress-tests/cypress/e2e/configs/Payment/Utils.js@@ -571,6 +571,7 @@ export const CONNECTOR_LISTS = {GIFT_CARD: ["adyen"],RELAY_OPERATIONS: ["bankofamerica"],PAY_LATER: ["klarna", "adyen", "aci", "stripe", "airwallex", "mollie"],+ AFFIRM: ["stripe"],AUTH_SERVICE_ELIGIBILITY: ["stripe", "cybersource"],STEP_UP_AUTH: ["cybersource"],PARTIAL_AUTH: ["nuvei", "checkout", "worldpay", "worldpayvantiv"],diff --git a/cypress-tests/cypress/e2e/spec/Payment/43-PayLater.cy.js b/cypress-tests/cypress/e2e/spec/Payment/43-PayLater.cy.jsindex 0e9586b56b..f2b230f754 100644--- a/cypress-tests/cypress/e2e/spec/Payment/43-PayLater.cy.js+++ b/cypress-tests/cypress/e2e/spec/Payment/43-PayLater.cy.js@@ -37,7 +37,7 @@ describe("PayLater tests", () => {});context("Klarna PayLater - Auto Capture flow test", () => {- it("Create Payment Intent -> List Merchant Payment Methods -> Confirm Payment -> Handle PayLater Redirection", () => {+ it("Create Payment Intent -> List Merchant Payment Methods -> Confirm Payment -> Handle PayLater Redirection -> Retrieve Payment", () => {let shouldContinue = true;cy.step("Create Payment Intent", () => {@@ -97,11 +97,25 @@ describe("PayLater tests", () => {expected_redirection);});++ cy.step("Retrieve Payment after Redirection", () => {+ if (!shouldContinue) {+ cy.task(+ "cli_log",+ "Skipping step: Retrieve Payment after Redirection"+ );+ return;+ }+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "pay_later_pm"+ ]["Klarna"];+ cy.retrievePaymentCallTest({ globalState, data });+ });});});context("Klarna PayLater - Manual Capture flow test", () => {- it("Create Payment Intent -> List Merchant Payment Methods -> Confirm Payment -> Handle PayLater Redirection", () => {+ it("Create Payment Intent -> List Merchant Payment Methods -> Confirm Payment -> Handle PayLater Redirection -> Retrieve Payment", () => {let shouldContinue = true;cy.step("Create Payment Intent", () => {@@ -161,6 +175,196 @@ describe("PayLater tests", () => {expected_redirection);});++ cy.step("Retrieve Payment after Redirection", () => {+ if (!shouldContinue) {+ cy.task(+ "cli_log",+ "Skipping step: Retrieve Payment after Redirection"+ );+ return;+ }+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "pay_later_pm"+ ]["Klarna"];+ cy.retrievePaymentCallTest({ globalState, data });+ });+ });+ });++ context("Affirm PayLater - Auto Capture flow test", () => {+ before("skip if connector does not support Affirm", function () {+ if (+ shouldIncludeConnector(+ globalState.get("connectorId"),+ CONNECTOR_LISTS.INCLUDE.AFFIRM+ )+ ) {+ this.skip();+ }+ });+ it("Create Payment Intent -> List Merchant Payment Methods -> Confirm Payment -> Handle PayLater Redirection -> Retrieve Payment", () => {+ let shouldContinue = true;++ cy.step("Create Payment Intent", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "pay_later_pm"+ ]["AutoCapture"];+ cy.createPaymentIntentTest(+ fixtures.createPaymentBody,+ data,+ "three_ds",+ "automatic",+ globalState+ );+ if (!utils.should_continue_further(data)) {+ shouldContinue = false;+ }+ });++ cy.step("List Merchant Payment Methods", () => {+ if (!shouldContinue) {+ cy.task("cli_log", "Skipping step: List Merchant Payment Methods");+ return;+ }+ cy.paymentMethodsCallTest(globalState);+ });++ cy.step("Confirm Payment", () => {+ if (!shouldContinue) {+ cy.task("cli_log", "Skipping step: Confirm Payment");+ return;+ }+ const confirmData = getConnectorDetails(globalState.get("connectorId"))[+ "pay_later_pm"+ ]["Affirm"];+ cy.confirmBankRedirectCallTest(+ fixtures.confirmBody,+ confirmData,+ true,+ globalState+ );+ if (!utils.should_continue_further(confirmData)) {+ shouldContinue = false;+ }+ });++ cy.step("Handle PayLater Redirection", () => {+ if (!shouldContinue) {+ cy.task("cli_log", "Skipping step: Handle PayLater Redirection");+ return;+ }+ const expected_redirection =+ globalState.get("baseUrl") + "/payments/completion";+ const payment_method_type = globalState.get("paymentMethodType");+ cy.handlePayLaterRedirection(+ globalState,+ payment_method_type,+ expected_redirection+ );+ });++ cy.step("Retrieve Payment after Redirection", () => {+ if (!shouldContinue) {+ cy.task(+ "cli_log",+ "Skipping step: Retrieve Payment after Redirection"+ );+ return;+ }+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "pay_later_pm"+ ]["Affirm"];+ cy.retrievePaymentCallTest({ globalState, data });+ });+ });+ });++ context("Affirm PayLater - Manual Capture flow test", () => {+ before("skip if connector does not support Affirm", function () {+ if (+ shouldIncludeConnector(+ globalState.get("connectorId"),+ CONNECTOR_LISTS.INCLUDE.AFFIRM+ )+ ) {+ this.skip();+ }+ });+ it("Create Payment Intent -> List Merchant Payment Methods -> Confirm Payment -> Handle PayLater Redirection -> Retrieve Payment", () => {+ let shouldContinue = true;++ cy.step("Create Payment Intent", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "pay_later_pm"+ ]["ManualCapture"];+ cy.createPaymentIntentTest(+ fixtures.createPaymentBody,+ data,+ "three_ds",+ "manual",+ globalState+ );+ if (!utils.should_continue_further(data)) {+ shouldContinue = false;+ }+ });++ cy.step("List Merchant Payment Methods", () => {+ if (!shouldContinue) {+ cy.task("cli_log", "Skipping step: List Merchant Payment Methods");+ return;+ }+ cy.paymentMethodsCallTest(globalState);+ });++ cy.step("Confirm Payment", () => {+ if (!shouldContinue) {+ cy.task("cli_log", "Skipping step: Confirm Payment");+ return;+ }+ const confirmData = getConnectorDetails(globalState.get("connectorId"))[+ "pay_later_pm"+ ]["Affirm"];+ cy.confirmBankRedirectCallTest(+ fixtures.confirmBody,+ confirmData,+ true,+ globalState+ );+ if (!utils.should_continue_further(confirmData)) {+ shouldContinue = false;+ }+ });++ cy.step("Handle PayLater Redirection", () => {+ if (!shouldContinue) {+ cy.task("cli_log", "Skipping step: Handle PayLater Redirection");+ return;+ }+ const expected_redirection =+ globalState.get("baseUrl") + "/payments/completion";+ const payment_method_type = globalState.get("paymentMethodType");+ cy.handlePayLaterRedirection(+ globalState,+ payment_method_type,+ expected_redirection+ );+ });++ cy.step("Retrieve Payment after Redirection", () => {+ if (!shouldContinue) {+ cy.task(+ "cli_log",+ "Skipping step: Retrieve Payment after Redirection"+ );+ return;+ }+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "pay_later_pm"+ ]["Affirm"];+ cy.retrievePaymentCallTest({ globalState, data });+ });});});});diff --git a/cypress-tests/cypress/support/redirectionHandler.js b/cypress-tests/cypress/support/redirectionHandler.jsindex c559c34a9f..1146e6a9cb 100644--- a/cypress-tests/cypress/support/redirectionHandler.js+++ b/cypress-tests/cypress/support/redirectionHandler.js@@ -246,7 +246,76 @@ function payLaterRedirection(case "stripe":// Stripe handles pay_later differently - may have different flowcy.log("Handling Stripe pay_later flow");- cy.get("body", { timeout: constants.TIMEOUT }).should("exist");++ if (paymentMethodType === "affirm") {+ cy.log("Handling Stripe Affirm redirect flow");+ cy.get("body", { timeout: constants.TIMEOUT }).should("exist");++ cy.get("body").then(($body) => {+ const bodyText = $body.text().toLowerCase();+ if (+ bodyText.includes("affirm") ||+ bodyText.includes("pay over time")+ ) {+ cy.log("Affirm page detected");++ cy.get("body").then(($b) => {+ const phoneInput = $b.find(+ 'input[type="tel"], input[name*="phone"], input[placeholder*="phone"], input[placeholder*="Phone"]'+ );+ if (phoneInput.length > 0) {+ cy.wrap(phoneInput[0])+ .should("be.visible")+ .clear()+ .type("5555555555");+ }+ });++ cy.get("body").then(($b) => {+ const pinInput = $b.find(+ 'input[type="password"], input[name*="pin"], input[placeholder*="PIN"]'+ );+ if (pinInput.length > 0) {+ cy.wrap(pinInput[0])+ .should("be.visible")+ .clear()+ .type("1234");+ }+ });++ cy.get("body").then(($b) => {+ const ssnInput = $b.find(+ 'input[name*="ssn"], input[placeholder*="SSN"], input[placeholder*="social"]'+ );+ if (ssnInput.length > 0) {+ cy.wrap(ssnInput[0])+ .should("be.visible")+ .clear()+ .type("1234");+ }+ });++ cy.get("body").then(($b) => {+ const termsCheckbox = $b.find(+ 'input[type="checkbox"][name*="terms"], input[type="checkbox"][name*="agree"]'+ );+ if (termsCheckbox.length > 0) {+ cy.wrap(termsCheckbox[0]).should("be.visible").check();+ }+ });++ cy.get("body").then(($b) => {+ const submitBtn = $b.find('button[type="submit"]');+ if (submitBtn.length > 0) {+ cy.wrap(submitBtn[0]).should("be.visible").click();+ }+ });+ }+ });+ } else {+ cy.get("body", { timeout: constants.TIMEOUT }).should("exist");+ }+verifyUrl = false;break;@@ -1136,6 +1205,30 @@ function bankRedirectRedirection(}break;+ case "paysafe":+ switch (paymentMethodType) {+ case "interac":+ cy.log("Handling Paysafe Interac bank redirect flow");++ verifyUrl = false;+ break;+ case "skrill":+ cy.log("Handling Paysafe Skrill wallet redirect flow");++ verifyUrl = false;+ break;+ case "pay_safe_card":+ cy.log("Handling Paysafe PaySafeCard gift card redirect flow");++ verifyUrl = false;+ break;+ default:+ throw new Error(+ `Unsupported Paysafe payment method type in handleFlow: ${paymentMethodType}`+ );+ }+ break;+case "volt":if (paymentMethodType === "open_banking_uk") {cy.log("Handling Volt OpenBankingUk redirect flow");@@ -1281,30 +1374,6 @@ function bankRedirectRedirection(}break;- case "paysafe":- switch (paymentMethodType) {- case "interac":- cy.log("Handling Paysafe Interac bank redirect flow");-- verifyUrl = false;- break;- case "skrill":- cy.log("Handling Paysafe Skrill wallet redirect flow");-- verifyUrl = false;- break;- case "pay_safe_card":- cy.log("Handling Paysafe PaySafeCard gift card redirect flow");-- verifyUrl = false;- break;- default:- throw new Error(- `Unsupported Paysafe payment method type in handleFlow: ${paymentMethodType}`- );- }- break;-default:throw new Error(`Unsupported connector in handleFlow: ${connectorId}`@@ -2215,12 +2284,10 @@ function paymentLinkCardRedirection(name.includes("card_number") ||autocomplete.includes("cc-number")) {- /* eslint-disable cypress/no-force */cy.wrap(input)- .focus()- .clear({ force: true })- .type(card_number, { delay: 30, force: true });- /* eslint-enable cypress/no-force */+ .should("be.visible")+ .clear()+ .type(card_number, { delay: 30 });cy.task("cli_log", `Filled card number in iframe ${index}`);} else if (placeholder.includes("expir") ||@@ -2230,15 +2297,12 @@ function paymentLinkCardRedirection(name.includes("exp") ||autocomplete.includes("cc-exp")) {- /* eslint-disable cypress/no-force */cy.wrap(input)- .focus()- .clear({ force: true })+ .should("be.visible")+ .clear().type(`${card_exp_month}${card_exp_year.slice(-2)}`, {delay: 30,- force: true,});- /* eslint-enable cypress/no-force */cy.task("cli_log", `Filled expiry in iframe ${index}`);} else if (placeholder.includes("cvc") ||@@ -2250,12 +2314,10 @@ function paymentLinkCardRedirection(name.includes("cvv") ||autocomplete.includes("cc-csc")) {- /* eslint-disable cypress/no-force */cy.wrap(input)- .focus()- .clear({ force: true })- .type(card_cvc, { delay: 30, force: true });- /* eslint-enable cypress/no-force */+ .should("be.visible")+ .clear()+ .type(card_cvc, { delay: 30 });cy.task("cli_log", `Filled CVC in iframe ${index}`);}});@@ -2270,12 +2332,10 @@ function paymentLinkCardRedirection(});});- /* eslint-disable cypress/no-force */cy.get("#submit", { timeout: 30000 }).should("be.visible").and("not.have.class", "hidden")- .click({ force: true });- /* eslint-enable cypress/no-force */+ .click();cy.task("cli_log", "Clicked submit button");if (expectedOutcome === "error") {