Skip to content

Commit

Permalink
chore: run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperswitch-bot[bot] committed Dec 25, 2024
1 parent dcc8625 commit 1875613
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 60 deletions.
14 changes: 9 additions & 5 deletions crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
)
}
_ => (),
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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(),
),
)
}
_ => (),
Expand Down Expand Up @@ -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)]
Expand Down
152 changes: 97 additions & 55 deletions crates/router/src/core/payments/tokenization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 {
Expand All @@ -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 (
Expand All @@ -334,7 +377,7 @@ where
payment_method_create_request.clone(),
))
.await?;

(
(res, dc, network_token_requestor_ref_id),
network_token_resp,
Expand All @@ -345,7 +388,6 @@ where
} else {
((res, dc, None), None)
}

}
};
let network_token_locker_id = match network_token_resp {
Expand Down

0 comments on commit 1875613

Please sign in to comment.