Skip to content

Commit

Permalink
feat(router): [BOA/CYBS] add avs_response and cvv validation result i…
Browse files Browse the repository at this point in the history
…n the response (#4376)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
AkshayaFoiger and hyperswitch-bot[bot] authored Apr 19, 2024
1 parent f4e5784 commit e458e49
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 22 deletions.
73 changes: 56 additions & 17 deletions crates/router/src/connector/bankofamerica/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ impl<F, T>
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 {
Expand All @@ -400,6 +406,7 @@ impl<F, T>
incremental_authorization_allowed: None,
}),
},
connector_response,
..item.data
})
}
Expand Down Expand Up @@ -714,7 +721,16 @@ pub struct ClientReferenceInformation {
#[serde(rename_all = "camelCase")]
pub struct ClientProcessorInformation {
avs: Option<Avs>,
card_verification: Option<CardVerification>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CardVerification {
result_code: Option<String>,
result_code_raw: Option<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ClientRiskInformation {
Expand Down Expand Up @@ -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,
})
}
}
}
Expand Down Expand Up @@ -1849,9 +1862,15 @@ impl<F>
|| 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
})
}
Expand Down Expand Up @@ -1892,9 +1911,16 @@ impl<F>
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
})
}
Expand All @@ -1909,6 +1935,19 @@ impl<F>
}
}

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<F>
TryFrom<
types::ResponseRouterData<
Expand Down
52 changes: 47 additions & 5 deletions crates/router/src/connector/cybersource/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,14 @@ pub struct ClientReferenceInformation {
pub struct ClientProcessorInformation {
network_transaction_id: Option<String>,
avs: Option<Avs>,
card_verification: Option<CardVerification>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CardVerification {
result_code: Option<String>,
result_code_raw: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1801,9 +1809,16 @@ impl<F>
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
})
}
Expand Down Expand Up @@ -2286,9 +2301,16 @@ impl<F>
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
})
}
Expand All @@ -2301,6 +2323,19 @@ impl<F>
}
}

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<F>
TryFrom<
types::ResponseRouterData<
Expand Down Expand Up @@ -2414,6 +2449,12 @@ impl<F, T>
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 {
Expand Down Expand Up @@ -2442,6 +2483,7 @@ impl<F, T>
),
}),
},
connector_response,
..item.data
})
}
Expand Down

0 comments on commit e458e49

Please sign in to comment.