mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 18:17:13 +08:00 
			
		
		
		
	feat(business_profile): add profile id in affected tables and modify api contract (#1971)
This commit is contained in:
		| @ -1,9 +1,9 @@ | ||||
| use std::marker::PhantomData; | ||||
|  | ||||
| use api_models::enums::{DisputeStage, DisputeStatus}; | ||||
| use common_utils::errors::CustomResult; | ||||
| #[cfg(feature = "payouts")] | ||||
| use common_utils::{crypto::Encryptable, pii::Email}; | ||||
| use common_utils::{errors::CustomResult, ext_traits::AsyncExt}; | ||||
| use error_stack::{IntoReport, ResultExt}; | ||||
| use router_env::{instrument, tracing}; | ||||
| use uuid::Uuid; | ||||
| @ -16,7 +16,8 @@ use crate::core::payments; | ||||
| use crate::{ | ||||
|     configs::settings, | ||||
|     consts, | ||||
|     core::errors::{self, RouterResult}, | ||||
|     core::errors::{self, RouterResult, StorageErrorExt}, | ||||
|     db::StorageInterface, | ||||
|     routes::AppState, | ||||
|     types::{ | ||||
|         self, domain, | ||||
| @ -839,3 +840,31 @@ pub fn get_connector_request_reference_id( | ||||
|         payment_attempt.attempt_id.clone() | ||||
|     } | ||||
| } | ||||
|  | ||||
| /// Validate whether the profile_id exists and is associated with the merchant_id | ||||
| pub async fn validate_and_get_business_profile( | ||||
|     db: &dyn StorageInterface, | ||||
|     profile_id: Option<&String>, | ||||
|     merchant_id: &str, | ||||
| ) -> RouterResult<Option<storage::business_profile::BusinessProfile>> { | ||||
|     profile_id | ||||
|         .async_map(|profile_id| async { | ||||
|             db.find_business_profile_by_profile_id(profile_id) | ||||
|                 .await | ||||
|                 .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { | ||||
|                     id: profile_id.to_owned(), | ||||
|                 }) | ||||
|         }) | ||||
|         .await | ||||
|         .transpose()? | ||||
|         .map(|business_profile| { | ||||
|             // Check if the merchant_id of business profile is same as the current merchant_id | ||||
|             if business_profile.merchant_id.ne(merchant_id) { | ||||
|                 Err(errors::ApiErrorResponse::AccessForbidden) | ||||
|             } else { | ||||
|                 Ok(business_profile) | ||||
|             } | ||||
|         }) | ||||
|         .transpose() | ||||
|         .into_report() | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Narayan Bhat
					Narayan Bhat