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(payments): add ucs bridge for post-capture void (#14801)

Akshaya Shankar7c67d8714d0a
diff --git a/Cargo.lock b/Cargo.lock
index d2ea4ba0a0..7765e0c8b5 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2236,7 +2236,7 @@ dependencies = [
[[package]]
name = "config_patch_derive"
version = "0.1.0"
-source = "git+https://github.com/juspay/connector-service?tag=2026.10.27.0#848ebddb8939809237bd706d14d8d59d35850207"
+source = "git+https://github.com/juspay/connector-service?tag=2026.10.27.1#e2629dec77e315acb0f109438a304bf06dc564db"
dependencies = [
"proc-macro2",
"quote",
@@ -4247,7 +4247,7 @@ dependencies = [
[[package]]
name = "grpc-api-types"
version = "0.1.0"
-source = "git+https://github.com/juspay/connector-service?tag=2026.10.27.0#848ebddb8939809237bd706d14d8d59d35850207"
+source = "git+https://github.com/juspay/connector-service?tag=2026.10.27.1#e2629dec77e315acb0f109438a304bf06dc564db"
dependencies = [
"axum 0.8.4",
"bytes 1.10.1",
@@ -8396,7 +8396,7 @@ dependencies = [
[[package]]
name = "rust-grpc-client"
version = "0.1.0"
-source = "git+https://github.com/juspay/connector-service?tag=2026.10.27.0#848ebddb8939809237bd706d14d8d59d35850207"
+source = "git+https://github.com/juspay/connector-service?tag=2026.10.27.1#e2629dec77e315acb0f109438a304bf06dc564db"
dependencies = [
"grpc-api-types",
]
@@ -11344,7 +11344,7 @@ checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9"
[[package]]
name = "ucs_cards"
version = "0.1.0"
-source = "git+https://github.com/juspay/connector-service?tag=2026.10.27.0#848ebddb8939809237bd706d14d8d59d35850207"
+source = "git+https://github.com/juspay/connector-service?tag=2026.10.27.1#e2629dec77e315acb0f109438a304bf06dc564db"
dependencies = [
"bytes 1.10.1",
"error-stack 0.4.1",
@@ -11360,7 +11360,7 @@ dependencies = [
[[package]]
name = "ucs_common_enums"
version = "0.1.0"
-source = "git+https://github.com/juspay/connector-service?tag=2026.10.27.0#848ebddb8939809237bd706d14d8d59d35850207"
+source = "git+https://github.com/juspay/connector-service?tag=2026.10.27.1#e2629dec77e315acb0f109438a304bf06dc564db"
dependencies = [
"serde",
"strum 0.26.3",
@@ -11371,7 +11371,7 @@ dependencies = [
[[package]]
name = "ucs_common_utils"
version = "0.1.0"
-source = "git+https://github.com/juspay/connector-service?tag=2026.10.27.0#848ebddb8939809237bd706d14d8d59d35850207"
+source = "git+https://github.com/juspay/connector-service?tag=2026.10.27.1#e2629dec77e315acb0f109438a304bf06dc564db"
dependencies = [
"anyhow",
"base64 0.21.7",
diff --git a/crates/external_services/Cargo.toml b/crates/external_services/Cargo.toml
index fc0163ea82..d2f5266b31 100644
--- a/crates/external_services/Cargo.toml
+++ b/crates/external_services/Cargo.toml
@@ -87,7 +87,7 @@ http = "1.3.1"
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", tag = "2026.10.27.0", package = "rust-grpc-client" }
+unified-connector-service-client = { git = "https://github.com/juspay/connector-service", tag = "2026.10.27.1", package = "rust-grpc-client" }
open-feature = { version = "0.2.5", optional = true }
bytes = { version = "1.10.1", optional = true }
futures = { version = "0.3.31", 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 88c22c5ed6..ea76402360 100644
--- a/crates/external_services/src/grpc_client/unified_connector_service.rs
+++ b/crates/external_services/src/grpc_client/unified_connector_service.rs
@@ -1004,6 +1004,41 @@ impl UnifiedConnectorServiceClient {
})
}
+ /// Performs Payment Post Capture Void (Reverse)
+ pub async fn payment_reverse(
+ &self,
+ payment_reverse_request: payments_grpc::PaymentServiceReverseRequest,
+ connector_auth_metadata: ConnectorAuthMetadata,
+ grpc_headers: GrpcHeadersUcs,
+ ) -> UnifiedConnectorServiceResult<tonic::Response<payments_grpc::PaymentServiceReverseResponse>>
+ {
+ let mut request = tonic::Request::new(payment_reverse_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.payment_service_client
+ .clone()
+ .reverse(request)
+ .await
+ .map_err(|error| {
+ error_stack::Report::new(UnifiedConnectorServiceError::from_grpc_error(
+ &error,
+ &connector_name,
+ ))
+ })
+ .inspect_err(|error| {
+ logger::error!(
+ grpc_error=?error,
+ method="payment_reverse",
+ connector_name=?connector_name,
+ "UCS payment reverse gRPC call failed"
+ )
+ })
+ }
+
/// Incoming webhook handle
pub async fn incoming_webhook_handle_event(
&self,
diff --git a/crates/hyperswitch_interfaces/Cargo.toml b/crates/hyperswitch_interfaces/Cargo.toml
index 2c5fb0defc..5bec9b6ac4 100644
--- a/crates/hyperswitch_interfaces/Cargo.toml
+++ b/crates/hyperswitch_interfaces/Cargo.toml
@@ -35,7 +35,7 @@ time = "0.3.41"
tonic = "0.14"
url = { version = "2.5.4", features = ["serde"] }
-unified-connector-service-client = { git = "https://github.com/juspay/connector-service", tag = "2026.10.27.0", package = "rust-grpc-client" }
+unified-connector-service-client = { git = "https://github.com/juspay/connector-service", tag = "2026.10.27.1", package = "rust-grpc-client" }
tokio = { version = "1.45.1", features = ["macros", "rt-multi-thread"] }
# First party crates
diff --git a/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs b/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs
index b9e648aeb4..60a9ecb687 100644
--- a/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs
+++ b/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs
@@ -702,8 +702,10 @@ impl ForeignTryFrom<(payments_grpc::PaymentStatus, Self)> for AttemptStatus {
payments_grpc::PaymentStatus::DeviceDataCollectionPending => {
Ok(Self::DeviceDataCollectionPending)
}
- payments_grpc::PaymentStatus::VoidedPostCapture => Ok(Self::Voided),
- payments_grpc::PaymentStatus::Unspecified => Ok(prev_status),
+ // Deprecated in UCS in favour of `PostCaptureVoidStatus`; kept for exhaustiveness.
+ #[allow(deprecated)]
+ payments_grpc::PaymentStatus::VoidedPostCapture
+ | payments_grpc::PaymentStatus::Unspecified => Ok(prev_status),
payments_grpc::PaymentStatus::PartiallyAuthorized => Ok(Self::PartiallyAuthorized),
payments_grpc::PaymentStatus::Expired => Ok(Self::Expired),
payments_grpc::PaymentStatus::Conflicted => Ok(Self::IntegrityFailure),
diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.toml
index a829102853..f7b1f8f700 100644
--- a/crates/router/Cargo.toml
+++ b/crates/router/Cargo.toml
@@ -256,8 +256,8 @@ rust_decimal = { version = "1.37.1", features = [
] }
rust-i18n = { git = "https://github.com/kashif-m/rust-i18n", rev = "f2d8096aaaff7a87a847c35a5394c269f75e077a" }
-unified-connector-service-client = { git = "https://github.com/juspay/connector-service", tag = "2026.10.27.0", package = "rust-grpc-client" }
-unified-connector-service-cards = { git = "https://github.com/juspay/connector-service", tag = "2026.10.27.0", package = "ucs_cards" }
+unified-connector-service-client = { git = "https://github.com/juspay/connector-service", tag = "2026.10.27.1", package = "rust-grpc-client" }
+unified-connector-service-cards = { git = "https://github.com/juspay/connector-service", tag = "2026.10.27.1", package = "ucs_cards" }
rustc-hash = "1.1.0"
rustls = { version = "0.23", default-features = false, features = [
"aws-lc-rs",
diff --git a/crates/router/src/core/payments/flows/cancel_post_capture_flow.rs b/crates/router/src/core/payments/flows/cancel_post_capture_flow.rs
index a964991279..294e04a136 100644
--- a/crates/router/src/core/payments/flows/cancel_post_capture_flow.rs
+++ b/crates/router/src/core/payments/flows/cancel_post_capture_flow.rs
@@ -1,4 +1,5 @@
use async_trait::async_trait;
+use hyperswitch_domain_models::router_data_v2::PaymentFlowData;
use super::{ConstructFlowSpecificData, Feature};
use crate::{
@@ -81,32 +82,30 @@ impl Feature<api::PostCaptureVoid, types::PaymentsCancelPostCaptureData>
connector_request: Option<services::Request>,
_business_profile: &domain::Profile,
_header_payload: hyperswitch_domain_models::payments::HeaderPayload,
- _return_raw_connector_response: Option<bool>,
- _gateway_context: payments::gateway::context::RouterGatewayContext,
+ return_raw_connector_response: Option<bool>,
+ gateway_context: payments::gateway::context::RouterGatewayContext,
) -> RouterResult<Self> {
metrics::PAYMENT_CANCEL_COUNT.add(
1,
router_env::metric_attributes!(("connector", connector.connector_name.to_string())),
);
- let connector_integration: services::BoxedPaymentConnectorIntegrationInterface<
- api::PostCaptureVoid,
- types::PaymentsCancelPostCaptureData,
- types::PaymentsResponseData,
- > = connector.connector.get_connector_integration();
-
- let resp = services::execute_connector_processing_step(
+ Box::pin(payments::gateway::handle_gateway_call::<
+ _,
+ _,
+ _,
+ PaymentFlowData,
+ _,
+ >(
state,
- connector_integration,
- &self,
+ self,
+ connector,
+ &gateway_context,
call_connector_action,
connector_request,
- None,
- )
+ return_raw_connector_response,
+ ))
.await
- .to_payment_failed_response()?;
-
- Ok(resp)
}
async fn add_access_token<'a>(
diff --git a/crates/router/src/core/payments/gateway.rs b/crates/router/src/core/payments/gateway.rs
index 4cb8cfc68b..4fdbc244b4 100644
--- a/crates/router/src/core/payments/gateway.rs
+++ b/crates/router/src/core/payments/gateway.rs
@@ -11,6 +11,7 @@ pub mod generate_qr_gateway;
pub mod incremental_authorization_gateway;
pub mod payment_method_token_create_gateway;
pub mod post_authenticate_gateway;
+pub mod post_capture_void_gateway;
pub mod post_capture_void_sync_gateway;
pub mod pre_authenticate_gateway;
pub mod pre_authorize_void_gateway;
diff --git a/crates/router/src/core/payments/gateway/post_capture_void_gateway.rs b/crates/router/src/core/payments/gateway/post_capture_void_gateway.rs
new file mode 100644
index 0000000000..c58be7fbe9
--- /dev/null
+++ b/crates/router/src/core/payments/gateway/post_capture_void_gateway.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 crate::{
+ core::{payments::gateway::context::RouterGatewayContext, unified_connector_service},
+ routes::SessionState,
+ services::logger,
+ types::{self, transformers::ForeignTryFrom},
+};
+
+// =============================================================================
+// PaymentGateway Implementation for domain::PostCaptureVoid
+// =============================================================================
+
+/// Implementation of PaymentGateway for api::PostCaptureVoid flow
+#[async_trait]
+impl<RCD>
+ payment_gateway::PaymentGateway<
+ SessionState,
+ RCD,
+ Self,
+ types::PaymentsCancelPostCaptureData,
+ types::PaymentsResponseData,
+ RouterGatewayContext,
+ > for domain::PostCaptureVoid
+where
+ RCD: Clone
+ + Send
+ + Sync
+ + 'static
+ + RouterDataConversion<
+ Self,
+ types::PaymentsCancelPostCaptureData,
+ types::PaymentsResponseData,
+ >,
+{
+ async fn execute(
+ self: Box<Self>,
+ state: &SessionState,
+ _connector_integration: BoxedConnectorIntegrationInterface<
+ Self,
+ RCD,
+ types::PaymentsCancelPostCaptureData,
+ types::PaymentsResponseData,
+ >,
+ router_data: &RouterData<
+ Self,
+ types::PaymentsCancelPostCaptureData,
+ types::PaymentsResponseData,
+ >,
+ _call_connector_action: CallConnectorAction,
+ _connector_request: Option<Request>,
+ _return_raw_connector_response: Option<bool>,
+ context: RouterGatewayContext,
+ ) -> CustomResult<
+ RouterData<Self, types::PaymentsCancelPostCaptureData, types::PaymentsResponseData>,
+ ConnectorError,
+ > {
+ let rollout_settings = context.rollout_settings();
+ 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 client = state
+ .grpc_client
+ .unified_connector_service_client
+ .clone()
+ .ok_or(ConnectorError::RequestEncodingFailed)
+ .attach_printable("Failed to fetch Unified Connector Service client")?;
+
+ let payment_reverse_request =
+ payments_grpc::PaymentServiceReverseRequest::foreign_try_from(router_data)
+ .change_context(ConnectorError::RequestEncodingFailed)
+ .attach_printable("Failed to construct Payment Reverse Request")?;
+
+ let connector_auth_metadata =
+ unified_connector_service::build_unified_connector_service_auth_metadata(
+ merchant_connector_account,
+ processor.get_account().get_id(),
+ router_data.connector.clone(),
+ )
+ .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 header_payload = state
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
+ .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(),
+ state,
+ payment_reverse_request,
+ header_payload,
+ rollout_settings,
+ |mut router_data, payment_reverse_request, grpc_headers| async move {
+ let response = match client
+ .payment_reverse(payment_reverse_request, connector_auth_metadata, grpc_headers)
+ .await
+ {
+ Ok(resp) => resp,
+ // UCS connector errors are handled by the wrapper — see `ucs_logging_wrapper_granular`.
+ Err(report) => {
+ return Err(report.attach_printable("Failed to void payment post capture"));
+ }
+ };
+
+ let payment_reverse_response = response.into_inner();
+
+ let (router_data_response, status_code) =
+ unified_connector_service::handle_unified_connector_service_response_for_payment_post_capture_void(
+ payment_reverse_response.clone(),
+ router_data.status,
+ )
+ .attach_printable("Failed to deserialize UCS response")?;
+
+ // The post capture void outcome is stored in the intent's state_metadata, so the
+ // attempt status is left as it is.
+ router_data.response = router_data_response.map(|(response, _)| response);
+ router_data.connector_http_status_code = Some(status_code);
+
+ Ok((router_data, (), payment_reverse_response))
+ },
+ ))
+ .await
+ .map(|(router_data, _)| router_data)
+ .map_err(payment_gateway::convert_ucs_error_to_connector_error)
+ }
+}
+
+/// Implementation of FlowGateway for api::PostCaptureVoid
+///
+/// This allows the flow to provide its specific gateway based on execution path
+impl<RCD>
+ payment_gateway::FlowGateway<
+ SessionState,
+ RCD,
+ types::PaymentsCancelPostCaptureData,
+ types::PaymentsResponseData,
+ RouterGatewayContext,
+ > for domain::PostCaptureVoid
+where
+ RCD: Clone
+ + Send
+ + Sync
+ + 'static
+ + RouterDataConversion<
+ Self,
+ types::PaymentsCancelPostCaptureData,
+ types::PaymentsResponseData,
+ >,
+{
+ fn get_gateway(
+ execution_path: ExecutionPath,
+ ) -> Box<
+ dyn payment_gateway::PaymentGateway<
+ SessionState,
+ RCD,
+ Self,
+ types::PaymentsCancelPostCaptureData,
+ 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/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs
index f2cc1c22f1..0b3490789f 100644
--- a/crates/router/src/core/payments/operations/payment_response.rs
+++ b/crates/router/src/core/payments/operations/payment_response.rs
@@ -1963,6 +1963,15 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsCancelPostCap
where
F: 'b + Send,
{
+ // A rejected post capture void leaves the captured payment as it is, so the error is
+ // recorded as the void's outcome in state_metadata instead of failing the payment.
+ let router_data = types::RouterData {
+ response: Ok(router_data
+ .response
+ .unwrap_or_else(|err| get_post_capture_void_response_from_error(&err))),
+ ..router_data
+ };
+
payment_data = Box::pin(payment_response_update_tracker(
db,
payment_data,
@@ -3618,6 +3627,22 @@ async fn delete_cvc_after_success(
}
}
+/// Builds the post capture void outcome for a connector error. A 5xx does not tell whether the
+/// connector processed the void, so it is kept pending for the sync to resolve.
+#[cfg(feature = "v1")]
+fn get_post_capture_void_response_from_error(err: &ErrorResponse) -> types::PaymentsResponseData {
+ let post_capture_void_status = match err.status_code {
+ 500..=511 => common_enums::PostCaptureVoidStatus::Pending,
+ _ => common_enums::PostCaptureVoidStatus::Failed,
+ };
+
+ types::PaymentsResponseData::PostCaptureVoidResponse {
+ post_capture_void_status,
+ connector_reference_id: err.connector_response_reference_id.clone(),
+ description: Some(err.message.clone()),
+ }
+}
+
#[cfg(feature = "v1")]
fn get_payment_intent_update_data<F: Clone, T: types::Capturable>(
payment_data: PaymentData<F>,
diff --git a/crates/router/src/core/unified_connector_service.rs b/crates/router/src/core/unified_connector_service.rs
index a5a3dd9f8e..792c724a7d 100644
--- a/crates/router/src/core/unified_connector_service.rs
+++ b/crates/router/src/core/unified_connector_service.rs
@@ -3624,6 +3624,22 @@ pub fn handle_unified_connector_service_response_for_payment_cancel(
Ok((router_data_response, status_code))
}
+/// Handles the unified connector service response for payment post capture void
+pub fn handle_unified_connector_service_response_for_payment_post_capture_void(
+ response: payments_grpc::PaymentServiceReverseResponse,
+ prev_status: AttemptStatus,
+) -> UnifiedConnectorServiceResult {
+ let status_code = transformers::convert_connector_service_status_code(response.status_code)?;
+
+ let router_data_response =
+ Result::<(PaymentsResponseData, AttemptStatus), ErrorResponse>::foreign_try_from((
+ response,
+ prev_status,
+ ))?;
+
+ Ok((router_data_response, status_code))
+}
+
/// Handles the unified connector service response for create access token
pub fn handle_unified_connector_service_response_for_create_access_token(
response: payments_grpc::MerchantAuthenticationServiceCreateServerAuthenticationTokenResponse,
diff --git a/crates/router/src/core/unified_connector_service/transformers.rs b/crates/router/src/core/unified_connector_service/transformers.rs
index e7871df024..fc3b5dbce0 100644
--- a/crates/router/src/core/unified_connector_service/transformers.rs
+++ b/crates/router/src/core/unified_connector_service/transformers.rs
@@ -28,7 +28,7 @@ use hyperswitch_domain_models::{
router_data::{AccessToken, ErrorResponse, L2L3Data, RouterData},
router_flow_types::{
fraud_check as frm_api,
- payments::{Authorize, Capture, PSync, PreAuthorizeVoid, SetupMandate},
+ payments::{Authorize, Capture, PSync, PostCaptureVoid, PreAuthorizeVoid, SetupMandate},
refunds::{Execute, RSync, VoidPostRefund},
unified_authentication_service as uas_flows, ExternalVaultProxy, IncrementalAuthorization,
Session,
@@ -36,9 +36,9 @@ use hyperswitch_domain_models::{
router_request_types::{
self, fraud_check::FraudCheckCheckoutData, AuthenticationData,
ExternalVaultProxyPaymentsData, PaymentsAuthorizeData, PaymentsCancelData,
- PaymentsCaptureData, PaymentsIncrementalAuthorizationData, PaymentsPreAuthorizeCancelData,
- PaymentsSessionData, PaymentsSyncData, RefundsData, SetupMandateRequestData,
- SyncRequestType,
+ PaymentsCancelPostCaptureData, PaymentsCaptureData, PaymentsIncrementalAuthorizationData,
+ PaymentsPreAuthorizeCancelData, PaymentsSessionData, PaymentsSyncData, RefundsData,
+ SetupMandateRequestData, SyncRequestType,
},
router_response_types::{
fraud_check::FraudCheckResponseData, NotifyConnectorResponseData, PaymentsResponseData,
@@ -9160,6 +9160,108 @@ impl
}
}
+impl
+ transformers::ForeignTryFrom<
+ &RouterData<PostCaptureVoid, PaymentsCancelPostCaptureData, PaymentsResponseData>,
+ > for payments_grpc::PaymentServiceReverseRequest
+{
+ type Error = error_stack::Report<UnifiedConnectorServiceError>;
+
+ fn foreign_try_from(
+ router_data: &RouterData<
+ PostCaptureVoid,
+ PaymentsCancelPostCaptureData,
+ PaymentsResponseData,
+ >,
+ ) -> Result<Self, Self::Error> {
+ let amount = router_data
+ .request
+ .minor_amount
+ .zip(router_data.request.currency)
+ .map(|(minor_amount, currency)| {
+ payments_grpc::Currency::foreign_try_from(currency).map(|currency| {
+ payments_grpc::Money {
+ minor_amount: minor_amount.get_amount_as_i64(),
+ currency: currency.into(),
+ }
+ })
+ })
+ .transpose()?;
+
+ Ok(Self {
+ merchant_reverse_id: Some(router_data.connector_request_reference_id.clone()),
+ connector_transaction_id: router_data.request.connector_transaction_id.clone(),
+ cancellation_reason: router_data.request.cancellation_reason.clone(),
+ all_keys_required: None,
+ browser_info: None,
+ metadata: None,
+ connector_feature_data: router_data
+ .request
+ .connector_meta
+ .as_ref()
+ .map(serde_json::to_string)
+ .transpose()
+ .change_context(UnifiedConnectorServiceError::RequestEncodingFailed)?
+ .map(|s| s.into()),
+ merchant_request_id: None,
+ test_mode: router_data.test_mode,
+ amount,
+ })
+ }
+}
+
+impl transformers::ForeignTryFrom<(payments_grpc::PaymentServiceReverseResponse, AttemptStatus)>
+ for Result<(PaymentsResponseData, AttemptStatus), ErrorResponse>
+{
+ type Error = error_stack::Report<UnifiedConnectorServiceError>;
+
+ fn foreign_try_from(
+ (response, prev_status): (payments_grpc::PaymentServiceReverseResponse, AttemptStatus),
+ ) -> Result<Self, Self::Error> {
+ let status_code = convert_connector_service_status_code(response.status_code)?;
+
+ let post_capture_void_status = match response.post_capture_void_status() {
+ payments_grpc::PostCaptureVoidStatus::Succeeded => {
+ common_enums::PostCaptureVoidStatus::Succeeded
+ }
+ // A 5xx does not tell whether the connector processed the void, so it is left for
+ // the sync to resolve
+ payments_grpc::PostCaptureVoidStatus::Failed if (500..=511).contains(&status_code) => {
+ common_enums::PostCaptureVoidStatus::Pending
+ }
+ payments_grpc::PostCaptureVoidStatus::Failed => {
+ common_enums::PostCaptureVoidStatus::Failed
+ }
+ payments_grpc::PostCaptureVoidStatus::Pending
+ | payments_grpc::PostCaptureVoidStatus::Unspecified => {
+ common_enums::PostCaptureVoidStatus::Pending
+ }
+ };
+
+ // A rejected void is the void's outcome, not a payment failure, so the error is carried
+ // as the description and the attempt status is left unchanged.
+ let description = response
+ .error
+ .as_ref()
+ .and_then(|error_info| error_info.connector_details.as_ref())
+ .and_then(|connector_details| {
+ connector_details
+ .message
+ .clone()
+ .or_else(|| connector_details.reason.clone())
+ });
+
+ Ok(Ok((
+ PaymentsResponseData::PostCaptureVoidResponse {
+ post_capture_void_status,
+ connector_reference_id: response.connector_reference_id,
+ description,
+ },
+ prev_status,
+ )))
+ }
+}
+
impl transformers::ForeignTryFrom<(payments_grpc::RefundStatus, Self)> for RefundStatus {
type Error = error_stack::Report<UnifiedConnectorServiceError>;