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
refactor(authentication): moved cavv storing from table to temp locker (#7978)
Sahkal Poddardbaf5679717c
diff --git a/crates/diesel_models/src/authentication.rs b/crates/diesel_models/src/authentication.rsindex 3e0039f4ac..7bfea7e2b6 100644--- a/crates/diesel_models/src/authentication.rs+++ b/crates/diesel_models/src/authentication.rs@@ -129,7 +129,6 @@ pub enum AuthenticationUpdate {acquirer_country_code: Option<String>,},AuthenticationUpdate {- authentication_value: Option<String>,trans_status: common_enums::TransactionStatus,authentication_type: common_enums::DecoupledAuthenticationType,acs_url: Option<String>,@@ -143,7 +142,6 @@ pub enum AuthenticationUpdate {},PostAuthenticationUpdate {trans_status: common_enums::TransactionStatus,- authentication_value: Option<String>,eci: Option<String>,authentication_status: common_enums::AuthenticationStatus,},@@ -177,7 +175,6 @@ pub struct AuthenticationUpdateInternal {pub connector_metadata: Option<serde_json::Value>,pub maximum_supported_version: Option<common_utils::types::SemanticVersion>,pub threeds_server_transaction_id: Option<String>,- pub cavv: Option<String>,pub authentication_flow_type: Option<String>,pub message_version: Option<common_utils::types::SemanticVersion>,pub eci: Option<String>,@@ -211,7 +208,6 @@ impl Default for AuthenticationUpdateInternal {connector_metadata: Default::default(),maximum_supported_version: Default::default(),threeds_server_transaction_id: Default::default(),- cavv: Default::default(),authentication_flow_type: Default::default(),message_version: Default::default(),eci: Default::default(),@@ -247,7 +243,6 @@ impl AuthenticationUpdateInternal {connector_metadata,maximum_supported_version,threeds_server_transaction_id,- cavv,authentication_flow_type,message_version,eci,@@ -282,7 +277,6 @@ impl AuthenticationUpdateInternal {.or(source.maximum_supported_version),threeds_server_transaction_id: threeds_server_transaction_id.or(source.threeds_server_transaction_id),- cavv: cavv.or(source.cavv),authentication_flow_type: authentication_flow_type.or(source.authentication_flow_type),message_version: message_version.or(source.message_version),eci: eci.or(source.eci),@@ -369,7 +363,6 @@ impl From<AuthenticationUpdate> for AuthenticationUpdateInternal {..Default::default()},AuthenticationUpdate::AuthenticationUpdate {- authentication_value,trans_status,authentication_type,acs_url,@@ -381,7 +374,6 @@ impl From<AuthenticationUpdate> for AuthenticationUpdateInternal {authentication_status,ds_trans_id,} => Self {- cavv: authentication_value,trans_status: Some(trans_status),authentication_type: Some(authentication_type),acs_url,@@ -396,12 +388,10 @@ impl From<AuthenticationUpdate> for AuthenticationUpdateInternal {},AuthenticationUpdate::PostAuthenticationUpdate {trans_status,- authentication_value,eci,authentication_status,} => Self {trans_status: Some(trans_status),- cavv: authentication_value,eci,authentication_status: Some(authentication_status),..Default::default()diff --git a/crates/hyperswitch_connectors/src/connectors/gpayments/gpayments_types.rs b/crates/hyperswitch_connectors/src/connectors/gpayments/gpayments_types.rsindex 787740523a..c1f7d50ac6 100644--- a/crates/hyperswitch_connectors/src/connectors/gpayments/gpayments_types.rs+++ b/crates/hyperswitch_connectors/src/connectors/gpayments/gpayments_types.rs@@ -196,7 +196,7 @@ pub struct GpaymentsAuthenticationSuccessResponse {pub acs_url: Option<url::Url>,#[serde(rename = "acsReferenceNumber")]pub acs_reference_number: String,- pub authentication_value: Option<String>,+ pub authentication_value: Option<Secret<String>>,}#[derive(Deserialize, Debug, Clone, Serialize, PartialEq)]@@ -230,7 +230,7 @@ impl From<AuthStatus> for common_enums::TransactionStatus {#[derive(Debug, Deserialize, Serialize)]#[serde(rename_all = "camelCase")]pub struct GpaymentsPostAuthenticationResponse {- pub authentication_value: Option<String>,+ pub authentication_value: Option<Secret<String>>,pub trans_status: AuthStatus,pub eci: Option<String>,}diff --git a/crates/hyperswitch_connectors/src/connectors/netcetera/transformers.rs b/crates/hyperswitch_connectors/src/connectors/netcetera/transformers.rsindex 467f92b5fd..c0574c1c4f 100644--- a/crates/hyperswitch_connectors/src/connectors/netcetera/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/netcetera/transformers.rs@@ -633,7 +633,7 @@ pub struct NetceteraAuthenticationSuccessResponse {#[serde(rename = "threeDSServerTransID")]pub three_ds_server_trans_id: String,pub trans_status: common_enums::TransactionStatus,- pub authentication_value: Option<String>,+ pub authentication_value: Option<Secret<String>>,pub eci: Option<String>,pub acs_challenge_mandated: Option<ACSChallengeMandatedIndicator>,pub authentication_response: AuthenticationResponse,@@ -693,7 +693,7 @@ pub struct ResultsResponseData {/// Payment System-specific value provided as part of the ACS registration for each supported DS./// Authentication Value may be used to provide proof of authentication.- pub authentication_value: Option<String>,+ pub authentication_value: Option<Secret<String>>,/// Payment System-specific value provided by the ACS to indicate the results of the attempt to authenticate/// the Cardholder.diff --git a/crates/hyperswitch_domain_models/src/router_request_types/authentication.rs b/crates/hyperswitch_domain_models/src/router_request_types/authentication.rsindex 74bdb94dd7..81fc33fbdc 100644--- a/crates/hyperswitch_domain_models/src/router_request_types/authentication.rs+++ b/crates/hyperswitch_domain_models/src/router_request_types/authentication.rs@@ -161,3 +161,9 @@ pub struct AcquirerDetails {pub struct ExternalThreeDSConnectorMetadata {pub pull_mechanism_for_external_3ds_enabled: Option<bool>,}++#[derive(Clone, Debug)]+pub struct AuthenticationStore {+ pub cavv: Option<String>,+ pub authentication: diesel_models::authentication::Authentication,+}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.rsindex 76251fa6dd..40237a1dac 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@@ -106,7 +106,7 @@ pub struct PreAuthenticationDetails {#[derive(Debug, Clone)]pub struct AuthenticationDetails {pub authn_flow_type: super::authentication::AuthNFlowType,- pub authentication_value: Option<String>,+ pub authentication_value: Option<Secret<String>>,pub trans_status: common_enums::TransactionStatus,pub connector_metadata: Option<serde_json::Value>,pub ds_trans_id: Option<String>,diff --git a/crates/hyperswitch_domain_models/src/router_response_types.rs b/crates/hyperswitch_domain_models/src/router_response_types.rsindex bfba6ad553..54d763dd9e 100644--- a/crates/hyperswitch_domain_models/src/router_response_types.rs+++ b/crates/hyperswitch_domain_models/src/router_response_types.rs@@ -536,14 +536,14 @@ pub enum AuthenticationResponseData {},AuthNResponse {authn_flow_type: AuthNFlowType,- authentication_value: Option<String>,+ authentication_value: Option<masking::Secret<String>>,trans_status: common_enums::TransactionStatus,connector_metadata: Option<serde_json::Value>,ds_trans_id: Option<String>,},PostAuthNResponse {trans_status: common_enums::TransactionStatus,- authentication_value: Option<String>,+ authentication_value: Option<masking::Secret<String>>,eci: Option<String>,},}diff --git a/crates/hyperswitch_interfaces/src/authentication.rs b/crates/hyperswitch_interfaces/src/authentication.rsindex 960672e1d1..6c2488767b 100644--- a/crates/hyperswitch_interfaces/src/authentication.rs+++ b/crates/hyperswitch_interfaces/src/authentication.rs@@ -6,7 +6,7 @@ pub struct ExternalAuthenticationPayload {/// trans_statuspub trans_status: common_enums::TransactionStatus,/// authentication_value- pub authentication_value: Option<String>,+ pub authentication_value: Option<masking::Secret<String>>,/// ecipub eci: Option<String>,}diff --git a/crates/router/src/connector/threedsecureio/transformers.rs b/crates/router/src/connector/threedsecureio/transformers.rsindex 2c7674c798..e6d608b68d 100644--- a/crates/router/src/connector/threedsecureio/transformers.rs+++ b/crates/router/src/connector/threedsecureio/transformers.rs@@ -513,7 +513,7 @@ pub struct ThreedsecureioAuthenticationSuccessResponse {#[serde(rename = "acsSignedContent")]pub acs_signed_content: Option<String>,#[serde(rename = "authenticationValue")]- pub authentication_value: Option<String>,+ pub authentication_value: Option<Secret<String>>,}#[derive(Debug, Serialize, Deserialize)]@@ -615,7 +615,7 @@ pub struct ThreedsecureioPostAuthenticationRequest {#[derive(Debug, Deserialize, Serialize)]#[serde(rename_all = "camelCase")]pub struct ThreedsecureioPostAuthenticationResponse {- pub authentication_value: Option<String>,+ pub authentication_value: Option<Secret<String>>,pub trans_status: ThreedsecureioTransStatus,pub eci: Option<String>,}diff --git a/crates/router/src/core/authentication.rs b/crates/router/src/core/authentication.rsindex 28d88ac1fc..3736475660 100644--- a/crates/router/src/core/authentication.rs+++ b/crates/router/src/core/authentication.rs@@ -42,6 +42,7 @@ pub async fn perform_authentication(psd2_sca_exemption_type: Option<common_enums::ScaExemptionType>,payment_id: common_utils::id_type::PaymentId,force_3ds_challenge: bool,+ merchant_key_store: &hyperswitch_domain_models::merchant_key_store::MerchantKeyStore,) -> CustomResult<api::authentication::AuthenticationResponse, ApiErrorResponse> {let router_data = transformers::construct_authentication_router_data(state,@@ -74,8 +75,14 @@ pub async fn perform_authentication(router_data,)).await?;- let authentication =- utils::update_trackers(state, response.clone(), authentication_data, None).await?;+ let authentication = utils::update_trackers(+ state,+ response.clone(),+ authentication_data,+ None,+ merchant_key_store,+ )+ .await?;response.response.map_err(|err| ApiErrorResponse::ExternalConnectorError {@@ -94,7 +101,10 @@ pub async fn perform_post_authentication(business_profile: domain::Profile,authentication_id: String,payment_id: &common_utils::id_type::PaymentId,-) -> CustomResult<storage::Authentication, ApiErrorResponse> {+) -> CustomResult<+ hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore,+ ApiErrorResponse,+> {let (authentication_connector, three_ds_connector_account) =utils::get_authentication_connector_data(state, key_store, &business_profile).await?;let is_pull_mechanism_enabled =@@ -112,7 +122,11 @@ pub async fn perform_post_authentication(.await.to_not_found_response(ApiErrorResponse::InternalServerError).attach_printable_lazy(|| format!("Error while fetching authentication record with authentication_id {authentication_id}"))?;- if !authentication.authentication_status.is_terminal_status() && is_pull_mechanism_enabled {++ let authentication_update = if !authentication.authentication_status.is_terminal_status()+ && is_pull_mechanism_enabled+ {+ // trigger in case of authenticate flowlet router_data = transformers::construct_post_authentication_router_data(state,authentication_connector.to_string(),@@ -124,10 +138,28 @@ pub async fn perform_post_authentication(let router_data =utils::do_auth_connector_call(state, authentication_connector.to_string(), router_data).await?;- utils::update_trackers(state, router_data, authentication, None).await+ utils::update_trackers(state, router_data, authentication, None, key_store).await?} else {- Ok(authentication)- }+ // trigger in case of webhook flow+ authentication+ };++ // getting authentication value from temp locker before moving ahead with authrisation+ let tokenized_data = crate::core::payment_methods::vault::get_tokenized_data(+ state,+ &authentication_id,+ false,+ key_store.key.get_inner(),+ )+ .await?;++ let authentication_store =+ hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore {+ cavv: Some(tokenized_data.value1),+ authentication: authentication_update,+ };++ Ok(authentication_store)}#[allow(clippy::too_many_arguments)]@@ -140,7 +172,10 @@ pub async fn perform_pre_authentication(acquirer_details: Option<types::AcquirerDetails>,payment_id: common_utils::id_type::PaymentId,organization_id: common_utils::id_type::OrganizationId,-) -> CustomResult<storage::Authentication, ApiErrorResponse> {+) -> CustomResult<+ hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore,+ ApiErrorResponse,+> {let (authentication_connector, three_ds_connector_account) =utils::get_authentication_connector_data(state, key_store, business_profile).await?;let authentication_connector_name = authentication_connector.to_string();@@ -176,13 +211,21 @@ pub async fn perform_pre_authentication().await?;- let updated_authentication =- utils::update_trackers(state, router_data, authentication, acquirer_details.clone())- .await?;+ let updated_authentication = utils::update_trackers(+ state,+ router_data,+ authentication,+ acquirer_details.clone(),+ key_store,+ )+ .await?;// from version call response, we will get to know the maximum supported 3ds version.// If the version is not greater than or equal to 3DS 2.0, We should not do the successive pre authentication call.if !updated_authentication.is_separate_authn_required() {- return Ok(updated_authentication);+ return Ok(hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore{+ authentication: updated_authentication,+ cavv: None, // since cavv wont be present in pre_authentication step+ });}updated_authentication} else {@@ -201,5 +244,19 @@ pub async fn perform_pre_authentication(let router_data =utils::do_auth_connector_call(state, authentication_connector_name, router_data).await?;- utils::update_trackers(state, router_data, authentication, acquirer_details).await+ let authentication_update = utils::update_trackers(+ state,+ router_data,+ authentication,+ acquirer_details,+ key_store,+ )+ .await?;++ Ok(+ hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore {+ authentication: authentication_update,+ cavv: None, // since cavv wont be present in pre_authentication step+ },+ )}diff --git a/crates/router/src/core/authentication/utils.rs b/crates/router/src/core/authentication/utils.rsindex 7b9baf7d50..71cc4bd840 100644--- a/crates/router/src/core/authentication/utils.rs+++ b/crates/router/src/core/authentication/utils.rs@@ -1,5 +1,7 @@+use common_utils::ext_traits::AsyncExt;use error_stack::ResultExt;use hyperswitch_domain_models::router_data_v2::ExternalAuthenticationFlowData;+use masking::ExposeInterface;use crate::{consts,@@ -53,6 +55,7 @@ pub async fn update_trackers<F: Clone, Req>(router_data: RouterData<F, Req, AuthenticationResponseData>,authentication: storage::Authentication,acquirer_details: Option<super::types::AcquirerDetails>,+ merchant_key_store: &hyperswitch_domain_models::merchant_key_store::MerchantKeyStore,) -> RouterResult<storage::Authentication> {let authentication_update = match router_data.response {Ok(response) => match response {@@ -91,10 +94,23 @@ pub async fn update_trackers<F: Clone, Req>(connector_metadata,ds_trans_id,} => {+ authentication_value+ .async_map(|auth_val| {+ crate::core::payment_methods::vault::create_tokenize(+ state,+ auth_val.expose(),+ None,+ authentication.authentication_id.clone(),+ merchant_key_store.key.get_inner(),+ )+ })+ .await+ .transpose()?;+let authentication_status =common_enums::AuthenticationStatus::foreign_from(trans_status.clone());+storage::AuthenticationUpdate::AuthenticationUpdate {- authentication_value,trans_status,acs_url: authn_flow_type.get_acs_url(),challenge_request: authn_flow_type.get_challenge_request(),@@ -111,14 +127,27 @@ pub async fn update_trackers<F: Clone, Req>(trans_status,authentication_value,eci,- } => storage::AuthenticationUpdate::PostAuthenticationUpdate {- authentication_status: common_enums::AuthenticationStatus::foreign_from(- trans_status.clone(),- ),- trans_status,- authentication_value,- eci,- },+ } => {+ authentication_value+ .async_map(|auth_val| {+ crate::core::payment_methods::vault::create_tokenize(+ state,+ auth_val.expose(),+ None,+ authentication.authentication_id.clone(),+ merchant_key_store.key.get_inner(),+ )+ })+ .await+ .transpose()?;+ storage::AuthenticationUpdate::PostAuthenticationUpdate {+ authentication_status: common_enums::AuthenticationStatus::foreign_from(+ trans_status.clone(),+ ),+ trans_status,+ eci,+ }+ }AuthenticationResponseData::PreAuthVersionCallResponse {maximum_supported_3ds_version,} => storage::AuthenticationUpdate::PreAuthenticationVersionCallUpdate {diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex 1b7249cfa4..1e4ad6da03 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -5338,7 +5338,7 @@ wherepub payment_link_data: Option<api_models::payments::PaymentLinkResponse>,pub incremental_authorization_details: Option<IncrementalAuthorizationDetails>,pub authorizations: Vec<diesel_models::authorization::Authorization>,- pub authentication: Option<storage::Authentication>,+ pub authentication: Option<domain::authentication::AuthenticationStore>,pub recurring_details: Option<RecurringDetails>,pub poll_config: Option<router_types::PollConfig>,pub tax_data: Option<TaxData>,@@ -7652,6 +7652,7 @@ pub async fn payment_external_authentication<F: Clone + Sync>(auth_response,authentication.clone(),None,+ merchant_context.get_merchant_key_store(),).await?;authentication::AuthenticationResponse::try_from(authentication)?@@ -7685,6 +7686,7 @@ pub async fn payment_external_authentication<F: Clone + Sync>(payment_intent.psd2_sca_exemption_type,payment_intent.payment_id,payment_intent.force_3ds_challenge_trigger.unwrap_or(false),+ merchant_context.get_merchant_key_store(),)).await?};@@ -7975,7 +7977,9 @@ pub trait OperationSessionGetters<F> {fn get_ephemeral_key(&self) -> Option<ephemeral_key::EphemeralKey>;fn get_setup_mandate(&self) -> Option<&MandateData>;fn get_poll_config(&self) -> Option<router_types::PollConfig>;- fn get_authentication(&self) -> Option<&storage::Authentication>;+ fn get_authentication(+ &self,+ ) -> Option<&hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore>;fn get_frm_message(&self) -> Option<FraudCheck>;fn get_refunds(&self) -> Vec<storage::Refund>;fn get_disputes(&self) -> Vec<storage::Dispute>;@@ -8106,7 +8110,10 @@ impl<F: Clone> OperationSessionGetters<F> for PaymentData<F> {self.poll_config.clone()}- fn get_authentication(&self) -> Option<&storage::Authentication> {+ fn get_authentication(+ &self,+ ) -> Option<&hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore>+ {self.authentication.as_ref()}@@ -8372,7 +8379,10 @@ impl<F: Clone> OperationSessionGetters<F> for PaymentIntentData<F> {todo!()}- fn get_authentication(&self) -> Option<&storage::Authentication> {+ fn get_authentication(+ &self,+ ) -> Option<&hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore>+ {todo!()}@@ -8593,7 +8603,10 @@ impl<F: Clone> OperationSessionGetters<F> for PaymentConfirmData<F> {todo!()}- fn get_authentication(&self) -> Option<&storage::Authentication> {+ fn get_authentication(+ &self,+ ) -> Option<&hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore>+ {todo!()}@@ -8815,7 +8828,10 @@ impl<F: Clone> OperationSessionGetters<F> for PaymentStatusData<F> {todo!()}- fn get_authentication(&self) -> Option<&storage::Authentication> {+ fn get_authentication(+ &self,+ ) -> Option<&hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore>+ {todo!()}@@ -9037,7 +9053,10 @@ impl<F: Clone> OperationSessionGetters<F> for PaymentCaptureData<F> {todo!()}- fn get_authentication(&self) -> Option<&storage::Authentication> {+ fn get_authentication(+ &self,+ ) -> Option<&hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore>+ {todo!()}diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rsindex 440eb12574..f93e5fcec1 100644--- a/crates/router/src/core/payments/operations/payment_confirm.rs+++ b/crates/router/src/core/payments/operations/payment_confirm.rs@@ -1021,7 +1021,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> forcard,token,}) => {- let authentication = Box::pin(authentication::perform_pre_authentication(+ let authentication_store = Box::pin(authentication::perform_pre_authentication(state,key_store,*card,@@ -1032,8 +1032,13 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> forpayment_data.payment_attempt.organization_id.clone(),)).await?;- if authentication.is_separate_authn_required()- || authentication.authentication_status.is_failed()+ if authentication_store+ .authentication+ .is_separate_authn_required()+ || authentication_store+ .authentication+ .authentication_status+ .is_failed(){*should_continue_confirm_transaction = false;let default_poll_config = types::PollConfig::default();@@ -1045,7 +1050,10 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for.store.find_config_by_key_unwrap_or(&types::PollConfig::get_poll_config_key(- authentication.authentication_connector.clone(),+ authentication_store+ .authentication+ .authentication_connector+ .clone(),),Some(default_config_str),)@@ -1059,12 +1067,12 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for.attach_printable("Error while parsing PollConfig")?;payment_data.poll_config = Some(poll_config)}- Some(authentication)+ Some(authentication_store)}Some(helpers::PaymentExternalAuthenticationFlow::PostAuthenticationFlow {authentication_id,}) => {- let authentication = Box::pin(authentication::perform_post_authentication(+ let authentication_store = Box::pin(authentication::perform_post_authentication(state,key_store,business_profile.clone(),@@ -1073,12 +1081,12 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for)).await?;//If authentication is not successful, skip the payment connector flows and mark the payment as failure- if authentication.authentication_status+ if authentication_store.authentication.authentication_status!= api_models::enums::AuthenticationStatus::Success{*should_continue_confirm_transaction = false;}- Some(authentication)+ Some(authentication_store)}None => None,};@@ -1223,7 +1231,11 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> forpayment_data.payment_attempt.organization_id.clone(),).await?;- payment_data.authentication = Some(authentication);+ let authentication_store = hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore {+ cavv: None, // since in case of CTP we will be storing all details in network token under payment_method_data+ authentication+ };+ payment_data.authentication = Some(authentication_store);},helpers::UnifiedAuthenticationServiceFlow::ClickToPayConfirmation => {let authentication_product_ids = business_profile@@ -1313,8 +1325,13 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> forpre_auth_response,authentication.clone(),acquirer_details,+ key_store).await?;- payment_data.authentication = Some(updated_authentication.clone());+ let authentication_store = hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore {+ cavv: None, // since in case of pre_authentication cavv is not present+ authentication+ };+ payment_data.authentication = Some(authentication_store.clone());if updated_authentication.is_separate_authn_required()|| updated_authentication.authentication_status.is_failed()@@ -1380,13 +1397,22 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> forpost_auth_response,authentication,None,+ key_store).await?} else {authentication};- payment_data.authentication = Some(updated_authentication.clone());++ let tokenized_data = crate::core::payment_methods::vault::get_tokenized_data(state, &authentication_id, false, key_store.key.get_inner()).await?;++ let authentication_store = hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore {+ cavv: Some(tokenized_data.value1),+ authentication: updated_authentication+ };++ payment_data.authentication = Some(authentication_store.clone());//If authentication is not successful, skip the payment connector flows and mark the payment as failure- if updated_authentication.authentication_status+ if authentication_store.authentication.authentication_status!= api_models::enums::AuthenticationStatus::Success{*should_continue_confirm_transaction = false;@@ -1579,9 +1605,9 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> forlet (intent_status, attempt_status, (error_code, error_message)) =match (frm_suggestion, payment_data.authentication.as_ref()) {(Some(frm_suggestion), _) => status_handler_for_frm_results(frm_suggestion),- (_, Some(authentication_details)) => {- status_handler_for_authentication_results(authentication_details)- }+ (_, Some(authentication_details)) => status_handler_for_authentication_results(+ &authentication_details.authentication,+ ),_ => default_status_result,};@@ -1696,10 +1722,24 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> forauthentication_connector,authentication_id,) = match payment_data.authentication.as_ref() {- Some(authentication) => (- Some(authentication.is_separate_authn_required()),- Some(authentication.authentication_connector.clone()),- Some(authentication.authentication_id.clone()),+ Some(authentication_store) => (+ Some(+ authentication_store+ .authentication+ .is_separate_authn_required(),+ ),+ Some(+ authentication_store+ .authentication+ .authentication_connector+ .clone(),+ ),+ Some(+ authentication_store+ .authentication+ .authentication_id+ .clone(),+ ),),None => (None, None, None),};diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rsindex c7b40b3e75..90b9889fff 100644--- a/crates/router/src/core/payments/operations/payment_response.rs+++ b/crates/router/src/core/payments/operations/payment_response.rs@@ -1995,19 +1995,20 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(payment_data.payment_attempt = payment_attempt;payment_data.authentication = match payment_data.authentication {- Some(authentication) => {+ Some(mut authentication_store) => {let authentication_update = storage::AuthenticationUpdate::PostAuthorizationUpdate {authentication_lifecycle_status: enums::AuthenticationLifecycleStatus::Used,};let updated_authentication = state.store.update_authentication_by_merchant_id_authentication_id(- authentication,+ authentication_store.authentication,authentication_update,).await.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;- Some(updated_authentication)+ authentication_store.authentication = updated_authentication;+ Some(authentication_store)}None => None,};diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rsindex bae603457c..58c784c652 100644--- a/crates/router/src/core/payments/operations/payment_status.rs+++ b/crates/router/src/core/payments/operations/payment_status.rs@@ -462,16 +462,28 @@ async fn get_tracker_for_sync<};let merchant_id = payment_intent.merchant_id.clone();- let authentication = payment_attempt.authentication_id.clone().async_map(|authentication_id| async move {++ let authentication_store = if let Some(ref authentication_id) =+ payment_attempt.authentication_id+ {+ let authentication =db.find_authentication_by_merchant_id_authentication_id(&merchant_id,authentication_id.clone(),).await.to_not_found_response(errors::ApiErrorResponse::InternalServerError)- .attach_printable_lazy(|| format!("Error while fetching authentication record with authentication_id {authentication_id}"))- }).await- .transpose()?;+ .attach_printable_lazy(|| format!("Error while fetching authentication record with authentication_id {authentication_id}"))?;++ Some(+ hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore {+ authentication,+ cavv: None, // marking this as None since we don't need authentication value in payment status flow+ },+ )+ } else {+ None+ };let payment_link_data = payment_intent.payment_link_id@@ -530,7 +542,7 @@ async fn get_tracker_for_sync<frm_message: frm_response,incremental_authorization_details: None,authorizations,- authentication,+ authentication: authentication_store,recurring_details: None,poll_config: None,tax_data: None,diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rsindex 211be32ce9..9ab06102fe 100644--- a/crates/router/src/core/payments/transformers.rs+++ b/crates/router/src/core/payments/transformers.rs@@ -2594,9 +2594,10 @@ where),}}))- .or(match payment_data.get_authentication().as_ref(){- Some(authentication) => {- if payment_intent.status == common_enums::IntentStatus::RequiresCustomerAction && authentication.cavv.is_none() && authentication.is_separate_authn_required(){+ .or(match payment_data.get_authentication(){+ Some(authentication_store) => {+ let authentication = &authentication_store.authentication;+ if payment_intent.status == common_enums::IntentStatus::RequiresCustomerAction && authentication_store.cavv.is_none() && authentication.is_separate_authn_required(){// if preAuthn and separate authentication needed.let poll_config = payment_data.get_poll_config().unwrap_or_default();let request_poll_id = core_utils::get_external_authentication_request_poll_id(&payment_intent.payment_id);diff --git a/crates/router/src/core/payments/types.rs b/crates/router/src/core/payments/types.rsindex 2d147db244..29d87944ea 100644--- a/crates/router/src/core/payments/types.rs+++ b/crates/router/src/core/payments/types.rs@@ -366,14 +366,21 @@ impl SurchargeMetadata {}}-impl ForeignTryFrom<&storage::Authentication> for AuthenticationData {+impl+ ForeignTryFrom<+ &hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore,+ > for AuthenticationData+{type Error = error_stack::Report<errors::ApiErrorResponse>;- fn foreign_try_from(authentication: &storage::Authentication) -> Result<Self, Self::Error> {+ fn foreign_try_from(+ authentication_store: &hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore,+ ) -> Result<Self, Self::Error> {+ let authentication = &authentication_store.authentication;if authentication.authentication_status == common_enums::AuthenticationStatus::Success {let threeds_server_transaction_id =authentication.threeds_server_transaction_id.clone();let message_version = authentication.message_version.clone();- let cavv = authentication+ let cavv = authentication_store.cavv.clone().get_required_value("cavv")diff --git a/crates/router/src/core/unified_authentication_service/utils.rs b/crates/router/src/core/unified_authentication_service/utils.rsindex efffd2f4a2..cbd4c2ee2e 100644--- a/crates/router/src/core/unified_authentication_service/utils.rs+++ b/crates/router/src/core/unified_authentication_service/utils.rs@@ -1,7 +1,7 @@use std::marker::PhantomData;use common_enums::enums::PaymentMethod;-use common_utils::ext_traits::ValueExt;+use common_utils::ext_traits::{AsyncExt, ValueExt};use error_stack::ResultExt;use hyperswitch_domain_models::{errors::api_error_response::ApiErrorResponse,@@ -10,6 +10,7 @@ use hyperswitch_domain_models::{router_data_v2::UasFlowData,router_request_types::unified_authentication_service::UasAuthenticationResponseData,};+use masking::ExposeInterface;use super::types::{IRRELEVANT_ATTEMPT_ID_IN_AUTHENTICATION_FLOW,@@ -130,6 +131,7 @@ pub async fn external_authentication_update_trackers<F: Clone, Req>(acquirer_details: Option<hyperswitch_domain_models::router_request_types::authentication::AcquirerDetails,>,+ merchant_key_store: &hyperswitch_domain_models::merchant_key_store::MerchantKeyStore,) -> RouterResult<diesel_models::authentication::Authentication> {let authentication_update = match router_data.response {Ok(response) => match response {@@ -180,9 +182,21 @@ pub async fn external_authentication_update_trackers<F: Clone, Req>(let authentication_status = common_enums::AuthenticationStatus::foreign_from(authentication_details.trans_status.clone(),);+ authentication_details+ .authentication_value+ .async_map(|auth_val| {+ crate::core::payment_methods::vault::create_tokenize(+ state,+ auth_val.expose(),+ None,+ authentication.authentication_id.clone(),+ merchant_key_store.key.get_inner(),+ )+ })+ .await+ .transpose()?;Ok(diesel_models::authentication::AuthenticationUpdate::AuthenticationUpdate {- authentication_value: authentication_details.authentication_value,trans_status: authentication_details.trans_status,acs_url: authentication_details.authn_flow_type.get_acs_url(),challenge_request: authentication_details@@ -211,16 +225,30 @@ pub async fn external_authentication_update_trackers<F: Clone, Req>(.trans_status.ok_or(ApiErrorResponse::InternalServerError).attach_printable("missing trans_status in PostAuthentication Details")?;++ let authentication_value = authentication_details+ .dynamic_data_details+ .and_then(|details| details.dynamic_data_value)+ .map(ExposeInterface::expose);++ authentication_value+ .async_map(|auth_val| {+ crate::core::payment_methods::vault::create_tokenize(+ state,+ auth_val,+ None,+ authentication.authentication_id.clone(),+ merchant_key_store.key.get_inner(),+ )+ })+ .await+ .transpose()?;Ok(diesel_models::authentication::AuthenticationUpdate::PostAuthenticationUpdate {authentication_status: common_enums::AuthenticationStatus::foreign_from(trans_status.clone(),),trans_status,- authentication_value: authentication_details- .dynamic_data_details- .and_then(|details| details.dynamic_data_value)- .map(masking::ExposeInterface::expose),eci: authentication_details.eci,},)diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rsindex fa6021a707..a651962848 100644--- a/crates/router/src/core/webhooks/incoming.rs+++ b/crates/router/src/core/webhooks/incoming.rs@@ -4,7 +4,7 @@ use actix_web::FromRequest;#[cfg(feature = "payouts")]use api_models::payouts as payout_models;use api_models::webhooks::{self, WebhookResponseTracker};-use common_utils::{errors::ReportSwitchExt, events::ApiEventsType};+use common_utils::{errors::ReportSwitchExt, events::ApiEventsType, ext_traits::AsyncExt};use diesel_models::ConnectorMandateReferenceId;use error_stack::{report, ResultExt};use hyperswitch_domain_models::{@@ -1250,7 +1250,6 @@ async fn external_authentication_incoming_webhook_flow(trans_status.clone(),),trans_status,- authentication_value: authentication_details.authentication_value,eci: authentication_details.eci,};let authentication =@@ -1297,6 +1296,20 @@ async fn external_authentication_incoming_webhook_flow(.await.change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Error while updating authentication")?;++ authentication_details+ .authentication_value+ .async_map(|auth_val| {+ crate::core::payment_methods::vault::create_tokenize(+ &state,+ auth_val.expose(),+ None,+ updated_authentication.authentication_id.clone(),+ merchant_context.get_merchant_key_store().key.get_inner(),+ )+ })+ .await+ .transpose()?;// Check if it's a payment authentication flow, payment_id would be there only for payment authentication flowsif let Some(payment_id) = updated_authentication.payment_id {let is_pull_mechanism_enabled = helper_utils::check_if_pull_mechanism_for_external_3ds_enabled_from_connector_metadata(merchant_connector_account.metadata.map(|metadata| metadata.expose()));diff --git a/crates/router/src/types/api/authentication.rs b/crates/router/src/types/api/authentication.rsindex a50f4fce8c..5d40eca13a 100644--- a/crates/router/src/types/api/authentication.rs+++ b/crates/router/src/types/api/authentication.rs@@ -58,7 +58,7 @@ impl TryFrom<storage::Authentication> for AuthenticationResponse {#[derive(Clone, serde::Deserialize, Debug, serde::Serialize)]pub struct PostAuthenticationResponse {pub trans_status: String,- pub authentication_value: Option<String>,+ pub authentication_value: Option<masking::Secret<String>>,pub eci: Option<String>,}diff --git a/crates/router/src/types/domain.rs b/crates/router/src/types/domain.rsindex 5ae0036b64..21ddf6079c 100644--- a/crates/router/src/types/domain.rs+++ b/crates/router/src/types/domain.rs@@ -47,6 +47,10 @@ pub mod payment_method_data {pub use hyperswitch_domain_models::payment_method_data::*;}+pub mod authentication {+ pub use hyperswitch_domain_models::router_request_types::authentication::*;+}+#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]pub mod vault {pub use hyperswitch_domain_models::vault::*;diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rsindex 760c30359d..98a47b4a1d 100644--- a/crates/router/src/types/transformers.rs+++ b/crates/router/src/types/transformers.rs@@ -980,8 +980,15 @@ impl ForeignFrom<storage::Authorization> for payments::IncrementalAuthorizationR}}-impl ForeignFrom<&storage::Authentication> for payments::ExternalAuthenticationDetailsResponse {- fn foreign_from(authn_data: &storage::Authentication) -> Self {+impl+ ForeignFrom<+ &hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore,+ > for payments::ExternalAuthenticationDetailsResponse+{+ fn foreign_from(+ authn_store: &hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore,+ ) -> Self {+ let authn_data = &authn_store.authentication;let version = authn_data.maximum_supported_version.as_ref()