Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(core): move update trackers after build request (#1472)
Narayan Bhat6114fb634063
diff --git a/crates/router/src/connector/airwallex.rs b/crates/router/src/connector/airwallex.rsindex 2c4915c40c..1a95f67042 100644--- a/crates/router/src/connector/airwallex.rs+++ b/crates/router/src/connector/airwallex.rs@@ -308,6 +308,7 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::Pinteg,authorize_data,payments::CallConnectorAction::Trigger,+ None,).await?;router_data.reference_id = resp.reference_id;diff --git a/crates/router/src/connector/nuvei.rs b/crates/router/src/connector/nuvei.rsindex b7d2c4ec3a..d8f5237379 100644--- a/crates/router/src/connector/nuvei.rs+++ b/crates/router/src/connector/nuvei.rs@@ -483,6 +483,7 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::Pinteg,authorize_data,payments::CallConnectorAction::Trigger,+ None,).await?;router_data.session_token = resp.session_token;@@ -510,6 +511,7 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::Pinteg,init_data,payments::CallConnectorAction::Trigger,+ None,).await?;match init_resp.response {diff --git a/crates/router/src/connector/shift4.rs b/crates/router/src/connector/shift4.rsindex 86dc4e5849..fd62faaeb2 100644--- a/crates/router/src/connector/shift4.rs+++ b/crates/router/src/connector/shift4.rs@@ -199,6 +199,7 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::Pinteg,init_data,payments::CallConnectorAction::Trigger,+ None,).await?;if init_resp.request.enrolled_for_3ds {diff --git a/crates/router/src/core/disputes.rs b/crates/router/src/core/disputes.rsindex e4e8404a2c..c90f91c927 100644--- a/crates/router/src/core/disputes.rs+++ b/crates/router/src/core/disputes.rs@@ -127,6 +127,7 @@ pub async fn accept_dispute(connector_integration,&router_data,payments::CallConnectorAction::Trigger,+ None,).await.to_dispute_failed_response()@@ -234,6 +235,7 @@ pub async fn submit_evidence(connector_integration,&router_data,payments::CallConnectorAction::Trigger,+ None,).await.to_dispute_failed_response()@@ -270,6 +272,7 @@ pub async fn submit_evidence(connector_integration_defend_dispute,&defend_dispute_router_data,payments::CallConnectorAction::Trigger,+ None,).await.to_dispute_failed_response()diff --git a/crates/router/src/core/files/helpers.rs b/crates/router/src/core/files/helpers.rsindex ed748badc0..751dd5b047 100644--- a/crates/router/src/core/files/helpers.rs+++ b/crates/router/src/core/files/helpers.rs@@ -188,6 +188,7 @@ pub async fn retrieve_file_from_connector(connector_integration,&router_data,payments::CallConnectorAction::Trigger,+ None,).await.change_context(errors::ApiErrorResponse::InternalServerError)@@ -339,6 +340,7 @@ pub async fn upload_and_get_provider_provider_file_id_connector_label(connector_integration,&router_data,payments::CallConnectorAction::Trigger,+ None,).await.change_context(errors::ApiErrorResponse::InternalServerError)diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex 8fe2d45f13..ebac8bb0d2 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -129,18 +129,6 @@ where).await?;- let (operation, mut payment_data) = operation- .to_update_tracker()?- .update_trackers(- &*state.store,- &validate_result.payment_id,- payment_data,- customer.clone(),- validate_result.storage_scheme,- updated_customer,- )- .await?;-if let Some(connector_details) = connector {if should_add_task_to_process_tracker(&payment_data) {operation@@ -160,6 +148,7 @@ where&customer,call_connector_action,tokenization_action,+ updated_customer,).await?;@@ -189,11 +178,24 @@ where.await?}};+if should_delete_pm_from_locker(payment_data.payment_intent.status) {vault::Vault::delete_locker_payment_method_by_lookup_key(state, &payment_data.token).await}+ } else {+ (_, payment_data) = operation+ .to_update_tracker()?+ .update_trackers(+ &*state.store,+ payment_data.clone(),+ customer.clone(),+ validate_result.storage_scheme,+ updated_customer,+ )+ .await?;}+Ok((payment_data, req, customer))}@@ -485,30 +487,28 @@ impl PaymentRedirectFlow for PaymentRedirectSync {}#[allow(clippy::too_many_arguments)]-pub async fn call_connector_service<F, Op, Req>(+pub async fn call_connector_service<F, RouterDReq, ApiRequest>(state: &AppState,merchant_account: &domain::MerchantAccount,connector: api::ConnectorData,- _operation: &Op,+ operation: &BoxedOperation<'_, F, ApiRequest>,payment_data: &mut PaymentData<F>,customer: &Option<domain::Customer>,call_connector_action: CallConnectorAction,tokenization_action: TokenizationAction,-) -> RouterResult<types::RouterData<F, Req, types::PaymentsResponseData>>+ updated_customer: Option<storage::CustomerUpdate>,+) -> RouterResult<types::RouterData<F, RouterDReq, types::PaymentsResponseData>>where- Op: Debug + Sync,F: Send + Clone + Sync,- Req: Send + Sync,+ RouterDReq: Send + Sync,// To create connector flow specific interface data- PaymentData<F>: ConstructFlowSpecificData<F, Req, types::PaymentsResponseData>,- types::RouterData<F, Req, types::PaymentsResponseData>: Feature<F, Req> + Send,+ PaymentData<F>: ConstructFlowSpecificData<F, RouterDReq, types::PaymentsResponseData>,+ types::RouterData<F, RouterDReq, types::PaymentsResponseData>: Feature<F, RouterDReq> + Send,// To construct connector flow specific api- dyn api::Connector: services::api::ConnectorIntegration<F, Req, types::PaymentsResponseData>,-- // To perform router related operation for PaymentResponse- PaymentResponse: Operation<F, Req>,+ dyn api::Connector:+ services::api::ConnectorIntegration<F, RouterDReq, types::PaymentsResponseData>,{let stime_connector = Instant::now();@@ -520,7 +520,7 @@ where.add_access_token(state, &connector, merchant_account).await?;- let mut should_continue_payment = access_token::update_router_data_with_access_token_result(+ let mut should_continue_further = access_token::update_router_data_with_access_token_result(&add_access_token_result,&mut router_data,&call_connector_action,@@ -534,12 +534,12 @@ whererouter_data.payment_method_token = Some(payment_method_token);};- (router_data, should_continue_payment) = complete_preprocessing_steps_if_required(+ (router_data, should_continue_further) = complete_preprocessing_steps_if_required(state,&connector,payment_data,router_data,- should_continue_payment,+ should_continue_further,).await?;@@ -551,7 +551,26 @@ wherepayment_data.sessions_token.push(session_token);};- let router_data_res = if should_continue_payment {+ let router_data_res = if should_continue_further {+ // Check if the actual flow specific request can be built with available data+ let request = router_data+ .build_flow_specific_connector_request(state, &connector, call_connector_action.clone())+ .await?;++ // Update the payment trackers just before calling the connector+ // Since the request is already built in the previous step,+ // there should be no error in request construction from hyperswitch end+ operation+ .to_update_tracker()?+ .update_trackers(+ &*state.store,+ payment_data.clone(),+ customer.clone(),+ merchant_account.storage_scheme,+ updated_customer,+ )+ .await?;+router_data.decide_flows(state,@@ -559,6 +578,7 @@ wherecustomer,call_connector_action,merchant_account,+ request,).await} else {@@ -609,6 +629,7 @@ wherecustomer,CallConnectorAction::Trigger,merchant_account,+ None,);join_handlers.push(res);diff --git a/crates/router/src/core/payments/access_token.rs b/crates/router/src/core/payments/access_token.rsindex ad4706abde..6bae1067b0 100644--- a/crates/router/src/core/payments/access_token.rs+++ b/crates/router/src/core/payments/access_token.rs@@ -13,6 +13,10 @@ use crate::{types::{self, api as api_types, domain, transformers::ForeignInto},};+/// After we get the access token, check if there was an error and if the flow should proceed further+/// Returns bool+/// true - Everything is well, continue with the flow+/// false - There was an error, cannot proceed furtherpub fn update_router_data_with_access_token_result<F, Req, Res>(add_access_token_result: &types::AddAccessTokenResult,router_data: &mut types::RouterData<F, Req, Res>,@@ -152,6 +156,7 @@ pub async fn refresh_connector_auth(connector_integration,router_data,payments::CallConnectorAction::Trigger,+ None,).await.change_context(errors::ApiErrorResponse::InternalServerError)diff --git a/crates/router/src/core/payments/customers.rs b/crates/router/src/core/payments/customers.rsindex 213a7cbc10..5bfe7fbe1c 100644--- a/crates/router/src/core/payments/customers.rs+++ b/crates/router/src/core/payments/customers.rs@@ -46,6 +46,7 @@ pub async fn create_connector_customer<F: Clone, T: Clone>(connector_integration,&customer_router_data,payments::CallConnectorAction::Trigger,+ None,).await.to_payment_failed_response()?;diff --git a/crates/router/src/core/payments/flows.rs b/crates/router/src/core/payments/flows.rsindex 4abbe9291f..e128bcb895 100644--- a/crates/router/src/core/payments/flows.rs+++ b/crates/router/src/core/payments/flows.rs@@ -39,6 +39,7 @@ pub trait Feature<F, T> {maybe_customer: &Option<domain::Customer>,call_connector_action: payments::CallConnectorAction,merchant_account: &domain::MerchantAccount,+ connector_request: Option<services::Request>,) -> RouterResult<Self>whereSelf: Sized,@@ -95,6 +96,15 @@ pub trait Feature<F, T> {{Ok(None)}++ async fn build_flow_specific_connector_request(+ &mut self,+ _state: &AppState,+ _connector: &api::ConnectorData,+ _call_connector_action: payments::CallConnectorAction,+ ) -> RouterResult<Option<services::Request>> {+ Ok(None)+ }}macro_rules! default_imp_for_complete_authorize{diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rsindex 1efc09ffbc..49d30f6e87 100644--- a/crates/router/src/core/payments/flows/authorize_flow.rs+++ b/crates/router/src/core/payments/flows/authorize_flow.rs@@ -51,24 +51,46 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAumut self,state: &AppState,connector: &api::ConnectorData,- customer: &Option<domain::Customer>,+ maybe_customer: &Option<domain::Customer>,call_connector_action: payments::CallConnectorAction,merchant_account: &domain::MerchantAccount,+ connector_request: Option<services::Request>,) -> RouterResult<Self> {- let resp = self- .decide_flow(+ let connector_integration: services::BoxedConnectorIntegration<+ '_,+ api::Authorize,+ types::PaymentsAuthorizeData,+ types::PaymentsResponseData,+ > = connector.connector.get_connector_integration();++ if self.should_proceed_with_authorize() {+ self.decide_authentication_type();+ logger::debug!(auth_type=?self.auth_type);+ let resp = services::execute_connector_processing_step(state,- connector,- customer,- Some(true),+ connector_integration,+ &self,call_connector_action,- merchant_account,+ connector_request,)- .await;+ .await+ .to_payment_failed_response()?;++ metrics::PAYMENT_COUNT.add(&metrics::CONTEXT, 1, &[]); // Metrics- metrics::PAYMENT_COUNT.add(&metrics::CONTEXT, 1, &[]); // Metrics+ let pm_id = tokenization::save_payment_method(+ state,+ connector,+ resp.to_owned(),+ maybe_customer,+ merchant_account,+ )+ .await?;- resp+ Ok(mandate::mandate_procedure(state, resp, maybe_customer, pm_id).await?)+ } else {+ Ok(self.clone())+ }}async fn add_access_token<'a>(@@ -117,26 +139,22 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu).await}-}-impl types::PaymentsAuthorizeRouterData {- pub async fn decide_flow<'a, 'b>(- &'b mut self,- state: &'a AppState,+ async fn build_flow_specific_connector_request(+ &mut self,+ state: &AppState,connector: &api::ConnectorData,- maybe_customer: &Option<domain::Customer>,- confirm: Option<bool>,call_connector_action: payments::CallConnectorAction,- merchant_account: &domain::MerchantAccount,- ) -> RouterResult<Self> {- match confirm {- Some(true) => {+ ) -> RouterResult<Option<services::Request>> {+ match call_connector_action {+ payments::CallConnectorAction::Trigger => {let connector_integration: services::BoxedConnectorIntegration<'_,api::Authorize,types::PaymentsAuthorizeData,types::PaymentsResponseData,> = connector.connector.get_connector_integration();+connector_integration.execute_pretasks(self, state).await@@ -155,36 +173,24 @@ impl types::PaymentsAuthorizeRouterData {);logger::debug!(completed_pre_tasks=?true);+if self.should_proceed_with_authorize() {self.decide_authentication_type();logger::debug!(auth_type=?self.auth_type);- let resp = services::execute_connector_processing_step(- state,- connector_integration,- self,- call_connector_action,- )- .await- .to_payment_failed_response()?;-- let pm_id = tokenization::save_payment_method(- state,- connector,- resp.to_owned(),- maybe_customer,- merchant_account,- )- .await?;- Ok(mandate::mandate_procedure(state, resp, maybe_customer, pm_id).await?)+ connector_integration+ .build_request(self, &state.conf.connectors)+ .to_payment_failed_response()} else {- Ok(self.clone())+ Ok(None)}}- _ => Ok(self.clone()),+ _ => Ok(None),}}+}+impl types::PaymentsAuthorizeRouterData {fn decide_authentication_type(&mut self) {if self.auth_type == storage_models::enums::AuthenticationType::ThreeDs&& !self.request.enrolled_for_3ds@@ -204,12 +210,6 @@ impl types::PaymentsAuthorizeRouterData {}}-pub enum Action {- Update,- Insert,- Skip,-}-impl mandate::MandateBehaviour for types::PaymentsAuthorizeData {fn get_amount(&self) -> i64 {self.amount@@ -264,6 +264,7 @@ pub async fn authorize_preprocessing_steps<F: Clone>(connector_integration,&preprocessing_router_data,payments::CallConnectorAction::Trigger,+ None,).await.to_payment_failed_response()?;diff --git a/crates/router/src/core/payments/flows/cancel_flow.rs b/crates/router/src/core/payments/flows/cancel_flow.rsindex c769d9c59a..06c8c88f0f 100644--- a/crates/router/src/core/payments/flows/cancel_flow.rs+++ b/crates/router/src/core/payments/flows/cancel_flow.rs@@ -41,9 +41,10 @@ impl Feature<api::Void, types::PaymentsCancelData>self,state: &AppState,connector: &api::ConnectorData,- customer: &Option<domain::Customer>,+ _customer: &Option<domain::Customer>,call_connector_action: payments::CallConnectorAction,_merchant_account: &domain::MerchantAccount,+ connector_request: Option<services::Request>,) -> RouterResult<Self> {metrics::PAYMENT_CANCEL_COUNT.add(&metrics::CONTEXT,@@ -53,14 +54,25 @@ impl Feature<api::Void, types::PaymentsCancelData>connector.connector_name.to_string(),)],);- self.decide_flow(++ let connector_integration: services::BoxedConnectorIntegration<+ '_,+ api::Void,+ types::PaymentsCancelData,+ types::PaymentsResponseData,+ > = connector.connector.get_connector_integration();++ let resp = services::execute_connector_processing_step(state,- connector,- customer,- Some(true),+ connector_integration,+ &self,call_connector_action,+ connector_request,).await+ .to_payment_failed_response()?;++ Ok(resp)}async fn add_access_token<'a>(@@ -71,33 +83,27 @@ impl Feature<api::Void, types::PaymentsCancelData>) -> RouterResult<types::AddAccessTokenResult> {access_token::add_access_token(state, connector, merchant_account, self).await}-}-impl types::PaymentsCancelRouterData {- #[allow(clippy::too_many_arguments)]- pub async fn decide_flow<'a, 'b>(- &'b self,+ async fn build_flow_specific_connector_request(+ &mut self,state: &AppState,connector: &api::ConnectorData,- _maybe_customer: &Option<domain::Customer>,- _confirm: Option<bool>,call_connector_action: payments::CallConnectorAction,- ) -> RouterResult<Self> {- let connector_integration: services::BoxedConnectorIntegration<- '_,- api::Void,- types::PaymentsCancelData,- types::PaymentsResponseData,- > = connector.connector.get_connector_integration();- let resp = services::execute_connector_processing_step(- state,- connector_integration,- self,- call_connector_action,- )- .await- .to_payment_failed_response()?;+ ) -> RouterResult<Option<services::Request>> {+ match call_connector_action {+ payments::CallConnectorAction::Trigger => {+ let connector_integration: services::BoxedConnectorIntegration<+ '_,+ api::Void,+ types::PaymentsCancelData,+ types::PaymentsResponseData,+ > = connector.connector.get_connector_integration();- Ok(resp)+ connector_integration+ .build_request(self, &state.conf.connectors)+ .to_payment_failed_response()+ }+ _ => Ok(None),+ }}}diff --git a/crates/router/src/core/payments/flows/capture_flow.rs b/crates/router/src/core/payments/flows/capture_flow.rsindex c4f1cfdae4..937c3daec6 100644--- a/crates/router/src/core/payments/flows/capture_flow.rs+++ b/crates/router/src/core/payments/flows/capture_flow.rs@@ -42,18 +42,29 @@ impl Feature<api::Capture, types::PaymentsCaptureData>self,state: &AppState,connector: &api::ConnectorData,- customer: &Option<domain::Customer>,+ _customer: &Option<domain::Customer>,call_connector_action: payments::CallConnectorAction,_merchant_account: &domain::MerchantAccount,+ connector_request: Option<services::Request>,) -> RouterResult<Self> {- self.decide_flow(+ let connector_integration: services::BoxedConnectorIntegration<+ '_,+ api::Capture,+ types::PaymentsCaptureData,+ types::PaymentsResponseData,+ > = connector.connector.get_connector_integration();++ let resp = services::execute_connector_processing_step(state,- connector,- customer,- Some(true),+ connector_integration,+ &self,call_connector_action,+ connector_request,).await+ .to_payment_failed_response()?;++ Ok(resp)}async fn add_access_token<'a>(@@ -64,33 +75,27 @@ impl Feature<api::Capture, types::PaymentsCaptureData>) -> RouterResult<types::AddAccessTokenResult> {access_token::add_access_token(state, connector, merchant_account, self).await}-}-impl types::PaymentsCaptureRouterData {- #[allow(clippy::too_many_arguments)]- pub async fn decide_flow<'a, 'b>(- &'b self,- state: &'a AppState,+ async fn build_flow_specific_connector_request(+ &mut self,+ state: &AppState,connector: &api::ConnectorData,- _maybe_customer: &Option<domain::Customer>,- _confirm: Option<bool>,call_connector_action: payments::CallConnectorAction,- ) -> RouterResult<Self> {- let connector_integration: services::BoxedConnectorIntegration<- '_,- api::Capture,- types::PaymentsCaptureData,- types::PaymentsResponseData,- > = connector.connector.get_connector_integration();- let resp = services::execute_connector_processing_step(- state,- connector_integration,- self,- call_connector_action,- )- .await- .to_payment_failed_response()?;+ ) -> RouterResult<Option<services::Request>> {+ match call_connector_action {+ payments::CallConnectorAction::Trigger => {+ let connector_integration: services::BoxedConnectorIntegration<+ '_,+ api::Capture,+ types::PaymentsCaptureData,+ types::PaymentsResponseData,+ > = connector.connector.get_connector_integration();- Ok(resp)+ connector_integration+ .build_request(self, &state.conf.connectors)+ .to_payment_failed_response()+ }+ _ => Ok(None),+ }}}diff --git a/crates/router/src/core/payments/flows/complete_authorize_flow.rs b/crates/router/src/core/payments/flows/complete_authorize_flow.rsindex 65502087b8..6e2646f537 100644--- a/crates/router/src/core/payments/flows/complete_authorize_flow.rs+++ b/crates/router/src/core/payments/flows/complete_authorize_flow.rs@@ -58,18 +58,29 @@ impl Feature<api::CompleteAuthorize, types::CompleteAuthorizeData>mut self,state: &AppState,connector: &api::ConnectorData,- customer: &Option<domain::Customer>,+ _customer: &Option<domain::Customer>,call_connector_action: payments::CallConnectorAction,_merchant_account: &domain::MerchantAccount,+ connector_request: Option<services::Request>,) -> RouterResult<Self> {- self.decide_flow(+ let connector_integration: services::BoxedConnectorIntegration<+ '_,+ api::CompleteAuthorize,+ types::CompleteAuthorizeData,+ types::PaymentsResponseData,+ > = connector.connector.get_connector_integration();++ let resp = services::execute_connector_processing_step(state,- connector,- customer,- Some(true),+ connector_integration,+ &self,call_connector_action,+ connector_request,).await+ .to_payment_failed_response()?;++ Ok(resp)}async fn add_access_token<'a>(@@ -80,32 +91,27 @@ impl Feature<api::CompleteAuthorize, types::CompleteAuthorizeData>) -> RouterResult<types::AddAccessTokenResult> {access_token::add_access_token(state, connector, merchant_account, self).await}-}-impl types::PaymentsCompleteAuthorizeRouterData {- pub async fn decide_flow<'a, 'b>(- &'b mut self,- state: &'a AppState,+ async fn build_flow_specific_connector_request(+ &mut self,+ state: &AppState,connector: &api::ConnectorData,- _maybe_customer: &Option<domain::Customer>,- _confirm: Option<bool>,call_connector_action: payments::CallConnectorAction,- ) -> RouterResult<Self> {- let connector_integration: services::BoxedConnectorIntegration<- '_,- api::CompleteAuthorize,- types::CompleteAuthorizeData,- types::PaymentsResponseData,- > = connector.connector.get_connector_integration();- let resp = services::execute_connector_processing_step(- state,- connector_integration,- self,- call_connector_action,- )- .await- .to_payment_failed_response()?;+ ) -> RouterResult<Option<services::Request>> {+ match call_connector_action {+ payments::CallConnectorAction::Trigger => {+ let connector_integration: services::BoxedConnectorIntegration<+ '_,+ api::CompleteAuthorize,+ types::CompleteAuthorizeData,+ types::PaymentsResponseData,+ > = connector.connector.get_connector_integration();- Ok(resp)+ connector_integration+ .build_request(self, &state.conf.connectors)+ .to_payment_failed_response()+ }+ _ => Ok(None),+ }}}diff --git a/crates/router/src/core/payments/flows/psync_flow.rs b/crates/router/src/core/payments/flows/psync_flow.rsindex 8492d9fd32..d4d593bd9b 100644--- a/crates/router/src/core/payments/flows/psync_flow.rs+++ b/crates/router/src/core/payments/flows/psync_flow.rs@@ -43,18 +43,28 @@ impl Feature<api::PSync, types::PaymentsSyncData>self,state: &AppState,connector: &api::ConnectorData,- customer: &Option<domain::Customer>,+ _customer: &Option<domain::Customer>,call_connector_action: payments::CallConnectorAction,_merchant_account: &domain::MerchantAccount,+ connector_request: Option<services::Request>,) -> RouterResult<Self> {- self.decide_flow(+ let connector_integration: services::BoxedConnectorIntegration<+ '_,+ api::PSync,+ types::PaymentsSyncData,+ types::PaymentsResponseData,+ > = connector.connector.get_connector_integration();+ let resp = services::execute_connector_processing_step(state,- connector,- customer,- Some(true),+ connector_integration,+ &self,call_connector_action,+ connector_request,).await+ .to_payment_failed_response()?;++ Ok(resp)}async fn add_access_token<'a>(@@ -65,32 +75,27 @@ impl Feature<api::PSync, types::PaymentsSyncData>) -> RouterResult<types::AddAccessTokenResult> {access_token::add_access_token(state, connector, merchant_account, self).await}-}-impl types::PaymentsSyncRouterData {- pub async fn decide_flow<'a, 'b>(- &'b self,- state: &'a AppState,+ async fn build_flow_specific_connector_request(+ &mut self,+ state: &AppState,connector: &api::ConnectorData,- _maybe_customer: &Option<domain::Customer>,- _confirm: Option<bool>,call_connector_action: payments::CallConnectorAction,- ) -> RouterResult<Self> {- let connector_integration: services::BoxedConnectorIntegration<- '_,- api::PSync,- types::PaymentsSyncData,- types::PaymentsResponseData,- > = connector.connector.get_connector_integration();- let resp = services::execute_connector_processing_step(- state,- connector_integration,- self,- call_connector_action,- )- .await- .to_payment_failed_response()?;+ ) -> RouterResult<Option<services::Request>> {+ match call_connector_action {+ payments::CallConnectorAction::Trigger => {+ let connector_integration: services::BoxedConnectorIntegration<+ '_,+ api::PSync,+ types::PaymentsSyncData,+ types::PaymentsResponseData,+ > = connector.connector.get_connector_integration();- Ok(resp)+ connector_integration+ .build_request(self, &state.conf.connectors)+ .to_payment_failed_response()+ }+ _ => Ok(None),+ }}}diff --git a/crates/router/src/core/payments/flows/session_flow.rs b/crates/router/src/core/payments/flows/session_flow.rsindex f30ff80a48..c6be6940e5 100644--- a/crates/router/src/core/payments/flows/session_flow.rs+++ b/crates/router/src/core/payments/flows/session_flow.rs@@ -49,6 +49,7 @@ impl Feature<api::Session, types::PaymentsSessionData> for types::PaymentsSessiocustomer: &Option<domain::Customer>,call_connector_action: payments::CallConnectorAction,_merchant_account: &domain::MerchantAccount,+ _connector_request: Option<services::Request>,) -> RouterResult<Self> {metrics::SESSION_TOKEN_CREATED.add(&metrics::CONTEXT,@@ -371,6 +372,7 @@ impl types::PaymentsSessionRouterData {connector_integration,self,call_connector_action,+ None,).await.to_payment_failed_response()?;diff --git a/crates/router/src/core/payments/flows/verify_flow.rs b/crates/router/src/core/payments/flows/verify_flow.rsindex 0b37dce2d8..274ad4fcdc 100644--- a/crates/router/src/core/payments/flows/verify_flow.rs+++ b/crates/router/src/core/payments/flows/verify_flow.rs@@ -40,19 +40,37 @@ impl Feature<api::Verify, types::VerifyRequestData> for types::VerifyRouterDataself,state: &AppState,connector: &api::ConnectorData,- customer: &Option<domain::Customer>,+ maybe_customer: &Option<domain::Customer>,call_connector_action: payments::CallConnectorAction,merchant_account: &domain::MerchantAccount,+ connector_request: Option<services::Request>,) -> RouterResult<Self> {- self.decide_flow(+ let connector_integration: services::BoxedConnectorIntegration<+ '_,+ api::Verify,+ types::VerifyRequestData,+ types::PaymentsResponseData,+ > = connector.connector.get_connector_integration();+ let resp = services::execute_connector_processing_step(state,- connector,- customer,- Some(true),+ connector_integration,+ &self,call_connector_action,- merchant_account,+ connector_request,).await+ .to_verify_failed_response()?;++ let pm_id = tokenization::save_payment_method(+ state,+ connector,+ resp.to_owned(),+ maybe_customer,+ merchant_account,+ )+ .await?;++ mandate::mandate_procedure(state, resp, maybe_customer, pm_id).await}async fn add_access_token<'a>(@@ -93,6 +111,29 @@ impl Feature<api::Verify, types::VerifyRequestData> for types::VerifyRouterData).await}++ async fn build_flow_specific_connector_request(+ &mut self,+ state: &AppState,+ connector: &api::ConnectorData,+ call_connector_action: payments::CallConnectorAction,+ ) -> RouterResult<Option<services::Request>> {+ match call_connector_action {+ payments::CallConnectorAction::Trigger => {+ let connector_integration: services::BoxedConnectorIntegration<+ '_,+ api::Verify,+ types::VerifyRequestData,+ types::PaymentsResponseData,+ > = connector.connector.get_connector_integration();++ connector_integration+ .build_request(self, &state.conf.connectors)+ .to_payment_failed_response()+ }+ _ => Ok(None),+ }+ }}impl TryFrom<types::VerifyRequestData> for types::ConnectorCustomerData {@@ -131,6 +172,7 @@ impl types::VerifyRouterData {connector_integration,self,call_connector_action,+ None,).await.to_verify_failed_response()?;diff --git a/crates/router/src/core/payments/operations.rs b/crates/router/src/core/payments/operations.rsindex c253a23315..0a61dd8755 100644--- a/crates/router/src/core/payments/operations.rs+++ b/crates/router/src/core/payments/operations.rs@@ -136,7 +136,6 @@ pub trait UpdateTracker<F, D, Req>: Send {async fn update_trackers<'b>(&'b self,db: &dyn StorageInterface,- payment_id: &api::PaymentIdType,payment_data: D,customer: Option<domain::Customer>,storage_scheme: enums::MerchantStorageScheme,diff --git a/crates/router/src/core/payments/operations/payment_cancel.rs b/crates/router/src/core/payments/operations/payment_cancel.rsindex f06bf9e252..0b32c0629a 100644--- a/crates/router/src/core/payments/operations/payment_cancel.rs+++ b/crates/router/src/core/payments/operations/payment_cancel.rs@@ -62,7 +62,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsCancelRequest>enums::IntentStatus::Processing,enums::IntentStatus::RequiresMerchantAction,],- "cancelled",+ "cancel",)?;let mut payment_attempt = db@@ -166,7 +166,6 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsCancelRequest> forasync fn update_trackers<'b>(&'b self,db: &dyn StorageInterface,- _payment_id: &api::PaymentIdType,mut payment_data: PaymentData<F>,_customer: Option<domain::Customer>,storage_scheme: enums::MerchantStorageScheme,diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rsindex cedc9d7a6d..621871d326 100644--- a/crates/router/src/core/payments/operations/payment_capture.rs+++ b/crates/router/src/core/payments/operations/payment_capture.rs@@ -174,7 +174,6 @@ impl<F: Clone> UpdateTracker<F, payments::PaymentData<F>, api::PaymentsCaptureReasync fn update_trackers<'b>(&'b self,_db: &dyn StorageInterface,- _payment_id: &api::PaymentIdType,payment_data: payments::PaymentData<F>,_customer: Option<domain::Customer>,_storage_scheme: enums::MerchantStorageScheme,diff --git a/crates/router/src/core/payments/operations/payment_complete_authorize.rs b/crates/router/src/core/payments/operations/payment_complete_authorize.rsindex 6f7bb3494e..4618076a16 100644--- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs+++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs@@ -292,7 +292,6 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Compleasync fn update_trackers<'b>(&'b self,_db: &dyn StorageInterface,- _payment_id: &api::PaymentIdType,payment_data: PaymentData<F>,_customer: Option<domain::Customer>,_storage_scheme: storage_enums::MerchantStorageScheme,diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rsindex bf80059e7d..2ee8b49962 100644--- a/crates/router/src/core/payments/operations/payment_confirm.rs+++ b/crates/router/src/core/payments/operations/payment_confirm.rs@@ -343,7 +343,6 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymenasync fn update_trackers<'b>(&'b self,db: &dyn StorageInterface,- _payment_id: &api::PaymentIdType,mut payment_data: PaymentData<F>,customer: Option<domain::Customer>,storage_scheme: storage_enums::MerchantStorageScheme,diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rsindex 563bdf4c9a..3754431d2f 100644--- a/crates/router/src/core/payments/operations/payment_create.rs+++ b/crates/router/src/core/payments/operations/payment_create.rs@@ -328,7 +328,6 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymenasync fn update_trackers<'b>(&'b self,db: &dyn StorageInterface,- _payment_id: &api::PaymentIdType,mut payment_data: PaymentData<F>,_customer: Option<domain::Customer>,storage_scheme: enums::MerchantStorageScheme,@@ -344,6 +343,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen},IntentStatus::RequiresConfirmation => {if let Some(true) = payment_data.confirm {+ //TODO: do this later, request validation should happen beforeSome(IntentStatus::Processing)} else {Nonediff --git a/crates/router/src/core/payments/operations/payment_method_validate.rs b/crates/router/src/core/payments/operations/payment_method_validate.rsindex ffdbe36c32..15d6ba59db 100644--- a/crates/router/src/core/payments/operations/payment_method_validate.rs+++ b/crates/router/src/core/payments/operations/payment_method_validate.rs@@ -201,7 +201,6 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::VerifyRequest> for PaymentMasync fn update_trackers<'b>(&'b self,db: &dyn StorageInterface,- _payment_id: &api::PaymentIdType,mut payment_data: PaymentData<F>,_customer: Option<domain::Customer>,storage_scheme: storage_enums::MerchantStorageScheme,diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rsindex 829951671b..9576eec59a 100644--- a/crates/router/src/core/payments/operations/payment_session.rs+++ b/crates/router/src/core/payments/operations/payment_session.rs@@ -185,7 +185,6 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsSessionRequest> forasync fn update_trackers<'b>(&'b self,db: &dyn StorageInterface,- _payment_id: &api::PaymentIdType,mut payment_data: PaymentData<F>,_customer: Option<domain::Customer>,storage_scheme: storage_enums::MerchantStorageScheme,diff --git a/crates/router/src/core/payments/operations/payment_start.rs b/crates/router/src/core/payments/operations/payment_start.rsindex 5cb6613a28..0c2fa20584 100644--- a/crates/router/src/core/payments/operations/payment_start.rs+++ b/crates/router/src/core/payments/operations/payment_start.rs@@ -157,7 +157,6 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsStartRequest> for Pasync fn update_trackers<'b>(&'b self,_db: &dyn StorageInterface,- _payment_id: &api::PaymentIdType,payment_data: PaymentData<F>,_customer: Option<domain::Customer>,_storage_scheme: storage_enums::MerchantStorageScheme,diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rsindex ff102a8791..7220ae3908 100644--- a/crates/router/src/core/payments/operations/payment_status.rs+++ b/crates/router/src/core/payments/operations/payment_status.rs@@ -112,7 +112,6 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymenasync fn update_trackers<'b>(&'b self,_db: &dyn StorageInterface,- _payment_id: &api::PaymentIdType,payment_data: PaymentData<F>,_customer: Option<domain::Customer>,_storage_scheme: enums::MerchantStorageScheme,@@ -130,7 +129,6 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRetrieveRequest> foasync fn update_trackers<'b>(&'b self,_db: &dyn StorageInterface,- _payment_id: &api::PaymentIdType,payment_data: PaymentData<F>,_customer: Option<domain::Customer>,_storage_scheme: enums::MerchantStorageScheme,diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rsindex 4b8ebd4abb..01e5498db1 100644--- a/crates/router/src/core/payments/operations/payment_update.rs+++ b/crates/router/src/core/payments/operations/payment_update.rs@@ -371,7 +371,6 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymenasync fn update_trackers<'b>(&'b self,db: &dyn StorageInterface,- _payment_id: &api::PaymentIdType,mut payment_data: PaymentData<F>,customer: Option<domain::Customer>,storage_scheme: storage_enums::MerchantStorageScheme,diff --git a/crates/router/src/core/payments/tokenization.rs b/crates/router/src/core/payments/tokenization.rsindex 34176380b8..b60d9a68aa 100644--- a/crates/router/src/core/payments/tokenization.rs+++ b/crates/router/src/core/payments/tokenization.rs@@ -227,6 +227,7 @@ pub async fn add_payment_method_token<F: Clone, T: Clone>(connector_integration,&pm_token_router_data,payments::CallConnectorAction::Trigger,+ None,).await.to_payment_failed_response()?;diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rsindex 810e12f462..32e41ae994 100644--- a/crates/router/src/core/refunds.rs+++ b/crates/router/src/core/refunds.rs@@ -189,6 +189,7 @@ pub async fn trigger_refund_to_gateway(connector_integration,&router_data,payments::CallConnectorAction::Trigger,+ None,).await.to_refund_failed_response()?@@ -408,6 +409,7 @@ pub async fn sync_refund_with_gateway(connector_integration,&router_data,payments::CallConnectorAction::Trigger,+ None,).await.to_refund_failed_response()?diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rsindex cc4ce8d00b..26cec958c0 100644--- a/crates/router/src/services/api.rs+++ b/crates/router/src/services/api.rs@@ -186,6 +186,9 @@ pub trait ConnectorIntegration<T, Req, Resp>: ConnectorIntegrationAny<T, Req, Re}}+/// Handle the flow by interacting with connector module+/// `connector_request` is applicable only in case if the `CallConnectorAction` is `Trigger`+/// In other cases, It will be created if required, even if it is not passed#[instrument(skip_all)]pub async fn execute_connector_processing_step<'b,@@ -198,6 +201,7 @@ pub async fn execute_connector_processing_step<connector_integration: BoxedConnectorIntegration<'a, T, Req, Resp>,req: &'b types::RouterData<T, Req, Resp>,call_connector_action: payments::CallConnectorAction,+ connector_request: Option<Request>,) -> CustomResult<types::RouterData<T, Req, Resp>, errors::ConnectorError>whereT: Clone + Debug,@@ -252,7 +256,8 @@ where),],);- match connector_integration++ let connector_request = connector_request.or(connector_integration.build_request(req, &state.conf.connectors).map_err(|error| {if matches!(@@ -260,7 +265,7 @@ where&errors::ConnectorError::RequestEncodingFailed| &errors::ConnectorError::RequestEncodingFailedWithReason(_)) {- metrics::RESPONSE_DESERIALIZATION_FAILURE.add(+ metrics::REQUEST_BUILD_FAILURE.add(&metrics::CONTEXT,1,&[metrics::request::add_attributes(@@ -270,7 +275,9 @@ where)}error- })? {+ })?);++ match connector_request {Some(request) => {logger::debug!(connector_request=?request);let response = call_connector_api(state, request).await;diff --git a/crates/router/tests/connectors/aci.rs b/crates/router/tests/connectors/aci.rsindex 6211dc24c3..168710e370 100644--- a/crates/router/tests/connectors/aci.rs+++ b/crates/router/tests/connectors/aci.rs@@ -148,6 +148,7 @@ async fn payments_create_success() {connector_integration,&request,payments::CallConnectorAction::Trigger,+ None,).await.unwrap();@@ -193,6 +194,7 @@ async fn payments_create_failure() {connector_integration,&request,payments::CallConnectorAction::Trigger,+ None,).await.is_err();@@ -225,6 +227,7 @@ async fn refund_for_successful_payments() {connector_integration,&request,payments::CallConnectorAction::Trigger,+ None,).await.unwrap();@@ -250,6 +253,7 @@ async fn refund_for_successful_payments() {connector_integration,&refund_request,payments::CallConnectorAction::Trigger,+ None,).await.unwrap();@@ -285,6 +289,7 @@ async fn refunds_create_failure() {connector_integration,&request,payments::CallConnectorAction::Trigger,+ None,).await.is_err();diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rsindex 9470b23f2b..927963ec0c 100644--- a/crates/router/tests/connectors/utils.rs+++ b/crates/router/tests/connectors/utils.rs@@ -442,6 +442,7 @@ async fn call_connector<integration,&request,payments::CallConnectorAction::Trigger,+ None,).await}