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(connector): [Adyen] Status mapping based on Payment method Type (#3567)
Swangi Kumariab6b5ab7b4cc
diff --git a/crates/router/src/connector/adyen.rs b/crates/router/src/connector/adyen.rsindex 84db2675b0..fa9a5617ff 100644--- a/crates/router/src/connector/adyen.rs+++ b/crates/router/src/connector/adyen.rs@@ -233,6 +233,7 @@ impl},None,false,+ data.request.payment_method_type,)).change_context(errors::ConnectorError::ResponseHandlingFailed)}@@ -506,6 +507,7 @@ impl},data.request.capture_method,is_multiple_capture_sync,+ data.request.payment_method_type,)).change_context(errors::ConnectorError::ResponseHandlingFailed)}@@ -627,6 +629,7 @@ impl},data.request.capture_method,false,+ data.request.payment_method_type,)).change_context(errors::ConnectorError::ResponseHandlingFailed)}diff --git a/crates/router/src/connector/adyen/transformers.rs b/crates/router/src/connector/adyen/transformers.rsindex aeb343bf81..0d8343b0c8 100644--- a/crates/router/src/connector/adyen/transformers.rs+++ b/crates/router/src/connector/adyen/transformers.rs@@ -217,22 +217,33 @@ pub struct AdyenBalanceResponse {/// This implementation will be used only in Authorize, Automatic capture flow./// It is also being used in Psync flow, However Psync will be called only after create payment call that too in redirect flow.-impl ForeignFrom<(bool, AdyenStatus)> for storage_enums::AttemptStatus {- fn foreign_from((is_manual_capture, adyen_status): (bool, AdyenStatus)) -> Self {+impl ForeignFrom<(bool, AdyenStatus, Option<common_enums::PaymentMethodType>)>+ for storage_enums::AttemptStatus+{+ fn foreign_from(+ (is_manual_capture, adyen_status, pmt): (+ bool,+ AdyenStatus,+ Option<common_enums::PaymentMethodType>,+ ),+ ) -> Self {match adyen_status {AdyenStatus::AuthenticationFinished => Self::AuthenticationSuccessful,- AdyenStatus::AuthenticationNotRequired | AdyenStatus::PresentToShopper => Self::Pending,+ AdyenStatus::AuthenticationNotRequired => Self::Pending,AdyenStatus::Authorised => match is_manual_capture {true => Self::Authorized,// In case of Automatic capture Authorized is the final status of the paymentfalse => Self::Charged,},AdyenStatus::Cancelled => Self::Voided,- AdyenStatus::ChallengeShopper | AdyenStatus::RedirectShopper => {- Self::AuthenticationPending- }+ AdyenStatus::ChallengeShopper+ | AdyenStatus::RedirectShopper+ | AdyenStatus::PresentToShopper => Self::AuthenticationPending,AdyenStatus::Error | AdyenStatus::Refused => Self::Failure,- AdyenStatus::Pending => Self::Pending,+ AdyenStatus::Pending => match pmt {+ Some(common_enums::PaymentMethodType::Pix) => Self::AuthenticationPending,+ _ => Self::Pending,+ },AdyenStatus::Received => Self::Started,#[cfg(feature = "payouts")]AdyenStatus::PayoutConfirmReceived => Self::Started,@@ -3001,6 +3012,7 @@ pub fn get_adyen_response(response: Response,is_capture_manual: bool,status_code: u16,+ pmt: Option<enums::PaymentMethodType>,) -> errors::CustomResult<(storage_enums::AttemptStatus,@@ -3010,7 +3022,7 @@ pub fn get_adyen_response(errors::ConnectorError,> {let status =- storage_enums::AttemptStatus::foreign_from((is_capture_manual, response.result_code));+ storage_enums::AttemptStatus::foreign_from((is_capture_manual, response.result_code, pmt));let status = update_attempt_status_based_on_event_type_if_needed(status, &response.event_code);let error = if response.refusal_reason.is_some() || response.refusal_reason_code.is_some() {Some(types::ErrorResponse {@@ -3056,6 +3068,7 @@ pub fn get_adyen_response(pub fn get_adyen_response_for_multiple_partial_capture(response: Response,status_code: u16,+ pmt: Option<enums::PaymentMethodType>,) -> errors::CustomResult<(storage_enums::AttemptStatus,@@ -3064,7 +3077,7 @@ pub fn get_adyen_response_for_multiple_partial_capture(),errors::ConnectorError,> {- let (status, error, _) = get_adyen_response(response.clone(), true, status_code)?;+ let (status, error, _) = get_adyen_response(response.clone(), true, status_code, pmt)?;let status = update_attempt_status_based_on_event_type_if_needed(status, &response.event_code);let capture_sync_response_list = utils::construct_captures_response_hashmap(vec![response]);Ok((@@ -3093,6 +3106,7 @@ pub fn get_redirection_response(response: RedirectionResponse,is_manual_capture: bool,status_code: u16,+ pmt: Option<enums::PaymentMethodType>,) -> errors::CustomResult<(storage_enums::AttemptStatus,@@ -3104,6 +3118,7 @@ pub fn get_redirection_response(let status = storage_enums::AttemptStatus::foreign_from((is_manual_capture,response.result_code.clone(),+ pmt,));let error = if response.refusal_reason.is_some() || response.refusal_reason_code.is_some() {Some(types::ErrorResponse {@@ -3157,6 +3172,7 @@ pub fn get_present_to_shopper_response(response: PresentToShopperResponse,is_manual_capture: bool,status_code: u16,+ pmt: Option<enums::PaymentMethodType>,) -> errors::CustomResult<(storage_enums::AttemptStatus,@@ -3168,6 +3184,7 @@ pub fn get_present_to_shopper_response(let status = storage_enums::AttemptStatus::foreign_from((is_manual_capture,response.result_code.clone(),+ pmt,));let error = if response.refusal_reason.is_some() || response.refusal_reason_code.is_some() {Some(types::ErrorResponse {@@ -3209,6 +3226,7 @@ pub fn get_qr_code_response(response: QrCodeResponseResponse,is_manual_capture: bool,status_code: u16,+ pmt: Option<enums::PaymentMethodType>,) -> errors::CustomResult<(storage_enums::AttemptStatus,@@ -3220,6 +3238,7 @@ pub fn get_qr_code_response(let status = storage_enums::AttemptStatus::foreign_from((is_manual_capture,response.result_code.clone(),+ pmt,));let error = if response.refusal_reason.is_some() || response.refusal_reason_code.is_some() {Some(types::ErrorResponse {@@ -3258,6 +3277,7 @@ pub fn get_redirection_error_response(response: RedirectionErrorResponse,is_manual_capture: bool,status_code: u16,+ pmt: Option<enums::PaymentMethodType>,) -> errors::CustomResult<(storage_enums::AttemptStatus,@@ -3267,7 +3287,7 @@ pub fn get_redirection_error_response(errors::ConnectorError,> {let status =- storage_enums::AttemptStatus::foreign_from((is_manual_capture, response.result_code));+ storage_enums::AttemptStatus::foreign_from((is_manual_capture, response.result_code, pmt));let error = Some(types::ErrorResponse {code: status.to_string(),message: response.refusal_reason.clone(),@@ -3548,36 +3568,38 @@ impl<F, Req>types::ResponseRouterData<F, AdyenPaymentResponse, Req, types::PaymentsResponseData>,Option<storage_enums::CaptureMethod>,bool,+ Option<enums::PaymentMethodType>,)> for types::RouterData<F, Req, types::PaymentsResponseData>{type Error = Error;fn try_from(- (item, capture_method, is_multiple_capture_psync_flow): (+ (item, capture_method, is_multiple_capture_psync_flow, pmt): (types::ResponseRouterData<F, AdyenPaymentResponse, Req, types::PaymentsResponseData>,Option<storage_enums::CaptureMethod>,bool,+ Option<enums::PaymentMethodType>,),) -> Result<Self, Self::Error> {let is_manual_capture = utils::is_manual_capture(capture_method);let (status, error, payment_response_data) = match item.response {AdyenPaymentResponse::Response(response) => {if is_multiple_capture_psync_flow {- get_adyen_response_for_multiple_partial_capture(*response, item.http_code)?+ get_adyen_response_for_multiple_partial_capture(*response, item.http_code, pmt)?} else {- get_adyen_response(*response, is_manual_capture, item.http_code)?+ get_adyen_response(*response, is_manual_capture, item.http_code, pmt)?}}AdyenPaymentResponse::PresentToShopper(response) => {- get_present_to_shopper_response(*response, is_manual_capture, item.http_code)?+ get_present_to_shopper_response(*response, is_manual_capture, item.http_code, pmt)?}AdyenPaymentResponse::QrCodeResponse(response) => {- get_qr_code_response(*response, is_manual_capture, item.http_code)?+ get_qr_code_response(*response, is_manual_capture, item.http_code, pmt)?}AdyenPaymentResponse::RedirectionResponse(response) => {- get_redirection_response(*response, is_manual_capture, item.http_code)?+ get_redirection_response(*response, is_manual_capture, item.http_code, pmt)?}AdyenPaymentResponse::RedirectionErrorResponse(response) => {- get_redirection_error_response(*response, is_manual_capture, item.http_code)?+ get_redirection_error_response(*response, is_manual_capture, item.http_code, pmt)?}};diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rsindex 1b4b2fc9fc..e92a924bf1 100644--- a/crates/router/src/core/payments/transformers.rs+++ b/crates/router/src/core/payments/transformers.rs@@ -1160,6 +1160,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsSyncData),None => types::SyncRequestType::SinglePaymentSync,},+ payment_method_type: payment_data.payment_attempt.payment_method_type,})}}diff --git a/crates/router/src/types.rs b/crates/router/src/types.rsindex 10e13a6af5..e163de9a5d 100644--- a/crates/router/src/types.rs+++ b/crates/router/src/types.rs@@ -534,6 +534,7 @@ pub struct PaymentsSyncData {pub connector_meta: Option<serde_json::Value>,pub sync_type: SyncRequestType,pub mandate_id: Option<api_models::payments::MandateIds>,+ pub payment_method_type: Option<storage_enums::PaymentMethodType>,}#[derive(Debug, Default, Clone)]diff --git a/crates/router/tests/connectors/bambora.rs b/crates/router/tests/connectors/bambora.rsindex c4da2b900d..9da29bb303 100644--- a/crates/router/tests/connectors/bambora.rs+++ b/crates/router/tests/connectors/bambora.rs@@ -109,6 +109,7 @@ async fn should_sync_authorized_payment() {capture_method: Some(diesel_models::enums::CaptureMethod::Manual),sync_type: types::SyncRequestType::SinglePaymentSync,connector_meta: None,+ payment_method_type: None,}),None,)@@ -223,6 +224,7 @@ async fn should_sync_auto_captured_payment() {capture_method: Some(enums::CaptureMethod::Automatic),sync_type: types::SyncRequestType::SinglePaymentSync,connector_meta: None,+ payment_method_type: None,}),None,)diff --git a/crates/router/tests/connectors/forte.rs b/crates/router/tests/connectors/forte.rsindex f0c182d62a..fdc6647c86 100644--- a/crates/router/tests/connectors/forte.rs+++ b/crates/router/tests/connectors/forte.rs@@ -154,6 +154,7 @@ async fn should_sync_authorized_payment() {sync_type: types::SyncRequestType::SinglePaymentSync,connector_meta: None,mandate_id: None,+ payment_method_type: None,}),get_default_payment_info(),)diff --git a/crates/router/tests/connectors/nexinets.rs b/crates/router/tests/connectors/nexinets.rsindex ff4a283e67..174e49fbc8 100644--- a/crates/router/tests/connectors/nexinets.rs+++ b/crates/router/tests/connectors/nexinets.rs@@ -124,6 +124,7 @@ async fn should_sync_authorized_payment() {sync_type: types::SyncRequestType::SinglePaymentSync,connector_meta,mandate_id: None,+ payment_method_type: None,}),None,)diff --git a/crates/router/tests/connectors/paypal.rs b/crates/router/tests/connectors/paypal.rsindex bfd2620e3f..874f6cda1d 100644--- a/crates/router/tests/connectors/paypal.rs+++ b/crates/router/tests/connectors/paypal.rs@@ -141,6 +141,7 @@ async fn should_sync_authorized_payment() {capture_method: None,sync_type: types::SyncRequestType::SinglePaymentSync,connector_meta,+ payment_method_type: None,}),get_default_payment_info(),)@@ -337,6 +338,7 @@ async fn should_sync_auto_captured_payment() {capture_method: Some(enums::CaptureMethod::Automatic),sync_type: types::SyncRequestType::SinglePaymentSync,connector_meta,+ payment_method_type: None,}),get_default_payment_info(),)diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rsindex 844777e2dc..bcae35d9fc 100644--- a/crates/router/tests/connectors/utils.rs+++ b/crates/router/tests/connectors/utils.rs@@ -971,6 +971,7 @@ impl Default for PaymentSyncType {capture_method: None,sync_type: types::SyncRequestType::SinglePaymentSync,connector_meta: None,+ payment_method_type: None,};Self(data)}diff --git a/crates/router/tests/connectors/zen.rs b/crates/router/tests/connectors/zen.rsindex c3bce7d51c..14b52e7104 100644--- a/crates/router/tests/connectors/zen.rs+++ b/crates/router/tests/connectors/zen.rs@@ -103,6 +103,7 @@ async fn should_sync_authorized_payment() {sync_type: types::SyncRequestType::SinglePaymentSync,connector_meta: None,mandate_id: None,+ payment_method_type: None,}),None,)@@ -217,6 +218,7 @@ async fn should_sync_auto_captured_payment() {sync_type: types::SyncRequestType::SinglePaymentSync,connector_meta: None,mandate_id: None,+ payment_method_type: None,}),None,)