feat(router): migrate payment_method_data to rust locker only if payment_method is card (#2929)

This commit is contained in:
Shankar Singh C
2023-11-21 22:38:40 +05:30
committed by GitHub
parent fcd206b6af
commit f8261a96e7
2 changed files with 51 additions and 25 deletions

View File

@ -1,6 +1,6 @@
use api_models::{enums as api_enums, locker_migration::MigrateCardResponse}; use api_models::{enums as api_enums, locker_migration::MigrateCardResponse};
use common_utils::errors::CustomResult; use common_utils::errors::CustomResult;
use diesel_models::PaymentMethod; use diesel_models::{enums as storage_enums, PaymentMethod};
use error_stack::{FutureExt, ResultExt}; use error_stack::{FutureExt, ResultExt};
use futures::TryFutureExt; use futures::TryFutureExt;
@ -79,10 +79,21 @@ pub async fn call_to_locker(
) -> CustomResult<usize, errors::ApiErrorResponse> { ) -> CustomResult<usize, errors::ApiErrorResponse> {
let mut cards_moved = 0; let mut cards_moved = 0;
for pm in payment_methods { for pm in payment_methods
.into_iter()
.filter(|pm| matches!(pm.payment_method, storage_enums::PaymentMethod::Card))
{
let card = let card =
cards::get_card_from_locker(state, customer_id, merchant_id, &pm.payment_method_id) cards::get_card_from_locker(state, customer_id, merchant_id, &pm.payment_method_id)
.await?; .await;
let card = match card {
Ok(card) => card,
Err(err) => {
logger::error!("Failed to fetch card from Basilisk HS locker : {:?}", err);
continue;
}
};
let card_details = api::CardDetail { let card_details = api::CardDetail {
card_number: card.card_number, card_number: card.card_number,
@ -103,28 +114,36 @@ pub async fn call_to_locker(
card_network: card.card_brand, card_network: card.card_brand,
}; };
let (_add_card_rs_resp, _is_duplicate) = cards::add_card_hs( let add_card_result = cards::add_card_hs(
state, state,
pm_create, pm_create,
&card_details, &card_details,
customer_id.to_string(), customer_id.to_string(),
merchant_account, merchant_account,
api_enums::LockerChoice::Tartarus, api_enums::LockerChoice::Tartarus,
Some(&pm.payment_method_id), Some(&pm.payment_method_id),
) )
.await .await
.change_context(errors::ApiErrorResponse::InternalServerError) .change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable(format!( .attach_printable(format!(
"Card migration failed for merchant_id: {merchant_id}, customer_id: {customer_id}, payment_method_id: {} ", "Card migration failed for merchant_id: {merchant_id}, customer_id: {customer_id}, payment_method_id: {} ",
pm.payment_method_id pm.payment_method_id
))?; ));
let (_add_card_rs_resp, _is_duplicate) = match add_card_result {
Ok(output) => output,
Err(err) => {
logger::error!("Failed to add card to Rust locker : {:?}", err);
continue;
}
};
cards_moved += 1; cards_moved += 1;
logger::info!( logger::info!(
"Card migrated for merchant_id: {merchant_id}, customer_id: {customer_id}, payment_method_id: {} ", "Card migrated for merchant_id: {merchant_id}, customer_id: {customer_id}, payment_method_id: {} ",
pm.payment_method_id pm.payment_method_id
); );
} }
Ok(cards_moved) Ok(cards_moved)

View File

@ -254,11 +254,18 @@ pub async fn add_card_to_locker(
&metrics::CARD_ADD_TIME, &metrics::CARD_ADD_TIME,
&[], &[],
) )
.await?; .await;
logger::debug!("card added to rust locker"); match add_card_to_rs_resp {
value @ Ok(_) => {
Ok(add_card_to_rs_resp) logger::debug!("Card added successfully");
value
}
Err(err) => {
logger::debug!(error =? err,"failed to add card");
Ok(add_card_to_hs_resp)
}
}
} }
pub async fn get_card_from_locker( pub async fn get_card_from_locker(