From b45231468db1e71a113ecc1f35841e80f82d8b3f Mon Sep 17 00:00:00 2001 From: Narayan Bhat <48803246+Narayanbhat166@users.noreply.github.com> Date: Thu, 22 Jun 2023 09:22:09 +0530 Subject: [PATCH] fix(update_trackers): handle preprocessing steps status update (#1496) Co-authored-by: Sangamesh --- .../router/src/connector/trustpay/transformers.rs | 1 + crates/router/src/core/payments.rs | 15 +++++++++------ crates/router/src/core/payments/flows.rs | 5 +++-- .../src/core/payments/flows/authorize_flow.rs | 15 +++++++++------ .../router/src/core/payments/flows/cancel_flow.rs | 12 +++++++----- .../src/core/payments/flows/capture_flow.rs | 12 +++++++----- .../payments/flows/complete_authorize_flow.rs | 12 +++++++----- .../router/src/core/payments/flows/psync_flow.rs | 12 +++++++----- .../router/src/core/payments/flows/verify_flow.rs | 13 ++++++++----- 9 files changed, 58 insertions(+), 39 deletions(-) diff --git a/crates/router/src/connector/trustpay/transformers.rs b/crates/router/src/connector/trustpay/transformers.rs index e93c0358b8..ffb84059f1 100644 --- a/crates/router/src/connector/trustpay/transformers.rs +++ b/crates/router/src/connector/trustpay/transformers.rs @@ -950,6 +950,7 @@ impl }, ))), }), + status: storage_models::enums::AttemptStatus::Pending, ..item.data }) } diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs index 90fbf07640..4c4c904958 100644 --- a/crates/router/src/core/payments.rs +++ b/crates/router/src/core/payments.rs @@ -553,13 +553,15 @@ where payment_data.sessions_token.push(session_token); }; - let connector_request = if should_continue_further { + // In case of authorize flow, pre-task and post-tasks are being called in build request + // if we do not want to proceed further, then the function will return Ok(None, false) + let (connector_request, should_continue_further) = if should_continue_further { // Check if the actual flow specific request can be built with available data router_data .build_flow_specific_connector_request(state, &connector, call_connector_action.clone()) .await? } else { - None + (None, false) }; // Update the payment trackers just before calling the connector @@ -576,11 +578,12 @@ where ) .await?; - // The status of payment_attempt and intent will be updated in the previous step - // This field will be used by the connector - router_data.status = payment_data.payment_attempt.status; - let router_data_res = if should_continue_further { + // The status of payment_attempt and intent will be updated in the previous step + // update this in router_data. + // This is added because few connector integrations do not update the status, + // and rely on previous status set in router_data + router_data.status = payment_data.payment_attempt.status; router_data .decide_flows( state, diff --git a/crates/router/src/core/payments/flows.rs b/crates/router/src/core/payments/flows.rs index e128bcb895..39110a0805 100644 --- a/crates/router/src/core/payments/flows.rs +++ b/crates/router/src/core/payments/flows.rs @@ -97,13 +97,14 @@ pub trait Feature { Ok(None) } + /// Returns the connector request and a bool which specifies whether to proceed with further async fn build_flow_specific_connector_request( &mut self, _state: &AppState, _connector: &api::ConnectorData, _call_connector_action: payments::CallConnectorAction, - ) -> RouterResult> { - Ok(None) + ) -> RouterResult<(Option, bool)> { + Ok((None, true)) } } diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs index 36d40d7480..9d530a0a03 100644 --- a/crates/router/src/core/payments/flows/authorize_flow.rs +++ b/crates/router/src/core/payments/flows/authorize_flow.rs @@ -146,7 +146,7 @@ impl Feature for types::PaymentsAu state: &AppState, connector: &api::ConnectorData, call_connector_action: payments::CallConnectorAction, - ) -> RouterResult> { + ) -> RouterResult<(Option, bool)> { match call_connector_action { payments::CallConnectorAction::Trigger => { let connector_integration: services::BoxedConnectorIntegration< @@ -179,14 +179,17 @@ impl Feature for types::PaymentsAu self.decide_authentication_type(); logger::debug!(auth_type=?self.auth_type); - connector_integration - .build_request(self, &state.conf.connectors) - .to_payment_failed_response() + Ok(( + connector_integration + .build_request(self, &state.conf.connectors) + .to_payment_failed_response()?, + true, + )) } else { - Ok(None) + Ok((None, false)) } } - _ => Ok(None), + _ => Ok((None, true)), } } } diff --git a/crates/router/src/core/payments/flows/cancel_flow.rs b/crates/router/src/core/payments/flows/cancel_flow.rs index 06c8c88f0f..6c590a9cf9 100644 --- a/crates/router/src/core/payments/flows/cancel_flow.rs +++ b/crates/router/src/core/payments/flows/cancel_flow.rs @@ -89,8 +89,8 @@ impl Feature state: &AppState, connector: &api::ConnectorData, call_connector_action: payments::CallConnectorAction, - ) -> RouterResult> { - match call_connector_action { + ) -> RouterResult<(Option, bool)> { + let request = match call_connector_action { payments::CallConnectorAction::Trigger => { let connector_integration: services::BoxedConnectorIntegration< '_, @@ -101,9 +101,11 @@ impl Feature connector_integration .build_request(self, &state.conf.connectors) - .to_payment_failed_response() + .to_payment_failed_response()? } - _ => Ok(None), - } + _ => None, + }; + + Ok((request, true)) } } diff --git a/crates/router/src/core/payments/flows/capture_flow.rs b/crates/router/src/core/payments/flows/capture_flow.rs index 937c3daec6..3c509d7df6 100644 --- a/crates/router/src/core/payments/flows/capture_flow.rs +++ b/crates/router/src/core/payments/flows/capture_flow.rs @@ -81,8 +81,8 @@ impl Feature state: &AppState, connector: &api::ConnectorData, call_connector_action: payments::CallConnectorAction, - ) -> RouterResult> { - match call_connector_action { + ) -> RouterResult<(Option, bool)> { + let request = match call_connector_action { payments::CallConnectorAction::Trigger => { let connector_integration: services::BoxedConnectorIntegration< '_, @@ -93,9 +93,11 @@ impl Feature connector_integration .build_request(self, &state.conf.connectors) - .to_payment_failed_response() + .to_payment_failed_response()? } - _ => Ok(None), - } + _ => None, + }; + + Ok((request, true)) } } diff --git a/crates/router/src/core/payments/flows/complete_authorize_flow.rs b/crates/router/src/core/payments/flows/complete_authorize_flow.rs index 6e2646f537..f78305de02 100644 --- a/crates/router/src/core/payments/flows/complete_authorize_flow.rs +++ b/crates/router/src/core/payments/flows/complete_authorize_flow.rs @@ -97,8 +97,8 @@ impl Feature state: &AppState, connector: &api::ConnectorData, call_connector_action: payments::CallConnectorAction, - ) -> RouterResult> { - match call_connector_action { + ) -> RouterResult<(Option, bool)> { + let request = match call_connector_action { payments::CallConnectorAction::Trigger => { let connector_integration: services::BoxedConnectorIntegration< '_, @@ -109,9 +109,11 @@ impl Feature connector_integration .build_request(self, &state.conf.connectors) - .to_payment_failed_response() + .to_payment_failed_response()? } - _ => Ok(None), - } + _ => None, + }; + + Ok((request, true)) } } diff --git a/crates/router/src/core/payments/flows/psync_flow.rs b/crates/router/src/core/payments/flows/psync_flow.rs index d4d593bd9b..4f1d877fea 100644 --- a/crates/router/src/core/payments/flows/psync_flow.rs +++ b/crates/router/src/core/payments/flows/psync_flow.rs @@ -81,8 +81,8 @@ impl Feature state: &AppState, connector: &api::ConnectorData, call_connector_action: payments::CallConnectorAction, - ) -> RouterResult> { - match call_connector_action { + ) -> RouterResult<(Option, bool)> { + let request = match call_connector_action { payments::CallConnectorAction::Trigger => { let connector_integration: services::BoxedConnectorIntegration< '_, @@ -93,9 +93,11 @@ impl Feature connector_integration .build_request(self, &state.conf.connectors) - .to_payment_failed_response() + .to_payment_failed_response()? } - _ => Ok(None), - } + _ => None, + }; + + Ok((request, true)) } } diff --git a/crates/router/src/core/payments/flows/verify_flow.rs b/crates/router/src/core/payments/flows/verify_flow.rs index a70e4419b3..bd30f1e786 100644 --- a/crates/router/src/core/payments/flows/verify_flow.rs +++ b/crates/router/src/core/payments/flows/verify_flow.rs @@ -118,7 +118,7 @@ impl Feature for types::VerifyRouterData state: &AppState, connector: &api::ConnectorData, call_connector_action: payments::CallConnectorAction, - ) -> RouterResult> { + ) -> RouterResult<(Option, bool)> { match call_connector_action { payments::CallConnectorAction::Trigger => { let connector_integration: services::BoxedConnectorIntegration< @@ -128,11 +128,14 @@ impl Feature for types::VerifyRouterData types::PaymentsResponseData, > = connector.connector.get_connector_integration(); - connector_integration - .build_request(self, &state.conf.connectors) - .to_payment_failed_response() + Ok(( + connector_integration + .build_request(self, &state.conf.connectors) + .to_payment_failed_response()?, + true, + )) } - _ => Ok(None), + _ => Ok((None, true)), } } }