mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 18:17:13 +08:00 
			
		
		
		
	fix: consume profile_id throughout payouts flow (#2501)
Co-authored-by: Kashif <mohammed.kashif@juspay.in>
This commit is contained in:
		| @ -40,31 +40,32 @@ pub async fn get_mca_for_payout<'a>( | ||||
|     merchant_account: &domain::MerchantAccount, | ||||
|     key_store: &domain::MerchantKeyStore, | ||||
|     payout_data: &PayoutData, | ||||
| ) -> RouterResult<helpers::MerchantConnectorAccountType> { | ||||
| ) -> RouterResult<(helpers::MerchantConnectorAccountType, String)> { | ||||
|     let payout_attempt = &payout_data.payout_attempt; | ||||
|     let profile_id = get_profile_id_from_business_details( | ||||
|         payout_attempt.business_country, | ||||
|         payout_attempt.business_label.as_ref(), | ||||
|         merchant_account, | ||||
|         payout_attempt.profile_id.as_ref(), | ||||
|         &*state.store, | ||||
|         false, | ||||
|     ) | ||||
|     .await | ||||
|     .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|     .attach_printable("profile_id is not set in payout_attempt")?; | ||||
|     match payout_data.merchant_connector_account.to_owned() { | ||||
|         Some(mca) => Ok(mca), | ||||
|         Some(mca) => Ok((mca, profile_id)), | ||||
|         None => { | ||||
|             let profile_id = payout_attempt | ||||
|                 .profile_id | ||||
|                 .as_ref() | ||||
|                 .ok_or(errors::ApiErrorResponse::MissingRequiredField { | ||||
|                     field_name: "business_profile", | ||||
|                 }) | ||||
|                 .into_report() | ||||
|                 .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|                 .attach_printable("profile_id is not set in payment_intent")?; | ||||
|  | ||||
|             let merchant_connector_account = helpers::get_merchant_connector_account( | ||||
|                 state, | ||||
|                 merchant_account.merchant_id.as_str(), | ||||
|                 None, | ||||
|                 key_store, | ||||
|                 profile_id, | ||||
|                 &profile_id, | ||||
|                 connector_id, | ||||
|             ) | ||||
|             .await?; | ||||
|             Ok(merchant_connector_account) | ||||
|             Ok((merchant_connector_account, profile_id)) | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -79,12 +80,7 @@ pub async fn construct_payout_router_data<'a, F>( | ||||
|     _request: &api_models::payouts::PayoutRequest, | ||||
|     payout_data: &mut PayoutData, | ||||
| ) -> RouterResult<types::PayoutsRouterData<F>> { | ||||
|     let (business_country, _) = helpers::get_business_details( | ||||
|         payout_data.payout_attempt.business_country, | ||||
|         payout_data.payout_attempt.business_label.as_ref(), | ||||
|         merchant_account, | ||||
|     )?; | ||||
|     let merchant_connector_account = get_mca_for_payout( | ||||
|     let (merchant_connector_account, profile_id) = get_mca_for_payout( | ||||
|         state, | ||||
|         connector_id, | ||||
|         merchant_account, | ||||
| @ -130,10 +126,11 @@ pub async fn construct_payout_router_data<'a, F>( | ||||
|     let payouts = &payout_data.payouts; | ||||
|     let payout_attempt = &payout_data.payout_attempt; | ||||
|     let customer_details = &payout_data.customer_details; | ||||
|     let connector_label = format!("{profile_id}_{}", payout_attempt.connector); | ||||
|     let connector_customer_id = customer_details | ||||
|         .as_ref() | ||||
|         .and_then(|c| c.connector_customer.as_ref()) | ||||
|         .and_then(|cc| cc.get("id")) | ||||
|         .and_then(|cc| cc.get(connector_label)) | ||||
|         .and_then(|id| serde_json::from_value::<String>(id.to_owned()).ok()); | ||||
|     let router_data = types::RouterData { | ||||
|         flow: PhantomData, | ||||
| @ -161,7 +158,6 @@ pub async fn construct_payout_router_data<'a, F>( | ||||
|             source_currency: payouts.source_currency, | ||||
|             entity_type: payouts.entity_type.to_owned(), | ||||
|             payout_type: payouts.payout_type, | ||||
|             country_code: business_country, | ||||
|             customer_details: customer_details | ||||
|                 .to_owned() | ||||
|                 .map(|c| payments::CustomerDetails { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Kashif
					Kashif