diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs index bf0a2509ce91..870520e8f35b 100644 --- a/crates/router/src/core/payments.rs +++ b/crates/router/src/core/payments.rs @@ -502,7 +502,9 @@ where network_token_data: token_data.clone(), }; payment_data.set_vault_operation( - PaymentMethodDataAction::SaveCardAndNetworkTokenData(card_and_network_token_data.clone()), + PaymentMethodDataAction::SaveCardAndNetworkTokenData( + card_and_network_token_data.clone(), + ), ) } _ => (), @@ -605,8 +607,8 @@ where .map_err(|e| logger::error!(routable_connector_error=?e)) .unwrap_or_default(); - let filtered_nt_supported_connectors = - get_filtered_nt_supported_connectors(&state, connectors.clone()); + let filtered_nt_supported_connectors = + get_filtered_nt_supported_connectors(&state, connectors.clone()); let is_nt_supported_connector_available = filtered_nt_supported_connectors.first().is_some(); @@ -646,7 +648,9 @@ where network_token_data: token_data.clone(), }; payment_data.set_vault_operation( - PaymentMethodDataAction::SaveCardAndNetworkTokenData(card_and_network_token_data.clone()), + PaymentMethodDataAction::SaveCardAndNetworkTokenData( + card_and_network_token_data.clone(), + ), ) } _ => (), @@ -4526,7 +4530,7 @@ where #[derive(Clone, serde::Serialize, Debug)] pub enum PaymentMethodDataAction { SaveCardData(hyperswitch_domain_models::payment_method_data::Card), - SaveCardAndNetworkTokenData(CardAndNetworkTokenData) + SaveCardAndNetworkTokenData(CardAndNetworkTokenData), } #[derive(Default, Clone, serde::Serialize, Debug)] diff --git a/crates/router/src/core/payments/tokenization.rs b/crates/router/src/core/payments/tokenization.rs index 2f70ea33502e..d606fed2f675 100644 --- a/crates/router/src/core/payments/tokenization.rs +++ b/crates/router/src/core/payments/tokenization.rs @@ -212,11 +212,19 @@ where pm_status = Some(payment_method_status); if let Some(payment_method_data_action) = vault_operation { - let network_token_requestor_reference_id = payment_method_info.and_then(|pm_info| pm_info.network_token_requestor_reference_id.clone()); + let network_token_requestor_reference_id = + payment_method_info.and_then(|pm_info| { + pm_info.network_token_requestor_reference_id.clone() + }); match payment_method_data_action { - payments::PaymentMethodDataAction::SaveCardData(card)=>{ - if payment_method_status == common_enums::PaymentMethodStatus::Inactive { - if let (Some(nt_ref_id), Some(tokenization_service)) = (network_token_requestor_reference_id.clone(), &state.conf.network_tokenization_service) { + payments::PaymentMethodDataAction::SaveCardData(card) => { + if payment_method_status + == common_enums::PaymentMethodStatus::Inactive + { + if let (Some(nt_ref_id), Some(tokenization_service)) = ( + network_token_requestor_reference_id.clone(), + &state.conf.network_tokenization_service, + ) { let _ = record_operation_time( async { network_tokenization::delete_network_token_from_tokenization_service( @@ -244,71 +252,105 @@ where card_issuer: None, card_type: None, }; - let (res, dc) = Box::pin(payment_methods::cards::add_card_to_locker( - state, - payment_method_create_request.to_owned(), - &card_data, - &customer_id, - merchant_account, - None, - )) - .await - .change_context(errors::ApiErrorResponse::InternalServerError) - .attach_printable("Add Card In Locker Failed")?; + let (res, dc) = + Box::pin(payment_methods::cards::add_card_to_locker( + state, + payment_method_create_request.to_owned(), + &card_data, + &customer_id, + merchant_account, + None, + )) + .await + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Add Card In Locker Failed")?; - ((res,dc,None),None) + ((res, dc, None), None) } - payments::PaymentMethodDataAction::SaveCardAndNetworkTokenData(save_card_and_network_token_data)=>{ + payments::PaymentMethodDataAction::SaveCardAndNetworkTokenData( + save_card_and_network_token_data, + ) => { let card_data = api::CardDetail { - card_number: save_card_and_network_token_data.card_data.card_number.clone(), - card_exp_month: save_card_and_network_token_data.card_data.card_exp_month.clone(), - card_exp_year: save_card_and_network_token_data.card_data.card_exp_year.clone(), + card_number: save_card_and_network_token_data + .card_data + .card_number + .clone(), + card_exp_month: save_card_and_network_token_data + .card_data + .card_exp_month + .clone(), + card_exp_year: save_card_and_network_token_data + .card_data + .card_exp_year + .clone(), card_holder_name: None, nick_name: None, card_issuing_country: None, - card_network: save_card_and_network_token_data.card_data.card_network.clone(), + card_network: save_card_and_network_token_data + .card_data + .card_network + .clone(), card_issuer: None, card_type: None, }; - let (res, dc) = Box::pin(payment_methods::cards::add_card_to_locker( - state, - payment_method_create_request.to_owned(), - &card_data, - &customer_id, - merchant_account, - None, - )) - .await - .change_context(errors::ApiErrorResponse::InternalServerError) - .attach_printable("Add Card In Locker Failed")?; + let (res, dc) = + Box::pin(payment_methods::cards::add_card_to_locker( + state, + payment_method_create_request.to_owned(), + &card_data, + &customer_id, + merchant_account, + None, + )) + .await + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Add Card In Locker Failed")?; let network_token_data = api::CardDetail { - card_number: save_card_and_network_token_data.network_token_data.token_number.clone(), - card_exp_month: save_card_and_network_token_data.network_token_data.token_exp_month.clone(), - card_exp_year: save_card_and_network_token_data.network_token_data.token_exp_year.clone(), + card_number: save_card_and_network_token_data + .network_token_data + .token_number + .clone(), + card_exp_month: save_card_and_network_token_data + .network_token_data + .token_exp_month + .clone(), + card_exp_year: save_card_and_network_token_data + .network_token_data + .token_exp_year + .clone(), card_holder_name: None, nick_name: None, card_issuing_country: None, - card_network: save_card_and_network_token_data.network_token_data.card_network.clone(), + card_network: save_card_and_network_token_data + .network_token_data + .card_network + .clone(), card_issuer: None, card_type: None, }; - let card_reference = network_token_requestor_reference_id.as_ref().map(|x| x.as_str()); - - let (network_token_resp, _dc) = Box::pin(payment_methods::cards::add_card_to_locker( - state, - payment_method_create_request.to_owned(), - &network_token_data, - &customer_id, - merchant_account, - card_reference, - )) - .await - .change_context(errors::ApiErrorResponse::InternalServerError) - .attach_printable("Add Network Token In Locker Failed")?; - - ((res, dc, network_token_requestor_reference_id), Some(network_token_resp)) + let card_reference = network_token_requestor_reference_id + .as_ref() + .map(|x| x.as_str()); + + let (network_token_resp, _dc) = + Box::pin(payment_methods::cards::add_card_to_locker( + state, + payment_method_create_request.to_owned(), + &network_token_data, + &customer_id, + merchant_account, + card_reference, + )) + .await + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Add Network Token In Locker Failed")?; + + ( + (res, dc, network_token_requestor_reference_id), + Some(network_token_resp), + ) } } } else { @@ -318,9 +360,10 @@ where payment_method_create_request.to_owned(), )) .await?; - + if is_network_tokenization_enabled { - let pm_data = &save_payment_method_data.request.get_payment_method_data(); + let pm_data = + &save_payment_method_data.request.get_payment_method_data(); match pm_data { domain::PaymentMethodData::Card(card) => { let ( @@ -334,7 +377,7 @@ where payment_method_create_request.clone(), )) .await?; - + ( (res, dc, network_token_requestor_ref_id), network_token_resp, @@ -345,7 +388,6 @@ where } else { ((res, dc, None), None) } - } }; let network_token_locker_id = match network_token_resp {