From 68b3310993c5196f9f9038f27c5cd7dad82b24d1 Mon Sep 17 00:00:00 2001 From: Chethan Rao <70657455+Chethan-rao@users.noreply.github.com> Date: Wed, 27 Sep 2023 18:21:34 +0530 Subject: [PATCH] refactor: insert requires cvv config to configs table if not found in db (#2208) --- .../router/src/core/payment_methods/cards.rs | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 7cc4eacbe355..c22b7323095b 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -1825,23 +1825,15 @@ pub async fn list_customer_payment_method( let key = key_store.key.get_inner().peek(); let is_requires_cvv = db - .find_config_by_key(format!("{}_requires_cvv", merchant_account.merchant_id).as_str()) - .await; + .find_config_by_key_unwrap_or( + format!("{}_requires_cvv", merchant_account.merchant_id).as_str(), + Some("true".to_string()), + ) + .await + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Failed to fetch merchant_id config for requires_cvv")?; - let requires_cvv = match is_requires_cvv { - // If an entry is found with the config value as `false`, we set requires_cvv to false - Ok(value) => value.config != "false", - Err(err) => { - if err.current_context().is_db_not_found() { - // By default, cvv is made required field for all merchants - true - } else { - Err(err - .change_context(errors::ApiErrorResponse::InternalServerError) - .attach_printable("Failed to fetch merchant_id config for requires_cvv"))? - } - } - }; + let requires_cvv = is_requires_cvv.config != "false"; let resp = db .find_payment_method_by_customer_id_merchant_id_list(