mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	refactor(payment_methods): Remove legacy locker code as it is not been used (#1666)
This commit is contained in:
		| @ -109,7 +109,6 @@ kms_encrypted_jwt_secret = ""    # Base64-encoded (KMS encrypted) ciphertext of | |||||||
| host = ""                      # Locker host | host = ""                      # Locker host | ||||||
| mock_locker = true             # Emulate a locker locally using Postgres | mock_locker = true             # Emulate a locker locally using Postgres | ||||||
| basilisk_host = ""             # Basilisk host | basilisk_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 | locker_signing_key_id = "1"    # Key_id to sign basilisk hs locker | ||||||
|  |  | ||||||
| [delayed_session_response] | [delayed_session_response] | ||||||
|  | |||||||
| @ -38,7 +38,6 @@ master_enc_key = "73ad7bbbbc640c845a150f67d058b279849370cd2c1f3c67c4dd6c869213e1 | |||||||
| host = "" | host = "" | ||||||
| mock_locker = true | mock_locker = true | ||||||
| basilisk_host = "" | basilisk_host = "" | ||||||
| locker_setup = "legacy_locker" |  | ||||||
|  |  | ||||||
| [jwekey] | [jwekey] | ||||||
| locker_key_identifier1 = "" | locker_key_identifier1 = "" | ||||||
|  | |||||||
| @ -56,7 +56,6 @@ impl Default for super::settings::Locker { | |||||||
|             host: "localhost".into(), |             host: "localhost".into(), | ||||||
|             mock_locker: true, |             mock_locker: true, | ||||||
|             basilisk_host: "localhost".into(), |             basilisk_host: "localhost".into(), | ||||||
|             locker_setup: super::settings::LockerSetup::LegacyLocker, |  | ||||||
|             locker_signing_key_id: "1".into(), |             locker_signing_key_id: "1".into(), | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -330,18 +330,9 @@ pub struct Locker { | |||||||
|     pub host: String, |     pub host: String, | ||||||
|     pub mock_locker: bool, |     pub mock_locker: bool, | ||||||
|     pub basilisk_host: String, |     pub basilisk_host: String, | ||||||
|     pub locker_setup: LockerSetup, |  | ||||||
|     pub locker_signing_key_id: String, |     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)] | #[derive(Debug, Deserialize, Clone)] | ||||||
| #[serde(default)] | #[serde(default)] | ||||||
| pub struct Refund { | pub struct Refund { | ||||||
|  | |||||||
| @ -34,7 +34,7 @@ pub async fn get_mandate( | |||||||
|         .await |         .await | ||||||
|         .to_not_found_response(errors::ApiErrorResponse::MandateNotFound)?; |         .to_not_found_response(errors::ApiErrorResponse::MandateNotFound)?; | ||||||
|     Ok(services::ApplicationResponse::Json( |     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 { |     } else { | ||||||
|         let mut response_vec = Vec::with_capacity(mandates.len()); |         let mut response_vec = Vec::with_capacity(mandates.len()); | ||||||
|         for mandate in mandates { |         for mandate in mandates { | ||||||
|             response_vec.push( |             response_vec.push(mandates::MandateResponse::from_db_mandate(state, mandate).await?); | ||||||
|                 mandates::MandateResponse::from_db_mandate(state, mandate, &merchant_account) |  | ||||||
|                     .await?, |  | ||||||
|             ); |  | ||||||
|         } |         } | ||||||
|         Ok(services::ApplicationResponse::Json(response_vec)) |         Ok(services::ApplicationResponse::Json(response_vec)) | ||||||
|     } |     } | ||||||
| @ -272,9 +269,11 @@ pub async fn retrieve_mandates_list( | |||||||
|         .await |         .await | ||||||
|         .change_context(errors::ApiErrorResponse::InternalServerError) |         .change_context(errors::ApiErrorResponse::InternalServerError) | ||||||
|         .attach_printable("Unable to retrieve mandates")?; |         .attach_printable("Unable to retrieve mandates")?; | ||||||
|     let mandates_list = future::try_join_all(mandates.into_iter().map(|mandate| { |     let mandates_list = future::try_join_all( | ||||||
|         mandates::MandateResponse::from_db_mandate(state, mandate, &merchant_account) |         mandates | ||||||
|     })) |             .into_iter() | ||||||
|  |             .map(|mandate| mandates::MandateResponse::from_db_mandate(state, mandate)), | ||||||
|  |     ) | ||||||
|     .await?; |     .await?; | ||||||
|     Ok(services::ApplicationResponse::Json(mandates_list)) |     Ok(services::ApplicationResponse::Json(mandates_list)) | ||||||
| } | } | ||||||
|  | |||||||
| @ -15,11 +15,11 @@ use api_models::{ | |||||||
| }; | }; | ||||||
| use common_utils::{ | use common_utils::{ | ||||||
|     consts, |     consts, | ||||||
|     ext_traits::{AsyncExt, BytesExt, StringExt, ValueExt}, |     ext_traits::{AsyncExt, StringExt, ValueExt}, | ||||||
|     generate_id, |     generate_id, | ||||||
| }; | }; | ||||||
| use diesel_models::{enums as storage_enums, payment_method}; | 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}; | use router_env::{instrument, tracing}; | ||||||
|  |  | ||||||
| #[cfg(feature = "basilisk")] | #[cfg(feature = "basilisk")] | ||||||
| @ -187,14 +187,8 @@ pub async fn add_card_to_locker( | |||||||
|     metrics::STORED_TO_LOCKER.add(&metrics::CONTEXT, 1, &[]); |     metrics::STORED_TO_LOCKER.add(&metrics::CONTEXT, 1, &[]); | ||||||
|     request::record_operation_time( |     request::record_operation_time( | ||||||
|         async { |         async { | ||||||
|             match state.conf.locker.locker_setup { |             add_card_hs(state, req, card, customer_id, merchant_account) | ||||||
|                 settings::LockerSetup::BasiliskLocker => { |                 .await | ||||||
|                     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| { |                 .map_err(|error| { | ||||||
|                     metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]); |                     metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]); | ||||||
|                     error |                     error | ||||||
| @ -210,28 +204,15 @@ pub async fn get_card_from_locker( | |||||||
|     customer_id: &str, |     customer_id: &str, | ||||||
|     merchant_id: &str, |     merchant_id: &str, | ||||||
|     card_reference: &str, |     card_reference: &str, | ||||||
|     locker_id: Option<String>, |  | ||||||
| ) -> errors::RouterResult<payment_methods::Card> { | ) -> errors::RouterResult<payment_methods::Card> { | ||||||
|     metrics::GET_FROM_LOCKER.add(&metrics::CONTEXT, 1, &[]); |     metrics::GET_FROM_LOCKER.add(&metrics::CONTEXT, 1, &[]); | ||||||
|  |  | ||||||
|     request::record_operation_time( |     request::record_operation_time( | ||||||
|         async { |         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) |             get_card_from_hs_locker(state, customer_id, merchant_id, card_reference) | ||||||
|                 .await |                 .await | ||||||
|                 .change_context(errors::ApiErrorResponse::InternalServerError) |                 .change_context(errors::ApiErrorResponse::InternalServerError) | ||||||
|                 .attach_printable("Failed while getting card from basilisk_hs") |                 .attach_printable("Failed while getting card from basilisk_hs") | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|                 .map_err(|error| { |                 .map_err(|error| { | ||||||
|                     metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]); |                     metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]); | ||||||
|                     error |                     error | ||||||
| @ -252,15 +233,8 @@ pub async fn delete_card_from_locker( | |||||||
|  |  | ||||||
|     request::record_operation_time( |     request::record_operation_time( | ||||||
|         async { |         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) |             delete_card_from_hs_locker(state, customer_id, merchant_id, card_reference) | ||||||
|                 .await |                 .await | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|                 .map_err(|error| { |                 .map_err(|error| { | ||||||
|                     metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]); |                     metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]); | ||||||
|                     error |                     error | ||||||
| @ -288,11 +262,15 @@ pub async fn add_card_hs( | |||||||
|     let db = &*state.store; |     let db = &*state.store; | ||||||
|     let merchant_id = &merchant_account.merchant_id; |     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 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) |         let response = services::call_connector_api(state, request) | ||||||
|             .await |             .await | ||||||
|             .change_context(errors::VaultError::SaveCardFailed); |             .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( | pub async fn update_payment_method( | ||||||
|     db: &dyn db::StorageInterface, |     db: &dyn db::StorageInterface, | ||||||
|     pm: payment_method::PaymentMethod, |     pm: payment_method::PaymentMethod, | ||||||
| @ -411,6 +336,7 @@ pub async fn get_card_from_hs_locker<'a>( | |||||||
|     #[cfg(feature = "kms")] |     #[cfg(feature = "kms")] | ||||||
|     let jwekey = &state.kms_secrets; |     let jwekey = &state.kms_secrets; | ||||||
|  |  | ||||||
|  |     if !locker.mock_locker { | ||||||
|         let request = payment_methods::mk_get_card_request_hs( |         let request = payment_methods::mk_get_card_request_hs( | ||||||
|             jwekey, |             jwekey, | ||||||
|             locker, |             locker, | ||||||
| @ -421,7 +347,6 @@ pub async fn get_card_from_hs_locker<'a>( | |||||||
|         .await |         .await | ||||||
|         .change_context(errors::VaultError::FetchCardFailed) |         .change_context(errors::VaultError::FetchCardFailed) | ||||||
|         .attach_printable("Making get card request failed")?; |         .attach_printable("Making get card request failed")?; | ||||||
|     if !locker.mock_locker { |  | ||||||
|         let response = services::call_connector_api(state, request) |         let response = services::call_connector_api(state, request) | ||||||
|             .await |             .await | ||||||
|             .change_context(errors::VaultError::FetchCardFailed) |             .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)] | #[instrument(skip_all)] | ||||||
| pub async fn delete_card_from_hs_locker<'a>( | pub async fn delete_card_from_hs_locker<'a>( | ||||||
|     state: &'a routes::AppState, |     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 | ///Mock api for local testing | ||||||
| #[instrument(skip_all)] | #[instrument(skip_all)] | ||||||
| pub async fn mock_add_card_hs( | 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)] | #[instrument(skip_all)] | ||||||
| pub async fn mock_get_card<'a>( | pub async fn mock_get_card<'a>( | ||||||
|     db: &dyn db::StorageInterface, |     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 parent_payment_method_token = generate_id(consts::ID_LENGTH, "token"); | ||||||
|         let hyperswitch_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 card = if pm.payment_method == enums::PaymentMethod::Card { | ||||||
|             let locker_id = merchant_account |             Some(get_lookup_key_from_locker(state, &hyperswitch_token, &pm).await?) | ||||||
|                 .locker_id |  | ||||||
|                 .to_owned() |  | ||||||
|                 .get_required_value("locker_id")?; |  | ||||||
|             Some(get_lookup_key_from_locker(state, &hyperswitch_token, &pm, &locker_id).await?) |  | ||||||
|         } else { |         } else { | ||||||
|             None |             None | ||||||
|         }; |         }; | ||||||
| @ -1809,14 +1624,12 @@ pub async fn get_lookup_key_from_locker( | |||||||
|     state: &routes::AppState, |     state: &routes::AppState, | ||||||
|     payment_token: &str, |     payment_token: &str, | ||||||
|     pm: &storage::PaymentMethod, |     pm: &storage::PaymentMethod, | ||||||
|     locker_id: &str, |  | ||||||
| ) -> errors::RouterResult<api::CardDetailFromLocker> { | ) -> errors::RouterResult<api::CardDetailFromLocker> { | ||||||
|     let card = get_card_from_locker( |     let card = get_card_from_locker( | ||||||
|         state, |         state, | ||||||
|         &pm.customer_id, |         &pm.customer_id, | ||||||
|         &pm.merchant_id, |         &pm.merchant_id, | ||||||
|         &pm.payment_method_id, |         &pm.payment_method_id, | ||||||
|         Some(locker_id.to_string()), |  | ||||||
|     ) |     ) | ||||||
|     .await |     .await | ||||||
|     .change_context(errors::ApiErrorResponse::InternalServerError) |     .change_context(errors::ApiErrorResponse::InternalServerError) | ||||||
| @ -2001,7 +1814,6 @@ impl BasiliskCardSupport { | |||||||
| pub async fn retrieve_payment_method( | pub async fn retrieve_payment_method( | ||||||
|     state: &routes::AppState, |     state: &routes::AppState, | ||||||
|     pm: api::PaymentMethodId, |     pm: api::PaymentMethodId, | ||||||
|     merchant_account: domain::MerchantAccount, |  | ||||||
| ) -> errors::RouterResponse<api::PaymentMethodResponse> { | ) -> errors::RouterResponse<api::PaymentMethodResponse> { | ||||||
|     let db = &*state.store; |     let db = &*state.store; | ||||||
|     let pm = db |     let pm = db | ||||||
| @ -2014,7 +1826,6 @@ pub async fn retrieve_payment_method( | |||||||
|             &pm.customer_id, |             &pm.customer_id, | ||||||
|             &pm.merchant_id, |             &pm.merchant_id, | ||||||
|             &pm.payment_method_id, |             &pm.payment_method_id, | ||||||
|             merchant_account.locker_id, |  | ||||||
|         ) |         ) | ||||||
|         .await |         .await | ||||||
|         .change_context(errors::ApiErrorResponse::InternalServerError) |         .change_context(errors::ApiErrorResponse::InternalServerError) | ||||||
|  | |||||||
| @ -355,13 +355,8 @@ pub async fn get_token_for_recurring_mandate( | |||||||
|         .to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?; |         .to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?; | ||||||
|  |  | ||||||
|     let token = Uuid::new_v4().to_string(); |     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 { |     if let diesel_models::enums::PaymentMethod::Card = payment_method.payment_method { | ||||||
|         let _ = |         let _ = cards::get_lookup_key_from_locker(state, &token, &payment_method).await?; | ||||||
|             cards::get_lookup_key_from_locker(state, &token, &payment_method, &locker_id).await?; |  | ||||||
|         if let Some(payment_method_from_request) = req.payment_method { |         if let Some(payment_method_from_request) = req.payment_method { | ||||||
|             let pm: storage_enums::PaymentMethod = payment_method_from_request; |             let pm: storage_enums::PaymentMethod = payment_method_from_request; | ||||||
|             if pm != payment_method.payment_method { |             if pm != payment_method.payment_method { | ||||||
|  | |||||||
| @ -186,7 +186,7 @@ pub async fn payment_method_retrieve_api( | |||||||
|         state.get_ref(), |         state.get_ref(), | ||||||
|         &req, |         &req, | ||||||
|         payload, |         payload, | ||||||
|         |state, auth, pm| cards::retrieve_payment_method(state, pm, auth.merchant_account), |         |state, _auth, pm| cards::retrieve_payment_method(state, pm), | ||||||
|         &auth::ApiKeyAuth, |         &auth::ApiKeyAuth, | ||||||
|     ) |     ) | ||||||
|     .await |     .await | ||||||
|  | |||||||
| @ -11,7 +11,7 @@ use crate::{ | |||||||
|     newtype, |     newtype, | ||||||
|     routes::AppState, |     routes::AppState, | ||||||
|     types::{ |     types::{ | ||||||
|         api, domain, |         api, | ||||||
|         storage::{self, enums as storage_enums}, |         storage::{self, enums as storage_enums}, | ||||||
|     }, |     }, | ||||||
| }; | }; | ||||||
| @ -23,20 +23,12 @@ newtype!( | |||||||
|  |  | ||||||
| #[async_trait::async_trait] | #[async_trait::async_trait] | ||||||
| pub(crate) trait MandateResponseExt: Sized { | pub(crate) trait MandateResponseExt: Sized { | ||||||
|     async fn from_db_mandate( |     async fn from_db_mandate(state: &AppState, mandate: storage::Mandate) -> RouterResult<Self>; | ||||||
|         state: &AppState, |  | ||||||
|         mandate: storage::Mandate, |  | ||||||
|         merchant_account: &domain::MerchantAccount, |  | ||||||
|     ) -> RouterResult<Self>; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| #[async_trait::async_trait] | #[async_trait::async_trait] | ||||||
| impl MandateResponseExt for MandateResponse { | impl MandateResponseExt for MandateResponse { | ||||||
|     async fn from_db_mandate( |     async fn from_db_mandate(state: &AppState, mandate: storage::Mandate) -> RouterResult<Self> { | ||||||
|         state: &AppState, |  | ||||||
|         mandate: storage::Mandate, |  | ||||||
|         merchant_account: &domain::MerchantAccount, |  | ||||||
|     ) -> RouterResult<Self> { |  | ||||||
|         let db = &*state.store; |         let db = &*state.store; | ||||||
|         let payment_method = db |         let payment_method = db | ||||||
|             .find_payment_method(&mandate.payment_method_id) |             .find_payment_method(&mandate.payment_method_id) | ||||||
| @ -49,7 +41,6 @@ impl MandateResponseExt for MandateResponse { | |||||||
|                 &payment_method.customer_id, |                 &payment_method.customer_id, | ||||||
|                 &payment_method.merchant_id, |                 &payment_method.merchant_id, | ||||||
|                 &payment_method.payment_method_id, |                 &payment_method.payment_method_id, | ||||||
|                 merchant_account.locker_id.clone(), |  | ||||||
|             ) |             ) | ||||||
|             .await?; |             .await?; | ||||||
|             let card_detail = payment_methods::transformers::get_card_detail(&payment_method, card) |             let card_detail = payment_methods::transformers::get_card_detail(&payment_method, card) | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Shankar Singh C
					Shankar Singh C