From e458e4907e39961f386900f21382c9ace3b7c392 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger <131388445+AkshayaFoiger@users.noreply.github.com> Date: Fri, 19 Apr 2024 12:19:35 +0530 Subject: [PATCH] feat(router): [BOA/CYBS] add avs_response and cvv validation result in the response (#4376) Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> --- .../connector/bankofamerica/transformers.rs | 73 ++++++++++++++----- .../src/connector/cybersource/transformers.rs | 52 +++++++++++-- 2 files changed, 103 insertions(+), 22 deletions(-) diff --git a/crates/router/src/connector/bankofamerica/transformers.rs b/crates/router/src/connector/bankofamerica/transformers.rs index 5eca31278a8b..3ea736486ef0 100644 --- a/crates/router/src/connector/bankofamerica/transformers.rs +++ b/crates/router/src/connector/bankofamerica/transformers.rs @@ -378,6 +378,12 @@ impl let error_response = get_error_response_if_failure((&info_response, mandate_status, item.http_code)); + let connector_response = info_response + .processor_information + .as_ref() + .map(types::AdditionalPaymentMethodConnectorResponse::from) + .map(types::ConnectorResponseData::with_additional_payment_method_data); + Ok(Self { status: mandate_status, response: match error_response { @@ -400,6 +406,7 @@ impl incremental_authorization_allowed: None, }), }, + connector_response, ..item.data }) } @@ -714,7 +721,16 @@ pub struct ClientReferenceInformation { #[serde(rename_all = "camelCase")] pub struct ClientProcessorInformation { avs: Option, + card_verification: Option, } + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct CardVerification { + result_code: Option, + result_code_raw: Option, +} + #[derive(Debug, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct ClientRiskInformation { @@ -1383,23 +1399,20 @@ fn get_payment_response( }); Ok(types::PaymentsResponseData::TransactionResponse { - resource_id: types::ResponseId::ConnectorTransactionId(info_response.id.clone()), - redirection_data: None, - mandate_reference, - connector_metadata: info_response - .processor_information - .as_ref() - .map(|processor_information| serde_json::json!({"avs_response": processor_information.avs})), - network_txn_id: None, - connector_response_reference_id: Some( - info_response - .client_reference_information - .code - .clone() - .unwrap_or(info_response.id.clone()), - ), - incremental_authorization_allowed: None, - }) + resource_id: types::ResponseId::ConnectorTransactionId(info_response.id.clone()), + redirection_data: None, + mandate_reference, + connector_metadata: None, + network_txn_id: None, + connector_response_reference_id: Some( + info_response + .client_reference_information + .code + .clone() + .unwrap_or(info_response.id.clone()), + ), + incremental_authorization_allowed: None, + }) } } } @@ -1849,9 +1862,15 @@ impl || is_setup_mandate_payment(&item.data.request), )); let response = get_payment_response((&info_response, status, item.http_code)); + let connector_response = info_response + .processor_information + .as_ref() + .map(types::AdditionalPaymentMethodConnectorResponse::from) + .map(types::ConnectorResponseData::with_additional_payment_method_data); Ok(Self { status, response, + connector_response, ..item.data }) } @@ -1892,9 +1911,16 @@ impl item.data.request.is_auto_capture()?, )); let response = get_payment_response((&info_response, status, item.http_code)); + let connector_response = info_response + .processor_information + .as_ref() + .map(types::AdditionalPaymentMethodConnectorResponse::from) + .map(types::ConnectorResponseData::with_additional_payment_method_data); + Ok(Self { status, response, + connector_response, ..item.data }) } @@ -1909,6 +1935,19 @@ impl } } +impl From<&ClientProcessorInformation> for types::AdditionalPaymentMethodConnectorResponse { + fn from(processor_information: &ClientProcessorInformation) -> Self { + let payment_checks = Some( + serde_json::json!({"avs_response": processor_information.avs, "card_verification": processor_information.card_verification}), + ); + + Self::Card { + authentication_data: None, + payment_checks, + } + } +} + impl TryFrom< types::ResponseRouterData< diff --git a/crates/router/src/connector/cybersource/transformers.rs b/crates/router/src/connector/cybersource/transformers.rs index 338048b87835..a3756770aeb7 100644 --- a/crates/router/src/connector/cybersource/transformers.rs +++ b/crates/router/src/connector/cybersource/transformers.rs @@ -1630,6 +1630,14 @@ pub struct ClientReferenceInformation { pub struct ClientProcessorInformation { network_transaction_id: Option, avs: Option, + card_verification: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct CardVerification { + result_code: Option, + result_code_raw: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -1753,15 +1761,15 @@ fn get_payment_response( .map(|payment_instrument| payment_instrument.id.expose()), payment_method_id: None, }); + Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId(info_response.id.clone()), redirection_data: None, mandate_reference, - connector_metadata: info_response - .processor_information - .as_ref() - .map(|processor_information| serde_json::json!({"avs_response": processor_information.avs})), - network_txn_id: info_response.processor_information.as_ref().and_then(|processor_information| processor_information.network_transaction_id.clone()), + connector_metadata: None, + network_txn_id: info_response.processor_information.as_ref().and_then( + |processor_information| processor_information.network_transaction_id.clone(), + ), connector_response_reference_id: Some( info_response .client_reference_information @@ -1801,9 +1809,16 @@ impl item.data.request.is_auto_capture()?, )); let response = get_payment_response((&info_response, status, item.http_code)); + let connector_response = info_response + .processor_information + .as_ref() + .map(types::AdditionalPaymentMethodConnectorResponse::from) + .map(types::ConnectorResponseData::with_additional_payment_method_data); + Ok(Self { status, response, + connector_response, ..item.data }) } @@ -2286,9 +2301,16 @@ impl item.data.request.is_auto_capture()?, )); let response = get_payment_response((&info_response, status, item.http_code)); + let connector_response = info_response + .processor_information + .as_ref() + .map(types::AdditionalPaymentMethodConnectorResponse::from) + .map(types::ConnectorResponseData::with_additional_payment_method_data); + Ok(Self { status, response, + connector_response, ..item.data }) } @@ -2301,6 +2323,19 @@ impl } } +impl From<&ClientProcessorInformation> for types::AdditionalPaymentMethodConnectorResponse { + fn from(processor_information: &ClientProcessorInformation) -> Self { + let payment_checks = Some( + serde_json::json!({"avs_response": processor_information.avs, "card_verification": processor_information.card_verification}), + ); + + Self::Card { + authentication_data: None, + payment_checks, + } + } +} + impl TryFrom< types::ResponseRouterData< @@ -2414,6 +2449,12 @@ impl let error_response = get_error_response_if_failure((&info_response, mandate_status, item.http_code)); + let connector_response = info_response + .processor_information + .as_ref() + .map(types::AdditionalPaymentMethodConnectorResponse::from) + .map(types::ConnectorResponseData::with_additional_payment_method_data); + Ok(Self { status: mandate_status, response: match error_response { @@ -2442,6 +2483,7 @@ impl ), }), }, + connector_response, ..item.data }) }