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: introduce placeholders for complete authorize and preprocessing through ucs (#9915)

Hrithikesh38725599d9a1
diff --git a/crates/hyperswitch_connectors/src/connectors/cybersource.rs b/crates/hyperswitch_connectors/src/connectors/cybersource.rs
index e8e8aede29..f485af538c 100644
--- a/crates/hyperswitch_connectors/src/connectors/cybersource.rs
+++ b/crates/hyperswitch_connectors/src/connectors/cybersource.rs
@@ -2292,6 +2292,46 @@ impl ConnectorSpecifications for Cybersource {
// during authorize flow, there is no pre processing flow. Only alternate PreAuthenticate flow
None
}
+ api::CurrentFlowInfo::CompleteAuthorize { request_data } => {
+ // TODO: add logic before deciding the pre processing flow Authenticate or PostAuthenticate
+ let redirect_response = request_data.redirect_response.as_ref()?;
+ match redirect_response.params.as_ref() {
+ Some(param) if !param.peek().is_empty() => {
+ Some(api::PreProcessingFlowName::Authenticate)
+ }
+ Some(_) | None => Some(api::PreProcessingFlowName::PostAuthenticate),
+ }
+ }
+ }
+ }
+ fn decide_should_continue_after_preprocessing(
+ &self,
+ current_flow: api::CurrentFlowInfo<'_>,
+ pre_processing_flow_name: api::PreProcessingFlowName,
+ preprocessing_flow_response: api::PreProcessingFlowResponse<'_>,
+ ) -> bool {
+ match (current_flow, pre_processing_flow_name) {
+ (api::CurrentFlowInfo::Authorize { .. }, _) => {
+ // during authorize flow, there is no pre processing flow. Only alternate PreAuthenticate flow
+ true
+ }
+ (
+ api::CurrentFlowInfo::CompleteAuthorize { .. },
+ api::PreProcessingFlowName::Authenticate,
+ )
+ | (
+ api::CurrentFlowInfo::CompleteAuthorize { .. },
+ api::PreProcessingFlowName::PostAuthenticate,
+ ) => {
+ (matches!(
+ preprocessing_flow_response.response,
+ Ok(PaymentsResponseData::TransactionResponse {
+ ref redirection_data,
+ ..
+ }) if redirection_data.is_none()
+ ) && preprocessing_flow_response.attempt_status
+ != common_enums::AttemptStatus::AuthenticationFailed)
+ }
}
}
fn get_alternate_flow_if_needed(
@@ -2309,6 +2349,8 @@ impl ConnectorSpecifications for Cybersource {
None
}
}
+ // No alternate flow for complete authorize
+ api::CurrentFlowInfo::CompleteAuthorize { .. } => None,
}
}
}
diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rs
index 908dda6a66..063868b034 100644
--- a/crates/hyperswitch_domain_models/src/router_request_types.rs
+++ b/crates/hyperswitch_domain_models/src/router_request_types.rs
@@ -655,35 +655,25 @@ pub struct PaymentsAuthenticateData {
pub amount: Option<i64>,
pub email: Option<pii::Email>,
pub currency: Option<storage_enums::Currency>,
- pub payment_method_type: Option<storage_enums::PaymentMethodType>,
- pub router_return_url: Option<String>,
pub complete_authorize_url: Option<String>,
pub browser_info: Option<BrowserInformation>,
- pub connector_transaction_id: Option<String>,
- pub enrolled_for_3ds: bool,
pub redirect_response: Option<CompleteAuthorizeRedirectResponse>,
-
- // New amount for amount frame work
pub minor_amount: Option<MinorUnit>,
}
-impl TryFrom<PaymentsAuthorizeData> for PaymentsAuthenticateData {
+impl TryFrom<CompleteAuthorizeData> for PaymentsAuthenticateData {
type Error = error_stack::Report<ApiErrorResponse>;
- fn try_from(data: PaymentsAuthorizeData) -> Result<Self, Self::Error> {
+ fn try_from(data: CompleteAuthorizeData) -> Result<Self, Self::Error> {
Ok(Self {
- payment_method_data: Some(data.payment_method_data),
+ payment_method_data: data.payment_method_data,
amount: Some(data.amount),
minor_amount: Some(data.minor_amount),
email: data.email,
currency: Some(data.currency),
- payment_method_type: data.payment_method_type,
- router_return_url: data.router_return_url,
complete_authorize_url: data.complete_authorize_url,
browser_info: data.browser_info,
- connector_transaction_id: None,
- redirect_response: None,
- enrolled_for_3ds: data.enrolled_for_3ds,
+ redirect_response: data.redirect_response,
})
}
}
diff --git a/crates/hyperswitch_interfaces/src/api.rs b/crates/hyperswitch_interfaces/src/api.rs
index de2516ed19..dbc21b99a9 100644
--- a/crates/hyperswitch_interfaces/src/api.rs
+++ b/crates/hyperswitch_interfaces/src/api.rs
@@ -57,17 +57,18 @@ use hyperswitch_domain_models::{
AuthenticationConfirmation, PostAuthenticate, PreAuthenticate, VerifyWebhookSource,
},
router_request_types::{
+ self,
unified_authentication_service::{
UasAuthenticationRequestData, UasAuthenticationResponseData,
UasConfirmationRequestData, UasPostAuthenticationRequestData,
UasPreAuthenticationRequestData,
},
AccessTokenAuthenticationRequestData, AccessTokenRequestData, MandateRevokeRequestData,
- PaymentsAuthorizeData, VerifyWebhookSourceRequestData,
+ VerifyWebhookSourceRequestData,
},
router_response_types::{
- ConnectorInfo, MandateRevokeResponseData, PaymentMethodDetails, SupportedPaymentMethods,
- VerifyWebhookSourceResponseData,
+ self, ConnectorInfo, MandateRevokeResponseData, PaymentMethodDetails,
+ SupportedPaymentMethods, VerifyWebhookSourceResponseData,
},
};
use masking::Maskable;
@@ -390,7 +391,12 @@ pub enum CurrentFlowInfo<'a> {
/// The authentication type being used
auth_type: &'a enums::AuthenticationType,
/// The payment authorize request data
- request_data: &'a PaymentsAuthorizeData,
+ request_data: &'a router_request_types::PaymentsAuthorizeData,
+ },
+ /// CompleteAuthorize flow information
+ CompleteAuthorize {
+ /// The payment authorize request data
+ request_data: &'a router_request_types::CompleteAuthorizeData,
},
}
@@ -406,11 +412,21 @@ pub enum AlternateFlow {
///
/// For example, PreProcessing flow must be made before Authorize flow.
/// Or PostAuthenticate flow must be made before CompleteAuthorize flow for cybersource.
-#[derive(Default, Debug, Clone, Copy)]
+#[derive(Debug, Clone, Copy)]
pub enum PreProcessingFlowName {
- #[default]
- /// Pre-processing flow
- PreProcessing,
+ /// Authentication flow must be made before the actual flow
+ Authenticate,
+ /// Post-authentication flow must be made before the actual flow
+ PostAuthenticate,
+}
+
+/// Response of the preprocessing flow
+#[derive(Debug)]
+pub struct PreProcessingFlowResponse<'a> {
+ /// Payment response data from the preprocessing flow
+ pub response: &'a Result<router_response_types::PaymentsResponseData, ErrorResponse>,
+ /// Attempt status after the preprocessing flow
+ pub attempt_status: enums::AttemptStatus,
}
/// The trait that provides specifications about the connector
@@ -420,7 +436,18 @@ pub trait ConnectorSpecifications {
&self,
_current_flow: CurrentFlowInfo<'_>,
) -> Option<PreProcessingFlowName> {
- Some(PreProcessingFlowName::default())
+ None
+ }
+ /// Based on the current flow and preprocessing_flow_response, decide if the main flow must be called or not
+ ///
+ /// By default, always continue with the main flow after the preprocessing flow.
+ fn decide_should_continue_after_preprocessing(
+ &self,
+ _current_flow: CurrentFlowInfo<'_>,
+ _pre_processing_flow_name: PreProcessingFlowName,
+ _preprocessing_flow_response: PreProcessingFlowResponse<'_>,
+ ) -> bool {
+ true
}
/// If Some is returned, the returned api flow must be made instead of the current flow.
fn get_alternate_flow_if_needed(
@@ -771,7 +798,7 @@ pub trait ConnectorValidation: ConnectorCommon + ConnectorSpecifications {
/// fn validate_psync_reference_id
fn validate_psync_reference_id(
&self,
- data: &hyperswitch_domain_models::router_request_types::PaymentsSyncData,
+ data: &router_request_types::PaymentsSyncData,
_is_three_ds: bool,
_status: enums::AttemptStatus,
_connector_meta_data: Option<common_utils::pii::SecretSerdeValue>,
diff --git a/crates/router/src/core/payments/flows.rs b/crates/router/src/core/payments/flows.rs
index a73570d7b5..2a7fb594fc 100644
--- a/crates/router/src/core/payments/flows.rs
+++ b/crates/router/src/core/payments/flows.rs
@@ -226,6 +226,7 @@ pub trait Feature<F, T> {
_merchant_context: &domain::MerchantContext,
_connector_data: &api::ConnectorData,
_unified_connector_service_execution_mode: ExecutionMode,
+ _merchant_order_reference_id: Option<String>,
) -> RouterResult<(Self, bool)>
where
F: 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 fbca96d93f..944eb2bccf 100644
--- a/crates/router/src/core/payments/flows/complete_authorize_flow.rs
+++ b/crates/router/src/core/payments/flows/complete_authorize_flow.rs
@@ -1,4 +1,6 @@
use async_trait::async_trait;
+use external_services::grpc_client;
+use hyperswitch_interfaces::{api as api_interface, api::ConnectorSpecifications};
use masking::ExposeInterface;
use super::{ConstructFlowSpecificData, Feature};
@@ -214,6 +216,113 @@ impl Feature<api::CompleteAuthorize, types::CompleteAuthorizeData>
) -> RouterResult<Self> {
complete_authorize_preprocessing_steps(state, &self, true, connector).await
}
+
+ async fn call_preprocessing_through_unified_connector_service<'a>(
+ self,
+ state: &SessionState,
+ header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
+ lineage_ids: &grpc_client::LineageIds,
+ #[cfg(feature = "v1")] merchant_connector_account: helpers::MerchantConnectorAccountType,
+ #[cfg(feature = "v2")]
+ merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,
+ merchant_context: &domain::MerchantContext,
+ connector_data: &api::ConnectorData,
+ unified_connector_service_execution_mode: common_enums::ExecutionMode,
+ merchant_order_reference_id: Option<String>,
+ ) -> RouterResult<(Self, bool)> {
+ let current_flow = api_interface::CurrentFlowInfo::CompleteAuthorize {
+ request_data: &self.request,
+ };
+ let optional_preprocessing_flow = connector_data
+ .connector
+ .get_preprocessing_flow_if_needed(current_flow);
+ match optional_preprocessing_flow {
+ Some(preprocessing_flow) => {
+ let updated_router_data = handle_preprocessing_through_unified_connector_service(
+ self,
+ state,
+ header_payload,
+ lineage_ids,
+ merchant_connector_account.clone(),
+ merchant_context,
+ connector_data,
+ unified_connector_service_execution_mode,
+ merchant_order_reference_id.clone(),
+ preprocessing_flow,
+ )
+ .await?;
+ let pre_processing_flow_response = api_interface::PreProcessingFlowResponse {
+ response: &updated_router_data.response,
+ attempt_status: updated_router_data.status,
+ };
+ let current_flow = api_interface::CurrentFlowInfo::CompleteAuthorize {
+ request_data: &updated_router_data.request,
+ };
+ let should_continue = connector_data
+ .connector
+ .decide_should_continue_after_preprocessing(
+ current_flow,
+ preprocessing_flow,
+ pre_processing_flow_response,
+ );
+ Ok((updated_router_data, should_continue))
+ }
+ None => Ok((self, true)),
+ }
+ }
+
+ async fn call_unified_connector_service<'a>(
+ &mut self,
+ _state: &SessionState,
+ _header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
+ _lineage_ids: grpc_client::LineageIds,
+ #[cfg(feature = "v1")] _merchant_connector_account: helpers::MerchantConnectorAccountType,
+ #[cfg(feature = "v2")]
+ _merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,
+ _merchant_context: &domain::MerchantContext,
+ _connector_data: &api::ConnectorData,
+ _unified_connector_service_execution_mode: common_enums::ExecutionMode,
+ _merchant_order_reference_id: Option<String>,
+ ) -> RouterResult<()> {
+ // Call UCS for Authorize flow
+ Ok(())
+ }
+}
+
+#[allow(clippy::too_many_arguments)]
+async fn handle_preprocessing_through_unified_connector_service(
+ router_data: types::RouterData<
+ api::CompleteAuthorize,
+ types::CompleteAuthorizeData,
+ types::PaymentsResponseData,
+ >,
+ _state: &SessionState,
+ _header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
+ _lineage_ids: &grpc_client::LineageIds,
+ #[cfg(feature = "v1")] _merchant_connector_account: helpers::MerchantConnectorAccountType,
+ #[cfg(feature = "v2")] _merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,
+ _merchant_context: &domain::MerchantContext,
+ _connector_data: &api::ConnectorData,
+ _unified_connector_service_execution_mode: common_enums::ExecutionMode,
+ _merchant_order_reference_id: Option<String>,
+ preprocessing_flow_name: api_interface::PreProcessingFlowName,
+) -> RouterResult<
+ types::RouterData<
+ api::CompleteAuthorize,
+ types::CompleteAuthorizeData,
+ types::PaymentsResponseData,
+ >,
+> {
+ match preprocessing_flow_name {
+ api_interface::PreProcessingFlowName::Authenticate => {
+ // Call UCS for Authenticate flow
+ Ok(router_data)
+ }
+ api_interface::PreProcessingFlowName::PostAuthenticate => {
+ // Call UCS for PostAuthenticate flow
+ Ok(router_data)
+ }
+ }
}
pub async fn complete_authorize_preprocessing_steps<F: Clone>(
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 9a8594f20c..29bb45be48 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -7874,7 +7874,7 @@ pub async fn process_through_ucs<'a, F, RouterDReq, ApiRequest, D>(
business_profile: &'a domain::Profile,
merchant_connector_account: MerchantConnectorAccountType,
connector_data: &api::ConnectorData,
- mut router_data: RouterData<F, RouterDReq, PaymentsResponseData>,
+ router_data: RouterData<F, RouterDReq, PaymentsResponseData>,
) -> RouterResult<(
RouterData<F, RouterDReq, PaymentsResponseData>,
MerchantConnectorAccountType,
@@ -7918,47 +7918,60 @@ where
GatewaySystem::UnifiedConnectorService,
)?;
- // Update trackers
- (_, *payment_data) = operation
- .to_update_tracker()?
- .update_trackers(
- state,
- req_state,
- payment_data.clone(),
- customer.clone(),
- merchant_context.get_merchant_account().storage_scheme,
- None,
- merchant_context.get_merchant_key_store(),
- frm_suggestion,
- header_payload.clone(),
- )
- .await?;
-
- // Call UCS
let lineage_ids = grpc_client::LineageIds::new(
business_profile.merchant_id.clone(),
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_order_reference_id
.clone();
-
- router_data
- .call_unified_connector_service(
+ let (mut router_data, should_continue) = router_data
+ .call_preprocessing_through_unified_connector_service(
state,
&header_payload,
- lineage_ids,
+ &lineage_ids,
merchant_connector_account.clone(),
merchant_context,
connector_data,
ExecutionMode::Primary, // UCS is called in primary mode
- merchant_order_reference_id,
+ merchant_order_reference_id.clone(),
)
.await?;
+ // Update trackers
+ (_, *payment_data) = operation
+ .to_update_tracker()?
+ .update_trackers(
+ state,
+ req_state,
+ payment_data.clone(),
+ customer.clone(),
+ merchant_context.get_merchant_account().storage_scheme,
+ None,
+ merchant_context.get_merchant_key_store(),
+ frm_suggestion,
+ header_payload.clone(),
+ )
+ .await?;
+
+ // Based on the preprocessing response, decide whether to continue with UCS call
+ if should_continue {
+ router_data
+ .call_unified_connector_service(
+ state,
+ &header_payload,
+ lineage_ids,
+ merchant_connector_account.clone(),
+ merchant_context,
+ connector_data,
+ ExecutionMode::Primary, // UCS is called in primary mode
+ merchant_order_reference_id,
+ )
+ .await?;
+ }
+
Ok((router_data, merchant_connector_account))
}