From 8029a895b2c27a1ac14a19aea23bbc06cc364809 Mon Sep 17 00:00:00 2001 From: SamraatBansal <55536657+SamraatBansal@users.noreply.github.com> Date: Thu, 12 Oct 2023 20:14:53 +0530 Subject: [PATCH] fix(connector): Trigger Psync after redirection url (#2422) --- .../router/src/connector/authorizedotnet.rs | 8 ++- crates/router/src/connector/bambora.rs | 8 ++- crates/router/src/connector/bluesnap.rs | 49 ++++++++++--------- crates/router/src/connector/checkout.rs | 24 +++------ crates/router/src/connector/globalpay.rs | 25 +++------- crates/router/src/connector/mollie.rs | 8 ++- crates/router/src/connector/noon.rs | 8 ++- crates/router/src/connector/payme.rs | 8 ++- crates/router/src/connector/paypal.rs | 8 ++- crates/router/src/connector/stripe.rs | 33 +++---------- crates/router/src/connector/trustpay.rs | 25 +++------- crates/router/src/connector/zen.rs | 8 ++- crates/router/src/services/api.rs | 2 +- 13 files changed, 98 insertions(+), 116 deletions(-) diff --git a/crates/router/src/connector/authorizedotnet.rs b/crates/router/src/connector/authorizedotnet.rs index 8e98fc5843..99e87ca1ed 100644 --- a/crates/router/src/connector/authorizedotnet.rs +++ b/crates/router/src/connector/authorizedotnet.rs @@ -878,8 +878,12 @@ impl services::ConnectorRedirectResponse for Authorizedotnet { &self, _query_params: &str, _json_payload: Option, - _action: services::PaymentAction, + action: services::PaymentAction, ) -> CustomResult { - Ok(payments::CallConnectorAction::Trigger) + match action { + services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => { + Ok(payments::CallConnectorAction::Trigger) + } + } } } diff --git a/crates/router/src/connector/bambora.rs b/crates/router/src/connector/bambora.rs index b59645a409..d5e8119b66 100644 --- a/crates/router/src/connector/bambora.rs +++ b/crates/router/src/connector/bambora.rs @@ -692,9 +692,13 @@ impl services::ConnectorRedirectResponse for Bambora { &self, _query_params: &str, _json_payload: Option, - _action: services::PaymentAction, + action: services::PaymentAction, ) -> CustomResult { - Ok(payments::CallConnectorAction::Trigger) + match action { + services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => { + Ok(payments::CallConnectorAction::Trigger) + } + } } } diff --git a/crates/router/src/connector/bluesnap.rs b/crates/router/src/connector/bluesnap.rs index 7a867ed56c..24d5787aa8 100644 --- a/crates/router/src/connector/bluesnap.rs +++ b/crates/router/src/connector/bluesnap.rs @@ -1095,31 +1095,36 @@ impl services::ConnectorRedirectResponse for Bluesnap { &self, _query_params: &str, json_payload: Option, - _action: services::PaymentAction, + action: services::PaymentAction, ) -> CustomResult { - let redirection_response: bluesnap::BluesnapRedirectionResponse = json_payload - .ok_or(errors::ConnectorError::MissingConnectorRedirectionPayload { - field_name: "json_payload", - })? - .parse_value("BluesnapRedirectionResponse") - .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; + match action { + services::PaymentAction::PSync => Ok(payments::CallConnectorAction::Trigger), + services::PaymentAction::CompleteAuthorize => { + let redirection_response: bluesnap::BluesnapRedirectionResponse = json_payload + .ok_or(errors::ConnectorError::MissingConnectorRedirectionPayload { + field_name: "json_payload", + })? + .parse_value("BluesnapRedirectionResponse") + .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; - let redirection_result: bluesnap::BluesnapThreeDsResult = redirection_response - .authentication_response - .parse_struct("BluesnapThreeDsResult") - .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; + let redirection_result: bluesnap::BluesnapThreeDsResult = redirection_response + .authentication_response + .parse_struct("BluesnapThreeDsResult") + .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; - match redirection_result.status.as_str() { - "Success" => Ok(payments::CallConnectorAction::Trigger), - _ => Ok(payments::CallConnectorAction::StatusUpdate { - status: enums::AttemptStatus::AuthenticationFailed, - error_code: redirection_result.code, - error_message: redirection_result - .info - .as_ref() - .and_then(|info| info.errors.as_ref().and_then(|error| error.first())) - .cloned(), - }), + match redirection_result.status.as_str() { + "Success" => Ok(payments::CallConnectorAction::Trigger), + _ => Ok(payments::CallConnectorAction::StatusUpdate { + status: enums::AttemptStatus::AuthenticationFailed, + error_code: redirection_result.code, + error_message: redirection_result + .info + .as_ref() + .and_then(|info| info.errors.as_ref().and_then(|error| error.first())) + .cloned(), + }), + } + } } } } diff --git a/crates/router/src/connector/checkout.rs b/crates/router/src/connector/checkout.rs index 52c4351287..f4cc4ac964 100644 --- a/crates/router/src/connector/checkout.rs +++ b/crates/router/src/connector/checkout.rs @@ -1289,25 +1289,15 @@ impl api::IncomingWebhook for Checkout { impl services::ConnectorRedirectResponse for Checkout { fn get_flow_type( &self, - query_params: &str, + _query_params: &str, _json_payload: Option, - _action: services::PaymentAction, + action: services::PaymentAction, ) -> CustomResult { - let query = - serde_urlencoded::from_str::(query_params) - .into_report() - .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; - let connector_action = query - .status - .map( - |checkout_status| payments::CallConnectorAction::StatusUpdate { - status: diesel_models::enums::AttemptStatus::from(checkout_status), - error_code: None, - error_message: None, - }, - ) - .unwrap_or(payments::CallConnectorAction::Trigger); - Ok(connector_action) + match action { + services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => { + Ok(payments::CallConnectorAction::Trigger) + } + } } } diff --git a/crates/router/src/connector/globalpay.rs b/crates/router/src/connector/globalpay.rs index 5b545c0d01..dfcddae777 100644 --- a/crates/router/src/connector/globalpay.rs +++ b/crates/router/src/connector/globalpay.rs @@ -926,25 +926,14 @@ impl api::IncomingWebhook for Globalpay { impl services::ConnectorRedirectResponse for Globalpay { fn get_flow_type( &self, - query_params: &str, + _query_params: &str, _json_payload: Option, - _action: services::PaymentAction, + action: services::PaymentAction, ) -> CustomResult { - let query = serde_urlencoded::from_str::(query_params) - .into_report() - .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; - Ok(query.status.map_or( - payments::CallConnectorAction::Trigger, - |status| match status { - response::GlobalpayPaymentStatus::Captured => { - payments::CallConnectorAction::StatusUpdate { - status: diesel_models::enums::AttemptStatus::from(status), - error_code: None, - error_message: None, - } - } - _ => payments::CallConnectorAction::Trigger, - }, - )) + match action { + services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => { + Ok(payments::CallConnectorAction::Trigger) + } + } } } diff --git a/crates/router/src/connector/mollie.rs b/crates/router/src/connector/mollie.rs index d0b2b635fc..38abed9dea 100644 --- a/crates/router/src/connector/mollie.rs +++ b/crates/router/src/connector/mollie.rs @@ -566,8 +566,12 @@ impl services::ConnectorRedirectResponse for Mollie { &self, _query_params: &str, _json_payload: Option, - _action: services::PaymentAction, + action: services::PaymentAction, ) -> CustomResult { - Ok(payments::CallConnectorAction::Trigger) + match action { + services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => { + Ok(payments::CallConnectorAction::Trigger) + } + } } } diff --git a/crates/router/src/connector/noon.rs b/crates/router/src/connector/noon.rs index 771c444a43..a8800ebcbe 100644 --- a/crates/router/src/connector/noon.rs +++ b/crates/router/src/connector/noon.rs @@ -621,9 +621,13 @@ impl services::ConnectorRedirectResponse for Noon { &self, _query_params: &str, _json_payload: Option, - _action: services::PaymentAction, + action: services::PaymentAction, ) -> CustomResult { - Ok(payments::CallConnectorAction::Trigger) + match action { + services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => { + Ok(payments::CallConnectorAction::Trigger) + } + } } } diff --git a/crates/router/src/connector/payme.rs b/crates/router/src/connector/payme.rs index 92a19d4296..e0d6229c00 100644 --- a/crates/router/src/connector/payme.rs +++ b/crates/router/src/connector/payme.rs @@ -340,9 +340,13 @@ impl services::ConnectorRedirectResponse for Payme { &self, _query_params: &str, _json_payload: Option, - _action: services::PaymentAction, + action: services::PaymentAction, ) -> CustomResult { - Ok(payments::CallConnectorAction::Trigger) + match action { + services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => { + Ok(payments::CallConnectorAction::Trigger) + } + } } } diff --git a/crates/router/src/connector/paypal.rs b/crates/router/src/connector/paypal.rs index 1faee2a16b..1f872868a0 100644 --- a/crates/router/src/connector/paypal.rs +++ b/crates/router/src/connector/paypal.rs @@ -1150,8 +1150,12 @@ impl services::ConnectorRedirectResponse for Paypal { &self, _query_params: &str, _json_payload: Option, - _action: PaymentAction, + action: PaymentAction, ) -> CustomResult { - Ok(payments::CallConnectorAction::Trigger) + match action { + services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => { + Ok(payments::CallConnectorAction::Trigger) + } + } } } diff --git a/crates/router/src/connector/stripe.rs b/crates/router/src/connector/stripe.rs index 734dca3016..ff89882543 100644 --- a/crates/router/src/connector/stripe.rs +++ b/crates/router/src/connector/stripe.rs @@ -1962,33 +1962,14 @@ impl api::IncomingWebhook for Stripe { impl services::ConnectorRedirectResponse for Stripe { fn get_flow_type( &self, - query_params: &str, + _query_params: &str, _json_payload: Option, - _action: services::PaymentAction, + action: services::PaymentAction, ) -> CustomResult { - let query = - serde_urlencoded::from_str::(query_params) - .into_report() - .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; - - crate::logger::debug!(stripe_redirect_response=?query); - - Ok(query - .redirect_status - .map_or( - payments::CallConnectorAction::Trigger, - |status| match status { - transformers::StripePaymentStatus::Failed - | transformers::StripePaymentStatus::Pending - | transformers::StripePaymentStatus::Succeeded => { - payments::CallConnectorAction::Trigger - } - _ => payments::CallConnectorAction::StatusUpdate { - status: enums::AttemptStatus::from(status), - error_code: None, - error_message: None, - }, - }, - )) + match action { + services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => { + Ok(payments::CallConnectorAction::Trigger) + } + } } } diff --git a/crates/router/src/connector/trustpay.rs b/crates/router/src/connector/trustpay.rs index f182b44497..b631a9611c 100644 --- a/crates/router/src/connector/trustpay.rs +++ b/crates/router/src/connector/trustpay.rs @@ -956,26 +956,15 @@ impl api::IncomingWebhook for Trustpay { impl services::ConnectorRedirectResponse for Trustpay { fn get_flow_type( &self, - query_params: &str, + _query_params: &str, _json_payload: Option, - _action: services::PaymentAction, + action: services::PaymentAction, ) -> CustomResult { - let query = - serde_urlencoded::from_str::(query_params) - .into_report() - .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; - crate::logger::debug!(trustpay_redirect_response=?query); - Ok(query.status.map_or( - payments::CallConnectorAction::Trigger, - |status| match status.as_str() { - "SuccessOk" => payments::CallConnectorAction::StatusUpdate { - status: diesel_models::enums::AttemptStatus::Charged, - error_code: None, - error_message: None, - }, - _ => payments::CallConnectorAction::Trigger, - }, - )) + match action { + services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => { + Ok(payments::CallConnectorAction::Trigger) + } + } } } diff --git a/crates/router/src/connector/zen.rs b/crates/router/src/connector/zen.rs index f65cb02b94..d93075c373 100644 --- a/crates/router/src/connector/zen.rs +++ b/crates/router/src/connector/zen.rs @@ -683,8 +683,12 @@ impl services::ConnectorRedirectResponse for Zen { &self, _query_params: &str, _json_payload: Option, - _action: services::PaymentAction, + action: services::PaymentAction, ) -> CustomResult { - Ok(payments::CallConnectorAction::Trigger) + match action { + services::PaymentAction::PSync | services::PaymentAction::CompleteAuthorize => { + Ok(payments::CallConnectorAction::Trigger) + } + } } } diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index 8506e26f58..6fe4c01cc2 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -1212,7 +1212,7 @@ pub fn build_redirection_form( (PreEscaped(format!("