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
feat: add support to call ucs authorize function during complete authorize (#10091)
Hrithikesh1d3def33b7b9
diff --git a/Cargo.lock b/Cargo.lockindex 4c26b6867e..7c721e57f4 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -3813,7 +3813,7 @@ dependencies = [[[package]]name = "grpc-api-types"version = "0.1.0"-source = "git+https://github.com/juspay/connector-service?rev=1d0d1e2b31f20e3127e9bf2c5b759a7c4dd91484#1d0d1e2b31f20e3127e9bf2c5b759a7c4dd91484"+source = "git+https://github.com/juspay/connector-service?rev=77eaaa6344de9657c83a65ed0d619f48dff0c4a5#77eaaa6344de9657c83a65ed0d619f48dff0c4a5"dependencies = ["axum 0.8.4","error-stack 0.5.0",@@ -7457,7 +7457,7 @@ dependencies = [[[package]]name = "rust-grpc-client"version = "0.1.0"-source = "git+https://github.com/juspay/connector-service?rev=1d0d1e2b31f20e3127e9bf2c5b759a7c4dd91484#1d0d1e2b31f20e3127e9bf2c5b759a7c4dd91484"+source = "git+https://github.com/juspay/connector-service?rev=77eaaa6344de9657c83a65ed0d619f48dff0c4a5#77eaaa6344de9657c83a65ed0d619f48dff0c4a5"dependencies = ["grpc-api-types",]@@ -10244,7 +10244,7 @@ checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9"[[package]]name = "ucs_cards"version = "0.1.0"-source = "git+https://github.com/juspay/connector-service?rev=1d0d1e2b31f20e3127e9bf2c5b759a7c4dd91484#1d0d1e2b31f20e3127e9bf2c5b759a7c4dd91484"+source = "git+https://github.com/juspay/connector-service?rev=77eaaa6344de9657c83a65ed0d619f48dff0c4a5#77eaaa6344de9657c83a65ed0d619f48dff0c4a5"dependencies = ["bytes 1.10.1","error-stack 0.4.1",@@ -10260,7 +10260,7 @@ dependencies = [[[package]]name = "ucs_common_enums"version = "0.1.0"-source = "git+https://github.com/juspay/connector-service?rev=1d0d1e2b31f20e3127e9bf2c5b759a7c4dd91484#1d0d1e2b31f20e3127e9bf2c5b759a7c4dd91484"+source = "git+https://github.com/juspay/connector-service?rev=77eaaa6344de9657c83a65ed0d619f48dff0c4a5#77eaaa6344de9657c83a65ed0d619f48dff0c4a5"dependencies = ["serde","strum 0.26.3",@@ -10271,7 +10271,7 @@ dependencies = [[[package]]name = "ucs_common_utils"version = "0.1.0"-source = "git+https://github.com/juspay/connector-service?rev=1d0d1e2b31f20e3127e9bf2c5b759a7c4dd91484#1d0d1e2b31f20e3127e9bf2c5b759a7c4dd91484"+source = "git+https://github.com/juspay/connector-service?rev=77eaaa6344de9657c83a65ed0d619f48dff0c4a5#77eaaa6344de9657c83a65ed0d619f48dff0c4a5"dependencies = ["anyhow","base64 0.21.7",diff --git a/crates/external_services/Cargo.toml b/crates/external_services/Cargo.tomlindex 331cf031a3..d6bbaf583f 100644--- a/crates/external_services/Cargo.toml+++ b/crates/external_services/Cargo.toml@@ -69,7 +69,7 @@ reqwest = { version = "0.11.27", features = ["rustls-tls"] }http = "0.2.12"url = { version = "2.5.4", features = ["serde"] }quick-xml = { version = "0.31.0", features = ["serialize"] }-unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "1d0d1e2b31f20e3127e9bf2c5b759a7c4dd91484", package = "rust-grpc-client" }+unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "77eaaa6344de9657c83a65ed0d619f48dff0c4a5", package = "rust-grpc-client" }open-feature = { version = "0.2.5", optional = true }superposition_provider = { version = "0.88.1", optional = true }diff --git a/crates/external_services/src/grpc_client/unified_connector_service.rs b/crates/external_services/src/grpc_client/unified_connector_service.rsindex c41c7016fa..15798c637f 100644--- a/crates/external_services/src/grpc_client/unified_connector_service.rs+++ b/crates/external_services/src/grpc_client/unified_connector_service.rs@@ -242,9 +242,9 @@ impl UnifiedConnectorServiceClient {.inspect_err(|error| {logger::error!(grpc_error=?error,- method="payment_pre_authenticate",+ method="payment_post_authenticate",connector_name=?connector_name,- "UCS payment pre authenticate gRPC call failed"+ "UCS payment post authenticate gRPC call failed")})}diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rsindex 639cbc026c..708e38d8fb 100644--- a/crates/hyperswitch_domain_models/src/router_request_types.rs+++ b/crates/hyperswitch_domain_models/src/router_request_types.rs@@ -657,6 +657,7 @@ impl TryFrom<PaymentsAuthorizeData> for PaymentsPreAuthenticateData {#[derive(Debug, Clone, Serialize)]pub struct PaymentsAuthenticateData {pub payment_method_data: Option<PaymentMethodData>,+ pub payment_method_type: Option<storage_enums::PaymentMethodType>,pub amount: Option<i64>,pub email: Option<pii::Email>,pub currency: Option<storage_enums::Currency>,@@ -672,6 +673,7 @@ impl TryFrom<CompleteAuthorizeData> for PaymentsAuthenticateData {fn try_from(data: CompleteAuthorizeData) -> Result<Self, Self::Error> {Ok(Self {payment_method_data: data.payment_method_data,+ payment_method_type: data.payment_method_type,amount: Some(data.amount),minor_amount: Some(data.minor_amount),email: data.email,@@ -686,6 +688,7 @@ impl TryFrom<CompleteAuthorizeData> for PaymentsAuthenticateData {#[derive(Debug, Clone, Serialize)]pub struct PaymentsPostAuthenticateData {pub payment_method_data: Option<PaymentMethodData>,+ pub payment_method_type: Option<storage_enums::PaymentMethodType>,pub amount: Option<i64>,pub email: Option<pii::Email>,pub currency: Option<storage_enums::Currency>,@@ -701,6 +704,7 @@ impl TryFrom<CompleteAuthorizeData> for PaymentsPostAuthenticateData {fn try_from(data: CompleteAuthorizeData) -> Result<Self, Self::Error> {Ok(Self {+ payment_method_type: data.payment_method_type,payment_method_data: data.payment_method_data,amount: Some(data.amount),minor_amount: Some(data.minor_amount),@@ -708,7 +712,7 @@ impl TryFrom<CompleteAuthorizeData> for PaymentsPostAuthenticateData {currency: Some(data.currency),browser_info: data.browser_info,connector_transaction_id: None,- redirect_response: None,+ redirect_response: data.redirect_response,})}}@@ -805,6 +809,8 @@ pub struct CompleteAuthorizeData {pub complete_authorize_url: Option<String>,pub metadata: Option<serde_json::Value>,pub customer_acceptance: Option<common_payments_types::CustomerAcceptance>,+ pub authentication_data: Option<UcsAuthenticationData>,+ pub payment_method_type: Option<storage_enums::PaymentMethodType>,// New amount for amount frame workpub minor_amount: MinorUnit,pub merchant_account_id: Option<Secret<String>>,@@ -1043,6 +1049,19 @@ impl}}+#[derive(Debug, Clone, Serialize)]+pub struct UcsAuthenticationData {+ pub eci: Option<String>,+ pub cavv: Option<Secret<String>>,+ pub threeds_server_transaction_id: Option<String>,+ pub message_version: Option<common_utils::types::SemanticVersion>,+ pub ds_trans_id: Option<String>,+ pub acs_trans_id: Option<String>,+ pub trans_status: Option<common_enums::TransactionStatus>,+ pub transaction_id: Option<String>,+ pub ucaf_collection_indicator: Option<String>,+}+#[derive(Debug, Clone, Serialize)]pub struct AuthenticationData {pub eci: Option<String>,diff --git a/crates/hyperswitch_domain_models/src/router_response_types.rs b/crates/hyperswitch_domain_models/src/router_response_types.rsindex c5d396a62a..a96373e950 100644--- a/crates/hyperswitch_domain_models/src/router_response_types.rs+++ b/crates/hyperswitch_domain_models/src/router_response_types.rs@@ -645,12 +645,6 @@ pub enum AuthenticationResponseData {},}-#[derive(Debug, Clone)]-pub struct CompleteAuthorizeRedirectResponse {- pub params: Option<masking::Secret<String>>,- pub payload: Option<pii::SecretSerdeValue>,-}-/// Represents details of a payment method.#[derive(Debug, Clone)]pub struct PaymentMethodDetails {diff --git a/crates/hyperswitch_interfaces/Cargo.toml b/crates/hyperswitch_interfaces/Cargo.tomlindex 3e12d8cfec..e2d927237e 100644--- a/crates/hyperswitch_interfaces/Cargo.toml+++ b/crates/hyperswitch_interfaces/Cargo.toml@@ -29,7 +29,7 @@ serde_json = "1.0.140"strum = { version = "0.26", features = ["derive"] }thiserror = "1.0.69"time = "0.3.41"-unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "1d0d1e2b31f20e3127e9bf2c5b759a7c4dd91484", package = "rust-grpc-client" }+unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "77eaaa6344de9657c83a65ed0d619f48dff0c4a5", package = "rust-grpc-client" }unified-connector-service-masking = { git = "https://github.com/juspay/hyperswitch", tag = "2025.09.24.0", package = "masking" }# First party crateshyperswitch_domain_models = { version = "0.1.0", path = "../hyperswitch_domain_models", default-features = false }diff --git a/crates/hyperswitch_interfaces/src/connector_integration_interface.rs b/crates/hyperswitch_interfaces/src/connector_integration_interface.rsindex 04883894fe..87f0d62828 100644--- a/crates/hyperswitch_interfaces/src/connector_integration_interface.rs+++ b/crates/hyperswitch_interfaces/src/connector_integration_interface.rs@@ -519,6 +519,25 @@ impl ConnectorValidation for ConnectorEnum {}impl ConnectorSpecifications for ConnectorEnum {+ fn decide_should_continue_after_preprocessing(+ &self,+ current_flow: api::CurrentFlowInfo<'_>,+ pre_processing_flow_name: api::PreProcessingFlowName,+ preprocessing_flow_response: api::PreProcessingFlowResponse<'_>,+ ) -> bool {+ match self {+ Self::Old(connector) => connector.decide_should_continue_after_preprocessing(+ current_flow,+ pre_processing_flow_name,+ preprocessing_flow_response,+ ),+ Self::New(connector) => connector.decide_should_continue_after_preprocessing(+ current_flow,+ pre_processing_flow_name,+ preprocessing_flow_response,+ ),+ }+ }fn get_preprocessing_flow_if_needed(&self,current_flow_info: api::CurrentFlowInfo<'_>,diff --git a/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs b/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rsindex 674151ca9a..ac6a34110a 100644--- a/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs+++ b/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs@@ -259,6 +259,7 @@ impl ForeignTryFrom<payments_grpc::PaymentStatus> for AttemptStatus {payments_grpc::PaymentStatus::DeviceDataCollectionPending => {Ok(Self::DeviceDataCollectionPending)}+ payments_grpc::PaymentStatus::VoidedPostCapture => Ok(Self::Voided),payments_grpc::PaymentStatus::AttemptStatusUnspecified => Ok(Self::Unresolved),}}diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.tomlindex d0bf766567..8e75fe5bcb 100644--- a/crates/router/Cargo.toml+++ b/crates/router/Cargo.toml@@ -89,8 +89,8 @@ reqwest = { version = "0.11.27", features = ["json", "rustls-tls", "gzip", "multring = "0.17.14"rust_decimal = { version = "1.37.1", features = ["serde-with-float", "serde-with-str"] }rust-i18n = { git = "https://github.com/kashif-m/rust-i18n", rev = "f2d8096aaaff7a87a847c35a5394c269f75e077a" }-unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "1d0d1e2b31f20e3127e9bf2c5b759a7c4dd91484", package = "rust-grpc-client" }-unified-connector-service-cards = { git = "https://github.com/juspay/connector-service", rev = "1d0d1e2b31f20e3127e9bf2c5b759a7c4dd91484", package = "ucs_cards" }+unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "77eaaa6344de9657c83a65ed0d619f48dff0c4a5", package = "rust-grpc-client" }+unified-connector-service-cards = { git = "https://github.com/juspay/connector-service", rev = "77eaaa6344de9657c83a65ed0d619f48dff0c4a5", package = "ucs_cards" }unified-connector-service-masking = { git = "https://github.com/juspay/hyperswitch", tag = "2025.09.24.0", package = "masking" }rustc-hash = "1.1.0"rustls = "0.22"diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rsindex 210126fc4d..7c4980d792 100644--- a/crates/router/src/core/payments/flows/authorize_flow.rs+++ b/crates/router/src/core/payments/flows/authorize_flow.rs@@ -965,21 +965,20 @@ async fn call_unified_connector_service_authorize(.external_vault_proxy_metadata(None).merchant_reference_id(merchant_reference_id).lineage_ids(lineage_ids);- let updated_router_data = Box::pin(ucs_logging_wrapper(+ let (updated_router_data, _) = Box::pin(ucs_logging_wrapper(router_data.clone(),state,payment_authorize_request,headers_builder,|mut router_data, payment_authorize_request, grpc_headers| async move {- let response = client- .payment_authorize(- payment_authorize_request,- connector_auth_metadata,- grpc_headers,- )- .await- .change_context(ApiErrorResponse::InternalServerError)- .attach_printable("Failed to authorize payment")?;+ let response = Box::pin(client.payment_authorize(+ payment_authorize_request,+ connector_auth_metadata,+ grpc_headers,+ ))+ .await+ .change_context(ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to authorize payment")?;let payment_authorize_response = response.into_inner();@@ -1039,7 +1038,7 @@ async fn call_unified_connector_service_authorize(router_data.connector_response = Some(customer_response);});- Ok((router_data, payment_authorize_response))+ Ok((router_data, (), payment_authorize_response))},)).await?;@@ -1175,7 +1174,7 @@ async fn call_unified_connector_service_pre_authenticate(.external_vault_proxy_metadata(None).merchant_reference_id(merchant_reference_id).lineage_ids(lineage_ids);- let updated_router_data = Box::pin(ucs_logging_wrapper(+ let (updated_router_data, _) = Box::pin(ucs_logging_wrapper(router_data.clone(),state,payment_pre_authenticate_request,@@ -1215,7 +1214,7 @@ async fn call_unified_connector_service_pre_authenticate(.map(|raw_connector_response| raw_connector_response.expose().into());router_data.connector_http_status_code = Some(status_code);- Ok((router_data, payment_pre_authenticate_response))+ Ok((router_data,(), payment_pre_authenticate_response))},)).await?;@@ -1275,7 +1274,7 @@ async fn call_unified_connector_service_repeat_payment(.external_vault_proxy_metadata(None).merchant_reference_id(merchant_reference_id).lineage_ids(lineage_ids);- let updated_router_data = Box::pin(ucs_logging_wrapper(+ let (updated_router_data, _) = Box::pin(ucs_logging_wrapper(router_data.clone(),state,payment_repeat_request,@@ -1350,7 +1349,7 @@ async fn call_unified_connector_service_repeat_payment(router_data.connector_response = Some(connector_response);});- Ok((router_data, payment_repeat_response))+ Ok((router_data, (), payment_repeat_response))},)).await?;diff --git a/crates/router/src/core/payments/flows/cancel_flow.rs b/crates/router/src/core/payments/flows/cancel_flow.rsindex af30f13bf5..f1f6d7ddc2 100644--- a/crates/router/src/core/payments/flows/cancel_flow.rs+++ b/crates/router/src/core/payments/flows/cancel_flow.rs@@ -216,7 +216,7 @@ impl Feature<api::Void, types::PaymentsCancelData>.merchant_reference_id(merchant_reference_id).lineage_ids(lineage_ids);- let updated_router_data = Box::pin(ucs_logging_wrapper(+ let (updated_router_data, _) = Box::pin(ucs_logging_wrapper(self.clone(),state,payment_void_request,@@ -244,7 +244,7 @@ impl Feature<api::Void, types::PaymentsCancelData>router_data.response = router_data_response;router_data.connector_http_status_code = Some(status_code);- Ok((router_data, payment_void_response))+ Ok((router_data, (), payment_void_response))},)).await?;diff --git a/crates/router/src/core/payments/flows/capture_flow.rs b/crates/router/src/core/payments/flows/capture_flow.rsindex 01ba9a7bb5..bfe4f78857 100644--- a/crates/router/src/core/payments/flows/capture_flow.rs+++ b/crates/router/src/core/payments/flows/capture_flow.rs@@ -222,7 +222,7 @@ impl Feature<api::Capture, types::PaymentsCaptureData>.external_vault_proxy_metadata(None).merchant_reference_id(merchant_reference_id).lineage_ids(lineage_ids);- let updated_router_data = Box::pin(ucs_logging_wrapper(+ let (updated_router_data, _) = Box::pin(ucs_logging_wrapper(self.clone(),state,payment_capture_request,@@ -258,7 +258,7 @@ impl Feature<api::Capture, types::PaymentsCaptureData>.map(MinorUnit::new);router_data.connector_http_status_code = Some(status_code);- Ok((router_data, payment_capture_response))+ Ok((router_data, (), payment_capture_response))},)).await?;diff --git a/crates/router/src/core/payments/flows/complete_authorize_flow.rs b/crates/router/src/core/payments/flows/complete_authorize_flow.rsindex 472231a9cc..4b4c75ff78 100644--- a/crates/router/src/core/payments/flows/complete_authorize_flow.rs+++ b/crates/router/src/core/payments/flows/complete_authorize_flow.rs@@ -5,7 +5,7 @@ use common_enums::connector_enums;use common_utils::{id_type, ucs_types};use error_stack::ResultExt;use external_services::grpc_client;-use hyperswitch_domain_models::router_response_types;+use hyperswitch_domain_models::{router_request_types, router_response_types};use hyperswitch_interfaces::{api as api_interface, api::ConnectorSpecifications};use masking::{self, ExposeInterface};use unified_connector_service_client::payments as payments_grpc;@@ -248,19 +248,20 @@ impl Feature<api::CompleteAuthorize, types::CompleteAuthorizeData>.get_preprocessing_flow_if_needed(current_flow);match optional_preprocessing_flow {Some(preprocessing_flow) => {- let updated_router_data = handle_preprocessing_through_unified_connector_service(- self,- state,- header_payload,- lineage_ids.clone(),- merchant_connector_account.clone(),- merchant_context,- connector_data,- unified_connector_service_execution_mode,- merchant_order_reference_id.clone(),- preprocessing_flow,- )- .await?;+ let updated_router_data =+ Box::pin(handle_preprocessing_through_unified_connector_service(+ self,+ state,+ header_payload,+ lineage_ids.clone(),+ merchant_connector_account.clone(),+ merchant_context,+ connector_data,+ unified_connector_service_execution_mode,+ merchant_order_reference_id.clone(),+ preprocessing_flow,+ ))+ .await?;let pre_processing_flow_response = api_interface::PreProcessingFlowResponse {response: &updated_router_data.response,attempt_status: updated_router_data.status,@@ -283,21 +284,32 @@ impl Feature<api::CompleteAuthorize, types::CompleteAuthorizeData>async fn call_unified_connector_service<'a>(&mut self,- _state: &SessionState,- _header_payload: &hyperswitch_domain_models::payments::HeaderPayload,- _lineage_ids: grpc_client::LineageIds,- #[cfg(feature = "v1")] _merchant_connector_account: helpers::MerchantConnectorAccountType,+ state: &SessionState,+ header_payload: &hyperswitch_domain_models::payments::HeaderPayload,+ lineage_ids: grpc_client::LineageIds,+ #[cfg(feature = "v1")] merchant_connector_account: helpers::MerchantConnectorAccountType,#[cfg(feature = "v2")]- _merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,- _merchant_context: &domain::MerchantContext,- _connector_data: &api::ConnectorData,- _unified_connector_service_execution_mode: common_enums::ExecutionMode,- _merchant_order_reference_id: Option<String>,+ merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,+ merchant_context: &domain::MerchantContext,+ connector_data: &api::ConnectorData,+ unified_connector_service_execution_mode: common_enums::ExecutionMode,+ merchant_order_reference_id: Option<String>,_call_connector_action: common_enums::CallConnectorAction,_creds_identifier: Option<String>,) -> RouterResult<()> {- // Call UCS for Authorize flow- Ok(())+ // Call UCS for Complete Authorize flow+ Box::pin(call_unified_connector_service_complete_authorize(+ self,+ state,+ header_payload,+ lineage_ids,+ merchant_connector_account,+ merchant_context,+ connector_data.connector_name,+ unified_connector_service_execution_mode,+ merchant_order_reference_id,+ ))+ .await}}@@ -328,7 +340,7 @@ async fn handle_preprocessing_through_unified_connector_service(match preprocessing_flow_name {api_interface::PreProcessingFlowName::Authenticate => {// Convert CompleteAuthorize to Authenticate for UCS call- let complete_authorize_request_data = router_data.request.clone();+ let mut complete_authorize_request_data = router_data.request.clone();let authenticate_request_data =types::PaymentsAuthenticateData::try_from(router_data.request.to_owned())?;let authenticate_response_data: Result<@@ -342,19 +354,20 @@ async fn handle_preprocessing_through_unified_connector_service(authenticate_response_data,);- // Call UCS for Authenticate flow- call_unified_connector_service_authenticate(- &mut authenticate_router_data,- state,- header_payload,- lineage_ids,- merchant_connector_account,- merchant_context,- connector_data.connector_name,- unified_connector_service_execution_mode,- merchant_order_reference_id,- )- .await?;+ // Call UCS for Authenticate flow and store authentication result for next step+ complete_authorize_request_data.authentication_data =+ call_unified_connector_service_authenticate(+ &mut authenticate_router_data,+ state,+ header_payload,+ lineage_ids,+ merchant_connector_account,+ merchant_context,+ connector_data.connector_name,+ unified_connector_service_execution_mode,+ merchant_order_reference_id,+ )+ .await?;// Convert back to CompleteAuthorize router data while preserving preprocessing response datalet authenticate_response = authenticate_router_data.response.clone();@@ -370,7 +383,7 @@ async fn handle_preprocessing_through_unified_connector_service(}api_interface::PreProcessingFlowName::PostAuthenticate => {// Convert CompleteAuthorize to PostAuthenticate for UCS call- let complete_authorize_request_data = router_data.request.clone();+ let mut complete_authorize_request_data = router_data.request.clone();let post_authenticate_request_data =types::PaymentsPostAuthenticateData::try_from(router_data.request.to_owned())?;let post_authenticate_response_data: Result<@@ -384,18 +397,19 @@ async fn handle_preprocessing_through_unified_connector_service(post_authenticate_response_data,);- // Call UCS for PostAuthenticate flow- call_unified_connector_service_post_authenticate(- &mut post_authenticate_router_data,- state,- header_payload,- lineage_ids,- merchant_connector_account,- merchant_context,- unified_connector_service_execution_mode,- merchant_order_reference_id,- )- .await?;+ // Call UCS for PostAuthenticate flow and store authentication result for next step+ complete_authorize_request_data.authentication_data =+ call_unified_connector_service_post_authenticate(+ &mut post_authenticate_router_data,+ state,+ header_payload,+ lineage_ids,+ merchant_connector_account,+ merchant_context,+ unified_connector_service_execution_mode,+ merchant_order_reference_id,+ )+ .await?;// Convert back to CompleteAuthorize router data while preserving preprocessing response datalet post_authenticate_response = post_authenticate_router_data.response.clone();@@ -503,7 +517,7 @@ async fn call_unified_connector_service_authenticate(connector: connector_enums::Connector,unified_connector_service_execution_mode: common_enums::ExecutionMode,merchant_order_reference_id: Option<String>,-) -> RouterResult<()> {+) -> RouterResult<Option<router_request_types::UcsAuthenticationData>> {let client = state.grpc_client.unified_connector_service_client@@ -537,7 +551,7 @@ async fn call_unified_connector_service_authenticate(.external_vault_proxy_metadata(None).merchant_reference_id(merchant_reference_id).lineage_ids(lineage_ids);- let updated_router_data = Box::pin(ucs_core::ucs_logging_wrapper(+ let (updated_router_data, authentication_data) = Box::pin(ucs_core::ucs_logging_wrapper(router_data.clone(),state,payment_authenticate_request,@@ -579,14 +593,30 @@ async fn call_unified_connector_service_authenticate(.map(|raw_connector_response| raw_connector_response.expose().into());router_data.connector_http_status_code = Some(status_code);- Ok((router_data, payment_authenticate_response))+ let domain_authentication_data = payment_authenticate_response+ .authentication_data+ .clone()+ .map(|grpc_authentication_data| {+ router_request_types::UcsAuthenticationData::foreign_try_from(+ grpc_authentication_data,+ )+ })+ .transpose()+ .change_context(ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to Convert to domain AuthenticationData")?;++ Ok((+ router_data,+ domain_authentication_data,+ payment_authenticate_response,+ ))},)).await?;// Copy back the updated data*router_data = updated_router_data;- Ok(())+ Ok(authentication_data)}#[allow(dead_code, clippy::too_many_arguments)]@@ -604,7 +634,7 @@ async fn call_unified_connector_service_post_authenticate(merchant_context: &domain::MerchantContext,unified_connector_service_execution_mode: common_enums::ExecutionMode,merchant_order_reference_id: Option<String>,-) -> RouterResult<()> {+) -> RouterResult<Option<router_request_types::UcsAuthenticationData>> {let client = state.grpc_client.unified_connector_service_client@@ -638,7 +668,7 @@ async fn call_unified_connector_service_post_authenticate(.external_vault_proxy_metadata(None).merchant_reference_id(merchant_reference_id).lineage_ids(lineage_ids);- let updated_router_data = Box::pin(ucs_core::ucs_logging_wrapper(+ let (updated_router_data, authentication_data) = Box::pin(ucs_core::ucs_logging_wrapper(router_data.clone(),state,payment_post_authenticate_request,@@ -674,14 +704,30 @@ async fn call_unified_connector_service_post_authenticate(.map(|raw_connector_response| raw_connector_response.expose().into());router_data.connector_http_status_code = Some(status_code);- Ok((router_data, payment_post_authenticate_response))+ let domain_authentication_data = payment_post_authenticate_response+ .authentication_data+ .clone()+ .map(|grpc_authentication_data| {+ router_request_types::UcsAuthenticationData::foreign_try_from(+ grpc_authentication_data,+ )+ })+ .transpose()+ .change_context(ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to Convert to domain AuthenticationData")?;++ Ok((+ router_data,+ domain_authentication_data,+ payment_post_authenticate_response,+ ))},)).await?;// Copy back the updated data*router_data = updated_router_data;- Ok(())+ Ok(authentication_data)}pub async fn complete_authorize_preprocessing_steps<F: Clone>(@@ -791,6 +837,120 @@ impl<F>}}+#[allow(clippy::too_many_arguments)]+async fn call_unified_connector_service_complete_authorize(+ router_data: &mut types::RouterData<+ api::CompleteAuthorize,+ types::CompleteAuthorizeData,+ types::PaymentsResponseData,+ >,+ state: &SessionState,+ header_payload: &hyperswitch_domain_models::payments::HeaderPayload,+ lineage_ids: grpc_client::LineageIds,+ #[cfg(feature = "v1")] merchant_connector_account: helpers::MerchantConnectorAccountType,+ #[cfg(feature = "v2")] merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,+ merchant_context: &domain::MerchantContext,+ _connector: connector_enums::Connector,+ unified_connector_service_execution_mode: common_enums::ExecutionMode,+ merchant_order_reference_id: Option<String>,+) -> RouterResult<()> {+ let client = state+ .grpc_client+ .unified_connector_service_client+ .clone()+ .ok_or(ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to fetch Unified Connector Service client")?;++ let payment_authorize_request =+ payments_grpc::PaymentServiceAuthorizeRequest::foreign_try_from(&(*router_data))+ .change_context(ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to construct Payment Complete Authorize Request")?;++ let connector_auth_metadata = ucs_core::build_unified_connector_service_auth_metadata(+ merchant_connector_account,+ merchant_context,+ )+ .change_context(ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to construct request metadata")?;++ let merchant_reference_id = header_payload+ .x_reference_id+ .clone()+ .or(merchant_order_reference_id)+ .map(|id| id_type::PaymentReferenceId::from_str(id.as_str()))+ .transpose()+ .inspect_err(|err| logger::warn!(error=?err, "Invalid Merchant ReferenceId found"))+ .ok()+ .flatten()+ .map(ucs_types::UcsReferenceId::Payment);++ let headers_builder = state+ .get_grpc_headers_ucs(unified_connector_service_execution_mode)+ .external_vault_proxy_metadata(None)+ .merchant_reference_id(merchant_reference_id)+ .lineage_ids(lineage_ids);++ let (updated_router_data, _) = Box::pin(ucs_core::ucs_logging_wrapper(+ router_data.clone(),+ state,+ payment_authorize_request,+ headers_builder,+ |mut router_data, payment_authorize_request, grpc_headers| async move {+ let response = Box::pin(client.payment_authorize(+ payment_authorize_request,+ connector_auth_metadata,+ grpc_headers,+ ))+ .await+ .change_context(ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to complete authorize payment")?;++ let payment_authorize_response = response.into_inner();++ let ucs_authorize_response =+ ucs_core::handle_unified_connector_service_response_for_payment_authorize(+ payment_authorize_response.clone(),+ )+ .change_context(ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to deserialize UCS response")?;++ let router_data_response =+ ucs_authorize_response+ .router_data_response+ .map(|(response, status)| {+ router_data.status = status;+ response+ });+ router_data.response = router_data_response;+ router_data.raw_connector_response = payment_authorize_response+ .raw_connector_response+ .clone()+ .map(|raw_connector_response| raw_connector_response.expose().into());+ router_data.connector_http_status_code = Some(ucs_authorize_response.status_code);++ // Populate connector_customer_id if present+ ucs_authorize_response+ .connector_customer_id+ .map(|connector_customer_id| {+ router_data.connector_customer = Some(connector_customer_id);+ });++ ucs_authorize_response+ .connector_response+ .map(|customer_response| {+ router_data.connector_response = Some(customer_response);+ });++ Ok((router_data, (), payment_authorize_response))+ },+ ))+ .await?;++ // Copy back the updated data+ *router_data = updated_router_data;+ Ok(())+}+async fn process_capture_flow(mut router_data: types::RouterData<api::CompleteAuthorize,diff --git a/crates/router/src/core/payments/flows/external_proxy_flow.rs b/crates/router/src/core/payments/flows/external_proxy_flow.rsindex 3c8437d8d6..a39cf5aac3 100644--- a/crates/router/src/core/payments/flows/external_proxy_flow.rs+++ b/crates/router/src/core/payments/flows/external_proxy_flow.rs@@ -418,18 +418,18 @@ impl Feature<api::ExternalVaultProxy, types::ExternalVaultProxyPaymentsData>.external_vault_proxy_metadata(Some(external_vault_proxy_metadata)).merchant_reference_id(merchant_reference_id).lineage_ids(lineage_ids);- let updated_router_data = Box::pin(ucs_logging_wrapper(+ let (updated_router_data, _) = Box::pin(ucs_logging_wrapper(self.clone(),state,payment_authorize_request.clone(),headers_builder,|mut router_data, payment_authorize_request, grpc_headers| async move {- let response = client+ let response = Box::pin(client.payment_authorize(payment_authorize_request,connector_auth_metadata,grpc_headers,- )+ )).await.change_context(ApiErrorResponse::InternalServerError).attach_printable("Failed to authorize payment")?;@@ -454,7 +454,7 @@ impl Feature<api::ExternalVaultProxy, types::ExternalVaultProxyPaymentsData>.map(|raw_connector_response| raw_connector_response.expose().into());router_data.connector_http_status_code = Some(ucs_data.status_code);- Ok((router_data, payment_authorize_response))+ Ok((router_data,(), payment_authorize_response))})).await?;diff --git a/crates/router/src/core/payments/flows/psync_flow.rs b/crates/router/src/core/payments/flows/psync_flow.rsindex 42ad5b0064..e1cf1182cd 100644--- a/crates/router/src/core/payments/flows/psync_flow.rs+++ b/crates/router/src/core/payments/flows/psync_flow.rs@@ -346,7 +346,7 @@ impl Feature<api::PSync, types::PaymentsSyncData>.merchant_reference_id(merchant_reference_id).lineage_ids(lineage_ids);let connector_name = self.connector.clone();- let updated_router_data = Box::pin(ucs_logging_wrapper(+ let (updated_router_data, _) = Box::pin(ucs_logging_wrapper(self.clone(),state,payment_get_request,@@ -415,7 +415,7 @@ impl Feature<api::PSync, types::PaymentsSyncData>.map(|raw_connector_response| raw_connector_response.expose().into());router_data.connector_http_status_code = Some(status_code);- Ok((router_data, payment_get_response))+ Ok((router_data, (), payment_get_response))},)).await?;diff --git a/crates/router/src/core/payments/flows/setup_mandate_flow.rs b/crates/router/src/core/payments/flows/setup_mandate_flow.rsindex 1202770e4d..82880fb97c 100644--- a/crates/router/src/core/payments/flows/setup_mandate_flow.rs+++ b/crates/router/src/core/payments/flows/setup_mandate_flow.rs@@ -329,7 +329,7 @@ impl Feature<api::SetupMandate, types::SetupMandateRequestData> for types::Setup.merchant_reference_id(merchant_reference_id).lineage_ids(lineage_ids);let connector_name = self.connector.clone();- let updated_router_data = Box::pin(ucs_logging_wrapper(+ let (updated_router_data, _) = Box::pin(ucs_logging_wrapper(self.clone(),state,payment_register_request,@@ -397,7 +397,7 @@ impl Feature<api::SetupMandate, types::SetupMandateRequestData> for types::Setuprouter_data.connector_customer = Some(connector_customer_id);});- Ok((router_data, payment_register_response))+ Ok((router_data, (), payment_register_response))},)).await?;diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rsindex abe86f6160..b212588995 100644--- a/crates/router/src/core/payments/transformers.rs+++ b/crates/router/src/core/payments/transformers.rs@@ -5803,6 +5803,12 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::CompleteAuthorizmerchant_config_currency,threeds_method_comp_ind: payment_data.threeds_method_comp_ind,is_stored_credential: payment_data.payment_attempt.is_stored_credential,+ payment_method_type: payment_data.payment_attempt.payment_method_type,+ authentication_data: payment_data+ .authentication+ .as_ref()+ .map(router_request_types::UcsAuthenticationData::foreign_try_from)+ .transpose()?,})}}diff --git a/crates/router/src/core/payments/types.rs b/crates/router/src/core/payments/types.rsindex 2abdfdc8ee..9cda545806 100644--- a/crates/router/src/core/payments/types.rs+++ b/crates/router/src/core/payments/types.rs@@ -9,7 +9,7 @@ use common_utils::{use error_stack::ResultExt;use hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt;pub use hyperswitch_domain_models::router_request_types::{- AuthenticationData, SplitRefundsRequest, StripeSplitRefund, SurchargeDetails,+ self, AuthenticationData, SplitRefundsRequest, StripeSplitRefund, SurchargeDetails,};use redis_interface::errors::RedisError;use router_env::{instrument, logger, tracing};@@ -363,14 +363,47 @@ impl SurchargeMetadata {}}-impl- ForeignTryFrom<- &hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore,- > for AuthenticationData+impl ForeignTryFrom<&router_request_types::authentication::AuthenticationStore>+ for router_request_types::UcsAuthenticationData{type Error = error_stack::Report<errors::ApiErrorResponse>;fn foreign_try_from(- authentication_store: &hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore,+ authentication_store: &router_request_types::authentication::AuthenticationStore,+ ) -> Result<Self, Self::Error> {+ let authentication = &authentication_store.authentication;+ if authentication.authentication_status == common_enums::AuthenticationStatus::Success {+ let threeds_server_transaction_id =+ authentication.threeds_server_transaction_id.clone();+ let message_version = authentication.message_version.clone();+ let cavv = authentication_store+ .cavv+ .clone()+ .get_required_value("cavv")+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("cavv must not be null when authentication_status is success")?;+ Ok(Self {+ trans_status: authentication.trans_status.clone(),+ eci: authentication.eci.clone(),+ cavv: Some(cavv),+ threeds_server_transaction_id,+ message_version,+ ds_trans_id: authentication.ds_trans_id.clone(),+ acs_trans_id: authentication.acs_trans_id.clone(),+ transaction_id: authentication.connector_authentication_id.clone(),+ ucaf_collection_indicator: None,+ })+ } else {+ Err(errors::ApiErrorResponse::PaymentAuthenticationFailed { data: None }.into())+ }+ }+}++impl ForeignTryFrom<&router_request_types::authentication::AuthenticationStore>+ for AuthenticationData+{+ type Error = error_stack::Report<errors::ApiErrorResponse>;+ fn foreign_try_from(+ authentication_store: &router_request_types::authentication::AuthenticationStore,) -> Result<Self, Self::Error> {let authentication = &authentication_store.authentication;if authentication.authentication_status == common_enums::AuthenticationStatus::Success {diff --git a/crates/router/src/core/unified_connector_service.rs b/crates/router/src/core/unified_connector_service.rsindex d4d1e3ec29..f1c97d7491 100644--- a/crates/router/src/core/unified_connector_service.rs+++ b/crates/router/src/core/unified_connector_service.rs@@ -1454,13 +1454,13 @@ pub fn extract_webhook_content_from_ucs_response(/// This function wraps UCS calls with comprehensive event logging./// It logs the actual gRPC request/response data, timing, and error information.#[instrument(skip_all, fields(connector_name, flow_type, payment_id))]-pub async fn ucs_logging_wrapper<T, F, Fut, Req, Resp, GrpcReq, GrpcResp>(+pub async fn ucs_logging_wrapper<T, F, Fut, Req, Resp, GrpcReq, GrpcResp, FlowOutput>(router_data: RouterData<T, Req, Resp>,state: &SessionState,grpc_request: GrpcReq,grpc_header_builder: external_services::grpc_client::GrpcHeadersUcsBuilderFinal,handler: F,-) -> RouterResult<RouterData<T, Req, Resp>>+) -> RouterResult<(RouterData<T, Req, Resp>, FlowOutput)>whereT: std::fmt::Debug + Clone + Send + 'static,Req: std::fmt::Debug + Clone + Send + Sync + 'static,@@ -1473,7 +1473,8 @@ whereexternal_services::grpc_client::GrpcHeadersUcs,) -> Fut+ Send,- Fut: std::future::Future<Output = RouterResult<(RouterData<T, Req, Resp>, GrpcResp)>> + Send,+ Fut: std::future::Future<Output = RouterResult<(RouterData<T, Req, Resp>, FlowOutput, GrpcResp)>>+ + Send,{tracing::Span::current().record("connector_name", &router_data.connector);tracing::Span::current().record("flow_type", std::any::type_name::<T>());@@ -1512,7 +1513,7 @@ where// Create and emit connector event after UCS calllet (status_code, response_body, router_result) = match result {- Ok((updated_router_data, grpc_response)) => {+ Ok((updated_router_data, flow_output, grpc_response)) => {let status = updated_router_data.connector_http_status_code.unwrap_or(200);@@ -1522,7 +1523,11 @@ where|_| serde_json::json!({"error": "failed_to_serialize_grpc_response"}),);- (status, Some(grpc_response_body), Ok(updated_router_data))+ (+ status,+ Some(grpc_response_body),+ Ok((updated_router_data, flow_output)),+ )}Err(error) => {// Update error metrics for UCS calls@@ -1572,8 +1577,8 @@ where// Set external latency on router datarouter_result.map(|mut router_data| {- router_data.external_latency =- Some(router_data.external_latency.unwrap_or(0) + external_latency);+ router_data.0.external_latency =+ Some(router_data.0.external_latency.unwrap_or(0) + external_latency);router_data})}@@ -1730,10 +1735,11 @@ pub async fn call_unified_connector_service_for_refund_execute(updated_router_data.response = refund_response_data;updated_router_data.connector_http_status_code = Some(status_code);- Ok((updated_router_data, grpc_response))+ Ok((updated_router_data, (), grpc_response))},)).await+ .map(|(router_data, _flow_response)| router_data)}/// Execute UCS refund sync request using RefundService.Get gRPC method@@ -1801,8 +1807,9 @@ pub async fn call_unified_connector_service_for_refund_sync(updated_router_data.response = refund_response_data;updated_router_data.connector_http_status_code = Some(status_code);- Ok((updated_router_data, grpc_response))+ Ok((updated_router_data, (), grpc_response))},)).await+ .map(|(router_data, _flow_response)| router_data)}diff --git a/crates/router/src/core/unified_connector_service/transformers.rs b/crates/router/src/core/unified_connector_service/transformers.rsindex aca8e95333..d44689c7e1 100644--- a/crates/router/src/core/unified_connector_service/transformers.rs+++ b/crates/router/src/core/unified_connector_service/transformers.rs@@ -1,7 +1,7 @@-use std::collections::HashMap;+use std::{collections::HashMap, str::FromStr};use common_enums::{AttemptStatus, AuthenticationType, RefundStatus};-use common_utils::{ext_traits::Encode, request::Method};+use common_utils::{ext_traits::Encode, request::Method, types};use diesel_models::enums as storage_enums;use error_stack::ResultExt;use external_services::grpc_client::unified_connector_service::UnifiedConnectorServiceError;@@ -143,6 +143,7 @@ implrequest_ref_id: connector_ref_id,capture_method: capture_method.map(|capture_method| capture_method.into()),handle_response,+amount: router_data.request.amount.get_amount_as_i64(),currency: currency.into(),state,@@ -166,25 +167,33 @@ implPaymentsResponseData,>,) -> Result<Self, Self::Error> {- // Based on the pattern from PaymentServicePreAuthenticateRequestlet currency = payments_grpc::Currency::foreign_try_from(router_data.request.currency.unwrap_or_default(),)?;- let payment_method = router_data- .request- .payment_method_data- .clone()- .map(|payment_method_data| {+ let payment_method_type = router_data.request.payment_method_type;+ let payment_method_data = router_data.request.payment_method_data.as_ref();+ let payment_method = payment_method_data+ .zip(payment_method_type)+ .map(|(payment_method_data, payment_method_type)| {unified_connector_service::build_unified_connector_service_payment_method(- payment_method_data,- common_enums::PaymentMethodType::Credit, // Default to Credit for now+ payment_method_data.clone(),+ payment_method_type,)}).transpose()?;let address = payments_grpc::PaymentAddress::foreign_try_from(router_data.address.clone())?;-+ let merchant_account_metadata = router_data+ .connector_meta_data+ .as_ref()+ .and_then(|val| val.peek().as_object())+ .map(|map| {+ map.iter()+ .filter_map(|(k, v)| v.as_str().map(|s| (k.clone(), s.to_string())))+ .collect::<HashMap<String, String>>()+ })+ .unwrap_or_default();Ok(Self {request_ref_id: Some(Identifier {id_type: Some(payments_grpc::identifier::IdType::Id(@@ -204,13 +213,22 @@ impl.clone().map(|e| e.expose().expose().into()),- customer_name: None, // PaymentsAuthenticateData doesn't have customer_name+ customer_name: None,address: Some(address),- authentication_data: None, // PaymentsAuthenticateData doesn't have enrolled_for_3ds- metadata: HashMap::new(), // PaymentsAuthenticateData doesn't have metadata- return_url: None, // PaymentsAuthenticateData doesn't have router_return_url+ authentication_data: None,+ metadata: HashMap::new(),+ return_url: None,continue_redirection_url: router_data.request.complete_authorize_url.clone(),state: None,+ redirection_response: router_data+ .request+ .redirect_response+ .clone()+ .map(|redirection_response| {+ payments_grpc::RedirectionResponse::foreign_try_from(redirection_response)+ })+ .transpose()?,+ merchant_account_metadata,browser_info: router_data.request.browser_info@@ -238,13 +256,32 @@ implPaymentsResponseData,>,) -> Result<Self, Self::Error> {- // Based on the pattern from PaymentServicePreAuthenticateRequestlet currency = payments_grpc::Currency::foreign_try_from(router_data.request.currency.unwrap_or_default(),)?;let address = payments_grpc::PaymentAddress::foreign_try_from(router_data.address.clone())?;-+ let payment_method_type = router_data.request.payment_method_type;+ let payment_method_data = router_data.request.payment_method_data.as_ref();+ let payment_method = payment_method_data+ .zip(payment_method_type)+ .map(|(payment_method_data, payment_method_type)| {+ unified_connector_service::build_unified_connector_service_payment_method(+ payment_method_data.clone(),+ payment_method_type,+ )+ })+ .transpose()?;+ let merchant_account_metadata = router_data+ .connector_meta_data+ .as_ref()+ .and_then(|val| val.peek().as_object())+ .map(|map| {+ map.iter()+ .filter_map(|(k, v)| v.as_str().map(|s| (k.clone(), s.to_string())))+ .collect::<HashMap<String, String>>()+ })+ .unwrap_or_default();Ok(Self {request_ref_id: Some(Identifier {id_type: Some(payments_grpc::identifier::IdType::Id(@@ -258,19 +295,28 @@ impl.minor_amount.map(|amount| amount.get_amount_as_i64()).unwrap_or(0),- payment_method: None,+ payment_method,email: router_data.request.clone().map(|e| e.expose().expose().into()),- customer_name: None, // PaymentsPostAuthenticateData doesn't have customer_name+ customer_name: None,address: Some(address),authentication_data: None,metadata: HashMap::new(),return_url: None,continue_redirection_url: None,state: None,+ merchant_account_metadata,+ redirection_response: router_data+ .request+ .redirect_response+ .clone()+ .map(|redirection_response| {+ payments_grpc::RedirectionResponse::foreign_try_from(redirection_response)+ })+ .transpose()?,browser_info: router_data.request.browser_info@@ -314,18 +360,17 @@ impl.transpose()?;let address = payments_grpc::PaymentAddress::foreign_try_from(router_data.address.clone())?;- let connector_metadata_string = router_data+ let merchant_account_metadata = router_data.connector_meta_data.as_ref()- .map(|metadata| metadata.encode_to_string_of_json())- .transpose()- .change_context(- UnifiedConnectorServiceError::RequestEncodingFailedWithReason(- "Failed to serialize router_data.connector_meta_data to string of json"- .to_string(),- ),- )?;- let mut metadata = router_data+ .and_then(|val| val.peek().as_object())+ .map(|map| {+ map.iter()+ .filter_map(|(k, v)| v.as_str().map(|s| (k.clone(), s.to_string())))+ .collect::<HashMap<String, String>>()+ })+ .unwrap_or_default();+ let metadata = router_data.request.metadata.as_ref()@@ -336,10 +381,6 @@ impl.collect::<HashMap<String, String>>()}).unwrap_or_default();- metadata.extend(- connector_metadata_string- .map(|connector_metadata| ("connector_meta_data".to_string(), connector_metadata)),- );Ok(Self {request_ref_id: Some(Identifier {id_type: Some(payments_grpc::identifier::IdType::Id(@@ -366,6 +407,7 @@ implreturn_url: router_data.request.router_return_url.clone(),continue_redirection_url: router_data.request.complete_authorize_url.clone(),state: None,+ merchant_account_metadata,browser_info: router_data.request.browser_info@@ -441,6 +483,144 @@ impl transformers::ForeignTryFrom<&RouterData<Capture, PaymentsCaptureData, Paym}}+impl+ transformers::ForeignTryFrom<+ &RouterData<+ api::CompleteAuthorize,+ crate::types::CompleteAuthorizeData,+ PaymentsResponseData,+ >,+ > for payments_grpc::PaymentServiceAuthorizeRequest+{+ type Error = error_stack::Report<UnifiedConnectorServiceError>;++ fn foreign_try_from(+ router_data: &RouterData<+ api::CompleteAuthorize,+ crate::types::CompleteAuthorizeData,+ PaymentsResponseData,+ >,+ ) -> Result<Self, Self::Error> {+ let currency = payments_grpc::Currency::foreign_try_from(router_data.request.currency)?;++ let payment_method_type = router_data.request.payment_method_type;+ let payment_method_data = router_data.request.payment_method_data.as_ref();+ let payment_method = payment_method_data+ .zip(payment_method_type)+ .map(|(payment_method_data, payment_method_type)| {+ unified_connector_service::build_unified_connector_service_payment_method(+ payment_method_data.clone(),+ payment_method_type,+ )+ })+ .transpose()?;++ let address = payments_grpc::PaymentAddress::foreign_try_from(router_data.address.clone())?;++ let auth_type =+ payments_grpc::AuthenticationType::foreign_try_from(AuthenticationType::NoThreeDs)?;++ let browser_info = router_data+ .request+ .browser_info+ .clone()+ .map(payments_grpc::BrowserInformation::foreign_try_from)+ .transpose()?;++ let capture_method = router_data+ .request+ .capture_method+ .map(payments_grpc::CaptureMethod::foreign_try_from)+ .transpose()?;++ let merchant_account_metadata = router_data+ .connector_meta_data+ .as_ref()+ .and_then(|val| val.peek().as_object())+ .map(|map| {+ map.iter()+ .filter_map(|(k, v)| v.as_str().map(|s| (k.clone(), s.to_string())))+ .collect::<HashMap<String, String>>()+ })+ .unwrap_or_default();+ let metadata = router_data+ .request+ .metadata+ .as_ref()+ .and_then(|val| val.as_object())+ .map(|map| {+ map.iter()+ .filter_map(|(k, v)| v.as_str().map(|s| (k.clone(), s.to_string())))+ .collect::<HashMap<String, String>>()+ })+ .unwrap_or_default();+ let authentication_data = router_data+ .request+ .authentication_data+ .clone()+ .map(payments_grpc::AuthenticationData::foreign_try_from)+ .transpose()?;++ Ok(Self {+ amount: router_data.request.amount,+ currency: currency.into(),+ payment_method,+ return_url: router_data.request.complete_authorize_url.clone(),+ address: Some(address),+ auth_type: auth_type.into(),+ enrolled_for_3ds: false,+ request_incremental_authorization: false,+ minor_amount: router_data.request.minor_amount.get_amount_as_i64(),+ email: router_data+ .request+ .clone()+ .map(|e| e.expose().expose().into()),+ browser_info,+ session_token: None,+ order_tax_amount: None,+ customer_name: None,+ capture_method: capture_method.map(|capture_method| capture_method.into()),+ webhook_url: None, // CompleteAuthorize doesn't have webhook_url+ complete_authorize_url: router_data.request.complete_authorize_url.clone(),+ setup_future_usage: router_data+ .request+ .setup_future_usage+ .map(payments_grpc::FutureUsage::foreign_try_from)+ .transpose()?+ .map(|s| s.into()),+ off_session: router_data.request.off_session,+ customer_acceptance: router_data+ .request+ .customer_acceptance+ .clone()+ .map(payments_grpc::CustomerAcceptance::foreign_try_from)+ .transpose()?,+ order_category: None,+ payment_experience: None,+ authentication_data,+ request_extended_authorization: None,+ merchant_order_reference_id: None,+ shipping_cost: None,+ request_ref_id: Some(Identifier {+ id_type: Some(payments_grpc::identifier::IdType::Id(+ router_data.connector_request_reference_id.clone(),+ )),+ }),+ customer_id: None,+ metadata,+ test_mode: router_data.test_mode,+ connector_customer_id: router_data.connector_customer.clone(),+ merchant_account_metadata,+ state: None,+ description: None,+ setup_mandate_details: None,+ statement_descriptor_name: None,+ statement_descriptor_suffix: None,+ })+ }+}+impltransformers::ForeignTryFrom<&RouterData<Authorize, PaymentsAuthorizeData, PaymentsResponseData>,@@ -487,18 +667,17 @@ impl.clone().map(payments_grpc::AuthenticationData::foreign_try_from).transpose()?;- let connector_metadata_string = router_data+ let merchant_account_metadata = router_data.connector_meta_data.as_ref()- .map(|metadata| metadata.encode_to_string_of_json())- .transpose()- .change_context(- UnifiedConnectorServiceError::RequestEncodingFailedWithReason(- "Failed to serialize router_data.connector_meta_data to string of json"- .to_string(),- ),- )?;- let mut metadata = router_data+ .and_then(|val| val.peek().as_object())+ .map(|map| {+ map.iter()+ .filter_map(|(k, v)| v.as_str().map(|s| (k.clone(), s.to_string())))+ .collect::<HashMap<String, String>>()+ })+ .unwrap_or_default();+ let metadata = router_data.request.metadata.as_ref()@@ -509,10 +688,6 @@ impl.collect::<HashMap<String, String>>()}).unwrap_or_default();- metadata.extend(- connector_metadata_string- .map(|connector_metadata| ("connector_meta_data".to_string(), connector_metadata)),- );let setup_future_usage = router_data.request.setup_future_usage@@ -549,6 +724,7 @@ impl.clone().map(|e| e.expose().expose().into()),browser_info,+session_token: None,order_tax_amount: router_data.request@@ -588,19 +764,14 @@ impl.as_ref().map(|id| id.get_string_repr().to_string()),metadata,- merchant_account_metadata: router_data- .connector_meta_data- .as_ref()- .and_then(|meta| meta.peek().as_object())- .map(|map| {- map.iter()- .filter_map(|(k, v)| v.as_str().map(|s| (k.clone(), s.to_string())))- .collect::<HashMap<String, String>>()- })- .unwrap_or_default(),test_mode: router_data.test_mode,connector_customer_id: router_data.connector_customer.clone(),state,+ merchant_account_metadata,+ description: None,+ setup_mandate_details: None,+ statement_descriptor_name: None,+ statement_descriptor_suffix: None,})}}@@ -687,6 +858,7 @@ impl.clone().map(|e| e.expose().expose().into()),browser_info,+session_token: None,order_tax_amount: router_data.request@@ -755,6 +927,10 @@ impltest_mode: router_data.test_mode,connector_customer_id: router_data.connector_customer.clone(),state: None,+ description: None,+ setup_mandate_details: None,+ statement_descriptor_name: None,+ statement_descriptor_suffix: None,})}}@@ -848,6 +1024,7 @@ implreturn_url: router_data.request.router_return_url.clone(),webhook_url: router_data.request.webhook_url.clone(),complete_authorize_url: router_data.request.complete_authorize_url.clone(),+session_token: None,order_tax_amount: None,order_category: None,@@ -975,6 +1152,12 @@ impltest_mode: router_data.test_mode,payment_method_type: None,state,+ return_url: None,+ description: None,+ connector_customer_id: None,+ address: None,+ off_session: None,+ recurring_mandate_payment_data: None,})}}@@ -1641,6 +1824,35 @@ impl transformers::ForeignTryFrom<AuthenticationType> for payments_grpc::Authent}}+impl transformers::ForeignTryFrom<router_request_types::CompleteAuthorizeRedirectResponse>+ for payments_grpc::RedirectionResponse+{+ type Error = error_stack::Report<UnifiedConnectorServiceError>;++ fn foreign_try_from(+ domain_redirect_response: router_request_types::CompleteAuthorizeRedirectResponse,+ ) -> Result<Self, Self::Error> {+ Ok(Self {+ params: domain_redirect_response+ .params+ .map(|params| params.expose()),+ payload: domain_redirect_response+ .payload+ .as_ref()+ .and_then(|val| {+ let exposed_val = val.clone().expose();+ exposed_val.as_object().cloned()+ })+ .map(|map| {+ map.into_iter()+ .filter_map(|(k, v)| v.as_str().map(|s| (k, s.to_string())))+ .collect::<HashMap<String, String>>()+ })+ .unwrap_or_default(),+ })+ }+}+impl transformers::ForeignTryFrom<router_request_types::BrowserInformation>for payments_grpc::BrowserInformation{@@ -1689,14 +1901,51 @@ impl transformers::ForeignTryFrom<AuthenticationData> for payments_grpc::Authentfn foreign_try_from(authentication_data: AuthenticationData) -> Result<Self, Self::Error> {Ok(Self {eci: authentication_data.eci,- cavv: authentication_data.cavv.peek().to_string(),+ cavv: Some(authentication_data.cavv.expose()),threeds_server_transaction_id: authentication_data.threeds_server_transaction_id.map(|id| Identifier {id_type: Some(payments_grpc::identifier::IdType::Id(id)),},),- message_version: None,+ message_version: authentication_data+ .message_version+ .map(|message_version| message_version.to_string()),ds_transaction_id: authentication_data.ds_trans_id,+ trans_status: None,+ acs_transaction_id: authentication_data.acs_trans_id,+ transaction_id: None,+ ucaf_collection_indicator: None,+ })+ }+}++impl transformers::ForeignTryFrom<router_request_types::UcsAuthenticationData>+ for payments_grpc::AuthenticationData+{+ type Error = error_stack::Report<UnifiedConnectorServiceError>;++ fn foreign_try_from(+ authentication_data: router_request_types::UcsAuthenticationData,+ ) -> Result<Self, Self::Error> {+ Ok(Self {+ eci: authentication_data.eci,+ cavv: authentication_data.cavv.map(ExposeInterface::expose),+ threeds_server_transaction_id: authentication_data.threeds_server_transaction_id.map(+ |id| Identifier {+ id_type: Some(payments_grpc::identifier::IdType::Id(id)),+ },+ ),+ message_version: authentication_data+ .message_version+ .map(|message_version| message_version.to_string()),+ ds_transaction_id: authentication_data.ds_trans_id,+ trans_status: authentication_data+ .trans_status+ .map(payments_grpc::TransactionStatus::foreign_from)+ .map(i32::from),+ acs_transaction_id: authentication_data.acs_trans_id,+ transaction_id: authentication_data.transaction_id,+ ucaf_collection_indicator: authentication_data.ucaf_collection_indicator,})}}@@ -1864,6 +2113,94 @@ impl transformers::ForeignTryFrom<payments_grpc::PaymentServicePostAuthenticateR}}+impl transformers::ForeignTryFrom<payments_grpc::AuthenticationData>+ for router_request_types::UcsAuthenticationData+{+ type Error = error_stack::Report<UnifiedConnectorServiceError>;+ fn foreign_try_from(response: payments_grpc::AuthenticationData) -> Result<Self, Self::Error> {+ let payments_grpc::AuthenticationData {+ eci,+ cavv,+ threeds_server_transaction_id,+ message_version,+ ds_transaction_id,+ trans_status,+ acs_transaction_id,+ transaction_id,+ ucaf_collection_indicator,+ } = response;+ let trans_status = trans_status+ .map(payments_grpc::TransactionStatus::try_from)+ .transpose()+ .change_context(UnifiedConnectorServiceError::ResponseDeserializationFailed)+ .attach_printable("Failed to convert TransactionStatus from grpc to domain")?+ .map(ForeignFrom::foreign_from);+ Ok(Self {+ trans_status,+ eci,+ cavv: cavv.map(masking::Secret::new),+ threeds_server_transaction_id: threeds_server_transaction_id+ .and_then(|id| id.id_type)+ .and_then(|id_type| match id_type {+ payments_grpc::identifier::IdType::Id(id) => Some(id),+ payments_grpc::identifier::IdType::EncodedData(encoded_data) => {+ Some(encoded_data)+ }+ payments_grpc::identifier::IdType::NoResponseIdMarker(_) => None,+ }),+ message_version: message_version+ .map(|message_version_str| {+ types::SemanticVersion::from_str(message_version_str.as_ref())+ .change_context(UnifiedConnectorServiceError::ResponseDeserializationFailed)+ .attach_printable("Failed to Deserialize message_version")+ })+ .transpose()?,+ ds_trans_id: ds_transaction_id,+ acs_trans_id: acs_transaction_id,+ transaction_id,+ ucaf_collection_indicator,+ })+ }+}++impl ForeignFrom<payments_grpc::TransactionStatus> for common_enums::TransactionStatus {+ fn foreign_from(value: payments_grpc::TransactionStatus) -> Self {+ match value {+ payments_grpc::TransactionStatus::Success => Self::Success,+ payments_grpc::TransactionStatus::Failure => Self::Failure,+ payments_grpc::TransactionStatus::VerificationNotPerformed => {+ Self::VerificationNotPerformed+ }+ payments_grpc::TransactionStatus::NotVerified => Self::NotVerified,+ payments_grpc::TransactionStatus::Rejected => Self::Rejected,+ payments_grpc::TransactionStatus::ChallengeRequired => Self::ChallengeRequired,+ payments_grpc::TransactionStatus::ChallengeRequiredDecoupledAuthentication => {+ Self::ChallengeRequiredDecoupledAuthentication+ }+ payments_grpc::TransactionStatus::InformationOnly => Self::InformationOnly,+ }+ }+}++impl ForeignFrom<common_enums::TransactionStatus> for payments_grpc::TransactionStatus {+ fn foreign_from(value: common_enums::TransactionStatus) -> Self {+ match value {+ common_enums::TransactionStatus::Success => Self::Success,+ common_enums::TransactionStatus::Failure => Self::Failure,+ common_enums::TransactionStatus::VerificationNotPerformed => {+ Self::VerificationNotPerformed+ }+ common_enums::TransactionStatus::NotVerified => Self::NotVerified,+ common_enums::TransactionStatus::Rejected => Self::Rejected,+ common_enums::TransactionStatus::ChallengeRequired => Self::ChallengeRequired,+ common_enums::TransactionStatus::ChallengeRequiredDecoupledAuthentication => {+ Self::ChallengeRequiredDecoupledAuthentication+ }+ common_enums::TransactionStatus::InformationOnly => Self::InformationOnly,+ }+ }+}+impl transformers::ForeignTryFrom<payments_grpc::PaymentServiceAuthenticateResponse>for Result<(PaymentsResponseData, AttemptStatus), ErrorResponse>{