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: UCS repeat payment in granular authorize (#10576)

gopikrishna000854f15fe9a76
diff --git a/crates/router/src/core/payments/gateway/authorize_gateway.rs b/crates/router/src/core/payments/gateway/authorize_gateway.rs
index 4e85e723a7..0ca876f213 100644
--- a/crates/router/src/core/payments/gateway/authorize_gateway.rs
+++ b/crates/router/src/core/payments/gateway/authorize_gateway.rs
@@ -15,8 +15,11 @@ use unified_connector_service_masking::ExposeInterface as UcsMaskingExposeInterf
use crate::{
core::{
- payments::gateway::context::RouterGatewayContext, unified_connector_service,
- unified_connector_service::handle_unified_connector_service_response_for_payment_authorize,
+ payments::gateway::context::RouterGatewayContext,
+ unified_connector_service::{
+ self, handle_unified_connector_service_response_for_payment_authorize,
+ handle_unified_connector_service_response_for_payment_repeat,
+ },
},
routes::SessionState,
services::logger,
@@ -76,13 +79,12 @@ where
.ok_or(ConnectorError::RequestEncodingFailed)
.attach_printable("Failed to fetch Unified Connector Service client")?;
- let granular_authorize_request =
- payments_grpc::PaymentServiceAuthorizeOnlyRequest::foreign_try_from((
- router_data,
- call_connector_action,
- ))
- .change_context(ConnectorError::RequestEncodingFailed)
- .attach_printable("Failed to construct Payment Get Request")?;
+ // Check if this is a repeat payment (MIT with mandate_id or MandatePayment)
+ let is_repeat_payment = router_data.request.mandate_id.is_some()
+ || matches!(
+ router_data.request.payment_method_data,
+ hyperswitch_domain_models::payment_method_data::PaymentMethodData::MandatePayment
+ );
let connector_auth_metadata =
unified_connector_service::build_unified_connector_service_auth_metadata(
@@ -92,6 +94,7 @@ where
)
.change_context(ConnectorError::RequestEncodingFailed)
.attach_printable("Failed to construct request metadata")?;
+
let merchant_reference_id = header_payload
.x_reference_id
.clone()
@@ -102,58 +105,133 @@ where
.ok()
.flatten()
.map(ucs_types::UcsReferenceId::Payment);
- let header_payload = state
+
+ let grpc_headers = 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,
- granular_authorize_request,
- header_payload,
- |mut router_data, granular_authorize_request, grpc_headers| async move {
- let response = Box::pin(client.payment_authorize_granular(
- granular_authorize_request,
- connector_auth_metadata,
- grpc_headers,
+
+ let updated_router_data = if is_repeat_payment {
+ logger::info!(
+ "Granular Gateway: Detected repeat payment, calling UCS RepeatPayment endpoint"
+ );
+
+ let payment_repeat_request =
+ payments_grpc::PaymentServiceRepeatEverythingRequest::foreign_try_from(router_data)
+ .change_context(ConnectorError::RequestEncodingFailed)
+ .attach_printable("Failed to construct Payment Repeat Request")?;
+
+ Box::pin(unified_connector_service::ucs_logging_wrapper_new(
+ router_data.clone(),
+ state,
+ payment_repeat_request,
+ grpc_headers,
+ |mut router_data, payment_repeat_request, grpc_headers| async move {
+ logger::debug!("Calling UCS payment_repeat gRPC method");
+ let response = Box::pin(client.payment_repeat(
+ payment_repeat_request,
+ connector_auth_metadata,
+ grpc_headers,
+ ))
+ .await
+ .attach_printable("Failed to repeat payment")?;
+
+ let payment_repeat_response = response.into_inner();
+
+ let ucs_data = handle_unified_connector_service_response_for_payment_repeat(
+ payment_repeat_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 = payment_repeat_response.captured_amount;
+ router_data.minor_amount_captured = payment_repeat_response
+ .minor_captured_amount
+ .map(MinorUnit::new);
+ router_data.raw_connector_response = payment_repeat_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);
+
+ ucs_data.connector_customer_id.map(|connector_customer_id| {
+ router_data.connector_customer = Some(connector_customer_id);
+ });
+
+ ucs_data.connector_response.map(|connector_response| {
+ router_data.connector_response = Some(connector_response);
+ });
+
+ Ok((router_data, payment_repeat_response))
+ },
+ ))
+ .await
+ .change_context(ConnectorError::ResponseHandlingFailed)?
+ } else {
+ logger::debug!("Granular Gateway: Regular authorize flow");
+ let granular_authorize_request =
+ payments_grpc::PaymentServiceAuthorizeOnlyRequest::foreign_try_from((
+ router_data,
+ call_connector_action,
))
- .await
- .attach_printable("Failed to get payment")?;
+ .change_context(ConnectorError::RequestEncodingFailed)
+ .attach_printable("Failed to construct Payment Get Request")?;
- let payment_authorize_response = response.into_inner();
+ Box::pin(unified_connector_service::ucs_logging_wrapper_new(
+ router_data.clone(),
+ state,
+ granular_authorize_request,
+ grpc_headers,
+ |mut router_data, granular_authorize_request, grpc_headers| async move {
+ let response = Box::pin(client.payment_authorize_granular(
+ granular_authorize_request,
+ connector_auth_metadata,
+ grpc_headers,
+ ))
+ .await
+ .attach_printable("Failed to get payment")?;
- let ucs_data = handle_unified_connector_service_response_for_payment_authorize(
- payment_authorize_response.clone(),
- )
- .attach_printable("Failed to deserialize UCS response")?;
+ let payment_authorize_response = response.into_inner();
- let router_data_response =
- ucs_data.router_data_response.map(|(response, status)| {
- router_data.status = status;
- response
+ let ucs_data = handle_unified_connector_service_response_for_payment_authorize(
+ payment_authorize_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 = payment_authorize_response.captured_amount;
+ router_data.minor_amount_captured = payment_authorize_response
+ .minor_captured_amount
+ .map(MinorUnit::new);
+ 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_data.status_code);
+
+ ucs_data.connector_response.map(|customer_response| {
+ router_data.connector_response = Some(customer_response);
});
- router_data.response = router_data_response;
-
- router_data.amount_captured = payment_authorize_response.captured_amount;
- router_data.minor_amount_captured = payment_authorize_response
- .minor_captured_amount
- .map(MinorUnit::new);
- 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_data.status_code);
-
- ucs_data.connector_response.map(|customer_response| {
- router_data.connector_response = Some(customer_response);
- });
-
- Ok((router_data, payment_authorize_response))
- },
- ))
- .await
- .change_context(ConnectorError::ResponseHandlingFailed)?;
+
+ Ok((router_data, payment_authorize_response))
+ },
+ ))
+ .await
+ .change_context(ConnectorError::ResponseHandlingFailed)?
+ };
Ok(updated_router_data)
}
diff --git a/crates/router/src/core/unified_connector_service/transformers.rs b/crates/router/src/core/unified_connector_service/transformers.rs
index 006519b23d..f7fe9fdf25 100644
--- a/crates/router/src/core/unified_connector_service/transformers.rs
+++ b/crates/router/src/core/unified_connector_service/transformers.rs
@@ -1502,6 +1502,12 @@ impl
.map(payments_grpc::CaptureMethod::foreign_try_from)
.transpose()?;
+ let payment_method_type = router_data
+ .request
+ .payment_method_type
+ .map(payments_grpc::PaymentMethodType::foreign_from)
+ .map(|pm_type| pm_type.into());
+
let address = payments_grpc::PaymentAddress::foreign_try_from(router_data.address.clone())?;
let mandate_reference = match &router_data.request.mandate_id {
@@ -1565,7 +1571,7 @@ impl
.map(|e| e.expose().expose().into()),
browser_info,
test_mode: router_data.test_mode,
- payment_method_type: None,
+ payment_method_type,
state,
return_url: router_data.request.router_return_url.clone(),
description: router_data.description.clone(),
@@ -2863,6 +2869,118 @@ impl ForeignFrom<common_enums::TransactionStatus> for payments_grpc::Transaction
}
}
+impl ForeignFrom<common_enums::PaymentMethodType> for payments_grpc::PaymentMethodType {
+ fn foreign_from(value: common_enums::PaymentMethodType) -> Self {
+ match value {
+ common_enums::PaymentMethodType::Ach => Self::Ach,
+ common_enums::PaymentMethodType::Affirm => Self::Affirm,
+ common_enums::PaymentMethodType::AfterpayClearpay => Self::AfterpayClearpay,
+ common_enums::PaymentMethodType::Alfamart => Self::Alfamart,
+ common_enums::PaymentMethodType::AliPay => Self::AliPay,
+ common_enums::PaymentMethodType::AliPayHk => Self::AliPayHk,
+ common_enums::PaymentMethodType::Alma => Self::Alma,
+ common_enums::PaymentMethodType::AmazonPay => Self::AmazonPay,
+ common_enums::PaymentMethodType::ApplePay => Self::ApplePay,
+ common_enums::PaymentMethodType::Atome => Self::Atome,
+ common_enums::PaymentMethodType::Bacs => Self::Bacs,
+ common_enums::PaymentMethodType::BancontactCard => Self::BancontactCard,
+ common_enums::PaymentMethodType::Becs => Self::Becs,
+ common_enums::PaymentMethodType::Benefit => Self::Benefit,
+ common_enums::PaymentMethodType::Bizum => Self::Bizum,
+ common_enums::PaymentMethodType::Blik => Self::Blik,
+ common_enums::PaymentMethodType::Boleto => Self::Boleto,
+ common_enums::PaymentMethodType::BcaBankTransfer => Self::BcaBankTransfer,
+ common_enums::PaymentMethodType::BniVa => Self::BniVa,
+ common_enums::PaymentMethodType::BriVa => Self::BriVa,
+ #[cfg(feature = "v2")]
+ common_enums::PaymentMethodType::Card => Self::Credit, // Card maps to CREDIT in proto
+ common_enums::PaymentMethodType::CardRedirect => Self::CardRedirect,
+ common_enums::PaymentMethodType::CimbVa => Self::CimbVa,
+ common_enums::PaymentMethodType::ClassicReward => Self::ClassicReward,
+ common_enums::PaymentMethodType::Credit => Self::Credit,
+ common_enums::PaymentMethodType::CryptoCurrency => Self::CryptoCurrency,
+ common_enums::PaymentMethodType::Cashapp => Self::Cashapp,
+ common_enums::PaymentMethodType::Dana => Self::Dana,
+ common_enums::PaymentMethodType::DanamonVa => Self::DanamonVa,
+ common_enums::PaymentMethodType::Debit => Self::Debit,
+ common_enums::PaymentMethodType::DuitNow => Self::DuitNow,
+ common_enums::PaymentMethodType::Efecty => Self::Efecty,
+ common_enums::PaymentMethodType::Eft => Self::Eft,
+ common_enums::PaymentMethodType::Eps => Self::Eps,
+ common_enums::PaymentMethodType::Fps => Self::Fps,
+ common_enums::PaymentMethodType::Evoucher => Self::Evoucher,
+ common_enums::PaymentMethodType::Giropay => Self::Giropay,
+ common_enums::PaymentMethodType::Givex => Self::Givex,
+ common_enums::PaymentMethodType::GooglePay => Self::GooglePay,
+ common_enums::PaymentMethodType::GoPay => Self::GoPay,
+ common_enums::PaymentMethodType::Gcash => Self::Gcash,
+ common_enums::PaymentMethodType::Ideal => Self::Ideal,
+ common_enums::PaymentMethodType::Interac => Self::Interac,
+ common_enums::PaymentMethodType::Indomaret => Self::Indomaret,
+ common_enums::PaymentMethodType::KakaoPay => Self::KakaoPay,
+ common_enums::PaymentMethodType::LocalBankRedirect => Self::LocalBankRedirect,
+ common_enums::PaymentMethodType::MandiriVa => Self::MandiriVa,
+ common_enums::PaymentMethodType::Knet => Self::Knet,
+ common_enums::PaymentMethodType::MbWay => Self::MbWay,
+ common_enums::PaymentMethodType::MobilePay => Self::MobilePay,
+ common_enums::PaymentMethodType::Momo => Self::Momo,
+ common_enums::PaymentMethodType::MomoAtm => Self::MomoAtm,
+ common_enums::PaymentMethodType::Multibanco => Self::Multibanco,
+ common_enums::PaymentMethodType::OnlineBankingThailand => Self::OnlineBankingThailand,
+ common_enums::PaymentMethodType::OnlineBankingCzechRepublic => {
+ Self::OnlineBankingCzechRepublic
+ }
+ common_enums::PaymentMethodType::OnlineBankingFinland => Self::OnlineBankingFinland,
+ common_enums::PaymentMethodType::OnlineBankingFpx => Self::OnlineBankingFpx,
+ common_enums::PaymentMethodType::OnlineBankingPoland => Self::OnlineBankingPoland,
+ common_enums::PaymentMethodType::OnlineBankingSlovakia => Self::OnlineBankingSlovakia,
+ common_enums::PaymentMethodType::Oxxo => Self::Oxxo,
+ common_enums::PaymentMethodType::PagoEfectivo => Self::PagoEfectivo,
+ common_enums::PaymentMethodType::PermataBankTransfer => Self::PermataBankTransfer,
+ common_enums::PaymentMethodType::OpenBankingUk => Self::OpenBankingUk,
+ common_enums::PaymentMethodType::PayBright => Self::PayBright,
+ common_enums::PaymentMethodType::Paypal => Self::PayPal,
+ common_enums::PaymentMethodType::Paze => Self::Paze,
+ common_enums::PaymentMethodType::Pix => Self::Pix,
+ common_enums::PaymentMethodType::PaySafeCard => Self::PaySafeCard,
+ common_enums::PaymentMethodType::Przelewy24 => Self::Przelewy24,
+ common_enums::PaymentMethodType::PromptPay => Self::PromptPay,
+ common_enums::PaymentMethodType::Pse => Self::Pse,
+ common_enums::PaymentMethodType::RedCompra => Self::RedCompra,
+ common_enums::PaymentMethodType::RedPagos => Self::RedPagos,
+ common_enums::PaymentMethodType::SamsungPay => Self::SamsungPay,
+ common_enums::PaymentMethodType::Sepa => Self::Sepa,
+ common_enums::PaymentMethodType::SepaBankTransfer => Self::SepaBankTransfer,
+ common_enums::PaymentMethodType::Sofort => Self::Sofort,
+ common_enums::PaymentMethodType::Swish => Self::Swish,
+ common_enums::PaymentMethodType::TouchNGo => Self::TouchNGo,
+ common_enums::PaymentMethodType::Trustly => Self::Trustly,
+ common_enums::PaymentMethodType::Twint => Self::Twint,
+ common_enums::PaymentMethodType::UpiCollect => Self::UpiCollect,
+ common_enums::PaymentMethodType::UpiIntent => Self::UpiIntent,
+ common_enums::PaymentMethodType::UpiQr => Self::UpiQr,
+ common_enums::PaymentMethodType::Vipps => Self::Vipps,
+ common_enums::PaymentMethodType::VietQr => Self::VietQr,
+ common_enums::PaymentMethodType::Venmo => Self::Venmo,
+ common_enums::PaymentMethodType::Walley => Self::Walley,
+ common_enums::PaymentMethodType::WeChatPay => Self::WeChatPay,
+ common_enums::PaymentMethodType::SevenEleven => Self::SevenEleven,
+ common_enums::PaymentMethodType::Lawson => Self::Lawson,
+ common_enums::PaymentMethodType::MiniStop => Self::MiniStop,
+ common_enums::PaymentMethodType::FamilyMart => Self::FamilyMart,
+ common_enums::PaymentMethodType::Seicomart => Self::Seicomart,
+ common_enums::PaymentMethodType::PayEasy => Self::PayEasy,
+ common_enums::PaymentMethodType::LocalBankTransfer => Self::LocalBankTransfer,
+ common_enums::PaymentMethodType::OpenBankingPIS => Self::OpenBankingPis,
+ common_enums::PaymentMethodType::DirectCarrierBilling => Self::DirectCarrierBilling,
+ common_enums::PaymentMethodType::InstantBankTransfer => Self::InstantBankTransfer,
+ common_enums::PaymentMethodType::RevolutPay => Self::RevolutPay,
+ // Variants that don't have direct proto equivalents
+ _ => Self::Unspecified,
+ }
+ }
+}
+
impl transformers::ForeignTryFrom<payments_grpc::PaymentServiceCreateOrderResponse>
for Result<PaymentsResponseData, ErrorResponse>
{