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 Nov 6, 2024
1 parent 77e31cb commit 1c1ef4e
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ impl<F: Send + Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsAuthor
.ok();
}
};
let payment_method_id = payment_data.payment_method_info.clone().map(|pm_info| pm_info.payment_method_id);
let payment_method_id = payment_data
.payment_method_info
.clone()
.map(|pm_info| pm_info.payment_method_id);
let connector_mandate_reference_id = payment_data
.payment_attempt
.connector_mandate_detail
Expand Down
236 changes: 118 additions & 118 deletions crates/router/src/core/payments/tokenization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,133 +179,133 @@ where
let pm_id = if customer_acceptance.is_some() {
if !matches!(
&save_payment_method_data.request.get_payment_method_data(),
domain::PaymentMethodData::NetworkToken(_))
{
let payment_method_create_request =
payment_methods::get_payment_method_create_request(
Some(&save_payment_method_data.request.get_payment_method_data()),
Some(save_payment_method_data.payment_method),
payment_method_type,
&customer_id.clone(),
billing_name,
payment_method_billing_address,
)
.await?;
let customer_id = customer_id.to_owned().get_required_value("customer_id")?;
let merchant_id = merchant_account.get_id();
let is_network_tokenization_enabled =
business_profile.is_network_tokenization_enabled;
let (
(mut resp, duplication_check, network_token_requestor_ref_id),
network_token_resp,
) = if !state.conf.locker.locker_enabled {
let (res, dc) = skip_saving_card_in_locker(
merchant_account,
payment_method_create_request.to_owned(),
)
.await?;
((res, dc, None), None)
} else {
pm_status = Some(common_enums::PaymentMethodStatus::from(
save_payment_method_data.attempt_status,
));
let (res, dc) = Box::pin(save_in_locker(
state,
merchant_account,
payment_method_create_request.to_owned(),
))
.await?;

if is_network_tokenization_enabled {
let pm_data =
&save_payment_method_data.request.get_payment_method_data();
match pm_data {
domain::PaymentMethodData::Card(card) => {
let (
network_token_resp,
_network_token_duplication_check, //the duplication check is discarded, since each card has only one token, handling card duplication check will be suffice
network_token_requestor_ref_id,
) = Box::pin(save_network_token_in_locker(
state,
merchant_account,
card,
payment_method_create_request.clone(),
))
.await?;
domain::PaymentMethodData::NetworkToken(_)
) {
let payment_method_create_request =
payment_methods::get_payment_method_create_request(
Some(&save_payment_method_data.request.get_payment_method_data()),
Some(save_payment_method_data.payment_method),
payment_method_type,
&customer_id.clone(),
billing_name,
payment_method_billing_address,
)
.await?;
let customer_id = customer_id.to_owned().get_required_value("customer_id")?;
let merchant_id = merchant_account.get_id();
let is_network_tokenization_enabled =
business_profile.is_network_tokenization_enabled;
let (
(mut resp, duplication_check, network_token_requestor_ref_id),
network_token_resp,
) = if !state.conf.locker.locker_enabled {
let (res, dc) = skip_saving_card_in_locker(
merchant_account,
payment_method_create_request.to_owned(),
)
.await?;
((res, dc, None), None)
} else {
pm_status = Some(common_enums::PaymentMethodStatus::from(
save_payment_method_data.attempt_status,
));
let (res, dc) = Box::pin(save_in_locker(
state,
merchant_account,
payment_method_create_request.to_owned(),
))
.await?;

if is_network_tokenization_enabled {
let pm_data =
&save_payment_method_data.request.get_payment_method_data();
match pm_data {
domain::PaymentMethodData::Card(card) => {
let (
network_token_resp,
_network_token_duplication_check, //the duplication check is discarded, since each card has only one token, handling card duplication check will be suffice
network_token_requestor_ref_id,
) = Box::pin(save_network_token_in_locker(
state,
merchant_account,
card,
payment_method_create_request.clone(),
))
.await?;

(
(res, dc, network_token_requestor_ref_id),
network_token_resp,
)
}
_ => ((res, dc, None), None), //network_token_resp is None in case of other payment methods
(
(res, dc, network_token_requestor_ref_id),
network_token_resp,
)
}
} else {
((res, dc, None), None)
_ => ((res, dc, None), None), //network_token_resp is None in case of other payment methods
}
};
let network_token_locker_id = match network_token_resp {
Some(ref token_resp) => {
if network_token_requestor_ref_id.is_some() {
Some(token_resp.payment_method_id.clone())
} else {
None
}
} else {
((res, dc, None), None)
}
};
let network_token_locker_id = match network_token_resp {
Some(ref token_resp) => {
if network_token_requestor_ref_id.is_some() {
Some(token_resp.payment_method_id.clone())
} else {
None
}
None => None,
};

let pm_card_details = resp.card.as_ref().map(|card| {
PaymentMethodsData::Card(CardDetailsPaymentMethod::from(card.clone()))
});
let key_manager_state = state.into();
let pm_data_encrypted: Option<Encryptable<Secret<serde_json::Value>>> =
pm_card_details
}
None => None,
};

let pm_card_details = resp.card.as_ref().map(|card| {
PaymentMethodsData::Card(CardDetailsPaymentMethod::from(card.clone()))
});
let key_manager_state = state.into();
let pm_data_encrypted: Option<Encryptable<Secret<serde_json::Value>>> =
pm_card_details
.async_map(|pm_card| {
create_encrypted_data(&key_manager_state, key_store, pm_card)
})
.await
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Unable to encrypt payment method data")?;

let pm_network_token_data_encrypted: Option<
Encryptable<Secret<serde_json::Value>>,
> = match network_token_resp {
Some(token_resp) => {
let pm_token_details = token_resp.card.as_ref().map(|card| {
PaymentMethodsData::Card(CardDetailsPaymentMethod::from(
card.clone(),
))
});

pm_token_details
.async_map(|pm_card| {
create_encrypted_data(&key_manager_state, key_store, pm_card)
})
.await
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Unable to encrypt payment method data")?;

let pm_network_token_data_encrypted: Option<
Encryptable<Secret<serde_json::Value>>,
> = match network_token_resp {
Some(token_resp) => {
let pm_token_details = token_resp.card.as_ref().map(|card| {
PaymentMethodsData::Card(CardDetailsPaymentMethod::from(
card.clone(),
))
});

pm_token_details
.async_map(|pm_card| {
create_encrypted_data(&key_manager_state, key_store, pm_card)
})
.await
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Unable to encrypt payment method data")?
}
None => None,
};

let encrypted_payment_method_billing_address: Option<
Encryptable<Secret<serde_json::Value>>,
> = payment_method_billing_address
.async_map(|address| {
create_encrypted_data(&key_manager_state, key_store, address.clone())
})
.await
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Unable to encrypt payment method billing address")?;

let mut payment_method_id = resp.payment_method_id.clone();
let mut locker_id = None;
.attach_printable("Unable to encrypt payment method data")?
}
None => None,
};

match duplication_check {
let encrypted_payment_method_billing_address: Option<
Encryptable<Secret<serde_json::Value>>,
> = payment_method_billing_address
.async_map(|address| {
create_encrypted_data(&key_manager_state, key_store, address.clone())
})
.await
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Unable to encrypt payment method billing address")?;

let mut payment_method_id = resp.payment_method_id.clone();
let mut locker_id = None;

match duplication_check {
Some(duplication_check) => match duplication_check {
payment_methods::transformers::DataDuplicationCheck::Duplicated => {
let payment_method = {
Expand Down Expand Up @@ -695,8 +695,8 @@ where
}
}

Some(resp.payment_method_id)
} else {
Some(resp.payment_method_id)
} else {
//saving the network token which means pm is already saved with us
//just fetch existing pm and update last used and meta data
let payment_method = {
Expand Down

0 comments on commit 1c1ef4e

Please sign in to comment.