mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	refactor(merchant_id): create domain type for merchant_id (#5408)
				
					
				
			Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com>
This commit is contained in:
		| @ -23,55 +23,56 @@ use crate::{ | ||||
| /// provides the complete merchant routing dictionary that is basically a list of all the routing | ||||
| /// configs a merchant configured with an active_id field that specifies the current active routing | ||||
| /// config | ||||
| pub async fn get_merchant_routing_dictionary( | ||||
|     db: &dyn StorageInterface, | ||||
|     merchant_id: &str, | ||||
| ) -> RouterResult<routing_types::RoutingDictionary> { | ||||
|     let key = get_routing_dictionary_key(merchant_id); | ||||
|     let maybe_dict = db.find_config_by_key(&key).await; | ||||
| // pub async fn get_merchant_routing_dictionary( | ||||
| //     db: &dyn StorageInterface, | ||||
| //     merchant_id: &str, | ||||
| // ) -> RouterResult<routing_types::RoutingDictionary> { | ||||
| //     let key = get_routing_dictionary_key(merchant_id); | ||||
| //     let maybe_dict = db.find_config_by_key(&key).await; | ||||
|  | ||||
|     match maybe_dict { | ||||
|         Ok(config) => config | ||||
|             .config | ||||
|             .parse_struct("RoutingDictionary") | ||||
|             .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|             .attach_printable("Merchant routing dictionary has invalid structure"), | ||||
| //     match maybe_dict { | ||||
| //         Ok(config) => config | ||||
| //             .config | ||||
| //             .parse_struct("RoutingDictionary") | ||||
| //             .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
| //             .attach_printable("Merchant routing dictionary has invalid structure"), | ||||
|  | ||||
|         Err(e) if e.current_context().is_db_not_found() => { | ||||
|             let new_dictionary = routing_types::RoutingDictionary { | ||||
|                 merchant_id: merchant_id.to_string(), | ||||
|                 active_id: None, | ||||
|                 records: Vec::new(), | ||||
|             }; | ||||
| //         Err(e) if e.current_context().is_db_not_found() => { | ||||
| //             let new_dictionary = routing_types::RoutingDictionary { | ||||
| //                 merchant_id: merchant_id.to_owned(), | ||||
| //                 active_id: None, | ||||
| //                 records: Vec::new(), | ||||
| //             }; | ||||
|  | ||||
|             let serialized = new_dictionary | ||||
|                 .encode_to_string_of_json() | ||||
|                 .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|                 .attach_printable("Error serializing newly created merchant dictionary")?; | ||||
| //             let serialized = new_dictionary | ||||
| //                 .encode_to_string_of_json() | ||||
| //                 .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
| //                 .attach_printable("Error serializing newly created merchant dictionary")?; | ||||
|  | ||||
|             let new_config = configs::ConfigNew { | ||||
|                 key, | ||||
|                 config: serialized, | ||||
|             }; | ||||
| //             let new_config = configs::ConfigNew { | ||||
| //                 key, | ||||
| //                 config: serialized, | ||||
| //             }; | ||||
|  | ||||
|             db.insert_config(new_config) | ||||
|                 .await | ||||
|                 .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|                 .attach_printable("Error inserting new routing dictionary for merchant")?; | ||||
| //             db.insert_config(new_config) | ||||
| //                 .await | ||||
| //                 .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
| //                 .attach_printable("Error inserting new routing dictionary for merchant")?; | ||||
|  | ||||
|             Ok(new_dictionary) | ||||
|         } | ||||
| //             Ok(new_dictionary) | ||||
| //         } | ||||
|  | ||||
|         Err(e) => Err(e) | ||||
|             .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|             .attach_printable("Error fetching routing dictionary for merchant"), | ||||
|     } | ||||
| } | ||||
| //         Err(e) => Err(e) | ||||
| //             .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
| //             .attach_printable("Error fetching routing dictionary for merchant"), | ||||
| //     } | ||||
| // } | ||||
|  | ||||
| /// Provides us with all the configured configs of the Merchant in the ascending time configured | ||||
| /// manner and chooses the first of them | ||||
| pub async fn get_merchant_default_config( | ||||
|     db: &dyn StorageInterface, | ||||
|     // Cannot make this as merchant id domain type because, we are passing profile id also here | ||||
|     merchant_id: &str, | ||||
|     transaction_type: &storage::enums::TransactionType, | ||||
| ) -> RouterResult<Vec<routing_types::RoutableConnectorChoice>> { | ||||
| @ -253,8 +254,13 @@ pub async fn update_business_profile_active_algorithm_ref( | ||||
|  | ||||
|     let profile_id = current_business_profile.profile_id.clone(); | ||||
|  | ||||
|     let routing_cache_key = | ||||
|         cache::CacheKind::Routing(format!("routing_config_{merchant_id}_{profile_id}").into()); | ||||
|     let routing_cache_key = cache::CacheKind::Routing( | ||||
|         format!( | ||||
|             "routing_config_{}_{profile_id}", | ||||
|             merchant_id.get_string_repr() | ||||
|         ) | ||||
|         .into(), | ||||
|     ); | ||||
|  | ||||
|     let (routing_algorithm, payout_routing_algorithm) = match transaction_type { | ||||
|         storage::enums::TransactionType::Payment => (Some(ref_val), None), | ||||
| @ -304,7 +310,7 @@ pub async fn update_business_profile_active_algorithm_ref( | ||||
| pub async fn validate_connectors_in_routing_config( | ||||
|     state: &SessionState, | ||||
|     key_store: &domain::MerchantKeyStore, | ||||
|     merchant_id: &str, | ||||
|     merchant_id: &common_utils::id_type::MerchantId, | ||||
|     profile_id: &str, | ||||
|     routing_algorithm: &routing_types::RoutingAlgorithm, | ||||
| ) -> RouterResult<()> { | ||||
| @ -318,7 +324,7 @@ pub async fn validate_connectors_in_routing_config( | ||||
|         ) | ||||
|         .await | ||||
|         .change_context(errors::ApiErrorResponse::MerchantConnectorAccountNotFound { | ||||
|             id: merchant_id.to_string(), | ||||
|             id: merchant_id.get_string_repr().to_owned(), | ||||
|         })?; | ||||
|  | ||||
|     let name_mca_id_set = all_mcas | ||||
| @ -426,10 +432,3 @@ pub fn get_default_config_key( | ||||
|         storage::enums::TransactionType::Payout => format!("routing_default_po_{merchant_id}"), | ||||
|     } | ||||
| } | ||||
| pub fn get_payment_config_routing_id(merchant_id: &str) -> String { | ||||
|     format!("payment_config_id_{merchant_id}") | ||||
| } | ||||
|  | ||||
| pub fn get_payment_method_surcharge_routing_id(merchant_id: &str) -> String { | ||||
|     format!("payment_method_surcharge_id_{merchant_id}") | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Narayan Bhat
					Narayan Bhat