Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(payment_methods): Remove legacy locker code as it is not been used (#1666)
Shankar Singh C8832dd60b98e
diff --git a/config/config.example.toml b/config/config.example.tomlindex 11dd3f43f1..61422f41e2 100644--- a/config/config.example.toml+++ b/config/config.example.toml@@ -109,7 +109,6 @@ kms_encrypted_jwt_secret = "" # Base64-encoded (KMS encrypted) ciphertext ofhost = "" # Locker hostmock_locker = true # Emulate a locker locally using Postgresbasilisk_host = "" # Basilisk host-locker_setup = "legacy_locker" # With locker to use while in the deployed environment (eg. legacy_locker, basilisk_locker)locker_signing_key_id = "1" # Key_id to sign basilisk hs locker[delayed_session_response]diff --git a/config/development.toml b/config/development.tomlindex 44d235a8d8..a3aafd6060 100644--- a/config/development.toml+++ b/config/development.toml@@ -38,7 +38,6 @@ master_enc_key = "73ad7bbbbc640c845a150f67d058b279849370cd2c1f3c67c4dd6c869213e1host = ""mock_locker = truebasilisk_host = ""-locker_setup = "legacy_locker"[jwekey]locker_key_identifier1 = ""diff --git a/crates/router/src/configs/defaults.rs b/crates/router/src/configs/defaults.rsindex 2b566d2664..9f1f8d6f55 100644--- a/crates/router/src/configs/defaults.rs+++ b/crates/router/src/configs/defaults.rs@@ -56,7 +56,6 @@ impl Default for super::settings::Locker {host: "localhost".into(),mock_locker: true,basilisk_host: "localhost".into(),- locker_setup: super::settings::LockerSetup::LegacyLocker,locker_signing_key_id: "1".into(),}}diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rsindex 58abd15581..341488dac9 100644--- a/crates/router/src/configs/settings.rs+++ b/crates/router/src/configs/settings.rs@@ -330,18 +330,9 @@ pub struct Locker {pub host: String,pub mock_locker: bool,pub basilisk_host: String,- pub locker_setup: LockerSetup,pub locker_signing_key_id: String,}-#[derive(Debug, Deserialize, Clone, Default)]-#[serde(rename_all = "snake_case")]-pub enum LockerSetup {- #[default]- LegacyLocker,- BasiliskLocker,-}-#[derive(Debug, Deserialize, Clone)]#[serde(default)]pub struct Refund {diff --git a/crates/router/src/core/mandate.rs b/crates/router/src/core/mandate.rsindex 0a11aa9bd4..3e09bf21a3 100644--- a/crates/router/src/core/mandate.rs+++ b/crates/router/src/core/mandate.rs@@ -34,7 +34,7 @@ pub async fn get_mandate(.await.to_not_found_response(errors::ApiErrorResponse::MandateNotFound)?;Ok(services::ApplicationResponse::Json(- mandates::MandateResponse::from_db_mandate(state, mandate, &merchant_account).await?,+ mandates::MandateResponse::from_db_mandate(state, mandate).await?,))}@@ -117,10 +117,7 @@ pub async fn get_customer_mandates(} else {let mut response_vec = Vec::with_capacity(mandates.len());for mandate in mandates {- response_vec.push(- mandates::MandateResponse::from_db_mandate(state, mandate, &merchant_account)- .await?,- );+ response_vec.push(mandates::MandateResponse::from_db_mandate(state, mandate).await?);}Ok(services::ApplicationResponse::Json(response_vec))}@@ -272,9 +269,11 @@ pub async fn retrieve_mandates_list(.await.change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Unable to retrieve mandates")?;- let mandates_list = future::try_join_all(mandates.into_iter().map(|mandate| {- mandates::MandateResponse::from_db_mandate(state, mandate, &merchant_account)- }))+ let mandates_list = future::try_join_all(+ mandates+ .into_iter()+ .map(|mandate| mandates::MandateResponse::from_db_mandate(state, mandate)),+ ).await?;Ok(services::ApplicationResponse::Json(mandates_list))}diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rsindex 36b58a1476..eb1b97aca5 100644--- a/crates/router/src/core/payment_methods/cards.rs+++ b/crates/router/src/core/payment_methods/cards.rs@@ -15,11 +15,11 @@ use api_models::{};use common_utils::{consts,- ext_traits::{AsyncExt, BytesExt, StringExt, ValueExt},+ ext_traits::{AsyncExt, StringExt, ValueExt},generate_id,};use diesel_models::{enums as storage_enums, payment_method};-use error_stack::{report, IntoReport, ResultExt};+use error_stack::{IntoReport, ResultExt};use router_env::{instrument, tracing};#[cfg(feature = "basilisk")]@@ -187,18 +187,12 @@ pub async fn add_card_to_locker(metrics::STORED_TO_LOCKER.add(&metrics::CONTEXT, 1, &[]);request::record_operation_time(async {- match state.conf.locker.locker_setup {- settings::LockerSetup::BasiliskLocker => {- add_card_hs(state, req, card, customer_id, merchant_account).await- }- settings::LockerSetup::LegacyLocker => {- add_card(state, req, card, customer_id, merchant_account).await- }- }- .map_err(|error| {- metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]);- error- })+ add_card_hs(state, req, card, customer_id, merchant_account)+ .await+ .map_err(|error| {+ metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]);+ error+ })},&metrics::CARD_ADD_TIME,)@@ -210,32 +204,19 @@ pub async fn get_card_from_locker(customer_id: &str,merchant_id: &str,card_reference: &str,- locker_id: Option<String>,) -> errors::RouterResult<payment_methods::Card> {metrics::GET_FROM_LOCKER.add(&metrics::CONTEXT, 1, &[]);request::record_operation_time(async {- match state.conf.locker.locker_setup {- settings::LockerSetup::LegacyLocker => {- get_card_from_legacy_locker(- state,- &locker_id.get_required_value("locker_id")?,- card_reference,- )- .await- }- settings::LockerSetup::BasiliskLocker => {- get_card_from_hs_locker(state, customer_id, merchant_id, card_reference)- .await- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Failed while getting card from basilisk_hs")- }- }- .map_err(|error| {- metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]);- error- })+ get_card_from_hs_locker(state, customer_id, merchant_id, card_reference)+ .await+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("Failed while getting card from basilisk_hs")+ .map_err(|error| {+ metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]);+ error+ })},&metrics::CARD_GET_TIME,)@@ -252,19 +233,12 @@ pub async fn delete_card_from_locker(request::record_operation_time(async {- match state.conf.locker.locker_setup {- settings::LockerSetup::LegacyLocker => {- delete_card(state, merchant_id, card_reference).await- }- settings::LockerSetup::BasiliskLocker => {- delete_card_from_hs_locker(state, customer_id, merchant_id, card_reference)- .await- }- }- .map_err(|error| {- metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]);- error- })+ delete_card_from_hs_locker(state, customer_id, merchant_id, card_reference)+ .await+ .map_err(|error| {+ metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]);+ error+ })},&metrics::CARD_DELETE_TIME,)@@ -288,11 +262,15 @@ pub async fn add_card_hs(let db = &*state.store;let merchant_id = &merchant_account.merchant_id;- let request =- payment_methods::mk_add_card_request_hs(jwekey, locker, &card, &customer_id, merchant_id)- .await?;-let stored_card_response = if !locker.mock_locker {+ let request = payment_methods::mk_add_card_request_hs(+ jwekey,+ locker,+ &card,+ &customer_id,+ merchant_id,+ )+ .await?;let response = services::call_connector_api(state, request).await.change_context(errors::VaultError::SaveCardFailed);@@ -331,59 +309,6 @@ pub async fn add_card_hs())}-// Legacy Locker Function-pub async fn add_card(- state: &routes::AppState,- req: api::PaymentMethodCreate,- card: api::CardDetail,- customer_id: String,- merchant_account: &domain::MerchantAccount,-) -> errors::CustomResult<(api::PaymentMethodResponse, bool), errors::VaultError> {- let locker = &state.conf.locker;- let db = &*state.store;- let merchant_id = &merchant_account.merchant_id;- let locker_id = merchant_account- .locker_id- .to_owned()- .get_required_value("locker_id")- .change_context(errors::VaultError::SaveCardFailed)?;-- let request = payment_methods::mk_add_card_request(- locker,- &card,- &customer_id,- &req,- &locker_id,- merchant_id,- )?;-- let response = if !locker.mock_locker {- let response = services::call_connector_api(state, request)- .await- .change_context(errors::VaultError::SaveCardFailed)?;-- let response: payment_methods::AddCardResponse = match response {- Ok(card) => card- .response- .parse_struct("AddCardResponse")- .change_context(errors::VaultError::ResponseDeserializationFailed),- Err(err) => Err(report!(errors::VaultError::UnexpectedResponseError(- err.response- ))),- }?;- response- } else {- let card_id = generate_id(consts::ID_LENGTH, "card");- mock_add_card(db, &card_id, &card, None, None, Some(&customer_id)).await?- };-- let duplicate_check = response.duplicate.unwrap_or(false);-- let payment_method_resp =- payment_methods::mk_add_card_response(card, response, req, merchant_id);- Ok((payment_method_resp, duplicate_check))-}-pub async fn update_payment_method(db: &dyn db::StorageInterface,pm: payment_method::PaymentMethod,@@ -411,17 +336,17 @@ pub async fn get_card_from_hs_locker<'a>(#[cfg(feature = "kms")]let jwekey = &state.kms_secrets;- let request = payment_methods::mk_get_card_request_hs(- jwekey,- locker,- customer_id,- merchant_id,- card_reference,- )- .await- .change_context(errors::VaultError::FetchCardFailed)- .attach_printable("Making get card request failed")?;if !locker.mock_locker {+ let request = payment_methods::mk_get_card_request_hs(+ jwekey,+ locker,+ customer_id,+ merchant_id,+ card_reference,+ )+ .await+ .change_context(errors::VaultError::FetchCardFailed)+ .attach_printable("Making get card request failed")?;let response = services::call_connector_api(state, request).await.change_context(errors::VaultError::FetchCardFailed)@@ -451,35 +376,6 @@ pub async fn get_card_from_hs_locker<'a>(}}-// Legacy Locker Function-#[instrument(skip_all)]-pub async fn get_card_from_legacy_locker<'a>(- state: &'a routes::AppState,- locker_id: &'a str,- card_id: &'a str,-) -> errors::RouterResult<payment_methods::Card> {- let locker = &state.conf.locker;- let request = payment_methods::mk_get_card_request(locker, locker_id, card_id)- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Making get card request failed")?;- let get_card_result = if !locker.mock_locker {- let response = services::call_connector_api(state, request)- .await- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Failed while executing call_connector_api for get_card");-- response.get_response_inner("AddCardResponse")?- } else {- let (get_card_response, _) = mock_get_card(&*state.store, card_id)- .await- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Failed while fetching card from mock_locker")?;- get_card_response- };-- payment_methods::mk_get_card_response(get_card_result)-}-#[instrument(skip_all)]pub async fn delete_card_from_hs_locker<'a>(state: &'a routes::AppState,@@ -526,33 +422,6 @@ pub async fn delete_card_from_hs_locker<'a>(}}-// Legacy Locker Function-#[instrument(skip_all)]-pub async fn delete_card<'a>(- state: &'a routes::AppState,- merchant_id: &'a str,- card_id: &'a str,-) -> errors::RouterResult<payment_methods::DeleteCardResp> {- let locker = &state.conf.locker;- let request = payment_methods::mk_delete_card_request(&state.conf.locker, merchant_id, card_id)- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Making Delete card request Failed")?;-- let card_delete_failure_message = "Failed while deleting card from card_locker";- let delete_card_resp = if !locker.mock_locker {- services::call_connector_api(state, request)- .await- .get_response_inner("DeleteCardResponse")?- } else {- mock_delete_card(&*state.store, card_id)- .await- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable(card_delete_failure_message)?- };-- payment_methods::mk_delete_card_response(delete_card_resp)-}-///Mock api for local testing#[instrument(skip_all)]pub async fn mock_add_card_hs(@@ -595,56 +464,6 @@ pub async fn mock_add_card_hs(})}-// Legacy Locker Function-pub async fn mock_add_card(- db: &dyn db::StorageInterface,- card_id: &str,- card: &api::CardDetail,- card_cvc: Option<String>,- payment_method_id: Option<String>,- customer_id: Option<&str>,-) -> errors::CustomResult<payment_methods::AddCardResponse, errors::VaultError> {- let locker_mock_up = storage::LockerMockUpNew {- card_id: card_id.to_string(),- external_id: uuid::Uuid::new_v4().to_string(),- card_fingerprint: uuid::Uuid::new_v4().to_string(),- card_global_fingerprint: uuid::Uuid::new_v4().to_string(),- merchant_id: "mm01".to_string(),- card_number: card.card_number.peek().to_string(),- card_exp_year: card.card_exp_year.peek().to_string(),- card_exp_month: card.card_exp_month.peek().to_string(),- card_cvc,- payment_method_id,- customer_id: customer_id.map(str::to_string),- name_on_card: card.card_holder_name.to_owned().expose_option(),- nickname: card.nick_name.to_owned().map(masking::Secret::expose),- };- let response = db- .insert_locker_mock_up(locker_mock_up)- .await- .change_context(errors::VaultError::SaveCardFailed)?;- Ok(payment_methods::AddCardResponse {- card_id: response.card_id,- external_id: response.external_id,- card_fingerprint: response.card_fingerprint.into(),- card_global_fingerprint: response.card_global_fingerprint.into(),- merchant_id: Some(response.merchant_id),- card_number: response- .card_number- .try_into()- .into_report()- .change_context(errors::VaultError::ResponseDeserializationFailed)- .attach_printable("Invalid card number format from the mock locker")- .map(Some)?,- card_exp_year: Some(response.card_exp_year.into()),- card_exp_month: Some(response.card_exp_month.into()),- name_on_card: response.name_on_card.map(|c| c.into()),- nickname: response.nickname,- customer_id: response.customer_id,- duplicate: response.duplicate,- })-}-#[instrument(skip_all)]pub async fn mock_get_card<'a>(db: &dyn db::StorageInterface,@@ -1710,11 +1529,7 @@ pub async fn list_customer_payment_method(let parent_payment_method_token = generate_id(consts::ID_LENGTH, "token");let hyperswitch_token = generate_id(consts::ID_LENGTH, "token");let card = if pm.payment_method == enums::PaymentMethod::Card {- let locker_id = merchant_account- .locker_id- .to_owned()- .get_required_value("locker_id")?;- Some(get_lookup_key_from_locker(state, &hyperswitch_token, &pm, &locker_id).await?)+ Some(get_lookup_key_from_locker(state, &hyperswitch_token, &pm).await?)} else {None};@@ -1809,14 +1624,12 @@ pub async fn get_lookup_key_from_locker(state: &routes::AppState,payment_token: &str,pm: &storage::PaymentMethod,- locker_id: &str,) -> errors::RouterResult<api::CardDetailFromLocker> {let card = get_card_from_locker(state,&pm.customer_id,&pm.merchant_id,&pm.payment_method_id,- Some(locker_id.to_string()),).await.change_context(errors::ApiErrorResponse::InternalServerError)@@ -2001,7 +1814,6 @@ impl BasiliskCardSupport {pub async fn retrieve_payment_method(state: &routes::AppState,pm: api::PaymentMethodId,- merchant_account: domain::MerchantAccount,) -> errors::RouterResponse<api::PaymentMethodResponse> {let db = &*state.store;let pm = db@@ -2014,7 +1826,6 @@ pub async fn retrieve_payment_method(&pm.customer_id,&pm.merchant_id,&pm.payment_method_id,- merchant_account.locker_id,).await.change_context(errors::ApiErrorResponse::InternalServerError)diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex 235e4f65b9..b74c8e35b0 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -355,13 +355,8 @@ pub async fn get_token_for_recurring_mandate(.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;let token = Uuid::new_v4().to_string();- let locker_id = merchant_account- .locker_id- .to_owned()- .get_required_value("locker_id")?;if let diesel_models::enums::PaymentMethod::Card = payment_method.payment_method {- let _ =- cards::get_lookup_key_from_locker(state, &token, &payment_method, &locker_id).await?;+ let _ = cards::get_lookup_key_from_locker(state, &token, &payment_method).await?;if let Some(payment_method_from_request) = req.payment_method {let pm: storage_enums::PaymentMethod = payment_method_from_request;if pm != payment_method.payment_method {diff --git a/crates/router/src/routes/payment_methods.rs b/crates/router/src/routes/payment_methods.rsindex 43bb2fd1bf..b1b10eb7bf 100644--- a/crates/router/src/routes/payment_methods.rs+++ b/crates/router/src/routes/payment_methods.rs@@ -186,7 +186,7 @@ pub async fn payment_method_retrieve_api(state.get_ref(),&req,payload,- |state, auth, pm| cards::retrieve_payment_method(state, pm, auth.merchant_account),+ |state, _auth, pm| cards::retrieve_payment_method(state, pm),&auth::ApiKeyAuth,).awaitdiff --git a/crates/router/src/types/api/mandates.rs b/crates/router/src/types/api/mandates.rsindex 4a56205800..8d6b9a15e3 100644--- a/crates/router/src/types/api/mandates.rs+++ b/crates/router/src/types/api/mandates.rs@@ -11,7 +11,7 @@ use crate::{newtype,routes::AppState,types::{- api, domain,+ api,storage::{self, enums as storage_enums},},};@@ -23,20 +23,12 @@ newtype!(#[async_trait::async_trait]pub(crate) trait MandateResponseExt: Sized {- async fn from_db_mandate(- state: &AppState,- mandate: storage::Mandate,- merchant_account: &domain::MerchantAccount,- ) -> RouterResult<Self>;+ async fn from_db_mandate(state: &AppState, mandate: storage::Mandate) -> RouterResult<Self>;}#[async_trait::async_trait]impl MandateResponseExt for MandateResponse {- async fn from_db_mandate(- state: &AppState,- mandate: storage::Mandate,- merchant_account: &domain::MerchantAccount,- ) -> RouterResult<Self> {+ async fn from_db_mandate(state: &AppState, mandate: storage::Mandate) -> RouterResult<Self> {let db = &*state.store;let payment_method = db.find_payment_method(&mandate.payment_method_id)@@ -49,7 +41,6 @@ impl MandateResponseExt for MandateResponse {&payment_method.customer_id,&payment_method.merchant_id,&payment_method.payment_method_id,- merchant_account.locker_id.clone(),).await?;let card_detail = payment_methods::transformers::get_card_detail(&payment_method, card)