mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	fix(payouts): add should_continue flag for propagating error for each call (#9531)
This commit is contained in:
		| @ -1657,29 +1657,35 @@ pub async fn create_payout( | |||||||
|     ) |     ) | ||||||
|     .await?; |     .await?; | ||||||
|  |  | ||||||
|     // 3. Fetch connector integration details |     // 3. Execute pretasks | ||||||
|     let connector_integration: services::BoxedPayoutConnectorIntegrationInterface< |     if helpers::should_continue_payout(&router_data) { | ||||||
|         api::PoCreate, |         complete_payout_quote_steps_if_required(state, connector_data, &mut router_data).await?; | ||||||
|         types::PayoutsData, |     }; | ||||||
|         types::PayoutsResponseData, |  | ||||||
|     > = connector_data.connector.get_connector_integration(); |  | ||||||
|  |  | ||||||
|     // 4. Execute pretasks |     // 4. Call connector service | ||||||
|     complete_payout_quote_steps_if_required(state, connector_data, &mut router_data).await?; |     let router_data_resp = match helpers::should_continue_payout(&router_data) { | ||||||
|  |         true => { | ||||||
|  |             let connector_integration: services::BoxedPayoutConnectorIntegrationInterface< | ||||||
|  |                 api::PoCreate, | ||||||
|  |                 types::PayoutsData, | ||||||
|  |                 types::PayoutsResponseData, | ||||||
|  |             > = connector_data.connector.get_connector_integration(); | ||||||
|  |  | ||||||
|     // 5. Call connector service |             services::execute_connector_processing_step( | ||||||
|     let router_data_resp = services::execute_connector_processing_step( |                 state, | ||||||
|         state, |                 connector_integration, | ||||||
|         connector_integration, |                 &router_data, | ||||||
|         &router_data, |                 payments::CallConnectorAction::Trigger, | ||||||
|         payments::CallConnectorAction::Trigger, |                 None, | ||||||
|         None, |                 None, | ||||||
|         None, |             ) | ||||||
|     ) |             .await | ||||||
|     .await |             .to_payout_failed_response()? | ||||||
|     .to_payout_failed_response()?; |         } | ||||||
|  |         false => router_data, | ||||||
|  |     }; | ||||||
|  |  | ||||||
|     // 6. Process data returned by the connector |     // 5. Process data returned by the connector | ||||||
|     let db = &*state.store; |     let db = &*state.store; | ||||||
|     match router_data_resp.response { |     match router_data_resp.response { | ||||||
|         Ok(payout_response_data) => { |         Ok(payout_response_data) => { | ||||||
| @ -1881,26 +1887,30 @@ pub async fn create_payout_retrieve( | |||||||
|     ) |     ) | ||||||
|     .await?; |     .await?; | ||||||
|  |  | ||||||
|     // 3. Fetch connector integration details |     // 3. Call connector service | ||||||
|     let connector_integration: services::BoxedPayoutConnectorIntegrationInterface< |     let router_data_resp = match helpers::should_continue_payout(&router_data) { | ||||||
|         api::PoSync, |         true => { | ||||||
|         types::PayoutsData, |             let connector_integration: services::BoxedPayoutConnectorIntegrationInterface< | ||||||
|         types::PayoutsResponseData, |                 api::PoSync, | ||||||
|     > = connector_data.connector.get_connector_integration(); |                 types::PayoutsData, | ||||||
|  |                 types::PayoutsResponseData, | ||||||
|  |             > = connector_data.connector.get_connector_integration(); | ||||||
|  |  | ||||||
|     // 4. Call connector service |             services::execute_connector_processing_step( | ||||||
|     let router_data_resp = services::execute_connector_processing_step( |                 state, | ||||||
|         state, |                 connector_integration, | ||||||
|         connector_integration, |                 &router_data, | ||||||
|         &router_data, |                 payments::CallConnectorAction::Trigger, | ||||||
|         payments::CallConnectorAction::Trigger, |                 None, | ||||||
|         None, |                 None, | ||||||
|         None, |             ) | ||||||
|     ) |             .await | ||||||
|     .await |             .to_payout_failed_response()? | ||||||
|     .to_payout_failed_response()?; |         } | ||||||
|  |         false => router_data, | ||||||
|  |     }; | ||||||
|  |  | ||||||
|     // 5. Process data returned by the connector |     // 4. Process data returned by the connector | ||||||
|     update_retrieve_payout_tracker(state, merchant_context, payout_data, &router_data_resp).await?; |     update_retrieve_payout_tracker(state, merchant_context, payout_data, &router_data_resp).await?; | ||||||
|  |  | ||||||
|     Ok(()) |     Ok(()) | ||||||
| @ -2384,26 +2394,30 @@ pub async fn fulfill_payout( | |||||||
|     ) |     ) | ||||||
|     .await?; |     .await?; | ||||||
|  |  | ||||||
|     // 3. Fetch connector integration details |     // 3. Call connector service | ||||||
|     let connector_integration: services::BoxedPayoutConnectorIntegrationInterface< |     let router_data_resp = match helpers::should_continue_payout(&router_data) { | ||||||
|         api::PoFulfill, |         true => { | ||||||
|         types::PayoutsData, |             let connector_integration: services::BoxedPayoutConnectorIntegrationInterface< | ||||||
|         types::PayoutsResponseData, |                 api::PoFulfill, | ||||||
|     > = connector_data.connector.get_connector_integration(); |                 types::PayoutsData, | ||||||
|  |                 types::PayoutsResponseData, | ||||||
|  |             > = connector_data.connector.get_connector_integration(); | ||||||
|  |  | ||||||
|     // 4. Call connector service |             services::execute_connector_processing_step( | ||||||
|     let router_data_resp = services::execute_connector_processing_step( |                 state, | ||||||
|         state, |                 connector_integration, | ||||||
|         connector_integration, |                 &router_data, | ||||||
|         &router_data, |                 payments::CallConnectorAction::Trigger, | ||||||
|         payments::CallConnectorAction::Trigger, |                 None, | ||||||
|         None, |                 None, | ||||||
|         None, |             ) | ||||||
|     ) |             .await | ||||||
|     .await |             .to_payout_failed_response()? | ||||||
|     .to_payout_failed_response()?; |         } | ||||||
|  |         false => router_data, | ||||||
|  |     }; | ||||||
|  |  | ||||||
|     // 5. Process data returned by the connector |     // 4. Process data returned by the connector | ||||||
|     let db = &*state.store; |     let db = &*state.store; | ||||||
|     match router_data_resp.response { |     match router_data_resp.response { | ||||||
|         Ok(payout_response_data) => { |         Ok(payout_response_data) => { | ||||||
|  | |||||||
| @ -38,6 +38,7 @@ use crate::{ | |||||||
|     routes::{metrics, SessionState}, |     routes::{metrics, SessionState}, | ||||||
|     services, |     services, | ||||||
|     types::{ |     types::{ | ||||||
|  |         self as router_types, | ||||||
|         api::{self, enums as api_enums}, |         api::{self, enums as api_enums}, | ||||||
|         domain::{self, types::AsyncLift}, |         domain::{self, types::AsyncLift}, | ||||||
|         storage, |         storage, | ||||||
| @ -1643,3 +1644,9 @@ pub async fn resolve_billing_address_for_payout( | |||||||
|         (None, None, None) => Ok((None, None)), |         (None, None, None) => Ok((None, None)), | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | pub fn should_continue_payout<F: Clone + 'static>( | ||||||
|  |     router_data: &router_types::PayoutsRouterData<F>, | ||||||
|  | ) -> bool { | ||||||
|  |     router_data.response.is_ok() | ||||||
|  | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Sakil Mostak
					Sakil Mostak