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
fix(ucs): complete Elavon PG hosted-page payments (#14843)
Tushar Shukla9c347dc076f7
diff --git a/crates/router/src/core/unified_connector_service/transformers.rs b/crates/router/src/core/unified_connector_service/transformers.rsindex cb487745f5..2aaf44ce49 100644--- a/crates/router/src/core/unified_connector_service/transformers.rs+++ b/crates/router/src/core/unified_connector_service/transformers.rs@@ -72,6 +72,28 @@ use crate::{const UPI_WAIT_SCREEN_DISPLAY_DURATION_MINUTES: i64 = 5;const UPI_POLL_DELAY_IN_SECS: u16 = 5;const UPI_POLL_FREQUENCY: u16 = 60;+const REDIRECT_COMPLETION_PAYMENT_METHOD_TOKEN_KEYS: [&str; 2] =+ ["payment_method_token", "payment_handle_token"];++fn build_redirect_completion_payment_method(+ connector_metadata: Option<&serde_json::Value>,+) -> Option<payments_grpc::PaymentMethod> {+ connector_metadata+ .and_then(|metadata| {+ REDIRECT_COMPLETION_PAYMENT_METHOD_TOKEN_KEYS+ .iter()+ .find_map(|key| metadata.get(*key).and_then(serde_json::Value::as_str))+ })+ .filter(|token| !token.trim().is_empty())+ .map(|token| payments_grpc::PaymentMethod {+ payment_method: Some(payments_grpc::payment_method::PaymentMethod::Token(+ payments_grpc::TokenPaymentMethodType {+ token: Some(Secret::new(token.to_string())),+ token_payment_method_type: None,+ },+ )),+ })+}impl ForeignFrom<&api_models::payments::ConnectorMetadata>for payments_grpc::AdditionalConnectorDetails@@ -965,24 +987,12 @@ impl)}).transpose()?- // Post-3DS settle: card data is not persisted through the redirect, so pay by the- // handle token the authenticate leg returned in connector metadata (stored on the- // request as connector_meta, same channel as authentication_data below).+ // Card data is not persisted through a redirect. Connectors that return a+ // single-use payment token in connector metadata can settle with that token..or_else(|| {- router_data- .request- .connector_meta- .as_ref()- .and_then(|metadata| metadata.get("payment_handle_token"))- .and_then(|token| token.as_str())- .map(|handle_token| payments_grpc::PaymentMethod {- payment_method: Some(payments_grpc::payment_method::PaymentMethod::Token(- payments_grpc::TokenPaymentMethodType {- token: Some(Secret::new(handle_token.to_string())),- token_payment_method_type: None,- },- )),- })+ build_redirect_completion_payment_method(+ router_data.request.connector_meta.as_ref(),+ )});let address = payments_grpc::PaymentAddress::foreign_try_from(router_data.address.clone())?;diff --git a/cypress-tests/cypress/e2e/configs/Payment/ElavonPg.js b/cypress-tests/cypress/e2e/configs/Payment/ElavonPg.jsnew file mode 100644index 0000000000..4bba29962c--- /dev/null+++ b/cypress-tests/cypress/e2e/configs/Payment/ElavonPg.js@@ -0,0 +1,111 @@+import { getCustomExchange } from "./Modifiers";++const hostedPageCard = {+ card_number: "4546341111111119",+ card_exp_month: "12",+ card_exp_year: "30",+ card_holder_name: "Elavon PG Test",+ card_cvc: "123",+};++const billing = {+ address: {+ line1: "1467",+ city: "San Francisco",+ state: "CA",+ zip: "94122",+ country: "US",+ first_name: "Elavon",+ last_name: "Test",+ },+ email: "[email protected]",+};++export const connectorDetails = {+ card_pm: {+ PaymentIntent: getCustomExchange({+ Request: {+ amount: 1000,+ currency: "USD",+ },+ Response: {+ status: 200,+ body: {+ status: "requires_payment_method",+ },+ },+ }),+ "3DSManualCapture": getCustomExchange({+ Request: {+ amount: 1000,+ currency: "USD",+ payment_method: "card",+ payment_method_type: "credit",+ payment_method_data: {+ card: hostedPageCard,+ },+ billing,+ customer_acceptance: null,+ },+ Response: {+ status: 200,+ body: {+ status: "requires_customer_action",+ },+ },+ }),+ SyncPayment: getCustomExchange({+ Response: {+ status: 200,+ body: {+ status: "requires_capture",+ },+ },+ }),+ Capture: getCustomExchange({+ Request: {+ amount_to_capture: 1000,+ },+ Response: {+ status: 200,+ body: {+ status: "succeeded",+ amount: 1000,+ amount_capturable: 0,+ amount_received: 1000,+ },+ },+ }),+ Refund: getCustomExchange({+ Request: {+ amount: 1000,+ },+ Response: {+ status: 200,+ body: {+ status: "succeeded",+ },+ },+ }),+ SyncRefund: getCustomExchange({+ Response: {+ status: 200,+ body: {+ status: "succeeded",+ },+ },+ }),+ Void: getCustomExchange({+ Request: {+ cancellation_reason: "requested_by_customer",+ },+ Response: {+ status: 200,+ body: {+ status: "cancelled",+ capture_method: "manual",+ },+ },+ }),+ },+};diff --git a/cypress-tests/cypress/e2e/configs/Payment/Utils.js b/cypress-tests/cypress/e2e/configs/Payment/Utils.jsindex 9118dd1e5c..67ffe80333 100644--- a/cypress-tests/cypress/e2e/configs/Payment/Utils.js+++ b/cypress-tests/cypress/e2e/configs/Payment/Utils.js@@ -31,6 +31,7 @@ import { connectorDetails as datatransConnectorDetails } from "./Datatrans.js";import { connectorDetails as deutschebankConnectorDetails } from "./Deutschebank.js";import { connectorDetails as dlocalConnectorDetails } from "./Dlocal.js";import { connectorDetails as elavonConnectorDetails } from "./Elavon.js";+import { connectorDetails as elavonPgConnectorDetails } from "./ElavonPg.js";import { connectorDetails as facilitapayConnectorDetails } from "./Facilitapay.js";import { connectorDetails as finixConnectorDetails } from "./Finix.js";import { connectorDetails as fiservConnectorDetails } from "./Fiserv.js";@@ -127,6 +128,7 @@ const connectorDetails = {datatrans: datatransConnectorDetails,deutschebank: deutschebankConnectorDetails,elavon: elavonConnectorDetails,+ elavon_pg: elavonPgConnectorDetails,facilitapay: facilitapayConnectorDetails,fiserv: fiservConnectorDetails,fiservemea: fiservemeaConnectorDetails,diff --git a/cypress-tests/cypress/e2e/spec/UnifiedConnectorService/0002-ElavonPgHostedFlows.cy.js b/cypress-tests/cypress/e2e/spec/UnifiedConnectorService/0002-ElavonPgHostedFlows.cy.jsnew file mode 100644index 0000000000..1a61a71787--- /dev/null+++ b/cypress-tests/cypress/e2e/spec/UnifiedConnectorService/0002-ElavonPgHostedFlows.cy.js@@ -0,0 +1,134 @@+import * as fixtures from "../../../fixtures/imports";+import State from "../../../utils/State";+import getConnectorDetails from "../../configs/Payment/Utils";+import { cardCreditEnabled } from "../../configs/PaymentMethodList/Commons";++let globalState;++function startHostedManualPayment() {+ const connectorDetails = getConnectorDetails("elavon_pg")["card_pm"];++ cy.createPaymentIntentTest(+ structuredClone(fixtures.createPaymentBody),+ connectorDetails["PaymentIntent"],+ "three_ds",+ "manual",+ globalState+ );+ cy.paymentMethodsCallTest(globalState);+ cy.confirmCallTest(+ structuredClone(fixtures.confirmBody),+ connectorDetails["3DSManualCapture"],+ true,+ globalState+ );+ cy.handleRedirection(globalState, fixtures.confirmBody["return_url"]);+ cy.retrievePaymentCallTest({+ globalState,+ data: connectorDetails["SyncPayment"],+ expectedIntentStatus: "requires_capture",+ });+}++function syncRefundThroughConnector(data) {+ const refundId = globalState.get("refundId");++ // Successful refunds are terminal, so force_sync alone is served from+ // storage. all_keys_required deliberately exercises UCS RSync.+ cy.request({+ method: "GET",+ url: `${globalState.get("baseUrl")}/refunds/${refundId}?force_sync=true&all_keys_required=true`,+ headers: {+ "Content-Type": "application/json",+ "api-key": globalState.get("apiKey"),+ },+ failOnStatusCode: false,+ }).then((response) => {+ expect(response.status).to.equal(data.Response.status);+ expect(response.headers["content-type"]).to.include("application/json");+ for (const key in data.Response.body) {+ expect(response.body[key]).to.equal(data.Response.body[key]);+ }+ expect(response.body.refund_id).to.equal(refundId);+ });+}++describe("Elavon PG hosted UCS flows", () => {+ before("initialize", function () {+ cy.task("getGlobalState").then((state) => {+ globalState = new State(state);+ if (Cypress.env("CONNECTOR") !== "elavon_pg") {+ cy.log("Skipping Elavon PG hosted flow tests");+ this.skip();+ }+ });+ });++ afterEach("flush global state", () => {+ cy.task("setGlobalState", globalState.data);+ });++ context("setup", () => {+ it("creates the merchant, API key, connector, customer, and UCS flag", () => {+ cy.merchantCreateCallTest(+ structuredClone(fixtures.merchantCreateBody),+ globalState+ );+ cy.apiKeyCreateTest(+ structuredClone(fixtures.apiKeyCreateBody),+ globalState+ );+ cy.createNamedConnectorCallTest(+ "payment_processor",+ structuredClone(fixtures.createConnectorBody),+ cardCreditEnabled,+ globalState,+ "elavon_pg",+ "elavon_pg_default"+ );+ cy.createCustomerCallTest(+ structuredClone(fixtures.customerCreateBody),+ globalState+ );+ cy.setupConfigs(globalState, "ucs_enabled", "true");+ });+ });++ context("hosted authorize, sync, capture, refund, and refund sync", () => {+ it("completes the HS to UCS to Elavon PG lifecycle", () => {+ const connectorDetails = getConnectorDetails("elavon_pg")["card_pm"];++ startHostedManualPayment();+ cy.captureCallTest(+ structuredClone(fixtures.captureBody),+ connectorDetails["Capture"],+ globalState+ );+ cy.refundCallTest(+ structuredClone(fixtures.refundBody),+ connectorDetails["Refund"],+ globalState+ );+ syncRefundThroughConnector(connectorDetails["SyncRefund"]);+ });+ });++ context("hosted authorize and void", () => {+ it("voids an authorized Elavon PG payment", () => {+ const connectorDetails = getConnectorDetails("elavon_pg")["card_pm"];++ startHostedManualPayment();+ cy.voidCallTest(+ structuredClone(fixtures.voidBody),+ connectorDetails["Void"],+ globalState+ );+ });+ });++ context("cleanup", () => {+ it("removes the UCS flag", () => {+ cy.setConfigs(globalState, "ucs_enabled", "true", "DELETE");+ });+ });+});diff --git a/cypress-tests/cypress/support/redirectionHandler.js b/cypress-tests/cypress/support/redirectionHandler.jsindex cf231d2191..837010f7ee 100644--- a/cypress-tests/cypress/support/redirectionHandler.js+++ b/cypress-tests/cypress/support/redirectionHandler.js@@ -3606,6 +3606,46 @@ function threeDsRedirection(return;}+ // Elavon PG uses its hosted page to collect the card details again before+ // completing 3DS and redirecting through Hyperswitch's CompleteAuthorize+ // endpoint. Keep this interaction in the test layer; the router only needs+ // to preserve the connector-issued payment token across that redirect.+ if (connectorId === "elavon_pg") {+ cy.get("#qa_card_holder_name", { timeout: CONSTANTS.TIMEOUT })+ .clear()+ .type("Elavon PG Test");+ cy.get("#qa_cc_section").clear().type("4546341111111119");+ cy.get("#qa_expiryDate_section").clear().type("1230");+ cy.get("#qa_secCode_section").clear().type("123");+ cy.get("#shopperEmailAddress").clear().type("[email protected]");++ cy.get("#qa_submit_payment", { timeout: CONSTANTS.WAIT_TIME })+ .should("be.visible")+ .and("be.enabled")+ .click();++ cy.get('iframe[name="acsIframe"]', { timeout: CONSTANTS.TIMEOUT })+ .should("be.visible")+ .should(($iframe) => {+ const doc = $iframe[0].contentDocument;+ expect(doc, "Elavon ACS iframe document").to.exist;+ expect(+ doc.querySelector("#challengeData"),+ "Elavon ACS challenge form to render inside the iframe"+ ).to.exist;+ })+ .its("0.contentDocument.body")+ .within(() => {+ cy.get("#challengeData").should("be.visible").clear().type("validdata");+ cy.get("#transStatus").select("Y").should("have.value", "Y");+ cy.get("a.buttonBase").should("contain.text", "Continue").click();+ });++ cy.url({ timeout: CONSTANTS.TIMEOUT }).should("include", expectedUrl.host);+ verifyReturnUrl(redirectionUrl, expectedUrl, true);+ return;+ }+// For all other connectors, use the standard flowwaitForRedirect(redirectionUrl.href);