From 9ac6dfab1133161c2f179f6d9da70e6d5fe88ba1 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 06:07:03 +0000 Subject: [PATCH] chore: run formatter --- crates/diesel_models/src/business_profile.rs | 3 +- .../payment_methods/network_tokenization.rs | 2 +- crates/router/src/core/payments.rs | 135 +++++++++++------- .../payments/operations/payment_approve.rs | 2 +- .../payments/operations/payment_cancel.rs | 2 +- .../payments/operations/payment_capture.rs | 2 +- .../operations/payment_post_session_tokens.rs | 2 +- .../payments/operations/payment_status.rs | 2 +- .../payments/operations/payment_update.rs | 2 +- .../payments_incremental_authorization.rs | 2 +- .../payments/operations/tax_calculation.rs | 2 +- .../router/src/core/payments/tokenization.rs | 39 ++--- .../router/src/core/payments/transformers.rs | 3 +- 13 files changed, 116 insertions(+), 82 deletions(-) diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs index 7128c4751c70..f6cbc0d34883 100644 --- a/crates/diesel_models/src/business_profile.rs +++ b/crates/diesel_models/src/business_profile.rs @@ -254,7 +254,8 @@ impl ProfileUpdateInternal { .unwrap_or(source.is_click_to_pay_enabled), authentication_product_ids: authentication_product_ids .or(source.authentication_product_ids), - is_tokenize_before_payment_enabled: is_tokenize_before_payment_enabled.unwrap_or(source.is_tokenize_before_payment_enabled), + is_tokenize_before_payment_enabled: is_tokenize_before_payment_enabled + .unwrap_or(source.is_tokenize_before_payment_enabled), } } } diff --git a/crates/router/src/core/payment_methods/network_tokenization.rs b/crates/router/src/core/payment_methods/network_tokenization.rs index 4b5652a13b84..d7af946c9caa 100644 --- a/crates/router/src/core/payment_methods/network_tokenization.rs +++ b/crates/router/src/core/payment_methods/network_tokenization.rs @@ -60,7 +60,7 @@ pub struct CardNetworkTokenResponse { pub struct CardNetworkTokenResponsePayload { pub card_brand: api_enums::CardNetwork, pub card_fingerprint: Option>, - pub card_reference: String,// + pub card_reference: String, // pub correlation_id: String, pub customer_id: String, pub par: String, diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs index af428598f00d..bbb4043cd79e 100644 --- a/crates/router/src/core/payments.rs +++ b/crates/router/src/core/payments.rs @@ -435,10 +435,15 @@ where } _ => (), }; - let customer_acceptance = payment_data.get_payment_attempt().customer_acceptance.clone(); + let customer_acceptance = payment_data + .get_payment_attempt() + .customer_acceptance + .clone(); let customer_id = payment_data.get_payment_intent().customer_id.clone(); let payment_method_data = payment_data.get_payment_method_data(); - let is_pre_tokenization_enabled = business_profile.is_network_tokenization_enabled && business_profile.is_tokenize_before_payment_enabled && customer_acceptance.is_some(); + let is_pre_tokenization_enabled = business_profile.is_network_tokenization_enabled + && business_profile.is_tokenize_before_payment_enabled + && customer_acceptance.is_some(); payment_data = match connector_details { ConnectorCallType::PreDetermined(connector) => { #[cfg(all(feature = "dynamic_routing", feature = "v1"))] @@ -464,8 +469,10 @@ where .network_transaction_id_supported_connectors .connector_list; //filered connectors list with ntid_supported_connectors - let filtered_ntid_supported_connectors = - filter_ntid_supported_connectors([connector.clone()].to_vec(), ntid_supported_connectors); + let filtered_ntid_supported_connectors = filter_ntid_supported_connectors( + [connector.clone()].to_vec(), + ntid_supported_connectors, + ); //fetch connectors that support network tokenization flow let network_tokenization_supported_connectors = &state @@ -473,23 +480,32 @@ where .network_tokenization_supported_connectors .connector_list; //filered connectors list with ntid_supported_connectors and network_tokenization_supported_connectors - let filtered_nt_supported_connectors = filter_network_tokenization_supported_connectors( - filtered_ntid_supported_connectors, - network_tokenization_supported_connectors, - ); + let filtered_nt_supported_connectors = + filter_network_tokenization_supported_connectors( + filtered_ntid_supported_connectors, + network_tokenization_supported_connectors, + ); - let is_nt_supported_connector_available = filtered_nt_supported_connectors.first().is_some(); + let is_nt_supported_connector_available = + filtered_nt_supported_connectors.first().is_some(); if is_pre_tokenization_enabled && is_nt_supported_connector_available { - let pre_tokenization_response = tokenization::pre_payment_tokenization(state,customer_id, payment_method_data).await?; + let pre_tokenization_response = tokenization::pre_payment_tokenization( + state, + customer_id, + payment_method_data, + ) + .await?; let pm_data = payment_data.get_payment_method_data(); match pre_tokenization_response { - (Some(token_response),Some(_token_ref)) => { + (Some(token_response), Some(_token_ref)) => { let token_data = domain::NetworkTokenData { token_number: token_response.authentication_details.token, token_exp_month: token_response.token_details.exp_month, token_exp_year: token_response.token_details.exp_year, - token_cryptogram: Some(token_response.authentication_details.cryptogram), + token_cryptogram: Some( + token_response.authentication_details.cryptogram, + ), card_issuer: None, card_network: None, card_type: None, @@ -504,21 +520,23 @@ where card_data: card_data.clone(), network_token_data: token_data.clone(), }; - payment_data.set_vault_operation(PaymentMethodDataAction::VaultData(vault_data.clone())) - }, - _ => () - } - payment_data.set_payment_method_data(Some(domain::PaymentMethodData::NetworkToken(token_data))); - - } - _ => { - match pm_data { - Some(domain::PaymentMethodData::Card(card_data)) => { - payment_data.set_vault_operation(PaymentMethodDataAction::SaveCardData(card_data.clone())) - }, - _ => () + payment_data.set_vault_operation( + PaymentMethodDataAction::VaultData(vault_data.clone()), + ) + } + _ => (), } + payment_data.set_payment_method_data(Some( + domain::PaymentMethodData::NetworkToken(token_data), + )); } + _ => match pm_data { + Some(domain::PaymentMethodData::Card(card_data)) => payment_data + .set_vault_operation(PaymentMethodDataAction::SaveCardData( + card_data.clone(), + )), + _ => (), + }, } } let (router_data, mca) = call_connector_service( @@ -605,14 +623,16 @@ where convert_connector_data_to_routable_connectors(&connectors) .map_err(|e| logger::error!(routable_connector_error=?e)) .unwrap_or_default(); - + let ntid_supported_connectors = &state .conf .network_transaction_id_supported_connectors .connector_list; //filered connectors list with ntid_supported_connectors - let filtered_ntid_supported_connectors = - filter_ntid_supported_connectors(connectors.clone(), ntid_supported_connectors); + let filtered_ntid_supported_connectors = filter_ntid_supported_connectors( + connectors.clone(), + ntid_supported_connectors, + ); //fetch connectors that support network tokenization flow let network_tokenization_supported_connectors = &state @@ -620,26 +640,35 @@ where .network_tokenization_supported_connectors .connector_list; //filered connectors list with ntid_supported_connectors and network_tokenization_supported_connectors - let filtered_nt_supported_connectors = filter_network_tokenization_supported_connectors( - filtered_ntid_supported_connectors, - network_tokenization_supported_connectors, - ); - let is_nt_supported_connector_available = filtered_nt_supported_connectors.first().is_some(); + let filtered_nt_supported_connectors = + filter_network_tokenization_supported_connectors( + filtered_ntid_supported_connectors, + network_tokenization_supported_connectors, + ); + let is_nt_supported_connector_available = + filtered_nt_supported_connectors.first().is_some(); let mut connectors = connectors.into_iter(); let connector_data = get_connector_data(&mut connectors)?; if is_pre_tokenization_enabled && is_nt_supported_connector_available { - let pre_tokenization_response = tokenization::pre_payment_tokenization(state,customer_id, payment_method_data).await?; + let pre_tokenization_response = tokenization::pre_payment_tokenization( + state, + customer_id, + payment_method_data, + ) + .await?; let pm_data = payment_data.get_payment_method_data(); match pre_tokenization_response { - (Some(token_response),Some(_token_ref)) => { + (Some(token_response), Some(_token_ref)) => { let token_data = domain::NetworkTokenData { token_number: token_response.authentication_details.token, token_exp_month: token_response.token_details.exp_month, token_exp_year: token_response.token_details.exp_year, - token_cryptogram: Some(token_response.authentication_details.cryptogram), + token_cryptogram: Some( + token_response.authentication_details.cryptogram, + ), card_issuer: None, card_network: None, card_type: None, @@ -654,22 +683,24 @@ where card_data: card_data.clone(), network_token_data: token_data.clone(), }; - payment_data.set_vault_operation(PaymentMethodDataAction::VaultData(vault_data.clone())) - }, - _ => () + payment_data.set_vault_operation( + PaymentMethodDataAction::VaultData(vault_data.clone()), + ) + } + _ => (), } - payment_data.set_payment_method_data(Some(domain::PaymentMethodData::NetworkToken(token_data))); - + payment_data.set_payment_method_data(Some( + domain::PaymentMethodData::NetworkToken(token_data), + )); } - _ => { - match pm_data { - Some(domain::PaymentMethodData::Card(card_data)) => { - payment_data.set_vault_operation(PaymentMethodDataAction::SaveCardData(card_data.clone())) - }, - _ => () - } - } - } + _ => match pm_data { + Some(domain::PaymentMethodData::Card(card_data)) => payment_data + .set_vault_operation(PaymentMethodDataAction::SaveCardData( + card_data.clone(), + )), + _ => (), + }, + } } let schedule_time = if should_add_task_to_process_tracker { @@ -4531,10 +4562,10 @@ where } #[derive(Clone, serde::Serialize, Debug)] -pub enum PaymentMethodDataAction{ +pub enum PaymentMethodDataAction { SaveCardData(hyperswitch_domain_models::payment_method_data::Card), SaveNetworkTokenData(hyperswitch_domain_models::payment_method_data::NetworkTokenData), - VaultData(VaultData) + VaultData(VaultData), } #[derive(Clone, serde::Serialize, Debug)] diff --git a/crates/router/src/core/payments/operations/payment_approve.rs b/crates/router/src/core/payments/operations/payment_approve.rs index ef1aca0894ed..82da4cead21b 100644 --- a/crates/router/src/core/payments/operations/payment_approve.rs +++ b/crates/router/src/core/payments/operations/payment_approve.rs @@ -195,7 +195,7 @@ impl GetTracker, api::PaymentsCaptureR tax_data: None, session_id: None, service_details: None, - vault_operation:None + vault_operation: None, }; let get_trackers_response = operations::GetTrackerResponse { diff --git a/crates/router/src/core/payments/operations/payment_cancel.rs b/crates/router/src/core/payments/operations/payment_cancel.rs index 40527e66aa5b..2fa132ae9430 100644 --- a/crates/router/src/core/payments/operations/payment_cancel.rs +++ b/crates/router/src/core/payments/operations/payment_cancel.rs @@ -206,7 +206,7 @@ impl GetTracker, api::PaymentsCancelRe tax_data: None, session_id: None, service_details: None, - vault_operation:None, + vault_operation: None, }; let get_trackers_response = operations::GetTrackerResponse { diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rs index 631069b1f854..767325f225ae 100644 --- a/crates/router/src/core/payments/operations/payment_capture.rs +++ b/crates/router/src/core/payments/operations/payment_capture.rs @@ -255,7 +255,7 @@ impl GetTracker, api::Paymen tax_data: None, session_id: None, service_details: None, - vault_operation: None, + vault_operation: None, }; let get_trackers_response = operations::GetTrackerResponse { diff --git a/crates/router/src/core/payments/operations/payment_post_session_tokens.rs b/crates/router/src/core/payments/operations/payment_post_session_tokens.rs index 8f5f61a39ac3..d7be71213ebc 100644 --- a/crates/router/src/core/payments/operations/payment_post_session_tokens.rs +++ b/crates/router/src/core/payments/operations/payment_post_session_tokens.rs @@ -166,7 +166,7 @@ impl GetTracker, api::PaymentsPostSess tax_data: None, session_id: None, service_details: None, - vault_operation: None, + vault_operation: None, }; let get_trackers_response = operations::GetTrackerResponse { operation: Box::new(self), diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rs index b77360494950..66860f8caf76 100644 --- a/crates/router/src/core/payments/operations/payment_status.rs +++ b/crates/router/src/core/payments/operations/payment_status.rs @@ -522,7 +522,7 @@ async fn get_tracker_for_sync< tax_data: None, session_id: None, service_details: None, - vault_operation:None, + vault_operation: None, }; let get_trackers_response = operations::GetTrackerResponse { diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index 10bab35107b7..fb8482877f39 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -492,7 +492,7 @@ impl GetTracker, api::PaymentsRequest> tax_data: None, session_id: None, service_details: None, - vault_operation: None, + vault_operation: None, }; let get_trackers_response = operations::GetTrackerResponse { diff --git a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs index 2c952f0de212..36fab81e7511 100644 --- a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs +++ b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs @@ -172,7 +172,7 @@ impl tax_data: None, session_id: None, service_details: None, - vault_operation: None, + vault_operation: None, }; let get_trackers_response = operations::GetTrackerResponse { diff --git a/crates/router/src/core/payments/operations/tax_calculation.rs b/crates/router/src/core/payments/operations/tax_calculation.rs index 1d78f771feb7..3f1293c89b20 100644 --- a/crates/router/src/core/payments/operations/tax_calculation.rs +++ b/crates/router/src/core/payments/operations/tax_calculation.rs @@ -180,7 +180,7 @@ impl tax_data: Some(tax_data), session_id: request.session_id.clone(), service_details: None, - vault_operation: None, + vault_operation: None, }; let get_trackers_response = operations::GetTrackerResponse { operation: Box::new(self), diff --git a/crates/router/src/core/payments/tokenization.rs b/crates/router/src/core/payments/tokenization.rs index 478a216a0dd2..0b7d99ffacda 100644 --- a/crates/router/src/core/payments/tokenization.rs +++ b/crates/router/src/core/payments/tokenization.rs @@ -12,8 +12,9 @@ use common_enums::{ConnectorMandateStatus, PaymentMethod}; use common_utils::{ crypto::Encryptable, ext_traits::{AsyncExt, Encode, ValueExt}, - id_type, pii, + id_type, metrics::utils::record_operation_time, + pii, }; use error_stack::{report, ResultExt}; use masking::{ExposeInterface, Secret}; @@ -775,19 +776,18 @@ where todo!() } -pub async fn pre_payment_tokenization ( +pub async fn pre_payment_tokenization( state: &SessionState, customer_id: Option, payment_method_data: Option<&domain::PaymentMethodData>, -) -> RouterResult<(Option, Option)> -{ +) -> RouterResult<(Option, Option)> { let customer_id = customer_id.to_owned().get_required_value("customer_id")?; match payment_method_data { Some(domain::PaymentMethodData::Card(card)) => { let network_tokenization_supported_card_networks = &state - .conf - .network_tokenization_supported_card_networks - .card_networks; + .conf + .network_tokenization_supported_card_networks + .card_networks; if card .card_network @@ -823,7 +823,7 @@ pub async fn pre_payment_tokenization ( // //filered connectors list with ntid_supported_connectors // let filtered_ntid_supported_connectors = // filter_ntid_supported_connectors(connectors.clone(), ntid_supported_connectors); - + // //fetch connectors that support network tokenization flow // let network_tokenization_supported_connectors = &state // .conf @@ -836,8 +836,11 @@ pub async fn pre_payment_tokenization ( // ); let network_tokenization_service = &state.conf.network_tokenization_service; - match (network_token_requestor_ref_id.clone(),network_tokenization_service) { - (Some(token_ref),Some(network_tokenization_service))=>{ + match ( + network_token_requestor_ref_id.clone(), + network_tokenization_service, + ) { + (Some(token_ref), Some(network_tokenization_service)) => { let x = record_operation_time( async { network_tokenization::get_network_token( @@ -858,17 +861,15 @@ pub async fn pre_payment_tokenization ( ) .await; match x { - Ok(token_response)=> Ok((Some(token_response), network_token_requestor_ref_id.clone())), - _ => Ok((None, None)) + Ok(token_response) => Ok(( + Some(token_response), + network_token_requestor_ref_id.clone(), + )), + _ => Ok((None, None)), } - - }, - _=> - Ok((None, None)) } - - - + _ => Ok((None, None)), + } } Err(err) => { logger::error!("Failed to tokenize card: {:?}", err); diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 0cf32b99468b..199e3b23a84c 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -2803,7 +2803,8 @@ impl TryFrom> for types::PaymentsAuthoriz } else { None }; - let payment_method_data = payment_data.payment_method_data.or_else(|| { // + let payment_method_data = payment_data.payment_method_data.or_else(|| { + // if payment_data.mandate_id.is_some() { Some(domain::PaymentMethodData::MandatePayment) } else {