Skip to content

Commit 417039d

Browse files
feat(connector): [AUTHORIZEDOTNET] Add AVS checks (#8511)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
1 parent 7f5ec74 commit 417039d

File tree

1 file changed

+53
-1
lines changed
  • crates/hyperswitch_connectors/src/connectors/authorizedotnet

1 file changed

+53
-1
lines changed

crates/hyperswitch_connectors/src/connectors/authorizedotnet/transformers.rs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ use common_utils::{
1111
use error_stack::ResultExt;
1212
use hyperswitch_domain_models::{
1313
payment_method_data::{Card, PaymentMethodData, WalletData},
14-
router_data::{ConnectorAuthType, ErrorResponse, RouterData},
14+
router_data::{
15+
AdditionalPaymentMethodConnectorResponse, ConnectorAuthType, ConnectorResponseData,
16+
ErrorResponse, RouterData,
17+
},
1518
router_flow_types::RSync,
1619
router_request_types::ResponseId,
1720
router_response_types::{
@@ -1138,6 +1141,7 @@ pub struct AuthorizedotnetTransactionResponse {
11381141
pub(super) account_number: Option<Secret<String>>,
11391142
pub(super) errors: Option<Vec<ErrorMessage>>,
11401143
secure_acceptance: Option<SecureAcceptance>,
1144+
avs_result_code: Option<String>,
11411145
}
11421146

11431147
#[derive(Debug, Clone, Deserialize, Serialize)]
@@ -1216,6 +1220,48 @@ impl From<AuthorizedotnetVoidStatus> for enums::AttemptStatus {
12161220
}
12171221
}
12181222

1223+
fn get_avs_response_description(code: &str) -> Option<&'static str> {
1224+
match code {
1225+
"A" => Some("The street address matched, but the postal code did not."),
1226+
"B" => Some("No address information was provided."),
1227+
"E" => Some(
1228+
"AVS data provided is invalid or AVS is not allowed for the card type that was used.",
1229+
),
1230+
"G" => Some("The card was issued by a bank outside the U.S. and does not support AVS."),
1231+
"N" => Some("Neither the street address nor postal code matched."),
1232+
"P" => Some("AVS is not applicable for this transaction."),
1233+
"R" => Some("Retry — AVS was unavailable or timed out."),
1234+
"S" => Some("AVS is not supported by card issuer."),
1235+
"U" => Some("Address information is unavailable."),
1236+
"W" => Some("The US ZIP+4 code matches, but the street address does not."),
1237+
"X" => Some("Both the street address and the US ZIP+4 code matched."),
1238+
"Y" => Some("The street address and postal code matched."),
1239+
"Z" => Some("The postal code matched, but the street address did not."),
1240+
_ => None,
1241+
}
1242+
}
1243+
1244+
fn convert_to_additional_payment_method_connector_response(
1245+
transaction_response: &AuthorizedotnetTransactionResponse,
1246+
) -> Option<AdditionalPaymentMethodConnectorResponse> {
1247+
match transaction_response.avs_result_code.as_deref() {
1248+
Some("P") | None => None,
1249+
Some(code) => {
1250+
let description = get_avs_response_description(code);
1251+
let payment_checks = serde_json::json!({
1252+
"avs_result_code": code,
1253+
"description": description
1254+
});
1255+
Some(AdditionalPaymentMethodConnectorResponse::Card {
1256+
authentication_data: None,
1257+
payment_checks: Some(payment_checks),
1258+
card_network: None,
1259+
domestic_network: None,
1260+
})
1261+
}
1262+
}
1263+
}
1264+
12191265
impl<F, T>
12201266
ForeignTryFrom<(
12211267
ResponseRouterData<F, AuthorizedotnetPaymentsResponse, T, PaymentsResponseData>,
@@ -1258,6 +1304,11 @@ impl<F, T>
12581304
.change_context(errors::ConnectorError::MissingRequiredField {
12591305
field_name: "connector_metadata",
12601306
})?;
1307+
1308+
let connector_response_data =
1309+
convert_to_additional_payment_method_connector_response(transaction_response)
1310+
.map(ConnectorResponseData::with_additional_payment_method_data);
1311+
12611312
let url = transaction_response
12621313
.secure_acceptance
12631314
.as_ref()
@@ -1305,6 +1356,7 @@ impl<F, T>
13051356
charges: None,
13061357
}),
13071358
},
1359+
connector_response: connector_response_data,
13081360
..item.data
13091361
})
13101362
}

0 commit comments

Comments
 (0)