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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(core): Introduce new decide flow mechanism for payment authorization (#9808)
Hrithikesh9af5a8c19f61
diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rsindex ed01e66e4a..cd3650c077 100644--- a/crates/common_enums/src/enums.rs+++ b/crates/common_enums/src/enums.rs@@ -348,6 +348,12 @@ pub enum AuthenticationType {NoThreeDs,}+impl AuthenticationType {+ pub fn is_three_ds(&self) -> bool {+ matches!(self, Self::ThreeDs)+ }+}+/// The status of the capture#[derive(Clone,diff --git a/crates/hyperswitch_connectors/src/connectors/cybersource.rs b/crates/hyperswitch_connectors/src/connectors/cybersource.rsindex 03f3de84d6..e8e8aede29 100644--- a/crates/hyperswitch_connectors/src/connectors/cybersource.rs+++ b/crates/hyperswitch_connectors/src/connectors/cybersource.rs@@ -2283,4 +2283,47 @@ impl ConnectorSpecifications for Cybersource {fn get_supported_webhook_flows(&self) -> Option<&'static [enums::EventClass]> {Some(&CYBERSOURCE_SUPPORTED_WEBHOOK_FLOWS)}+ fn get_preprocessing_flow_if_needed(+ &self,+ current_flow_info: api::CurrentFlowInfo<'_>,+ ) -> Option<api::PreProcessingFlowName> {+ match current_flow_info {+ api::CurrentFlowInfo::Authorize { .. } => {+ // during authorize flow, there is no pre processing flow. Only alternate PreAuthenticate flow+ None+ }+ }+ }+ fn get_alternate_flow_if_needed(+ &self,+ current_flow: api::CurrentFlowInfo<'_>,+ ) -> Option<api::AlternateFlow> {+ match current_flow {+ api::CurrentFlowInfo::Authorize {+ request_data,+ auth_type,+ } => {+ if self.is_3ds_setup_required(request_data, *auth_type) {+ Some(api::AlternateFlow::PreAuthenticate)+ } else {+ None+ }+ }+ }+ }+}++impl Cybersource {+ pub fn is_3ds_setup_required(+ &self,+ request: &PaymentsAuthorizeData,+ auth_type: common_enums::AuthenticationType,+ ) -> bool {+ router_env::logger::info!(router_data_request=?request, auth_type=?auth_type, "Checking if 3DS setup is required for Cybersource");+ auth_type.is_three_ds()+ && request.is_card()+ && (request.connector_mandate_id().is_none()+ && request.get_optional_network_transaction_id().is_none())+ && request.authentication_data.is_none()+ }}diff --git a/crates/hyperswitch_connectors/src/default_implementations.rs b/crates/hyperswitch_connectors/src/default_implementations.rsindex b3e3e710b4..41b6565e01 100644--- a/crates/hyperswitch_connectors/src/default_implementations.rs+++ b/crates/hyperswitch_connectors/src/default_implementations.rs@@ -1973,12 +1973,14 @@ default_imp_for_pre_authenticate_steps!(connectors::Paybox,connectors::Payeezy,connectors::Payload,+ connectors::Paysafe,connectors::Payme,connectors::Payone,connectors::Paypal,connectors::Paystack,connectors::Paytm,connectors::Payu,+ connectors::Peachpayments,connectors::Phonepe,connectors::Placetopay,connectors::Plaid,@@ -2119,6 +2121,7 @@ default_imp_for_authenticate_steps!(connectors::Opennode,connectors::Paybox,connectors::Payeezy,+ connectors::Paysafe,connectors::Payload,connectors::Payme,connectors::Payone,@@ -2126,6 +2129,7 @@ default_imp_for_authenticate_steps!(connectors::Paystack,connectors::Paytm,connectors::Payu,+ connectors::Peachpayments,connectors::Phonepe,connectors::Placetopay,connectors::Plaid,@@ -2267,12 +2271,14 @@ default_imp_for_post_authenticate_steps!(connectors::Paybox,connectors::Payeezy,connectors::Payload,+ connectors::Paysafe,connectors::Payme,connectors::Payone,connectors::Paypal,connectors::Paystack,connectors::Paytm,connectors::Payu,+ connectors::Peachpayments,connectors::Phonepe,connectors::Placetopay,connectors::Plaid,@@ -9420,6 +9426,31 @@ impl<const T: u8>{}+#[cfg(feature = "dummy_connector")]+impl<const T: u8> PaymentsAuthenticate for connectors::DummyConnector<T> {}+#[cfg(feature = "dummy_connector")]+impl<const T: u8> PaymentsPreAuthenticate for connectors::DummyConnector<T> {}+#[cfg(feature = "dummy_connector")]+impl<const T: u8> PaymentsPostAuthenticate for connectors::DummyConnector<T> {}++#[cfg(feature = "dummy_connector")]+impl<const T: u8> ConnectorIntegration<Authenticate, PaymentsAuthenticateData, PaymentsResponseData>+ for connectors::DummyConnector<T>+{+}+#[cfg(feature = "dummy_connector")]+impl<const T: u8>+ ConnectorIntegration<PreAuthenticate, PaymentsPreAuthenticateData, PaymentsResponseData>+ for connectors::DummyConnector<T>+{+}+#[cfg(feature = "dummy_connector")]+impl<const T: u8>+ ConnectorIntegration<PostAuthenticate, PaymentsPostAuthenticateData, PaymentsResponseData>+ for connectors::DummyConnector<T>+{+}+#[cfg(feature = "dummy_connector")]impl<const T: u8> ExternalAuthentication for connectors::DummyConnector<T> {}#[cfg(feature = "dummy_connector")]diff --git a/crates/hyperswitch_connectors/src/default_implementations_v2.rs b/crates/hyperswitch_connectors/src/default_implementations_v2.rsindex d861913755..cc4b1d5387 100644--- a/crates/hyperswitch_connectors/src/default_implementations_v2.rs+++ b/crates/hyperswitch_connectors/src/default_implementations_v2.rs@@ -27,6 +27,7 @@ use hyperswitch_domain_models::{revenue_recovery::{BillingConnectorInvoiceSync, BillingConnectorPaymentsSync, InvoiceRecordBack,},+ unified_authentication_service::{Authenticate, PostAuthenticate, PreAuthenticate},webhooks::VerifyWebhookSource,AccessTokenAuth, AccessTokenAuthentication, ExternalVaultCreateFlow,ExternalVaultDeleteFlow, ExternalVaultInsertFlow, ExternalVaultRetrieveFlow,@@ -42,13 +43,15 @@ use hyperswitch_domain_models::{CreateOrderRequestData, DefendDisputeRequestData, DisputeSyncData,ExternalVaultProxyPaymentsData, FetchDisputesRequestData, GiftCardBalanceCheckRequestData,MandateRevokeRequestData, PaymentMethodTokenizationData, PaymentsApproveData,- PaymentsAuthorizeData, PaymentsCancelData, PaymentsCancelPostCaptureData,- PaymentsCaptureData, PaymentsExtendAuthorizationData, PaymentsIncrementalAuthorizationData,- PaymentsPostProcessingData, PaymentsPostSessionTokensData, PaymentsPreProcessingData,- PaymentsRejectData, PaymentsSessionData, PaymentsSyncData, PaymentsTaxCalculationData,- PaymentsUpdateMetadataData, RefundsData, RetrieveFileRequestData,- SdkPaymentsSessionUpdateData, SetupMandateRequestData, SubmitEvidenceRequestData,- UploadFileRequestData, VaultRequestData, VerifyWebhookSourceRequestData,+ PaymentsAuthenticateData, PaymentsAuthorizeData, PaymentsCancelData,+ PaymentsCancelPostCaptureData, PaymentsCaptureData, PaymentsExtendAuthorizationData,+ PaymentsIncrementalAuthorizationData, PaymentsPostAuthenticateData,+ PaymentsPostProcessingData, PaymentsPostSessionTokensData, PaymentsPreAuthenticateData,+ PaymentsPreProcessingData, PaymentsRejectData, PaymentsSessionData, PaymentsSyncData,+ PaymentsTaxCalculationData, PaymentsUpdateMetadataData, RefundsData,+ RetrieveFileRequestData, SdkPaymentsSessionUpdateData, SetupMandateRequestData,+ SubmitEvidenceRequestData, UploadFileRequestData, VaultRequestData,+ VerifyWebhookSourceRequestData,},router_response_types::{revenue_recovery::{@@ -109,9 +112,10 @@ use hyperswitch_interfaces::{PaymentCreateOrderV2, PaymentExtendAuthorizationV2, PaymentIncrementalAuthorizationV2,PaymentPostCaptureVoidV2, PaymentPostSessionTokensV2, PaymentRejectV2,PaymentSessionUpdateV2, PaymentSessionV2, PaymentSyncV2, PaymentTokenV2,- PaymentUpdateMetadataV2, PaymentV2, PaymentVoidV2, PaymentsCompleteAuthorizeV2,- PaymentsGiftCardBalanceCheckV2, PaymentsPostProcessingV2, PaymentsPreProcessingV2,- TaxCalculationV2,+ PaymentUpdateMetadataV2, PaymentV2, PaymentVoidV2, PaymentsAuthenticateV2,+ PaymentsCompleteAuthorizeV2, PaymentsGiftCardBalanceCheckV2,+ PaymentsPostAuthenticateV2, PaymentsPostProcessingV2, PaymentsPreAuthenticateV2,+ PaymentsPreProcessingV2, TaxCalculationV2,},refunds_v2::{RefundExecuteV2, RefundSyncV2, RefundV2},revenue_recovery_v2::{@@ -151,6 +155,9 @@ macro_rules! default_imp_for_new_connector_integration_payment {impl ConnectorCustomerV2 for $path::$connector{}impl PaymentsPreProcessingV2 for $path::$connector{}impl PaymentsGiftCardBalanceCheckV2 for $path::$connector{}+ impl PaymentsPreAuthenticateV2 for $path::$connector{}+ impl PaymentsAuthenticateV2 for $path::$connector{}+ impl PaymentsPostAuthenticateV2 for $path::$connector{}impl PaymentsPostProcessingV2 for $path::$connector{}impl TaxCalculationV2 for $path::$connector{}impl PaymentSessionUpdateV2 for $path::$connector{}@@ -253,7 +260,7 @@ macro_rules! default_imp_for_new_connector_integration_payment {PaymentsTaxCalculationData,TaxCalculationResponseData,> for $path::$connector{}- impl ConnectorIntegrationV2<+ impl ConnectorIntegrationV2<SdkSessionUpdate,PaymentFlowData,SdkPaymentsSessionUpdateData,@@ -275,6 +282,24 @@ macro_rules! default_imp_for_new_connector_integration_payment {> for $path::$connector{}impl ConnectorIntegrationV2<CreateOrder, PaymentFlowData, CreateOrderRequestData, PaymentsResponseData>for $path::$connector{}+ impl ConnectorIntegrationV2<+ PreAuthenticate,+ PaymentFlowData,+ PaymentsPreAuthenticateData,+ PaymentsResponseData,+ > for $path::$connector{}+ impl ConnectorIntegrationV2<+ Authenticate,+ PaymentFlowData,+ PaymentsAuthenticateData,+ PaymentsResponseData,+ > for $path::$connector{}+ impl ConnectorIntegrationV2<+ PostAuthenticate,+ PaymentFlowData,+ PaymentsPostAuthenticateData,+ PaymentsResponseData,+ > for $path::$connector{})*};}diff --git a/crates/hyperswitch_interfaces/src/api.rs b/crates/hyperswitch_interfaces/src/api.rsindex 65089db607..d91d609a9b 100644--- a/crates/hyperswitch_interfaces/src/api.rs+++ b/crates/hyperswitch_interfaces/src/api.rs@@ -30,7 +30,9 @@ pub mod vault_v2;use std::fmt::Debug;use common_enums::{- enums::{CallConnectorAction, CaptureMethod, EventClass, PaymentAction, PaymentMethodType},+ enums::{+ self, CallConnectorAction, CaptureMethod, EventClass, PaymentAction, PaymentMethodType,+ },PaymentMethod,};use common_utils::{@@ -61,7 +63,7 @@ use hyperswitch_domain_models::{UasPreAuthenticationRequestData,},AccessTokenAuthenticationRequestData, AccessTokenRequestData, MandateRevokeRequestData,- VerifyWebhookSourceRequestData,+ PaymentsAuthorizeData, VerifyWebhookSourceRequestData,},router_response_types::{ConnectorInfo, MandateRevokeResponseData, PaymentMethodDetails, SupportedPaymentMethods,@@ -378,8 +380,55 @@ pub trait ConnectorCommon {}}+/// Current flow information passed to the connector specifications trait+///+/// In order to make some desicion about the preprocessing or alternate flow+#[derive(Clone, Debug)]+pub enum CurrentFlowInfo<'a> {+ /// Authorize flow information+ Authorize {+ /// The authentication type being used+ auth_type: &'a enums::AuthenticationType,+ /// The payment authorize request data+ request_data: &'a PaymentsAuthorizeData,+ },+}++/// Alternate API flow that must be made instead of the current flow.+/// For example, PreAuthenticate flow must be made instead of Authorize flow.+#[derive(Debug, Clone, Copy)]+pub enum AlternateFlow {+ /// Pre-authentication flow+ PreAuthenticate,+}++/// The Preprocessing flow that must be made before the current flow.+///+/// 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)]+pub enum PreProcessingFlowName {+ #[default]+ /// Pre-processing flow+ PreProcessing,+}+/// The trait that provides specifications about the connectorpub trait ConnectorSpecifications {+ /// Preprocessing flow name if any, that must be made before the current flow.+ fn get_preprocessing_flow_if_needed(+ &self,+ _current_flow: CurrentFlowInfo<'_>,+ ) -> Option<PreProcessingFlowName> {+ Some(PreProcessingFlowName::default())+ }+ /// If Some is returned, the returned api flow must be made instead of the current flow.+ fn get_alternate_flow_if_needed(+ &self,+ _current_flow: CurrentFlowInfo<'_>,+ ) -> Option<AlternateFlow> {+ None+ }/// Details related to payment method supported by the connectorfn get_supported_payment_methods(&self) -> Option<&'static SupportedPaymentMethods> {None@@ -719,7 +768,7 @@ pub trait ConnectorValidation: ConnectorCommon + ConnectorSpecifications {&self,data: &hyperswitch_domain_models::router_request_types::PaymentsSyncData,_is_three_ds: bool,- _status: common_enums::enums::AttemptStatus,+ _status: enums::AttemptStatus,_connector_meta_data: Option<common_utils::pii::SecretSerdeValue>,) -> CustomResult<(), errors::ConnectorError> {data.connector_transaction_iddiff --git a/crates/hyperswitch_interfaces/src/api/payments.rs b/crates/hyperswitch_interfaces/src/api/payments.rsindex 511c630303..f11428d348 100644--- a/crates/hyperswitch_interfaces/src/api/payments.rs+++ b/crates/hyperswitch_interfaces/src/api/payments.rs@@ -35,6 +35,9 @@ pub trait Payment:+ api::ConnectorSpecifications+ api::ConnectorValidation+ PaymentAuthorize+ + PaymentsPreAuthenticate+ + PaymentsAuthenticate+ + PaymentsPostAuthenticate+ PaymentAuthorizeSessionToken+ PaymentsCompleteAuthorize+ PaymentSyncdiff --git a/crates/hyperswitch_interfaces/src/api/payments_v2.rs b/crates/hyperswitch_interfaces/src/api/payments_v2.rsindex 5bc7c2067a..9e4f7cbfd3 100644--- a/crates/hyperswitch_interfaces/src/api/payments_v2.rs+++ b/crates/hyperswitch_interfaces/src/api/payments_v2.rs@@ -289,6 +289,9 @@ pub trait PaymentV2:+ ConnectorSpecifications+ ConnectorValidation+ PaymentAuthorizeV2+ + PaymentsPreAuthenticateV2+ + PaymentsAuthenticateV2+ + PaymentsPostAuthenticateV2+ PaymentAuthorizeSessionTokenV2+ PaymentsCompleteAuthorizeV2+ PaymentSyncV2diff --git a/crates/hyperswitch_interfaces/src/connector_integration_interface.rs b/crates/hyperswitch_interfaces/src/connector_integration_interface.rsindex b6455d45b4..aa3740b3c2 100644--- a/crates/hyperswitch_interfaces/src/connector_integration_interface.rs+++ b/crates/hyperswitch_interfaces/src/connector_integration_interface.rs@@ -508,6 +508,25 @@ impl ConnectorValidation for ConnectorEnum {}impl ConnectorSpecifications for ConnectorEnum {+ fn get_preprocessing_flow_if_needed(+ &self,+ current_flow_info: api::CurrentFlowInfo<'_>,+ ) -> Option<api::PreProcessingFlowName> {+ match self {+ Self::Old(connector) => connector.get_preprocessing_flow_if_needed(current_flow_info),+ Self::New(connector) => connector.get_preprocessing_flow_if_needed(current_flow_info),+ }+ }+ fn get_alternate_flow_if_needed(+ &self,+ current_flow: api::CurrentFlowInfo<'_>,+ ) -> Option<api::AlternateFlow> {+ match self {+ Self::Old(connector) => connector.get_alternate_flow_if_needed(current_flow),+ Self::New(connector) => connector.get_alternate_flow_if_needed(current_flow),+ }+ }+fn get_supported_payment_methods(&self) -> Option<&'static SupportedPaymentMethods> {match self {Self::Old(connector) => connector.get_supported_payment_methods(),diff --git a/crates/router/src/core/api_locking.rs b/crates/router/src/core/api_locking.rsindex dd3712e380..cc84e70e2c 100644--- a/crates/router/src/core/api_locking.rs+++ b/crates/router/src/core/api_locking.rs@@ -91,12 +91,12 @@ impl LockAction {).await.change_context(errors::ApiErrorResponse::InternalServerError)?;- let lock_aqcuired = results.iter().all(|res| {+ let lock_acquired = results.iter().all(|res| {// each redis value must match the request_id// if even 1 does match, the lock is not acquired*res.get_value() == request_id});- if lock_aqcuired {+ if lock_acquired {logger::info!("Lock acquired for locking inputs {:?}", inputs);return Ok(());} else {diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex 3b8ad0b54e..813075ead3 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -4310,6 +4310,7 @@ wherefrm_suggestion,business_profile,merchant_connector_account,+ &connector,router_data,).await@@ -4902,6 +4903,7 @@ wherelineage_ids,merchant_connector_account_type_details.clone(),merchant_context,+ &connector,ExecutionMode::Primary, // UCS is called in primary modemerchant_order_reference_id,)@@ -5013,6 +5015,7 @@ wherelineage_ids,merchant_connector_account_type_details.clone(),merchant_context,+ &connector,ExecutionMode::Primary, //UCS is called in primary modemerchant_order_reference_id,)diff --git a/crates/router/src/core/payments/access_token.rs b/crates/router/src/core/payments/access_token.rsindex 5512b1b2fd..4ddf998bde 100644--- a/crates/router/src/core/payments/access_token.rs+++ b/crates/router/src/core/payments/access_token.rs@@ -12,7 +12,7 @@ use crate::{},routes::{metrics, SessionState},services::{self, logger},- types::{self, api as api_types, domain},+ types::{self, api as api_types},};/// After we get the access token, check if there was an error and if the flow should proceed further@@ -56,7 +56,6 @@ pub async fn add_access_token<>(state: &SessionState,connector: &api_types::ConnectorData,- merchant_context: &domain::MerchantContext,router_data: &types::RouterData<F, Req, Res>,creds_identifier: Option<&str>,) -> RouterResult<types::AddAccessTokenResult> {@@ -64,7 +63,7 @@ pub async fn add_access_token<.connector_name.supports_access_token(router_data.payment_method){- let merchant_id = merchant_context.get_merchant_account().get_id();+ let merchant_id = &router_data.merchant_id;let store = &*state.store;// `merchant_connector_id` may not be present in the below cases@@ -90,7 +89,7 @@ pub async fn add_access_token<Some(access_token) => {router_env::logger::debug!("Access token found in redis for merchant_id: {:?}, payment_id: {:?}, connector: {} which has expiry of: {} seconds",- merchant_context.get_merchant_account().get_id(),+ merchant_id,router_data.payment_id,connector.connector_name,access_token.expires@@ -140,51 +139,46 @@ pub async fn add_access_token<refresh_token_request_data,refresh_token_response_data,);- refresh_connector_auth(- state,- connector,- merchant_context,- &refresh_token_router_data,- )- .await?- .async_map(|access_token| async move {- let store = &*state.store;+ refresh_connector_auth(state, connector, &refresh_token_router_data)+ .await?+ .async_map(|access_token| async move {+ let store = &*state.store;- // The expiry should be adjusted for network delays from the connector- // The access token might not have been expired when request is sent- // But once it reaches the connector, it might expire because of the network delay- // Subtract few seconds from the expiry in order to account for these network delays- // This will reduce the expiry time by `REDUCE_ACCESS_TOKEN_EXPIRY_TIME` seconds- let modified_access_token_with_expiry = types::AccessToken {- expires: access_token- .expires- .saturating_sub(consts::REDUCE_ACCESS_TOKEN_EXPIRY_TIME.into()),- ..access_token- };+ // The expiry should be adjusted for network delays from the connector+ // The access token might not have been expired when request is sent+ // But once it reaches the connector, it might expire because of the network delay+ // Subtract few seconds from the expiry in order to account for these network delays+ // This will reduce the expiry time by `REDUCE_ACCESS_TOKEN_EXPIRY_TIME` seconds+ let modified_access_token_with_expiry = types::AccessToken {+ expires: access_token+ .expires+ .saturating_sub(consts::REDUCE_ACCESS_TOKEN_EXPIRY_TIME.into()),+ ..access_token+ };- logger::debug!(- access_token_expiry_after_modification =- modified_access_token_with_expiry.expires- );+ logger::debug!(+ access_token_expiry_after_modification =+ modified_access_token_with_expiry.expires+ );- if let Err(access_token_set_error) = store- .set_access_token(- merchant_id,- &merchant_connector_id_or_connector_name,- modified_access_token_with_expiry.clone(),- )- .await- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("DB error when setting the access token")- {- // If we are not able to set the access token in redis, the error should just be logged and proceed with the payment- // Payments should not fail, once the access token is successfully created- // The next request will create new access token, if required- logger::error!(access_token_set_error=?access_token_set_error);- }- Some(modified_access_token_with_expiry)- })- .await+ if let Err(access_token_set_error) = store+ .set_access_token(+ merchant_id,+ &merchant_connector_id_or_connector_name,+ modified_access_token_with_expiry.clone(),+ )+ .await+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("DB error when setting the access token")+ {+ // If we are not able to set the access token in redis, the error should just be logged and proceed with the payment+ // Payments should not fail, once the access token is successfully created+ // The next request will create new access token, if required+ logger::error!(access_token_set_error=?access_token_set_error);+ }+ Some(modified_access_token_with_expiry)+ })+ .await}};@@ -203,7 +197,6 @@ pub async fn add_access_token<pub async fn refresh_connector_auth(state: &SessionState,connector: &api_types::ConnectorData,- _merchant_context: &domain::MerchantContext,router_data: &types::RouterData<api_types::AccessTokenAuth,types::AccessTokenRequestData,diff --git a/crates/router/src/core/payments/flows.rs b/crates/router/src/core/payments/flows.rsindex 694ae406c8..a73570d7b5 100644--- a/crates/router/src/core/payments/flows.rs+++ b/crates/router/src/core/payments/flows.rs@@ -27,6 +27,7 @@ use hyperswitch_domain_models::router_flow_types::{use hyperswitch_domain_models::{payments as domain_payments, router_request_types::PaymentsCaptureData,};+use hyperswitch_interfaces::api as api_interfaces;use crate::{core::{@@ -210,6 +211,31 @@ pub trait Feature<F, T> {) {}+ fn get_current_flow_info(&self) -> Option<api_interfaces::CurrentFlowInfo<'_>> {+ None+ }++ async fn call_preprocessing_through_unified_connector_service<'a>(+ self,+ _state: &SessionState,+ _header_payload: &domain_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: ExecutionMode,+ ) -> RouterResult<(Self, bool)>+ where+ F: Clone,+ Self: Sized,+ dyn api::Connector: services::ConnectorIntegration<F, T, types::PaymentsResponseData>,+ {+ // Default behaviour is to do nothing and continue further+ Ok((self, true))+ }+async fn call_unified_connector_service<'a>(&mut self,_state: &SessionState,@@ -219,6 +245,7 @@ pub trait Feature<F, T> {#[cfg(feature = "v2")]_merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,_merchant_context: &domain::MerchantContext,+ _connector_data: &api::ConnectorData,_unified_connector_service_execution_mode: ExecutionMode,_merchant_order_reference_id: Option<String>,) -> RouterResult<()>diff --git a/crates/router/src/core/payments/flows/approve_flow.rs b/crates/router/src/core/payments/flows/approve_flow.rsindex af79bbd5b3..87486f3977 100644--- a/crates/router/src/core/payments/flows/approve_flow.rs+++ b/crates/router/src/core/payments/flows/approve_flow.rs@@ -86,13 +86,12 @@ impl Feature<api::Approve, types::PaymentsApproveData>&self,state: &SessionState,connector: &api::ConnectorData,- merchant_context: &domain::MerchantContext,+ _merchant_context: &domain::MerchantContext,creds_identifier: Option<&str>,) -> RouterResult<types::AddAccessTokenResult> {Box::pin(access_token::add_access_token(state,connector,- merchant_context,self,creds_identifier,))diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rsindex 11072c6efb..a5d202c5c8 100644--- a/crates/router/src/core/payments/flows/authorize_flow.rs+++ b/crates/router/src/core/payments/flows/authorize_flow.rs@@ -11,6 +11,7 @@ use hyperswitch_domain_models::payments::PaymentConfirmData;use hyperswitch_domain_models::{errors::api_error_response::ApiErrorResponse, payments as domain_payments,};+use hyperswitch_interfaces::{api as api_interface, api::ConnectorSpecifications};use masking::{ExposeInterface, Secret};use unified_connector_service_client::payments as payments_grpc;@@ -183,6 +184,12 @@ impl#[async_trait]impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAuthorizeRouterData {+ fn get_current_flow_info(&self) -> Option<api_interface::CurrentFlowInfo<'_>> {+ Some(api_interface::CurrentFlowInfo::Authorize {+ auth_type: &self.auth_type,+ request_data: &self.request,+ })+ }async fn decide_flows<'a>(mut self,state: &SessionState,@@ -220,7 +227,6 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu);auth_router_data.integrity_check = integrity_result;metrics::PAYMENT_COUNT.add(1, &[]); // Move outside of the if block-match auth_router_data.response.clone() {Err(_) => Ok(auth_router_data),Ok(authorize_response) => {@@ -255,13 +261,12 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu&self,state: &SessionState,connector: &api::ConnectorData,- merchant_context: &domain::MerchantContext,+ _merchant_context: &domain::MerchantContext,creds_identifier: Option<&str>,) -> RouterResult<types::AddAccessTokenResult> {Box::pin(access_token::add_access_token(state,connector,- merchant_context,self,creds_identifier,))@@ -533,6 +538,7 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu#[cfg(feature = "v2")]merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,merchant_context: &domain::MerchantContext,+ connector_data: &api::ConnectorData,unified_connector_service_execution_mode: enums::ExecutionMode,merchant_order_reference_id: Option<String>,) -> RouterResult<()> {@@ -549,17 +555,31 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu)).await} else {- Box::pin(call_unified_connector_service_authorize(- self,- state,- header_payload,- lineage_ids,- merchant_connector_account,- merchant_context,- unified_connector_service_execution_mode,- merchant_order_reference_id,- ))- .await+ let alternate_flow = connector_data.connector.get_alternate_flow_if_needed(+ api_interface::CurrentFlowInfo::Authorize {+ auth_type: &self.auth_type,+ request_data: &self.request,+ },+ );+ match alternate_flow {+ Some(api_interface::AlternateFlow::PreAuthenticate) => {+ // Todo: Call UCS PreAuthenticate here+ Ok(())+ }+ None => {+ Box::pin(call_unified_connector_service_authorize(+ self,+ state,+ header_payload,+ lineage_ids,+ merchant_connector_account,+ merchant_context,+ unified_connector_service_execution_mode,+ merchant_order_reference_id,+ ))+ .await+ }+ }}}}diff --git a/crates/router/src/core/payments/flows/cancel_flow.rs b/crates/router/src/core/payments/flows/cancel_flow.rsindex 72b7fd4efe..2dd933ba50 100644--- a/crates/router/src/core/payments/flows/cancel_flow.rs+++ b/crates/router/src/core/payments/flows/cancel_flow.rs@@ -117,13 +117,12 @@ impl Feature<api::Void, types::PaymentsCancelData>&self,state: &SessionState,connector: &api::ConnectorData,- merchant_context: &domain::MerchantContext,+ _merchant_context: &domain::MerchantContext,creds_identifier: Option<&str>,) -> RouterResult<types::AddAccessTokenResult> {Box::pin(access_token::add_access_token(state,connector,- merchant_context,self,creds_identifier,))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.rsindex 50560bc422..0ac493c56c 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@@ -112,13 +112,12 @@ impl Feature<api::PostCaptureVoid, types::PaymentsCancelPostCaptureData>&self,state: &SessionState,connector: &api::ConnectorData,- merchant_context: &domain::MerchantContext,+ _merchant_context: &domain::MerchantContext,creds_identifier: Option<&str>,) -> RouterResult<types::AddAccessTokenResult> {Box::pin(access_token::add_access_token(state,connector,- merchant_context,self,creds_identifier,))diff --git a/crates/router/src/core/payments/flows/capture_flow.rs b/crates/router/src/core/payments/flows/capture_flow.rsindex 2401644506..d761a163a5 100644--- a/crates/router/src/core/payments/flows/capture_flow.rs+++ b/crates/router/src/core/payments/flows/capture_flow.rs@@ -125,13 +125,12 @@ impl Feature<api::Capture, types::PaymentsCaptureData>&self,state: &SessionState,connector: &api::ConnectorData,- merchant_context: &domain::MerchantContext,+ _merchant_context: &domain::MerchantContext,creds_identifier: Option<&str>,) -> RouterResult<types::AddAccessTokenResult> {Box::pin(access_token::add_access_token(state,connector,- merchant_context,self,creds_identifier,))diff --git a/crates/router/src/core/payments/flows/complete_authorize_flow.rs b/crates/router/src/core/payments/flows/complete_authorize_flow.rsindex 9ac2b073ea..fbca96d93f 100644--- a/crates/router/src/core/payments/flows/complete_authorize_flow.rs+++ b/crates/router/src/core/payments/flows/complete_authorize_flow.rs@@ -143,13 +143,12 @@ impl Feature<api::CompleteAuthorize, types::CompleteAuthorizeData>&self,state: &SessionState,connector: &api::ConnectorData,- merchant_context: &domain::MerchantContext,+ _merchant_context: &domain::MerchantContext,creds_identifier: Option<&str>,) -> RouterResult<types::AddAccessTokenResult> {Box::pin(access_token::add_access_token(state,connector,- merchant_context,self,creds_identifier,))diff --git a/crates/router/src/core/payments/flows/extend_authorization_flow.rs b/crates/router/src/core/payments/flows/extend_authorization_flow.rsindex fbf704820c..f67500ea9f 100644--- a/crates/router/src/core/payments/flows/extend_authorization_flow.rs+++ b/crates/router/src/core/payments/flows/extend_authorization_flow.rs@@ -112,13 +112,12 @@ impl Feature<api::ExtendAuthorization, types::PaymentsExtendAuthorizationData>&self,state: &SessionState,connector: &api::ConnectorData,- merchant_context: &domain::MerchantContext,+ _merchant_context: &domain::MerchantContext,creds_identifier: Option<&str>,) -> RouterResult<types::AddAccessTokenResult> {Box::pin(access_token::add_access_token(state,connector,- merchant_context,self,creds_identifier,))diff --git a/crates/router/src/core/payments/flows/external_proxy_flow.rs b/crates/router/src/core/payments/flows/external_proxy_flow.rsindex de008596ae..71289348ef 100644--- a/crates/router/src/core/payments/flows/external_proxy_flow.rs+++ b/crates/router/src/core/payments/flows/external_proxy_flow.rs@@ -117,11 +117,10 @@ impl Feature<api::ExternalVaultProxy, types::ExternalVaultProxyPaymentsData>&self,state: &SessionState,connector: &api::ConnectorData,- merchant_context: &domain::MerchantContext,+ _merchant_context: &domain::MerchantContext,creds_identifier: Option<&str>,) -> RouterResult<types::AddAccessTokenResult> {- access_token::add_access_token(state, connector, merchant_context, self, creds_identifier)- .await+ access_token::add_access_token(state, connector, self, creds_identifier).await}async fn add_session_token<'a>(diff --git a/crates/router/src/core/payments/flows/incremental_authorization_flow.rs b/crates/router/src/core/payments/flows/incremental_authorization_flow.rsindex 85ee5821b9..21d275b730 100644--- a/crates/router/src/core/payments/flows/incremental_authorization_flow.rs+++ b/crates/router/src/core/payments/flows/incremental_authorization_flow.rs@@ -107,13 +107,12 @@ impl Feature<api::IncrementalAuthorization, types::PaymentsIncrementalAuthorizat&self,state: &SessionState,connector: &api::ConnectorData,- merchant_context: &domain::MerchantContext,+ _merchant_context: &domain::MerchantContext,creds_identifier: Option<&str>,) -> RouterResult<types::AddAccessTokenResult> {Box::pin(access_token::add_access_token(state,connector,- merchant_context,self,creds_identifier,))diff --git a/crates/router/src/core/payments/flows/post_session_tokens_flow.rs b/crates/router/src/core/payments/flows/post_session_tokens_flow.rsindex bbcf666c70..089dca99cd 100644--- a/crates/router/src/core/payments/flows/post_session_tokens_flow.rs+++ b/crates/router/src/core/payments/flows/post_session_tokens_flow.rs@@ -106,13 +106,12 @@ impl Feature<api::PostSessionTokens, types::PaymentsPostSessionTokensData>&self,state: &SessionState,connector: &api::ConnectorData,- merchant_context: &domain::MerchantContext,+ _merchant_context: &domain::MerchantContext,creds_identifier: Option<&str>,) -> RouterResult<types::AddAccessTokenResult> {Box::pin(access_token::add_access_token(state,connector,- merchant_context,self,creds_identifier,))diff --git a/crates/router/src/core/payments/flows/psync_flow.rs b/crates/router/src/core/payments/flows/psync_flow.rsindex e72c5f846f..cf8fe04738 100644--- a/crates/router/src/core/payments/flows/psync_flow.rs+++ b/crates/router/src/core/payments/flows/psync_flow.rs@@ -173,13 +173,12 @@ impl Feature<api::PSync, types::PaymentsSyncData>&self,state: &SessionState,connector: &api::ConnectorData,- merchant_context: &domain::MerchantContext,+ _merchant_context: &domain::MerchantContext,creds_identifier: Option<&str>,) -> RouterResult<types::AddAccessTokenResult> {Box::pin(access_token::add_access_token(state,connector,- merchant_context,self,creds_identifier,))@@ -235,6 +234,7 @@ impl Feature<api::PSync, types::PaymentsSyncData>#[cfg(feature = "v2")]merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,merchant_context: &domain::MerchantContext,+ _connector_data: &api::ConnectorData,unified_connector_service_execution_mode: enums::ExecutionMode,merchant_order_reference_id: Option<String>,) -> RouterResult<()> {diff --git a/crates/router/src/core/payments/flows/reject_flow.rs b/crates/router/src/core/payments/flows/reject_flow.rsindex 533d9e70f3..5c6fb58ce1 100644--- a/crates/router/src/core/payments/flows/reject_flow.rs+++ b/crates/router/src/core/payments/flows/reject_flow.rs@@ -85,13 +85,12 @@ impl Feature<api::Reject, types::PaymentsRejectData>&self,state: &SessionState,connector: &api::ConnectorData,- merchant_context: &domain::MerchantContext,+ _merchant_context: &domain::MerchantContext,creds_identifier: Option<&str>,) -> RouterResult<types::AddAccessTokenResult> {Box::pin(access_token::add_access_token(state,connector,- merchant_context,self,creds_identifier,))diff --git a/crates/router/src/core/payments/flows/session_flow.rs b/crates/router/src/core/payments/flows/session_flow.rsindex de4454d99c..3356ccf667 100644--- a/crates/router/src/core/payments/flows/session_flow.rs+++ b/crates/router/src/core/payments/flows/session_flow.rs@@ -126,13 +126,12 @@ impl Feature<api::Session, types::PaymentsSessionData> for types::PaymentsSessio&self,state: &routes::SessionState,connector: &api::ConnectorData,- merchant_context: &domain::MerchantContext,+ _merchant_context: &domain::MerchantContext,creds_identifier: Option<&str>,) -> RouterResult<types::AddAccessTokenResult> {Box::pin(access_token::add_access_token(state,connector,- merchant_context,self,creds_identifier,))diff --git a/crates/router/src/core/payments/flows/session_update_flow.rs b/crates/router/src/core/payments/flows/session_update_flow.rsindex 49962f5998..06db8ba7d0 100644--- a/crates/router/src/core/payments/flows/session_update_flow.rs+++ b/crates/router/src/core/payments/flows/session_update_flow.rs@@ -104,13 +104,12 @@ impl Feature<api::SdkSessionUpdate, types::SdkPaymentsSessionUpdateData>&self,state: &SessionState,connector: &api::ConnectorData,- merchant_context: &domain::MerchantContext,+ _merchant_context: &domain::MerchantContext,creds_identifier: Option<&str>,) -> RouterResult<types::AddAccessTokenResult> {Box::pin(access_token::add_access_token(state,connector,- merchant_context,self,creds_identifier,))diff --git a/crates/router/src/core/payments/flows/setup_mandate_flow.rs b/crates/router/src/core/payments/flows/setup_mandate_flow.rsindex 8894d9994f..45caef1655 100644--- a/crates/router/src/core/payments/flows/setup_mandate_flow.rs+++ b/crates/router/src/core/payments/flows/setup_mandate_flow.rs@@ -155,13 +155,12 @@ impl Feature<api::SetupMandate, types::SetupMandateRequestData> for types::Setup&self,state: &SessionState,connector: &api::ConnectorData,- merchant_context: &domain::MerchantContext,+ _merchant_context: &domain::MerchantContext,creds_identifier: Option<&str>,) -> RouterResult<types::AddAccessTokenResult> {Box::pin(access_token::add_access_token(state,connector,- merchant_context,self,creds_identifier,))@@ -275,6 +274,7 @@ impl Feature<api::SetupMandate, types::SetupMandateRequestData> for types::Setup#[cfg(feature = "v2")]merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,merchant_context: &domain::MerchantContext,+ _connector_data: &api::ConnectorData,unified_connector_service_execution_mode: enums::ExecutionMode,merchant_order_reference_id: Option<String>,) -> RouterResult<()> {diff --git a/crates/router/src/core/payments/flows/update_metadata_flow.rs b/crates/router/src/core/payments/flows/update_metadata_flow.rsindex fa683935d9..10ec980455 100644--- a/crates/router/src/core/payments/flows/update_metadata_flow.rs+++ b/crates/router/src/core/payments/flows/update_metadata_flow.rs@@ -103,13 +103,12 @@ impl Feature<api::UpdateMetadata, types::PaymentsUpdateMetadataData>&self,state: &SessionState,connector: &api::ConnectorData,- merchant_context: &domain::MerchantContext,+ _merchant_context: &domain::MerchantContext,creds_identifier: Option<&str>,) -> RouterResult<types::AddAccessTokenResult> {Box::pin(access_token::add_access_token(state,connector,- merchant_context,self,creds_identifier,))diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex a01a906e8f..9a8594f20c 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -7873,6 +7873,7 @@ pub async fn process_through_ucs<'a, F, RouterDReq, ApiRequest, D>(frm_suggestion: Option<enums::FrmSuggestion>,business_profile: &'a domain::Profile,merchant_connector_account: MerchantConnectorAccountType,+ connector_data: &api::ConnectorData,mut router_data: RouterData<F, RouterDReq, PaymentsResponseData>,) -> RouterResult<(RouterData<F, RouterDReq, PaymentsResponseData>,@@ -7952,6 +7953,7 @@ wherelineage_ids,merchant_connector_account.clone(),merchant_context,+ connector_data,ExecutionMode::Primary, // UCS is called in primary modemerchant_order_reference_id,)@@ -8106,7 +8108,7 @@ wherestate,req_state,merchant_context,- connector,+ connector.clone(),operation,payment_data,customer,@@ -8134,6 +8136,7 @@ whereunified_connector_service_header_payload,lineage_ids,unified_connector_service_merchant_connector_account,+ &connector,unified_connector_service_merchant_context,unified_connector_service_merchant_order_reference_id,)@@ -8154,6 +8157,7 @@ pub async fn execute_shadow_unified_connector_service_call<F, RouterDReq>(header_payload: domain_payments::HeaderPayload,lineage_ids: grpc_client::LineageIds,merchant_connector_account: MerchantConnectorAccountType,+ connector_data: &api::ConnectorData,merchant_context: domain::MerchantContext,merchant_order_reference_id: Option<String>,) where@@ -8171,6 +8175,7 @@ pub async fn execute_shadow_unified_connector_service_call<F, RouterDReq>(lineage_ids,merchant_connector_account,&merchant_context,+ connector_data,ExecutionMode::Shadow, // Shadow mode for UCSmerchant_order_reference_id,)diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rsindex 3d8463c255..37e04ec4f4 100644--- a/crates/router/src/core/refunds.rs+++ b/crates/router/src/core/refunds.rs@@ -187,7 +187,6 @@ pub async fn trigger_refund_to_gateway(let add_access_token_result = Box::pin(access_token::add_access_token(state,&connector,- merchant_context,&router_data,creds_identifier.as_deref(),))@@ -621,7 +620,6 @@ pub async fn sync_refund_with_gateway(let add_access_token_result = Box::pin(access_token::add_access_token(state,&connector,- merchant_context,&router_data,creds_identifier.as_deref(),))diff --git a/crates/router/src/core/refunds_v2.rs b/crates/router/src/core/refunds_v2.rsindex bb4f2535ee..146b80b031 100644--- a/crates/router/src/core/refunds_v2.rs+++ b/crates/router/src/core/refunds_v2.rs@@ -172,7 +172,6 @@ pub async fn trigger_refund_to_gateway(let add_access_token_result = Box::pin(access_token::add_access_token(state,&connector,- merchant_context,&router_data,None,))@@ -279,7 +278,6 @@ pub async fn internal_trigger_refund_to_gateway(let add_access_token_result = Box::pin(access_token::add_access_token(state,&connector,- merchant_context,&router_data,None,))@@ -818,7 +816,6 @@ pub async fn sync_refund_with_gateway(let add_access_token_result = Box::pin(access_token::add_access_token(state,&connector,- merchant_context,&router_data,None,))@@ -904,7 +901,6 @@ pub async fn internal_sync_refund_with_gateway(let add_access_token_result = Box::pin(access_token::add_access_token(state,&connector,- merchant_context,&router_data,None,))