Skip to content

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

feat(core): Implement ucs granular setup mandate flow (#10383)

Hrithikeshe005913f643d
diff --git a/Cargo.lock b/Cargo.lock
index 894d170a7a..ac52cc6cf3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3789,7 +3789,7 @@ dependencies = [
[[package]]
name = "grpc-api-types"
version = "0.1.0"
-source = "git+https://github.com/juspay/connector-service?rev=8edf9f744597c4f8712550a060a2bc1700c174d9#8edf9f744597c4f8712550a060a2bc1700c174d9"
+source = "git+https://github.com/juspay/connector-service?rev=b5a367c1c775c32503feb00cdc6cd063cc97ea3b#b5a367c1c775c32503feb00cdc6cd063cc97ea3b"
dependencies = [
"axum 0.8.4",
"error-stack 0.5.0",
@@ -7427,7 +7427,7 @@ dependencies = [
[[package]]
name = "rust-grpc-client"
version = "0.1.0"
-source = "git+https://github.com/juspay/connector-service?rev=8edf9f744597c4f8712550a060a2bc1700c174d9#8edf9f744597c4f8712550a060a2bc1700c174d9"
+source = "git+https://github.com/juspay/connector-service?rev=b5a367c1c775c32503feb00cdc6cd063cc97ea3b#b5a367c1c775c32503feb00cdc6cd063cc97ea3b"
dependencies = [
"grpc-api-types",
]
@@ -10217,7 +10217,7 @@ checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9"
[[package]]
name = "ucs_cards"
version = "0.1.0"
-source = "git+https://github.com/juspay/connector-service?rev=8edf9f744597c4f8712550a060a2bc1700c174d9#8edf9f744597c4f8712550a060a2bc1700c174d9"
+source = "git+https://github.com/juspay/connector-service?rev=b5a367c1c775c32503feb00cdc6cd063cc97ea3b#b5a367c1c775c32503feb00cdc6cd063cc97ea3b"
dependencies = [
"bytes 1.10.1",
"error-stack 0.4.1",
@@ -10233,7 +10233,7 @@ dependencies = [
[[package]]
name = "ucs_common_enums"
version = "0.1.0"
-source = "git+https://github.com/juspay/connector-service?rev=8edf9f744597c4f8712550a060a2bc1700c174d9#8edf9f744597c4f8712550a060a2bc1700c174d9"
+source = "git+https://github.com/juspay/connector-service?rev=b5a367c1c775c32503feb00cdc6cd063cc97ea3b#b5a367c1c775c32503feb00cdc6cd063cc97ea3b"
dependencies = [
"serde",
"strum 0.26.3",
@@ -10244,7 +10244,7 @@ dependencies = [
[[package]]
name = "ucs_common_utils"
version = "0.1.0"
-source = "git+https://github.com/juspay/connector-service?rev=8edf9f744597c4f8712550a060a2bc1700c174d9#8edf9f744597c4f8712550a060a2bc1700c174d9"
+source = "git+https://github.com/juspay/connector-service?rev=b5a367c1c775c32503feb00cdc6cd063cc97ea3b#b5a367c1c775c32503feb00cdc6cd063cc97ea3b"
dependencies = [
"anyhow",
"base64 0.21.7",
diff --git a/crates/external_services/Cargo.toml b/crates/external_services/Cargo.toml
index d99c6771a7..67d9263477 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 = "8edf9f744597c4f8712550a060a2bc1700c174d9", package = "rust-grpc-client" }
+unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "b5a367c1c775c32503feb00cdc6cd063cc97ea3b", 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.rs
index 34353d48b9..9a6098d9a3 100644
--- a/crates/external_services/src/grpc_client/unified_connector_service.rs
+++ b/crates/external_services/src/grpc_client/unified_connector_service.rs
@@ -429,6 +429,36 @@ impl UnifiedConnectorServiceClient {
})
}
+ /// Performs Payment Setup Mandate
+ pub async fn payment_setup_mandate_granular(
+ &self,
+ payment_register_request: payments_grpc::PaymentServiceRegisterRequest,
+ connector_auth_metadata: ConnectorAuthMetadata,
+ grpc_headers: GrpcHeadersUcs,
+ ) -> UnifiedConnectorServiceResult<tonic::Response<payments_grpc::PaymentServiceRegisterResponse>>
+ {
+ let mut request = tonic::Request::new(payment_register_request);
+
+ let connector_name = connector_auth_metadata.connector_name.clone();
+ let metadata =
+ build_unified_connector_service_grpc_headers(connector_auth_metadata, grpc_headers)?;
+ *request.metadata_mut() = metadata;
+
+ self.client
+ .clone()
+ .register_only(request)
+ .await
+ .change_context(UnifiedConnectorServiceError::PaymentRegisterFailure)
+ .inspect_err(|error| {
+ logger::error!(
+ grpc_error=?error,
+ method="payment_setup_mandate_granular",
+ connector_name=?connector_name,
+ "UCS payment granular setup mandate gRPC call failed"
+ )
+ })
+ }
+
/// Performs Payment repeat (MIT - Merchant Initiated Transaction).
pub async fn payment_repeat(
&self,
diff --git a/crates/hyperswitch_interfaces/Cargo.toml b/crates/hyperswitch_interfaces/Cargo.toml
index ad62e10fc2..453fceee7d 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 = "8edf9f744597c4f8712550a060a2bc1700c174d9", package = "rust-grpc-client" }
+unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "b5a367c1c775c32503feb00cdc6cd063cc97ea3b", package = "rust-grpc-client" }
unified-connector-service-masking = { git = "https://github.com/juspay/hyperswitch", tag = "2025.09.24.0", package = "masking" }
tokio = { version = "1.45.1", features = ["macros", "rt-multi-thread"] }
# First party crates
diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.toml
index 112f3b4389..71cb0f54bf 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", "mult
ring = "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 = "8edf9f744597c4f8712550a060a2bc1700c174d9", package = "rust-grpc-client" }
-unified-connector-service-cards = { git = "https://github.com/juspay/connector-service", rev = "8edf9f744597c4f8712550a060a2bc1700c174d9", package = "ucs_cards" }
+unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "b5a367c1c775c32503feb00cdc6cd063cc97ea3b", package = "rust-grpc-client" }
+unified-connector-service-cards = { git = "https://github.com/juspay/connector-service", rev = "b5a367c1c775c32503feb00cdc6cd063cc97ea3b", 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/gateway/setup_mandate.rs b/crates/router/src/core/payments/gateway/setup_mandate.rs
new file mode 100644
index 0000000000..45d5f8aed5
--- /dev/null
+++ b/crates/router/src/core/payments/gateway/setup_mandate.rs
@@ -0,0 +1,201 @@
+use std::str::FromStr;
+
+use async_trait::async_trait;
+use common_enums::{CallConnectorAction, ExecutionPath};
+use common_utils::{errors::CustomResult, id_type, request::Request, ucs_types};
+use error_stack::ResultExt;
+use hyperswitch_domain_models::{router_data::RouterData, router_flow_types as domain};
+use hyperswitch_interfaces::{
+ api::gateway as payment_gateway,
+ connector_integration_interface::{BoxedConnectorIntegrationInterface, RouterDataConversion},
+ errors::ConnectorError,
+};
+use unified_connector_service_client::payments as payments_grpc;
+use unified_connector_service_masking::ExposeInterface as UcsMaskingExposeInterface;
+
+use crate::{
+ core::{
+ payments::gateway::context::RouterGatewayContext, unified_connector_service,
+ unified_connector_service::handle_unified_connector_service_response_for_payment_authorize,
+ },
+ routes::SessionState,
+ services::logger,
+ types::{self, transformers::ForeignTryFrom, MinorUnit},
+};
+
+// =============================================================================
+// PaymentGateway Implementation for domain::SetupMandate
+// =============================================================================
+
+/// Implementation of PaymentGateway for api::PSync flow
+#[async_trait]
+impl<RCD>
+ payment_gateway::PaymentGateway<
+ SessionState,
+ RCD,
+ Self,
+ types::SetupMandateRequestData,
+ types::PaymentsResponseData,
+ RouterGatewayContext,
+ > for domain::SetupMandate
+where
+ RCD: Clone
+ + Send
+ + Sync
+ + 'static
+ + RouterDataConversion<Self, types::SetupMandateRequestData, types::PaymentsResponseData>,
+{
+ async fn execute(
+ self: Box<Self>,
+ state: &SessionState,
+ _connector_integration: BoxedConnectorIntegrationInterface<
+ Self,
+ RCD,
+ types::SetupMandateRequestData,
+ types::PaymentsResponseData,
+ >,
+ router_data: &RouterData<Self, types::SetupMandateRequestData, types::PaymentsResponseData>,
+ call_connector_action: CallConnectorAction,
+ _connector_request: Option<Request>,
+ _return_raw_connector_response: Option<bool>,
+ context: RouterGatewayContext,
+ ) -> CustomResult<
+ RouterData<Self, types::SetupMandateRequestData, types::PaymentsResponseData>,
+ ConnectorError,
+ > {
+ let merchant_connector_account = context.merchant_connector_account;
+ let platform = context.platform;
+ let lineage_ids = context.lineage_ids;
+ let header_payload = context.header_payload;
+ let unified_connector_service_execution_mode = context.execution_mode;
+ let merchant_order_reference_id = header_payload.x_reference_id.clone();
+ let client = state
+ .grpc_client
+ .unified_connector_service_client
+ .clone()
+ .ok_or(ConnectorError::RequestEncodingFailed)
+ .attach_printable("Failed to fetch Unified Connector Service client")?;
+
+ let setup_mandate_request =
+ payments_grpc::PaymentServiceAuthorizeOnlyRequest::foreign_try_from((
+ router_data,
+ call_connector_action,
+ ))
+ .change_context(ConnectorError::RequestEncodingFailed)
+ .attach_printable("Failed to construct Payment Get Request")?;
+
+ let connector_auth_metadata =
+ unified_connector_service::build_unified_connector_service_auth_metadata(
+ merchant_connector_account,
+ &platform,
+ )
+ .change_context(ConnectorError::RequestEncodingFailed)
+ .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 header_payload = 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(unified_connector_service::ucs_logging_wrapper_new(
+ router_data.clone(),
+ state,
+ setup_mandate_request,
+ header_payload,
+ |mut router_data, setup_mandate_request, grpc_headers| async move {
+ let response = Box::pin(client.payment_setup_mandate_granular(
+ setup_mandate_request,
+ connector_auth_metadata,
+ grpc_headers,
+ ))
+ .await
+ .attach_printable("Failed to get payment")?;
+
+ let setup_mandate_response = response.into_inner();
+
+ let ucs_data = handle_unified_connector_service_response_for_payment_authorize(
+ setup_mandate_response.clone(),
+ )
+ .attach_printable("Failed to deserialize UCS response")?;
+
+ let router_data_response =
+ ucs_data.router_data_response.map(|(response, status)| {
+ router_data.status = status;
+ response
+ });
+ router_data.response = router_data_response;
+ router_data.amount_captured = setup_mandate_response.captured_amount;
+ router_data.minor_amount_captured = setup_mandate_response
+ .minor_captured_amount
+ .map(MinorUnit::new);
+ router_data.raw_connector_response = setup_mandate_response
+ .raw_connector_response
+ .clone()
+ .map(|raw_connector_response| raw_connector_response.expose().into());
+ router_data.connector_http_status_code = Some(ucs_data.status_code);
+
+ // Populate connector_customer_id if present
+ ucs_data.connector_customer_id.map(|connector_customer_id| {
+ router_data.connector_customer = Some(connector_customer_id);
+ });
+
+ ucs_data.connector_response.map(|customer_response| {
+ router_data.connector_response = Some(customer_response);
+ });
+
+ Ok((router_data, setup_mandate_response))
+ },
+ ))
+ .await
+ .change_context(ConnectorError::ResponseHandlingFailed)?;
+
+ Ok(updated_router_data)
+ }
+}
+
+/// Implementation of FlowGateway for api::PSync
+///
+/// This allows the flow to provide its specific gateway based on execution path
+impl<RCD>
+ payment_gateway::FlowGateway<
+ SessionState,
+ RCD,
+ types::SetupMandateRequestData,
+ types::PaymentsResponseData,
+ RouterGatewayContext,
+ > for domain::SetupMandate
+where
+ RCD: Clone
+ + Send
+ + Sync
+ + 'static
+ + RouterDataConversion<Self, types::SetupMandateRequestData, types::PaymentsResponseData>,
+{
+ fn get_gateway(
+ execution_path: ExecutionPath,
+ ) -> Box<
+ dyn payment_gateway::PaymentGateway<
+ SessionState,
+ RCD,
+ Self,
+ types::SetupMandateRequestData,
+ types::PaymentsResponseData,
+ RouterGatewayContext,
+ >,
+ > {
+ match execution_path {
+ ExecutionPath::Direct => Box::new(payment_gateway::DirectGateway),
+ ExecutionPath::UnifiedConnectorService
+ | ExecutionPath::ShadowUnifiedConnectorService => Box::new(Self),
+ }
+ }
+}
diff --git a/crates/router/src/core/unified_connector_service.rs b/crates/router/src/core/unified_connector_service.rs
index 10ffba1b65..8c70b65eb7 100644
--- a/crates/router/src/core/unified_connector_service.rs
+++ b/crates/router/src/core/unified_connector_service.rs
@@ -943,7 +943,6 @@ pub fn build_unified_connector_service_payment_method_for_external_proxy(
nick_name: external_vault_card.nick_name.map(|n| n.expose()),
card_issuing_country_alpha2: external_vault_card.card_issuing_country.clone(),
};
-
Ok(payments_grpc::PaymentMethod {
payment_method: Some(PaymentMethod::CardProxy(card_details)),
})