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(authentication): Generate authn values in response for pci merchant using modular auth (#11610)

Sahkal Poddara22f7d11690b
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index 2e1eef8389..ef2d4849fa 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -10154,14 +10154,6 @@
"description": "The business profile that is associated with this authentication",
"nullable": true
},
- "customer": {
- "allOf": [
- {
- "$ref": "#/components/schemas/CustomerDetails"
- }
- ],
- "nullable": true
- },
"amount": {
"$ref": "#/components/schemas/MinorUnit"
},
@@ -10218,6 +10210,19 @@
}
}
},
+ "AuthenticationDetails": {
+ "type": "object",
+ "properties": {
+ "three_ds_data": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/ExternalThreeDsData"
+ }
+ ],
+ "nullable": true
+ }
+ }
+ },
"AuthenticationEligibilityCheckData": {
"oneOf": [
{
@@ -10906,6 +10911,14 @@
],
"nullable": true
},
+ "authentication_details": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/AuthenticationDetails"
+ }
+ ],
+ "nullable": true
+ },
"billing": {
"allOf": [
{
@@ -19945,48 +19958,35 @@
},
"ExternalThreeDsData": {
"type": "object",
- "description": "Represents external 3DS authentication data used in the payment flow.",
"required": [
- "authentication_cryptogram",
- "ds_trans_id",
- "version",
- "eci",
"transaction_status"
],
"properties": {
"authentication_cryptogram": {
- "$ref": "#/components/schemas/Cryptogram"
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/Cryptogram"
+ }
+ ],
+ "nullable": true
},
"ds_trans_id": {
"type": "string",
- "description": "Directory Server Transaction ID generated during the 3DS process."
+ "description": "Directory Server Transaction ID generated during the 3DS process.",
+ "nullable": true
},
"version": {
"type": "string",
- "description": "The version of the 3DS protocol used (e.g., \"2.1.0\" or \"2.2.0\")."
+ "description": "The version of the 3DS protocol used (e.g., \"2.1.0\" or \"2.2.0\").",
+ "nullable": true
},
"eci": {
"type": "string",
- "description": "Electronic Commerce Indicator (ECI) value representing the 3DS authentication result."
+ "description": "Electronic Commerce Indicator (ECI) value representing the 3DS authentication result.",
+ "nullable": true
},
"transaction_status": {
"$ref": "#/components/schemas/TransactionStatus"
- },
- "exemption_indicator": {
- "allOf": [
- {
- "$ref": "#/components/schemas/ExemptionIndicator"
- }
- ],
- "nullable": true
- },
- "network_params": {
- "allOf": [
- {
- "$ref": "#/components/schemas/NetworkParams"
- }
- ],
- "nullable": true
}
}
},
diff --git a/crates/api_models/src/authentication.rs b/crates/api_models/src/authentication.rs
index a6eb60477d..1fde17314b 100644
--- a/crates/api_models/src/authentication.rs
+++ b/crates/api_models/src/authentication.rs
@@ -28,10 +28,6 @@ pub struct AuthenticationCreateRequest {
#[schema(value_type = Option<String>)]
pub profile_id: Option<id_type::ProfileId>,
- /// Customer details.
- #[schema(value_type = Option<CustomerDetails>)]
- pub customer: Option<CustomerDetails>,
-
/// The amount for the transaction, required.
#[schema(value_type = MinorUnit, example = 1000)]
pub amount: common_utils::types::MinorUnit,
@@ -688,6 +684,10 @@ pub struct AuthenticationSyncResponse {
/// The tokens for vaulted data
pub vault_token_data: Option<AuthenticationVaultTokenData>,
+ /// The authentication details after external authentication
+ #[schema(value_type = Option<AuthenticationDetails>)]
+ pub authentication_details: Option<AuthenticationDetails>,
+
/// Billing address.
#[schema(value_type = Option<Address>)]
pub billing: Option<Address>,
@@ -747,6 +747,43 @@ pub struct AuthenticationSyncResponse {
pub profile_acquirer_id: Option<id_type::ProfileAcquirerId>,
}
+#[derive(Debug, Clone, Serialize, ToSchema)]
+pub struct AuthenticationDetails {
+ // Three Ds Data after external authentication
+ pub three_ds_data: Option<ExternalThreeDsData>,
+}
+
+#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
+pub struct ExternalThreeDsData {
+ /// Contains the authentication cryptogram data (CAVV or TAVV).
+ #[schema(value_type = Option<Cryptogram>)]
+ pub authentication_cryptogram: Option<Cryptogram>,
+ /// Directory Server Transaction ID generated during the 3DS process.
+ #[schema(value_type = Option<String>)]
+ pub ds_trans_id: Option<String>,
+ /// The version of the 3DS protocol used (e.g., "2.1.0" or "2.2.0").
+ #[schema(value_type = Option<String>)]
+ pub version: Option<common_utils::types::SemanticVersion>,
+ /// Electronic Commerce Indicator (ECI) value representing the 3DS authentication result.
+ #[schema(value_type = Option<String>)]
+ pub eci: Option<String>,
+ /// Indicates the transaction status from the 3DS authentication flow.
+ #[schema(value_type = TransactionStatus)]
+ pub transaction_status: common_enums::TransactionStatus,
+}
+
+/// Represents the 3DS cryptogram data returned after authentication.
+#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
+#[serde(rename_all = "snake_case")]
+pub enum Cryptogram {
+ /// Cardholder Authentication Verification Value (CAVV) cryptogram.
+ Cavv {
+ /// The authentication cryptogram provided by the issuer or ACS.
+ #[schema(value_type = Option<String>)]
+ authentication_cryptogram: hyperswitch_masking::Secret<String>,
+ },
+}
+
#[cfg(feature = "v1")]
#[derive(Debug, Clone, Serialize, ToSchema)]
#[serde(tag = "type", rename_all = "snake_case")]
diff --git a/crates/common_utils/src/id_type/merchant.rs b/crates/common_utils/src/id_type/merchant.rs
index a7126d2fba..b177d0b285 100644
--- a/crates/common_utils/src/id_type/merchant.rs
+++ b/crates/common_utils/src/id_type/merchant.rs
@@ -201,9 +201,9 @@ impl MerchantId {
}
/// get should call auth tokenization for modular authentication
- pub fn get_should_disable_auth_tokenization(&self) -> String {
+ pub fn get_should_disable_vault_tokenization(&self) -> String {
format!(
- "should_disable_auth_tokenization_{}",
+ "should_disable_vault_tokenization_{}",
self.get_string_repr()
)
}
diff --git a/crates/hyperswitch_domain_models/src/authentication.rs b/crates/hyperswitch_domain_models/src/authentication.rs
index eea880dad0..8b52610995 100644
--- a/crates/hyperswitch_domain_models/src/authentication.rs
+++ b/crates/hyperswitch_domain_models/src/authentication.rs
@@ -15,7 +15,12 @@ use rustc_hash::FxHashMap;
use serde_json::Value;
use super::behaviour;
-use crate::type_encryption::{crypto_operation, AsyncLift, CryptoOperation};
+use crate::{
+ router_request_types::unified_authentication_service::{
+ DynamicData, PostAuthenticationDetails,
+ },
+ type_encryption::{crypto_operation, AsyncLift, CryptoOperation},
+};
#[derive(Clone, Debug, router_derive::ToEncryption, serde::Serialize)]
pub struct Authentication {
@@ -122,6 +127,25 @@ impl Authentication {
.transpose()?
.unwrap_or(false))
}
+
+ pub fn get_post_authentication_details(
+ &self,
+ authentication_value: Option<String>,
+ ) -> PostAuthenticationDetails {
+ PostAuthenticationDetails {
+ token_details: None,
+ dynamic_data_details: Some(DynamicData {
+ dynamic_data_value: authentication_value.map(Secret::new),
+ dynamic_data_type: None,
+ ds_trans_id: self.ds_trans_id.clone(),
+ }),
+ raw_card_details: None,
+ trans_status: self.trans_status.clone(),
+ eci: self.eci.clone(),
+ challenge_cancel: self.challenge_cancel.clone(),
+ challenge_code_reason: self.challenge_code_reason.clone(),
+ }
+ }
}
#[derive(Debug, Clone, serde::Serialize)]
diff --git a/crates/hyperswitch_domain_models/src/router_request_types/unified_authentication_service.rs b/crates/hyperswitch_domain_models/src/router_request_types/unified_authentication_service.rs
index b1854f846d..5c849722f4 100644
--- a/crates/hyperswitch_domain_models/src/router_request_types/unified_authentication_service.rs
+++ b/crates/hyperswitch_domain_models/src/router_request_types/unified_authentication_service.rs
@@ -217,26 +217,36 @@ pub struct ThreeDsMetaData {
}
#[cfg(feature = "v1")]
-impl From<PostAuthenticationDetails>
- for Option<api_models::authentication::AuthenticationPaymentMethodDataResponse>
-{
- fn from(item: PostAuthenticationDetails) -> Self {
- match (item.raw_card_details, item.token_details) {
- (Some(card_data), _) => Some(
- api_models::authentication::AuthenticationPaymentMethodDataResponse::CardData {
- card_expiry_year: Some(card_data.expiration_year),
- card_expiry_month: Some(card_data.expiration_month),
- },
- ),
- (None, Some(network_token_data)) => {
- Some(
+impl PostAuthenticationDetails {
+ pub fn to_authentication_payment_method_data_response(
+ self,
+ ) -> Option<api_models::authentication::AuthenticationPaymentMethodDataResponse> {
+ match (self.raw_card_details, self.token_details) {
+ (Some(card_data), _) => Some(
+ api_models::authentication::AuthenticationPaymentMethodDataResponse::CardData {
+ card_expiry_year: Some(card_data.expiration_year),
+ card_expiry_month: Some(card_data.expiration_month),
+ },
+ ),
+ (None, Some(network_token_data)) => Some(
api_models::authentication::AuthenticationPaymentMethodDataResponse::NetworkTokenData {
network_token_expiry_year: Some(network_token_data.token_expiration_year),
network_token_expiry_month: Some(network_token_data.token_expiration_month),
},
- )
+ ),
+ (None, None) => None,
}
- (None, None) => None,
+ }
+
+ pub fn get_post_authentication_details(&self) -> Self {
+ Self {
+ eci: self.eci.clone(),
+ token_details: self.token_details.clone(),
+ dynamic_data_details: self.dynamic_data_details.clone(),
+ trans_status: self.trans_status.clone(),
+ challenge_cancel: self.challenge_cancel.clone(),
+ challenge_code_reason: self.challenge_code_reason.clone(),
+ raw_card_details: self.raw_card_details.clone(),
}
}
}
diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs
index 3da5009695..fb8244695c 100644
--- a/crates/openapi/src/openapi.rs
+++ b/crates/openapi/src/openapi.rs
@@ -1019,6 +1019,8 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::authentication::AuthenticationPaymentMethodData,
api_models::authentication::AuthenticationVaultTokenData,
api_models::authentication::AuthenticationPaymentMethodDataResponse,
+ api_models::authentication::AuthenticationDetails,
+ api_models::authentication::ExternalThreeDsData,
api_models::open_router::OpenRouterDecideGatewayRequest,
api_models::open_router::DecideGatewayResponse,
api_models::open_router::UpdateScorePayload,
diff --git a/crates/router/src/core/unified_authentication_service.rs b/crates/router/src/core/unified_authentication_service.rs
index 00a5cad0fb..cc9371304b 100644
--- a/crates/router/src/core/unified_authentication_service.rs
+++ b/crates/router/src/core/unified_authentication_service.rs
@@ -25,6 +25,8 @@ use api_models::{
use common_utils::{errors::CustomResult, ext_traits::ValueExt, types::AmountConvertor};
use diesel_models::authentication::Authentication;
use error_stack::ResultExt;
+#[cfg(feature = "v1")]
+use hyperswitch_domain_models::router_request_types::unified_authentication_service::UasAuthenticationResponseData;
use hyperswitch_domain_models::{
errors::api_error_response::ApiErrorResponse,
ext_traits::OptionExt,
@@ -57,7 +59,7 @@ use crate::{
metrics, payment_methods,
payments::{helpers, validate_customer_details_for_click_to_pay},
unified_authentication_service::types::{
- ClickToPay, ExternalAuthentication, UnifiedAuthenticationService,
+ AuthSyncStrategy, ClickToPay, ExternalAuthentication, UnifiedAuthenticationService,
UNIFIED_AUTHENTICATION_SERVICE,
},
utils as core_utils,
@@ -1748,6 +1750,226 @@ impl
}
}
+/// Determines the appropriate authentication sync strategy based on current state
+#[cfg(feature = "v1")]
+fn determine_auth_sync_strategy(
+ authentication: &hyperswitch_domain_models::authentication::Authentication,
+ should_disable_vault_tokenization: bool,
+ auth_flow: AuthFlow,
+) -> AuthSyncStrategy {
+ if !authentication.authentication_status.is_terminal_status() {
+ AuthSyncStrategy::ExecutePostAuth
+ } else if authentication.authentication_status.is_success()
+ && should_disable_vault_tokenization
+ && auth_flow == AuthFlow::Merchant
+ {
+ AuthSyncStrategy::UseStoredAuthValue
+ } else {
+ AuthSyncStrategy::NoOperation
+ }
+}
+
+/// Executes the full post-authentication flow including connector call, tokenization, and tracker updates
+#[cfg(feature = "v1")]
+#[allow(clippy::too_many_arguments)]
+async fn execute_post_authentication_flow(
+ state: &SessionState,
+ platform: &domain::Platform,
+ business_profile: &domain::Profile,
+ authentication: &hyperswitch_domain_models::authentication::Authentication,
+ authentication_connector: &common_enums::AuthenticationConnectors,
+ three_ds_connector_account: &MerchantConnectorAccountType,
+ authentication_id: &common_utils::id_type::AuthenticationId,
+ merchant_id: &common_utils::id_type::MerchantId,
+ merchant_account: &domain::MerchantAccount,
+ should_disable_vault_tokenization: bool,
+) -> RouterResult<(
+ hyperswitch_domain_models::authentication::Authentication,
+ Option<api_models::authentication::AuthenticationPaymentMethodDataResponse>,
+ Option<api_models::authentication::AuthenticationVaultTokenData>,
+ Option<api_models::authentication::AuthenticationDetails>,
+)> {
+ let post_auth_response = if authentication_connector.is_click_to_pay() {
+ let response = ClickToPay::post_authentication(
+ state,
+ business_profile,
+ None,
+ &three_ds_connector_account.clone(),
+ &authentication_connector.to_string(),
+ authentication_id,
+ common_enums::PaymentMethod::Card,
+ merchant_id,
+ None,
+ None,
+ )
+ .await?;
+ metrics::POST_AUTHENTICATION_CARDS_SUCCESSFULLY_DECRYPTED.add(1, &[]);
+ response
+ } else {
+ let routing_region = utils::fetch_routing_region_for_uas(
+ state,
+ merchant_id.clone(),
+ merchant_account.organization_id.clone(),
+ )
+ .await
+ .change_context(ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to fetch routing path")?;
+ ExternalAuthentication::post_authentication(
+ state,
+ business_profile,
+ None,
+ three_ds_connector_account,
+ &authentication_connector.to_string(),
+ authentication_id,
+ common_enums::PaymentMethod::Card,
+ merchant_id,
+ Some(authentication),
+ Some(routing_region),
+ )
+ .await?
+ };
+
+ let (vault_token_data, authentication_details) = if should_disable_vault_tokenization {
+ // Do not tokenize if the disable flag is present in the config
+ let authentication_details =
+ if let Ok(UasAuthenticationResponseData::PostAuthentication {
+ authentication_details,
+ }) = post_auth_response.response.clone()
+ {
+ let authentication_cryptogram = authentication_details
+ .dynamic_data_details
+ .as_ref()
+ .and_then(|data| {
+ data.dynamic_data_value.clone().map(|dynamic_data_value| {
+ api_models::authentication::Cryptogram::Cavv {
+ authentication_cryptogram: dynamic_data_value,
+ }
+ })
+ });
+ let authentication_details = api_models::authentication::AuthenticationDetails {
+ three_ds_data: Some(api_models::authentication::ExternalThreeDsData {
+ authentication_cryptogram,
+ eci: authentication_details.eci.clone(),
+ ds_trans_id: authentication_details
+ .dynamic_data_details
+ .as_ref()
+ .and_then(|data| data.ds_trans_id.clone()),
+ transaction_status: authentication_details
+ .trans_status
+ .unwrap_or(common_enums::TransactionStatus::Failure),
+ version: authentication.maximum_supported_version.clone(),
+ }),
+ };
+ Some(authentication_details)
+ } else {
+ None
+ };
+
+ (None, authentication_details)
+ } else {
+ let response = Box::pin(utils::get_auth_multi_token_from_external_vault(
+ state,
+ platform,
+ business_profile,
+ &post_auth_response,
+ ))
+ .await?;
+ metrics::POST_AUTHENTICATION_TOKEN_PUSHED_TO_VGS.add(1, &[]);
+ (response, None)
+ };
+
+ let payment_method_data = utils::get_authentication_payment_method_data(&post_auth_response);
+
+ let auth_update_response = utils::external_authentication_update_trackers(
+ state,
+ post_auth_response,
+ authentication.clone(),
+ None,
+ platform.get_processor().get_key_store(),
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ )
+ .await?;
+
+ Ok((
+ auth_update_response,
+ payment_method_data,
+ vault_token_data,
+ authentication_details,
+ ))
+}
+
+/// Uses the stored authentication value for terminal success cases in merchant flow
+#[cfg(feature = "v1")]
+async fn use_stored_authentication_value(
+ state: &SessionState,
+ platform: &domain::Platform,
+ authentication: &hyperswitch_domain_models::authentication::Authentication,
+ authentication_id: &common_utils::id_type::AuthenticationId,
+ should_disable_vault_tokenization: bool,
+) -> RouterResult<(
+ hyperswitch_domain_models::authentication::Authentication,
+ Option<api_models::authentication::AuthenticationPaymentMethodDataResponse>,
+ Option<api_models::authentication::AuthenticationVaultTokenData>,
+ Option<api_models::authentication::AuthenticationDetails>,
+)> {
+ if should_disable_vault_tokenization {
+ let authentication_value = payment_methods::vault::get_tokenized_data(
+ state,
+ authentication_id.get_string_repr(),
+ false,
+ platform.get_processor().get_key_store().key.get_inner(),
+ )
+ .await
+ .inspect_err(|err| router_env::logger::error!(tokenized_data_result=?err))
+ .attach_printable("cavv not present after authentication flow")
+ .ok();
+
+ let post_authentication_details = authentication
+ .get_post_authentication_details(authentication_value.map(|value| value.value1));
+
+ let authentication_cryptogram = post_authentication_details
+ .dynamic_data_details
+ .as_ref()
+ .and_then(|data| {
+ data.dynamic_data_value.clone().map(|dynamic_data_value| {
+ api_models::authentication::Cryptogram::Cavv {
+ authentication_cryptogram: dynamic_data_value,
+ }
+ })
+ });
+
+ let authentication_details = api_models::authentication::AuthenticationDetails {
+ three_ds_data: Some(api_models::authentication::ExternalThreeDsData {
+ authentication_cryptogram,
+ eci: post_authentication_details.eci,
+ ds_trans_id: post_authentication_details
+ .dynamic_data_details
+ .as_ref()
+ .and_then(|data| data.ds_trans_id.clone()),
+ transaction_status: post_authentication_details
+ .trans_status
+ .unwrap_or(common_enums::TransactionStatus::Failure),
+ version: authentication.maximum_supported_version.clone(),
+ }),
+ };
+
+ Ok((
+ authentication.clone(),
+ None,
+ None,
+ Some(authentication_details),
+ ))
+ } else {
+ Ok((authentication.clone(), None, None, None))
+ }
+}
+
#[cfg(feature = "v1")]
pub async fn authentication_sync_core(
state: SessionState,
@@ -1882,99 +2104,46 @@ pub async fn authentication_sync_core(
.await?;
}
- let (updated_authentication, payment_method_data, vault_token_data) =
- if !authentication.authentication_status.is_terminal_status() {
- let post_auth_response = if authentication_connector.is_click_to_pay() {
- let response = ClickToPay::post_authentication(
- &state,
- &business_profile,
- None,
- &three_ds_connector_account.clone(),
- &authentication_connector.to_string(),
- &authentication_id,
- common_enums::PaymentMethod::Card,
- merchant_id,
- None,
- None,
- )
- .await?;
- metrics::POST_AUTHENTICATION_CARDS_SUCCESSFULLY_DECRYPTED.add(1, &[]);
- response
- } else {
- let routing_region = utils::fetch_routing_region_for_uas(
- &state,
- merchant_id.clone(),
- merchant_account.organization_id.clone(),
- )
- .await
- .change_context(ApiErrorResponse::InternalServerError)
- .attach_printable("Failed to fetch routing path")?;
- ExternalAuthentication::post_authentication(
+ // Determine whether to tokenise or not
+ let should_disable_vault_tokenization =
+ utils::should_disable_vault_tokenization(&state, &authentication.merchant_id).await;
+
+ // Determine the authentication sync strategy based on current state
+ let strategy = determine_auth_sync_strategy(
+ &authentication,
+ should_disable_vault_tokenization,
+ auth_flow,
+ );
+
+ // Execute the appropriate flow based on the strategy
+ let (updated_authentication, payment_method_data, vault_token_data, authentication_details) =
+ match strategy {
+ AuthSyncStrategy::ExecutePostAuth => {
+ Box::pin(execute_post_authentication_flow(
&state,
+ &platform,
&business_profile,
- None,
+ &authentication,
+ &authentication_connector,
&three_ds_connector_account,
- &authentication_connector.to_string(),
&authentication_id,
- common_enums::PaymentMethod::Card,
merchant_id,
- Some(&authentication),
- Some(routing_region),
- )
+ merchant_account,
+ should_disable_vault_tokenization,
+ ))
.await?
- };
-
- let config = db
- .find_config_by_key_unwrap_or(
- &merchant_id.get_should_disable_auth_tokenization(),
- Some("false".to_string()),
- )
- .await;
- let should_disable_auth_tokenization = match config {
- Ok(conf) => conf.config == "true",
- Err(error) => {
- router_env::logger::error!(?error);
- false
- }
- };
-
- let vault_token_data = if should_disable_auth_tokenization {
- // Do not tokenize if the disable flag is present in the config
- None
- } else {
- let response = Box::pin(utils::get_auth_multi_token_from_external_vault(
+ }
+ AuthSyncStrategy::UseStoredAuthValue => {
+ use_stored_authentication_value(
&state,
&platform,
- &business_profile,
- &post_auth_response,
- ))
- .await?;
- metrics::POST_AUTHENTICATION_TOKEN_PUSHED_TO_VGS.add(1, &[]);
- response
- };
-
- let payment_method_data =
- utils::get_authentication_payment_method_data(&post_auth_response);
-
- let auth_update_response = utils::external_authentication_update_trackers(
- &state,
- post_auth_response,
- authentication.clone(),
- None,
- platform.get_processor().get_key_store(),
- None,
- None,
- None,
- None,
- None,
- None,
- None,
- )
- .await?;
-
- (auth_update_response, payment_method_data, vault_token_data)
- } else {
- (authentication, None, None)
+ &authentication,
+ &authentication_id,
+ should_disable_vault_tokenization,
+ )
+ .await?
+ }
+ AuthSyncStrategy::NoOperation => (authentication, None, None, None),
};
let eci = match auth_flow {
@@ -2092,6 +2261,7 @@ pub async fn authentication_sync_core(
.and_then(|details| details.three_ds_requestor_app_url),
profile_acquirer_id: updated_authentication.profile_acquirer_id.clone(),
eci,
+ authentication_details,
};
Ok(hyperswitch_domain_models::api::ApplicationResponse::Json(
response,
diff --git a/crates/router/src/core/unified_authentication_service/types.rs b/crates/router/src/core/unified_authentication_service/types.rs
index 508fa378e9..282ff5b9e9 100644
--- a/crates/router/src/core/unified_authentication_service/types.rs
+++ b/crates/router/src/core/unified_authentication_service/types.rs
@@ -184,3 +184,14 @@ pub trait UnifiedAuthenticationService {
.into())
}
}
+
+/// Strategy for handling authentication sync based on current state
+#[derive(Debug, Clone, Copy)]
+pub enum AuthSyncStrategy {
+ /// Execute full post-authentication flow (call connector, tokenize, update trackers)
+ ExecutePostAuth,
+ /// Use previously stored authentication value (terminal success + merchant flow + no tokenization)
+ UseStoredAuthValue,
+ /// No operation needed (terminal status but conditions for stored value not met)
+ NoOperation,
+}
diff --git a/crates/router/src/core/unified_authentication_service/utils.rs b/crates/router/src/core/unified_authentication_service/utils.rs
index d5961153ff..311c4a23ac 100644
--- a/crates/router/src/core/unified_authentication_service/utils.rs
+++ b/crates/router/src/core/unified_authentication_service/utils.rs
@@ -617,7 +617,7 @@ pub fn get_authentication_payment_method_data<F, Req>(
authentication_details,
}) = router_data.response.clone()
{
- authentication_details.into()
+ authentication_details.to_authentication_payment_method_data_response()
} else {
None
}
@@ -730,3 +730,32 @@ async fn fetch_region(state: &SessionState, key: &str) -> Option<RoutingRegion>
.ok()
.map(|conf| RoutingRegion::from_str(&conf.config).unwrap_or(RoutingRegion::Region1))
}
+
+pub async fn get_bool_config(state: &SessionState, key: &str, default_value: bool) -> bool {
+ let default_str = if default_value { "true" } else { "false" };
+
+ let config = state
+ .store
+ .find_config_by_key_unwrap_or(key, Some(default_str.to_string()))
+ .await;
+
+ match config {
+ Ok(conf) => conf.config == "true",
+ Err(error) => {
+ router_env::logger::error!(?error);
+ default_value
+ }
+ }
+}
+
+pub async fn should_disable_vault_tokenization(
+ state: &SessionState,
+ merchant_id: &common_utils::id_type::MerchantId,
+) -> bool {
+ get_bool_config(
+ state,
+ &merchant_id.get_should_disable_vault_tokenization(),
+ false,
+ )
+ .await
+}