fix(payouts): add should_continue flag for propagating error for each call (#9531)

This commit is contained in:
Sakil Mostak
2025-10-10 12:50:43 +05:30
committed by GitHub
parent b3a4eb918d
commit f95c976c42
2 changed files with 77 additions and 56 deletions

View File

@ -1657,29 +1657,35 @@ pub async fn create_payout(
)
.await?;
// 3. Fetch connector integration details
let connector_integration: services::BoxedPayoutConnectorIntegrationInterface<
api::PoCreate,
types::PayoutsData,
types::PayoutsResponseData,
> = connector_data.connector.get_connector_integration();
// 3. Execute pretasks
if helpers::should_continue_payout(&router_data) {
complete_payout_quote_steps_if_required(state, connector_data, &mut router_data).await?;
};
// 4. Execute pretasks
complete_payout_quote_steps_if_required(state, connector_data, &mut router_data).await?;
// 4. Call connector service
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
let router_data_resp = services::execute_connector_processing_step(
state,
connector_integration,
&router_data,
payments::CallConnectorAction::Trigger,
None,
None,
)
.await
.to_payout_failed_response()?;
services::execute_connector_processing_step(
state,
connector_integration,
&router_data,
payments::CallConnectorAction::Trigger,
None,
None,
)
.await
.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;
match router_data_resp.response {
Ok(payout_response_data) => {
@ -1881,26 +1887,30 @@ pub async fn create_payout_retrieve(
)
.await?;
// 3. Fetch connector integration details
let connector_integration: services::BoxedPayoutConnectorIntegrationInterface<
api::PoSync,
types::PayoutsData,
types::PayoutsResponseData,
> = connector_data.connector.get_connector_integration();
// 3. Call connector service
let router_data_resp = match helpers::should_continue_payout(&router_data) {
true => {
let connector_integration: services::BoxedPayoutConnectorIntegrationInterface<
api::PoSync,
types::PayoutsData,
types::PayoutsResponseData,
> = connector_data.connector.get_connector_integration();
// 4. Call connector service
let router_data_resp = services::execute_connector_processing_step(
state,
connector_integration,
&router_data,
payments::CallConnectorAction::Trigger,
None,
None,
)
.await
.to_payout_failed_response()?;
services::execute_connector_processing_step(
state,
connector_integration,
&router_data,
payments::CallConnectorAction::Trigger,
None,
None,
)
.await
.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?;
Ok(())
@ -2384,26 +2394,30 @@ pub async fn fulfill_payout(
)
.await?;
// 3. Fetch connector integration details
let connector_integration: services::BoxedPayoutConnectorIntegrationInterface<
api::PoFulfill,
types::PayoutsData,
types::PayoutsResponseData,
> = connector_data.connector.get_connector_integration();
// 3. Call connector service
let router_data_resp = match helpers::should_continue_payout(&router_data) {
true => {
let connector_integration: services::BoxedPayoutConnectorIntegrationInterface<
api::PoFulfill,
types::PayoutsData,
types::PayoutsResponseData,
> = connector_data.connector.get_connector_integration();
// 4. Call connector service
let router_data_resp = services::execute_connector_processing_step(
state,
connector_integration,
&router_data,
payments::CallConnectorAction::Trigger,
None,
None,
)
.await
.to_payout_failed_response()?;
services::execute_connector_processing_step(
state,
connector_integration,
&router_data,
payments::CallConnectorAction::Trigger,
None,
None,
)
.await
.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;
match router_data_resp.response {
Ok(payout_response_data) => {

View File

@ -38,6 +38,7 @@ use crate::{
routes::{metrics, SessionState},
services,
types::{
self as router_types,
api::{self, enums as api_enums},
domain::{self, types::AsyncLift},
storage,
@ -1643,3 +1644,9 @@ pub async fn resolve_billing_address_for_payout(
(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()
}