From a475d18c72f1237c303b77c397a3072938679a27 Mon Sep 17 00:00:00 2001 From: Sk Sakil Mostak Date: Thu, 30 Nov 2023 17:07:47 +0530 Subject: [PATCH] fix: parse response for card with no 3ds check --- crates/router/src/connector/paypal.rs | 156 ++++++++++-------- .../src/connector/paypal/transformers.rs | 14 +- 2 files changed, 101 insertions(+), 69 deletions(-) diff --git a/crates/router/src/connector/paypal.rs b/crates/router/src/connector/paypal.rs index 9ab19b295570..029e7e81df30 100644 --- a/crates/router/src/connector/paypal.rs +++ b/crates/router/src/connector/paypal.rs @@ -570,42 +570,94 @@ impl .parse_struct("paypal PaypalPreProcessingResponse") .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; - // permutation for status to continue payment - match ( - response - .payment_source - .card - .authentication_result - .three_d_secure - .enrollment_status - .as_ref(), - response - .payment_source - .card - .authentication_result - .three_d_secure - .authentication_status - .as_ref(), - response - .payment_source - .card - .authentication_result - .liability_shift - .clone(), - ) { - ( - Some(paypal::EnrollementStatus::Ready), - Some(paypal::AuthenticationStatus::Success), - paypal::LiabilityShift::Possible, - ) - | ( - Some(paypal::EnrollementStatus::Ready), - Some(paypal::AuthenticationStatus::Attempted), - paypal::LiabilityShift::Possible, - ) - | (Some(paypal::EnrollementStatus::NotReady), None, paypal::LiabilityShift::No) - | (Some(paypal::EnrollementStatus::Unavailable), None, paypal::LiabilityShift::No) - | (Some(paypal::EnrollementStatus::Bypassed), None, paypal::LiabilityShift::No) => { + match response { + // if card supports 3DS check for liability + paypal::PaypalPreProcessingResponse::PaypalLiabilityResponse(liability_response) => { + // permutation for status to continue payment + match ( + liability_response + .payment_source + .card + .authentication_result + .three_d_secure + .enrollment_status + .as_ref(), + liability_response + .payment_source + .card + .authentication_result + .three_d_secure + .authentication_status + .as_ref(), + liability_response + .payment_source + .card + .authentication_result + .liability_shift + .clone(), + ) { + ( + Some(paypal::EnrollementStatus::Ready), + Some(paypal::AuthenticationStatus::Success), + paypal::LiabilityShift::Possible, + ) + | ( + Some(paypal::EnrollementStatus::Ready), + Some(paypal::AuthenticationStatus::Attempted), + paypal::LiabilityShift::Possible, + ) + | (Some(paypal::EnrollementStatus::NotReady), None, paypal::LiabilityShift::No) + | (Some(paypal::EnrollementStatus::Unavailable), None, paypal::LiabilityShift::No) + | (Some(paypal::EnrollementStatus::Bypassed), None, paypal::LiabilityShift::No) => { + Ok(types::PaymentsPreProcessingRouterData { + status: storage_enums::AttemptStatus::AuthenticationSuccessful, + response: Ok(types::PaymentsResponseData::TransactionResponse { + resource_id: types::ResponseId::NoResponseId, + redirection_data: None, + mandate_reference: None, + connector_metadata: None, + network_txn_id: None, + connector_response_reference_id: None, + }), + ..data.clone() + }) + } + _ => Ok(types::PaymentsPreProcessingRouterData { + response: Err(ErrorResponse { + attempt_status: Some(enums::AttemptStatus::Failure), + code: consts::NO_ERROR_CODE.to_string(), + message: consts::NO_ERROR_MESSAGE.to_string(), + connector_transaction_id: None, + reason: Some(format!("{} Connector Responsded with LiabilityShift: {:?}, EnrollmentStatus: {:?}, and AuthenticationStatus: {:?}", + consts::CANNOT_CONTINUE_AUTH, + liability_response + .payment_source + .card + .authentication_result + .liability_shift, + liability_response + .payment_source + .card + .authentication_result + .three_d_secure + .enrollment_status + .unwrap_or(paypal::EnrollementStatus::Null), + liability_response + .payment_source + .card + .authentication_result + .three_d_secure + .authentication_status + .unwrap_or(paypal::AuthenticationStatus::Null), + )), + status_code: res.status_code, + }), + ..data.clone() + }), + } + } + // if card does not supports 3DS check for liability + paypal::PaypalPreProcessingResponse::PaypalNonLiablityResponse(_) => { Ok(types::PaymentsPreProcessingRouterData { status: storage_enums::AttemptStatus::AuthenticationSuccessful, response: Ok(types::PaymentsResponseData::TransactionResponse { @@ -619,38 +671,6 @@ impl ..data.clone() }) } - _ => Ok(types::PaymentsPreProcessingRouterData { - response: Err(ErrorResponse { - attempt_status: Some(enums::AttemptStatus::Failure), - code: consts::NO_ERROR_CODE.to_string(), - message: consts::NO_ERROR_MESSAGE.to_string(), - connector_transaction_id: None, - reason: Some(format!("{} Connector Responsded with LiabilityShift: {:?}, EnrollmentStatus: {:?}, and AuthenticationStatus: {:?}", - consts::CANNOT_CONTINUE_AUTH, - response - .payment_source - .card - .authentication_result - .liability_shift, - response - .payment_source - .card - .authentication_result - .three_d_secure - .enrollment_status - .unwrap_or(paypal::EnrollementStatus::Null), - response - .payment_source - .card - .authentication_result - .three_d_secure - .authentication_status - .unwrap_or(paypal::AuthenticationStatus::Null), - )), - status_code: res.status_code, - }), - ..data.clone() - }), } } diff --git a/crates/router/src/connector/paypal/transformers.rs b/crates/router/src/connector/paypal/transformers.rs index 04328cead233..2e1f79402784 100644 --- a/crates/router/src/connector/paypal/transformers.rs +++ b/crates/router/src/connector/paypal/transformers.rs @@ -926,10 +926,22 @@ pub struct PaypalThreeDsResponse { } #[derive(Debug, Clone, Serialize, Deserialize)] -pub struct PaypalPreProcessingResponse { +#[serde(untagged)] +pub enum PaypalPreProcessingResponse { + PaypalLiabilityResponse(PaypalLiabilityResponse), + PaypalNonLiablityResponse(PaypalNonLiablityResponse), +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PaypalLiabilityResponse { pub payment_source: CardParams, } +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PaypalNonLiablityResponse { + payment_source: CardsData, +} + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct CardParams { pub card: AuthResult,