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

chore: Added Resource ID header for UCS requests HS<>UCS (#11088)

Amitsingh Tanwar1a0537926d0a
diff --git a/crates/common_utils/src/id_type.rs b/crates/common_utils/src/id_type.rs
index ce5826dcbe..1f54b8cd09 100644
--- a/crates/common_utils/src/id_type.rs
+++ b/crates/common_utils/src/id_type.rs
@@ -53,7 +53,7 @@ pub use self::{
merchant::MerchantId,
merchant_connector_account::MerchantConnectorAccountId,
organization::OrganizationId,
- payment::{PaymentId, PaymentReferenceId},
+ payment::{PaymentId, PaymentReferenceId, PaymentResourceId},
profile::ProfileId,
profile_acquirer::ProfileAcquirerId,
refunds::RefundReferenceId,
diff --git a/crates/common_utils/src/id_type/payment.rs b/crates/common_utils/src/id_type/payment.rs
index 611f59bb04..33cd41102c 100644
--- a/crates/common_utils/src/id_type/payment.rs
+++ b/crates/common_utils/src/id_type/payment.rs
@@ -79,6 +79,17 @@ crate::impl_try_from_cow_str_id_type!(PaymentReferenceId, "payment_reference_id"
crate::impl_queryable_id_type!(PaymentReferenceId);
crate::impl_to_sql_from_sql_id_type!(PaymentReferenceId);
+crate::id_type!(PaymentResourceId, "A type for payment_resource_id");
+crate::impl_id_type_methods!(PaymentResourceId, "payment_resource_id");
+
+// This is to display the `PaymentResourceId` as PaymentResourceId(abcd)
+crate::impl_debug_id_type!(PaymentResourceId);
+crate::impl_try_from_cow_str_id_type!(PaymentResourceId, "payment_resource_id");
+
+// Database related implementations so that this field can be used directly in the database tables
+crate::impl_queryable_id_type!(PaymentResourceId);
+crate::impl_to_sql_from_sql_id_type!(PaymentResourceId);
+
// This is implemented so that we can use payment id directly as attribute in metrics
#[cfg(feature = "metrics")]
impl From<PaymentId> for router_env::opentelemetry::Value {
@@ -95,3 +106,12 @@ impl std::str::FromStr for PaymentReferenceId {
Self::try_from(cow_string)
}
}
+
+impl std::str::FromStr for PaymentResourceId {
+ type Err = error_stack::Report<ValidationError>;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ let cow_string = std::borrow::Cow::Owned(s.to_string());
+ Self::try_from(cow_string)
+ }
+}
diff --git a/crates/common_utils/src/ucs_types.rs b/crates/common_utils/src/ucs_types.rs
index 25809819f5..7af39e2e3f 100644
--- a/crates/common_utils/src/ucs_types.rs
+++ b/crates/common_utils/src/ucs_types.rs
@@ -12,11 +12,6 @@ pub enum UcsReferenceId {
/// This variant wraps a [`PaymentReferenceId`](id_type::PaymentReferenceId)
/// and is used to identify a payment transaction within the UCS.
Payment(id_type::PaymentReferenceId),
- /// A refund reference ID.
- ///
- /// This variant wraps a [`RefundReferenceId`](id_type::RefundReferenceId)
- /// and is used to identify a refund transaction within the UCS.
- Refund(id_type::RefundReferenceId),
}
impl UcsReferenceId {
@@ -32,6 +27,42 @@ impl UcsReferenceId {
pub fn get_string_repr(&self) -> &str {
match self {
Self::Payment(id) => id.get_string_repr(),
+ }
+ }
+}
+
+/// Represents a resource ID for the Unified Connector Service (UCS).
+///
+/// This enum can hold either a payment resource ID or a refund resource ID,
+/// allowing for a unified way to handle different types of transaction resources
+/// when interacting with the UCS.
+#[derive(Debug)]
+pub enum UcsResourceId {
+ /// A payment resource ID.
+ ///
+ /// This variant wraps a [`PaymentResourceId`](id_type::PaymentResourceId)
+ /// and is used to identify a payment transaction within the UCS.
+ PaymentAttempt(id_type::PaymentResourceId),
+ /// A refund resource ID.
+ ///
+ /// This variant wraps a [`RefundResourceId`](id_type::RefundResourceId)
+ /// and is used to identify a refund transaction within the UCS.
+ Refund(id_type::RefundReferenceId),
+}
+
+impl UcsResourceId {
+ /// Returns the string representation of the resource ID.
+ ///
+ /// This method matches the enum variant and calls the `get_string_repr`
+ /// method of the underlying ID type (either `PaymentResourceId` or `RefundResourceId`)
+ /// to get its string representation.
+ ///
+ /// # Returns
+ ///
+ /// A string slice (`&str`) representing the resource ID.
+ pub fn get_string_repr(&self) -> &str {
+ match self {
+ Self::PaymentAttempt(id) => id.get_string_repr(),
Self::Refund(id) => id.get_string_repr(),
}
}
diff --git a/crates/external_services/src/grpc_client.rs b/crates/external_services/src/grpc_client.rs
index 70ded8df6f..6ee19fffe3 100644
--- a/crates/external_services/src/grpc_client.rs
+++ b/crates/external_services/src/grpc_client.rs
@@ -164,6 +164,8 @@ pub struct GrpcHeadersUcs {
external_vault_proxy_metadata: Option<String>,
/// Merchant Reference Id
merchant_reference_id: Option<ucs_types::UcsReferenceId>,
+ /// Resource id
+ resource_id: Option<ucs_types::UcsResourceId>,
shadow_mode: Option<bool>,
/// Config override as JSON string to pass to UCS
@@ -177,6 +179,7 @@ pub type GrpcHeadersUcsBuilderInitial = GrpcHeadersUcsBuilder<(
(),
(),
(),
+ (),
(Option<bool>,),
(Option<String>,),
)>;
@@ -187,6 +190,7 @@ pub type GrpcHeadersUcsBuilderFinal = GrpcHeadersUcsBuilder<(
(LineageIds,),
(Option<String>,),
(Option<ucs_types::UcsReferenceId>,),
+ (Option<ucs_types::UcsResourceId>,),
(Option<bool>,),
(Option<String>,),
)>;
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 0df62f59b9..bc92d171f2 100644
--- a/crates/external_services/src/grpc_client/unified_connector_service.rs
+++ b/crates/external_services/src/grpc_client/unified_connector_service.rs
@@ -805,6 +805,7 @@ pub fn build_unified_connector_service_grpc_headers(
lineage_ids,
external_vault_proxy_metadata,
merchant_reference_id,
+ resource_id,
shadow_mode,
config_override,
} = grpc_headers;
@@ -887,6 +888,16 @@ pub fn build_unified_connector_service_grpc_headers(
);
};
+ if let Some(resource_id) = resource_id {
+ metadata.append(
+ consts::UCS_HEADER_RESOURCE_ID,
+ parse(
+ consts::UCS_HEADER_RESOURCE_ID,
+ resource_id.get_string_repr(),
+ )?,
+ );
+ };
+
if let Some(ref request_id) = request_id {
metadata.append(
common_utils_consts::X_REQUEST_ID,
diff --git a/crates/external_services/src/lib.rs b/crates/external_services/src/lib.rs
index 5e82b54d48..6fd57efe37 100644
--- a/crates/external_services/src/lib.rs
+++ b/crates/external_services/src/lib.rs
@@ -96,6 +96,9 @@ pub mod consts {
/// Header key for sending the merchant reference id to UCS
pub(crate) const UCS_HEADER_REFERENCE_ID: &str = "x-reference-id";
+
+ /// Header key for sending the resource id to UCS
+ pub(crate) const UCS_HEADER_RESOURCE_ID: &str = "x-resource-id";
}
/// Metrics for interactions with external systems.
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index a3b8bd4555..aff0f06d88 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -5514,13 +5514,6 @@ where
business_profile.get_id().clone(),
);
- // Extract merchant_order_reference_id from payment data for UCS audit trail
- let merchant_order_reference_id = payment_data
- .get_payment_intent()
- .merchant_reference_id
- .clone()
- .map(|id| id.get_string_repr().to_string());
-
router_data
.call_unified_connector_service_with_external_vault_proxy(
state,
@@ -5530,7 +5523,6 @@ where
external_vault_merchant_connector_account_type_details.clone(),
processor,
ExecutionMode::Primary, //UCS is called in primary mode
- merchant_order_reference_id,
)
.await?;
diff --git a/crates/router/src/core/payments/flows.rs b/crates/router/src/core/payments/flows.rs
index 0bbb4c234c..79f06e7bc0 100644
--- a/crates/router/src/core/payments/flows.rs
+++ b/crates/router/src/core/payments/flows.rs
@@ -296,7 +296,6 @@ pub trait Feature<F, T> {
_external_vault_merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,
_processor: &domain::Processor,
_unified_connector_service_execution_mode: common_enums::ExecutionMode,
- _merchant_order_reference_id: Option<String>,
) -> RouterResult<()>
where
F: Clone,
diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs
index e74246ecb8..78cf708459 100644
--- a/crates/router/src/core/payments/flows/authorize_flow.rs
+++ b/crates/router/src/core/payments/flows/authorize_flow.rs
@@ -1418,7 +1418,6 @@ pub async fn call_unified_connector_service_pre_authenticate(
processor: &domain::Processor,
connector: enums::connector_enums::Connector,
unified_connector_service_execution_mode: enums::ExecutionMode,
- merchant_order_reference_id: Option<String>,
) -> errors::CustomResult<
(
types::RouterData<
@@ -1450,20 +1449,24 @@ pub async fn call_unified_connector_service_pre_authenticate(
)
.change_context(interface_errors::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"))
+ let merchant_reference_id = unified_connector_service::parse_merchant_reference_id(
+ header_payload
+ .x_reference_id
+ .as_deref()
+ .unwrap_or(router_data.payment_id.as_str()),
+ )
+ .map(ucs_types::UcsReferenceId::Payment);
+ let resource_id = id_type::PaymentResourceId::from_str(router_data.attempt_id.as_str())
+ .inspect_err(
+ |err| logger::warn!(error=?err, "Invalid Payment AttemptId for UCS resource id"),
+ )
.ok()
- .flatten()
- .map(ucs_types::UcsReferenceId::Payment);
+ .map(ucs_types::UcsResourceId::PaymentAttempt);
let headers_builder = state
.get_grpc_headers_ucs(unified_connector_service_execution_mode)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
+ .resource_id(resource_id)
.lineage_ids(lineage_ids);
Box::pin(unified_connector_service::ucs_logging_wrapper_granular(
router_data.clone(),
diff --git a/crates/router/src/core/payments/flows/complete_authorize_flow.rs b/crates/router/src/core/payments/flows/complete_authorize_flow.rs
index 62e3d2ea7a..d8bac0ca9d 100644
--- a/crates/router/src/core/payments/flows/complete_authorize_flow.rs
+++ b/crates/router/src/core/payments/flows/complete_authorize_flow.rs
@@ -625,7 +625,6 @@ pub async fn call_unified_connector_service_authenticate(
processor: &domain::Processor,
connector: connector_enums::Connector,
unified_connector_service_execution_mode: common_enums::ExecutionMode,
- merchant_order_reference_id: Option<String>,
) -> errors::CustomResult<
types::RouterData<
api::Authenticate,
@@ -653,20 +652,24 @@ pub async fn call_unified_connector_service_authenticate(
)
.change_context(interface_errors::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"))
+ let merchant_reference_id = ucs_core::parse_merchant_reference_id(
+ header_payload
+ .x_reference_id
+ .as_deref()
+ .unwrap_or(router_data.payment_id.as_str()),
+ )
+ .map(ucs_types::UcsReferenceId::Payment);
+ let resource_id = id_type::PaymentResourceId::from_str(router_data.attempt_id.as_str())
+ .inspect_err(
+ |err| logger::warn!(error=?err, "Invalid Payment AttemptId for UCS resource id"),
+ )
.ok()
- .flatten()
- .map(ucs_types::UcsReferenceId::Payment);
+ .map(ucs_types::UcsResourceId::PaymentAttempt);
let headers_builder = state
.get_grpc_headers_ucs(unified_connector_service_execution_mode)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
+ .resource_id(resource_id)
.lineage_ids(lineage_ids);
let (router_data, _) = Box::pin(ucs_core::ucs_logging_wrapper_granular(
router_data.clone(),
@@ -734,7 +737,6 @@ pub async fn call_unified_connector_service_post_authenticate(
#[cfg(feature = "v2")] merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,
processor: &domain::Processor,
unified_connector_service_execution_mode: common_enums::ExecutionMode,
- merchant_order_reference_id: Option<String>,
) -> errors::CustomResult<
types::RouterData<
api::PostAuthenticate,
@@ -762,20 +764,24 @@ pub async fn call_unified_connector_service_post_authenticate(
)
.change_context(interface_errors::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"))
+ let merchant_reference_id = ucs_core::parse_merchant_reference_id(
+ header_payload
+ .x_reference_id
+ .as_deref()
+ .unwrap_or(router_data.payment_id.as_str()),
+ )
+ .map(ucs_types::UcsReferenceId::Payment);
+ let resource_id = id_type::PaymentResourceId::from_str(router_data.attempt_id.as_str())
+ .inspect_err(
+ |err| logger::warn!(error=?err, "Invalid Payment AttemptId for UCS resource id"),
+ )
.ok()
- .flatten()
- .map(ucs_types::UcsReferenceId::Payment);
+ .map(ucs_types::UcsResourceId::PaymentAttempt);
let headers_builder = state
.get_grpc_headers_ucs(unified_connector_service_execution_mode)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
+ .resource_id(resource_id)
.lineage_ids(lineage_ids);
let (router_data, _) = Box::pin(ucs_core::ucs_logging_wrapper_granular(
router_data.clone(),
diff --git a/crates/router/src/core/payments/flows/external_proxy_flow.rs b/crates/router/src/core/payments/flows/external_proxy_flow.rs
index 7b0feb0650..be8da9f69c 100644
--- a/crates/router/src/core/payments/flows/external_proxy_flow.rs
+++ b/crates/router/src/core/payments/flows/external_proxy_flow.rs
@@ -358,7 +358,6 @@ impl Feature<api::ExternalVaultProxy, types::ExternalVaultProxyPaymentsData>
external_vault_merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,
processor: &domain::Processor,
unified_connector_service_execution_mode: enums::ExecutionMode,
- merchant_order_reference_id: Option<String>,
) -> RouterResult<()> {
let client = state
.grpc_client
@@ -387,20 +386,25 @@ impl Feature<api::ExternalVaultProxy, types::ExternalVaultProxyPaymentsData>
)
.change_context(ApiErrorResponse::InternalServerError)
.attach_printable("Failed to construct external vault proxy 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"))
+ let merchant_reference_id = unified_connector_service::parse_merchant_reference_id(
+ header_payload
+ .x_reference_id
+ .as_deref()
+ .unwrap_or(self.payment_id.as_str()),
+ )
+ .map(ucs_types::UcsReferenceId::Payment);
+ let resource_id = id_type::PaymentResourceId::from_str(self.attempt_id.as_str())
+ .inspect_err(
+ |err| logger::warn!(error=?err, "Invalid Payment AttemptId for UCS resource id"),
+ )
.ok()
- .flatten()
- .map(ucs_types::UcsReferenceId::Payment);
+ .map(ucs_types::UcsResourceId::PaymentAttempt);
+
let headers_builder = state
.get_grpc_headers_ucs(unified_connector_service_execution_mode)
.external_vault_proxy_metadata(Some(external_vault_proxy_metadata))
.merchant_reference_id(merchant_reference_id)
+ .resource_id(resource_id)
.lineage_ids(lineage_ids);
let (updated_router_data, _) = Box::pin(ucs_logging_wrapper(
self.clone(),
diff --git a/crates/router/src/core/payments/gateway/access_token_gateway.rs b/crates/router/src/core/payments/gateway/access_token_gateway.rs
index 10f4b1162e..7c3b8d787b 100644
--- a/crates/router/src/core/payments/gateway/access_token_gateway.rs
+++ b/crates/router/src/core/payments/gateway/access_token_gateway.rs
@@ -103,21 +103,26 @@ where
)
.change_context(ConnectorError::RequestEncodingFailed)
.attach_printable("Failed to construct request metadata")?;
-
- let merchant_reference_id = header_payload
- .x_reference_id
- .clone()
- .map(|id| id_type::PaymentReferenceId::from_str(id.as_str()))
- .transpose()
- .inspect_err(|err| logger::warn!(error=?err, "Invalid Merchant ReferenceId found"))
+ let merchant_reference_id = unified_connector_service::parse_merchant_reference_id(
+ header_payload
+ .x_reference_id
+ .as_deref()
+ .unwrap_or(router_data.payment_id.as_str()),
+ )
+ .map(ucs_types::UcsReferenceId::Payment);
+
+ let resource_id = id_type::PaymentResourceId::from_str(router_data.attempt_id.as_str())
+ .inspect_err(
+ |err| logger::warn!(error=?err, "Invalid Payment AttemptId for UCS resource id"),
+ )
.ok()
- .flatten()
- .map(ucs_types::UcsReferenceId::Payment);
+ .map(ucs_types::UcsResourceId::PaymentAttempt);
let header_payload = state
.get_grpc_headers_ucs(unified_connector_service_execution_mode)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
+ .resource_id(resource_id)
.lineage_ids(lineage_ids);
Box::pin(unified_connector_service::ucs_logging_wrapper_granular(
diff --git a/crates/router/src/core/payments/gateway/authenticate_gateway.rs b/crates/router/src/core/payments/gateway/authenticate_gateway.rs
index b2027c8817..82da6c1999 100644
--- a/crates/router/src/core/payments/gateway/authenticate_gateway.rs
+++ b/crates/router/src/core/payments/gateway/authenticate_gateway.rs
@@ -67,7 +67,6 @@ where
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 connector_enum =
common_enums::connector_enums::Connector::from_str(&router_data.connector)
.change_context(ConnectorError::InvalidConnectorName)
@@ -81,7 +80,6 @@ where
processor,
connector_enum,
unified_connector_service_execution_mode,
- merchant_order_reference_id,
)
.await
}
diff --git a/crates/router/src/core/payments/gateway/authorize_gateway.rs b/crates/router/src/core/payments/gateway/authorize_gateway.rs
index e1b80023a9..d60a958ddf 100644
--- a/crates/router/src/core/payments/gateway/authorize_gateway.rs
+++ b/crates/router/src/core/payments/gateway/authorize_gateway.rs
@@ -71,7 +71,6 @@ where
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
@@ -95,21 +94,25 @@ where
.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"))
+ let merchant_reference_id = unified_connector_service::parse_merchant_reference_id(
+ header_payload
+ .x_reference_id
+ .as_deref()
+ .unwrap_or(router_data.payment_id.as_str()),
+ )
+ .map(ucs_types::UcsReferenceId::Payment);
+ let resource_id = id_type::PaymentResourceId::from_str(router_data.attempt_id.as_str())
+ .inspect_err(
+ |err| logger::warn!(error=?err, "Invalid Payment AttemptId for UCS resource id"),
+ )
.ok()
- .flatten()
- .map(ucs_types::UcsReferenceId::Payment);
+ .map(ucs_types::UcsResourceId::PaymentAttempt);
let grpc_headers = state
.get_grpc_headers_ucs(unified_connector_service_execution_mode)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
+ .resource_id(resource_id)
.lineage_ids(lineage_ids);
let updated_router_data = if is_repeat_payment {
diff --git a/crates/router/src/core/payments/gateway/cancel_gateway.rs b/crates/router/src/core/payments/gateway/cancel_gateway.rs
index d0b411eb9d..706ac8951d 100644
--- a/crates/router/src/core/payments/gateway/cancel_gateway.rs
+++ b/crates/router/src/core/payments/gateway/cancel_gateway.rs
@@ -64,7 +64,6 @@ where
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
@@ -86,21 +85,26 @@ where
.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"))
+ let merchant_reference_id = unified_connector_service::parse_merchant_reference_id(
+ header_payload
+ .x_reference_id
+ .as_deref()
+ .unwrap_or(router_data.payment_id.as_str()),
+ )
+ .map(ucs_types::UcsReferenceId::Payment);
+
+ let resource_id = id_type::PaymentResourceId::from_str(router_data.attempt_id.as_str())
+ .inspect_err(
+ |err| logger::warn!(error=?err, "Invalid Payment AttemptId for UCS resource id"),
+ )
.ok()
- .flatten()
- .map(ucs_types::UcsReferenceId::Payment);
+ .map(ucs_types::UcsResourceId::PaymentAttempt);
let header_payload = state
.get_grpc_headers_ucs(unified_connector_service_execution_mode)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
+ .resource_id(resource_id)
.lineage_ids(lineage_ids);
Box::pin(unified_connector_service::ucs_logging_wrapper_granular(
diff --git a/crates/router/src/core/payments/gateway/capture_gateway.rs b/crates/router/src/core/payments/gateway/capture_gateway.rs
index 971b2075ae..c828c5f446 100644
--- a/crates/router/src/core/payments/gateway/capture_gateway.rs
+++ b/crates/router/src/core/payments/gateway/capture_gateway.rs
@@ -64,7 +64,6 @@ where
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
@@ -85,20 +84,26 @@ where
)
.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"))
+ let merchant_reference_id = unified_connector_service::parse_merchant_reference_id(
+ header_payload
+ .x_reference_id
+ .as_deref()
+ .unwrap_or(router_data.payment_id.as_str()),
+ )
+ .map(ucs_types::UcsReferenceId::Payment);
+
+ let resource_id = id_type::PaymentResourceId::from_str(router_data.attempt_id.as_str())
+ .inspect_err(
+ |err| logger::warn!(error=?err, "Invalid Payment AttemptId for UCS resource id"),
+ )
.ok()
- .flatten()
- .map(ucs_types::UcsReferenceId::Payment);
+ .map(ucs_types::UcsResourceId::PaymentAttempt);
+
let header_payload = state
.get_grpc_headers_ucs(unified_connector_service_execution_mode)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
+ .resource_id(resource_id)
.lineage_ids(lineage_ids);
Box::pin(unified_connector_service::ucs_logging_wrapper_granular(
router_data.clone(),
diff --git a/crates/router/src/core/payments/gateway/complete_authorize_gateway.rs b/crates/router/src/core/payments/gateway/complete_authorize_gateway.rs
index f24a4e5271..8621052169 100644
--- a/crates/router/src/core/payments/gateway/complete_authorize_gateway.rs
+++ b/crates/router/src/core/payments/gateway/complete_authorize_gateway.rs
@@ -68,7 +68,6 @@ where
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
@@ -92,20 +91,24 @@ where
)
.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"))
+ let merchant_reference_id = unified_connector_service::parse_merchant_reference_id(
+ header_payload
+ .x_reference_id
+ .as_deref()
+ .unwrap_or(router_data.payment_id.as_str()),
+ )
+ .map(ucs_types::UcsReferenceId::Payment);
+ let resource_id = id_type::PaymentResourceId::from_str(router_data.attempt_id.as_str())
+ .inspect_err(
+ |err| logger::warn!(error=?err, "Invalid Payment AttemptId for UCS resource id"),
+ )
.ok()
- .flatten()
- .map(ucs_types::UcsReferenceId::Payment);
+ .map(ucs_types::UcsResourceId::PaymentAttempt);
let header_payload = state
.get_grpc_headers_ucs(unified_connector_service_execution_mode)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
+ .resource_id(resource_id)
.lineage_ids(lineage_ids);
Box::pin(unified_connector_service::ucs_logging_wrapper_granular(
router_data.clone(),
diff --git a/crates/router/src/core/payments/gateway/create_customer_gateway.rs b/crates/router/src/core/payments/gateway/create_customer_gateway.rs
index 786c93180d..1d3a6b21f1 100644
--- a/crates/router/src/core/payments/gateway/create_customer_gateway.rs
+++ b/crates/router/src/core/payments/gateway/create_customer_gateway.rs
@@ -2,7 +2,7 @@ use std::str::FromStr;
use async_trait::async_trait;
use common_enums::{CallConnectorAction, ExecutionPath};
-use common_utils::{errors::CustomResult, request::Request};
+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,
@@ -71,6 +71,7 @@ where
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
+ let header_payload = context.header_payload;
let unified_connector_service_execution_mode = context.execution_mode;
let client = state
@@ -96,11 +97,26 @@ where
)
.change_context(ConnectorError::RequestEncodingFailed)
.attach_printable("Failed to construct request metadata")?;
+ let merchant_reference_id = unified_connector_service::parse_merchant_reference_id(
+ header_payload
+ .x_reference_id
+ .as_deref()
+ .unwrap_or(router_data.payment_id.as_str()),
+ )
+ .map(ucs_types::UcsReferenceId::Payment);
+
+ let resource_id = id_type::PaymentResourceId::from_str(router_data.attempt_id.as_str())
+ .inspect_err(
+ |err| logger::warn!(error=?err, "Invalid Payment AttemptId for UCS resource id"),
+ )
+ .ok()
+ .map(ucs_types::UcsResourceId::PaymentAttempt);
let grpc_headers = state
.get_grpc_headers_ucs(unified_connector_service_execution_mode)
.external_vault_proxy_metadata(None)
- .merchant_reference_id(None)
+ .merchant_reference_id(merchant_reference_id)
+ .resource_id(resource_id)
.lineage_ids(lineage_ids);
Box::pin(unified_connector_service::ucs_logging_wrapper_granular(
router_data.clone(),
diff --git a/crates/router/src/core/payments/gateway/create_order_gateway.rs b/crates/router/src/core/payments/gateway/create_order_gateway.rs
index af5a1a70b5..e7873c274c 100644
--- a/crates/router/src/core/payments/gateway/create_order_gateway.rs
+++ b/crates/router/src/core/payments/gateway/create_order_gateway.rs
@@ -69,7 +69,6 @@ where
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
@@ -90,20 +89,26 @@ where
)
.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"))
+ let merchant_reference_id = unified_connector_service::parse_merchant_reference_id(
+ header_payload
+ .x_reference_id
+ .as_deref()
+ .unwrap_or(router_data.payment_id.as_str()),
+ )
+ .map(ucs_types::UcsReferenceId::Payment);
+
+ let resource_id = id_type::PaymentResourceId::from_str(router_data.attempt_id.as_str())
+ .inspect_err(
+ |err| logger::warn!(error=?err, "Invalid Payment AttemptId for UCS resource id"),
+ )
.ok()
- .flatten()
- .map(ucs_types::UcsReferenceId::Payment);
+ .map(ucs_types::UcsResourceId::PaymentAttempt);
+
let header_payload = state
.get_grpc_headers_ucs(unified_connector_service_execution_mode)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
+ .resource_id(resource_id)
.lineage_ids(lineage_ids);
Box::pin(unified_connector_service::ucs_logging_wrapper_granular(
router_data.clone(),
diff --git a/crates/router/src/core/payments/gateway/incremental_authorization_gateway.rs b/crates/router/src/core/payments/gateway/incremental_authorization_gateway.rs
index 465d77b38e..2bffb2e267 100644
--- a/crates/router/src/core/payments/gateway/incremental_authorization_gateway.rs
+++ b/crates/router/src/core/payments/gateway/incremental_authorization_gateway.rs
@@ -77,7 +77,6 @@ where
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
@@ -100,20 +99,26 @@ where
)
.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"))
+ let merchant_reference_id = unified_connector_service::parse_merchant_reference_id(
+ header_payload
+ .x_reference_id
+ .as_deref()
+ .unwrap_or(router_data.payment_id.as_str()),
+ )
+ .map(ucs_types::UcsReferenceId::Payment);
+
+ let resource_id = id_type::PaymentResourceId::from_str(router_data.attempt_id.as_str())
+ .inspect_err(
+ |err| logger::warn!(error=?err, "Invalid Payment AttemptId for UCS resource id"),
+ )
.ok()
- .flatten()
- .map(ucs_types::UcsReferenceId::Payment);
+ .map(ucs_types::UcsResourceId::PaymentAttempt);
+
let header_payload = state
.get_grpc_headers_ucs(unified_connector_service_execution_mode)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
+ .resource_id(resource_id)
.lineage_ids(lineage_ids);
let updated_router_data =
Box::pin(unified_connector_service::ucs_logging_wrapper_granular(
diff --git a/crates/router/src/core/payments/gateway/payment_method_token_create_gateway.rs b/crates/router/src/core/payments/gateway/payment_method_token_create_gateway.rs
index cbce196919..8602c6dce7 100644
--- a/crates/router/src/core/payments/gateway/payment_method_token_create_gateway.rs
+++ b/crates/router/src/core/payments/gateway/payment_method_token_create_gateway.rs
@@ -75,7 +75,6 @@ where
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
@@ -98,20 +97,25 @@ where
)
.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"))
+ let merchant_reference_id = unified_connector_service::parse_merchant_reference_id(
+ header_payload
+ .x_reference_id
+ .as_deref()
+ .unwrap_or(router_data.payment_id.as_str()),
+ )
+ .map(ucs_types::UcsReferenceId::Payment);
+ let resource_id = id_type::PaymentResourceId::from_str(router_data.attempt_id.as_str())
+ .inspect_err(
+ |err| logger::warn!(error=?err, "Invalid Payment AttemptId for UCS resource id"),
+ )
.ok()
- .flatten()
- .map(ucs_types::UcsReferenceId::Payment);
+ .map(ucs_types::UcsResourceId::PaymentAttempt);
+
let header_payload = state
.get_grpc_headers_ucs(unified_connector_service_execution_mode)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
+ .resource_id(resource_id)
.lineage_ids(lineage_ids);
Box::pin(unified_connector_service::ucs_logging_wrapper_granular(
router_data.clone(),
diff --git a/crates/router/src/core/payments/gateway/post_authenticate_gateway.rs b/crates/router/src/core/payments/gateway/post_authenticate_gateway.rs
index baf5e416c6..eba7a60d66 100644
--- a/crates/router/src/core/payments/gateway/post_authenticate_gateway.rs
+++ b/crates/router/src/core/payments/gateway/post_authenticate_gateway.rs
@@ -63,7 +63,6 @@ where
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();
complete_authorize_flow::call_unified_connector_service_post_authenticate(
router_data,
state,
@@ -72,7 +71,6 @@ where
merchant_connector_account,
processor,
unified_connector_service_execution_mode,
- merchant_order_reference_id,
)
.await
}
diff --git a/crates/router/src/core/payments/gateway/pre_authenticate_gateway.rs b/crates/router/src/core/payments/gateway/pre_authenticate_gateway.rs
index 935925a172..36a55996f1 100644
--- a/crates/router/src/core/payments/gateway/pre_authenticate_gateway.rs
+++ b/crates/router/src/core/payments/gateway/pre_authenticate_gateway.rs
@@ -66,7 +66,6 @@ where
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 connector_enum =
common_enums::connector_enums::Connector::from_str(&router_data.connector)
.change_context(ConnectorError::InvalidConnectorName)
@@ -80,7 +79,6 @@ where
processor,
connector_enum,
unified_connector_service_execution_mode,
- merchant_order_reference_id,
)
.await
.map(|(router_data, _)| router_data)
diff --git a/crates/router/src/core/payments/gateway/psync_gateway.rs b/crates/router/src/core/payments/gateway/psync_gateway.rs
index a389535aa0..07d6b06919 100644
--- a/crates/router/src/core/payments/gateway/psync_gateway.rs
+++ b/crates/router/src/core/payments/gateway/psync_gateway.rs
@@ -73,7 +73,6 @@ where
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 is_ucs_psync_disabled = state
.conf
.grpc_client
@@ -116,20 +115,26 @@ where
)
.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"))
+ let merchant_reference_id = unified_connector_service::parse_merchant_reference_id(
+ header_payload
+ .x_reference_id
+ .as_deref()
+ .unwrap_or(router_data.payment_id.as_str()),
+ )
+ .map(ucs_types::UcsReferenceId::Payment);
+
+ let resource_id = id_type::PaymentResourceId::from_str(router_data.attempt_id.as_str())
+ .inspect_err(
+ |err| logger::warn!(error=?err, "Invalid Payment AttemptId for UCS resource id"),
+ )
.ok()
- .flatten()
- .map(ucs_types::UcsReferenceId::Payment);
+ .map(ucs_types::UcsResourceId::PaymentAttempt);
+
let header_payload = state
.get_grpc_headers_ucs(unified_connector_service_execution_mode)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
+ .resource_id(resource_id)
.lineage_ids(lineage_ids);
let connector_name = router_data.connector.clone();
Box::pin(unified_connector_service::ucs_logging_wrapper_granular(
diff --git a/crates/router/src/core/payments/gateway/session_gateway.rs b/crates/router/src/core/payments/gateway/session_gateway.rs
index 4dadb4ce4d..e40fe69221 100644
--- a/crates/router/src/core/payments/gateway/session_gateway.rs
+++ b/crates/router/src/core/payments/gateway/session_gateway.rs
@@ -69,7 +69,6 @@ where
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
@@ -90,20 +89,26 @@ where
)
.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"))
+ let merchant_reference_id = unified_connector_service::parse_merchant_reference_id(
+ header_payload
+ .x_reference_id
+ .as_deref()
+ .unwrap_or(router_data.payment_id.as_str()),
+ )
+ .map(ucs_types::UcsReferenceId::Payment);
+
+ let resource_id = id_type::PaymentResourceId::from_str(router_data.attempt_id.as_str())
+ .inspect_err(
+ |err| logger::warn!(error=?err, "Invalid Payment AttemptId for UCS resource id"),
+ )
.ok()
- .flatten()
- .map(ucs_types::UcsReferenceId::Payment);
+ .map(ucs_types::UcsResourceId::PaymentAttempt);
+
let header_payload = state
.get_grpc_headers_ucs(unified_connector_service_execution_mode)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
+ .resource_id(resource_id)
.lineage_ids(lineage_ids);
let updated_router_data =
Box::pin(unified_connector_service::ucs_logging_wrapper_granular(
diff --git a/crates/router/src/core/payments/gateway/session_token_gateway.rs b/crates/router/src/core/payments/gateway/session_token_gateway.rs
index a8335834ba..b1befea969 100644
--- a/crates/router/src/core/payments/gateway/session_token_gateway.rs
+++ b/crates/router/src/core/payments/gateway/session_token_gateway.rs
@@ -71,7 +71,6 @@ where
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
@@ -93,20 +92,26 @@ where
)
.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"))
+ let merchant_reference_id = unified_connector_service::parse_merchant_reference_id(
+ header_payload
+ .x_reference_id
+ .as_deref()
+ .unwrap_or(router_data.payment_id.as_str()),
+ )
+ .map(ucs_types::UcsReferenceId::Payment);
+
+ let resource_id = id_type::PaymentResourceId::from_str(router_data.attempt_id.as_str())
+ .inspect_err(
+ |err| logger::warn!(error=?err, "Invalid Payment AttemptId for UCS resource id"),
+ )
.ok()
- .flatten()
- .map(ucs_types::UcsReferenceId::Payment);
+ .map(ucs_types::UcsResourceId::PaymentAttempt);
+
let header_payload = state
.get_grpc_headers_ucs(unified_connector_service_execution_mode)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
+ .resource_id(resource_id)
.lineage_ids(lineage_ids);
Box::pin(unified_connector_service::ucs_logging_wrapper_granular(
router_data.clone(),
diff --git a/crates/router/src/core/payments/gateway/setup_mandate.rs b/crates/router/src/core/payments/gateway/setup_mandate.rs
index 52493f99e9..dcff2978bf 100644
--- a/crates/router/src/core/payments/gateway/setup_mandate.rs
+++ b/crates/router/src/core/payments/gateway/setup_mandate.rs
@@ -67,7 +67,6 @@ where
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
@@ -88,20 +87,26 @@ where
)
.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"))
+ let merchant_reference_id = unified_connector_service::parse_merchant_reference_id(
+ header_payload
+ .x_reference_id
+ .as_deref()
+ .unwrap_or(router_data.payment_id.as_str()),
+ )
+ .map(ucs_types::UcsReferenceId::Payment);
+
+ let resource_id = id_type::PaymentResourceId::from_str(router_data.attempt_id.as_str())
+ .inspect_err(
+ |err| logger::warn!(error=?err, "Invalid Payment AttemptId for UCS resource id"),
+ )
.ok()
- .flatten()
- .map(ucs_types::UcsReferenceId::Payment);
+ .map(ucs_types::UcsResourceId::PaymentAttempt);
+
let header_payload = state
.get_grpc_headers_ucs(unified_connector_service_execution_mode)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
+ .resource_id(resource_id)
.lineage_ids(lineage_ids);
Box::pin(unified_connector_service::ucs_logging_wrapper_granular(
router_data.clone(),
diff --git a/crates/router/src/core/unified_connector_service.rs b/crates/router/src/core/unified_connector_service.rs
index 55b77ad96c..23f0870d5a 100644
--- a/crates/router/src/core/unified_connector_service.rs
+++ b/crates/router/src/core/unified_connector_service.rs
@@ -1,4 +1,4 @@
-use std::{str::FromStr, time::Instant};
+use std::{borrow::Cow, str::FromStr, time::Instant};
use api_models::admin;
#[cfg(feature = "v2")]
@@ -15,6 +15,7 @@ use common_utils::{
ext_traits::ValueExt,
id_type,
request::{Method, RequestBuilder, RequestContent},
+ ucs_types,
};
use diesel_models::types::FeatureMetadata;
use error_stack::ResultExt;
@@ -1412,6 +1413,17 @@ pub fn build_unified_connector_service_auth_metadata(
}
}
+pub fn parse_merchant_reference_id(id: &str) -> Option<id_type::PaymentReferenceId> {
+ id_type::PaymentReferenceId::from_str(id)
+ .inspect_err(|err| {
+ logger::warn!(
+ error = ?err,
+ "Invalid Merchant ReferenceId found"
+ )
+ })
+ .ok()
+}
+
#[cfg(feature = "v2")]
pub fn build_unified_connector_service_external_vault_proxy_metadata(
external_vault_merchant_connector_account: MerchantConnectorAccountTypeDetails,
@@ -1883,6 +1895,7 @@ pub async fn call_unified_connector_service_for_webhook(
))
.external_vault_proxy_metadata(None)
.merchant_reference_id(None)
+ .resource_id(None)
.build();
// Make UCS call - client availability already verified
@@ -2334,11 +2347,28 @@ pub async fn call_unified_connector_service_for_refund_execute(
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to convert merchant_id to profile_id for UCS refund")?;
let lineage_ids = LineageIds::new(merchant_id, profile_id);
+ let merchant_reference_id =
+ id_type::PaymentReferenceId::from_str(router_data.payment_id.as_str())
+ .inspect_err(|err| logger::warn!(error=?err, "Invalid PaymentId for UCS reference id"))
+ .ok()
+ .map(ucs_types::UcsReferenceId::Payment);
+ let resource_id = router_data
+ .refund_id
+ .as_ref()
+ .and_then(|refund_id| {
+ id_type::RefundReferenceId::try_from(Cow::Owned(refund_id.to_string()))
+ .inspect_err(
+ |err| logger::warn!(error=?err, "Invalid RefundId for UCS resource id"),
+ )
+ .ok()
+ })
+ .map(ucs_types::UcsResourceId::Refund);
let grpc_header_builder = state
.get_grpc_headers_ucs(execution_mode)
.lineage_ids(lineage_ids)
.external_vault_proxy_metadata(None)
- .merchant_reference_id(None);
+ .merchant_reference_id(merchant_reference_id)
+ .resource_id(resource_id);
// Make UCS refund call with logging wrapper
Box::pin(ucs_logging_wrapper(
@@ -2409,12 +2439,29 @@ pub async fn call_unified_connector_service_for_refund_sync(
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to convert merchant_id to profile_id for UCS refund")?;
let lineage_ids = LineageIds::new(merchant_id, profile_id);
+ let merchant_reference_id =
+ id_type::PaymentReferenceId::from_str(router_data.payment_id.as_str())
+ .inspect_err(|err| logger::warn!(error=?err, "Invalid PaymentId for UCS reference id"))
+ .ok()
+ .map(ucs_types::UcsReferenceId::Payment);
+ let resource_id = router_data
+ .refund_id
+ .as_ref()
+ .and_then(|refund_id| {
+ id_type::RefundReferenceId::try_from(Cow::Owned(refund_id.to_string()))
+ .inspect_err(
+ |err| logger::warn!(error=?err, "Invalid RefundId for UCS resource id"),
+ )
+ .ok()
+ })
+ .map(ucs_types::UcsResourceId::Refund);
let grpc_header_builder = state
.get_grpc_headers_ucs(execution_mode)
.lineage_ids(lineage_ids)
.external_vault_proxy_metadata(None)
- .merchant_reference_id(None);
+ .merchant_reference_id(merchant_reference_id)
+ .resource_id(resource_id);
// Make UCS refund sync call with logging wrapper
Box::pin(ucs_logging_wrapper(