Skip to content

Commit b4655a1

Browse files
committed
avs check added
1 parent 62ec934 commit b4655a1

File tree

1 file changed

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

1 file changed

+51
-1
lines changed

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

Lines changed: 51 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,46 @@ 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("AVS data provided is invalid or AVS is not allowed for the card type that was used."),
1228+
"G" => Some("The card was issued by a bank outside the U.S. and does not support AVS."),
1229+
"N" => Some("Neither the street address nor postal code matched."),
1230+
"P" => Some("AVS is not applicable for this transaction."),
1231+
"R" => Some("Retry — AVS was unavailable or timed out."),
1232+
"S" => Some("AVS is not supported by card issuer."),
1233+
"U" => Some("Address information is unavailable."),
1234+
"W" => Some("The US ZIP+4 code matches, but the street address does not."),
1235+
"X" => Some("Both the street address and the US ZIP+4 code matched."),
1236+
"Y" => Some("The street address and postal code matched."),
1237+
"Z" => Some("The postal code matched, but the street address did not."),
1238+
_ => None,
1239+
}
1240+
}
1241+
1242+
fn convert_to_additional_payment_method_connector_response(
1243+
transaction_response: &AuthorizedotnetTransactionResponse,
1244+
) -> Option<AdditionalPaymentMethodConnectorResponse> {
1245+
match transaction_response.avs_result_code.as_deref() {
1246+
Some("P") | None => None,
1247+
Some(code) => {
1248+
let description = get_avs_response_description(code);
1249+
let payment_checks = serde_json::json!({
1250+
"avs_result_code": code,
1251+
"description": description
1252+
});
1253+
Some(AdditionalPaymentMethodConnectorResponse::Card {
1254+
authentication_data: None,
1255+
payment_checks: Some(payment_checks),
1256+
card_network: None,
1257+
domestic_network: None,
1258+
})
1259+
}
1260+
}
1261+
}
1262+
12191263
impl<F, T>
12201264
ForeignTryFrom<(
12211265
ResponseRouterData<F, AuthorizedotnetPaymentsResponse, T, PaymentsResponseData>,
@@ -1258,6 +1302,11 @@ impl<F, T>
12581302
.change_context(errors::ConnectorError::MissingRequiredField {
12591303
field_name: "connector_metadata",
12601304
})?;
1305+
1306+
let connector_response_data =
1307+
convert_to_additional_payment_method_connector_response(transaction_response)
1308+
.map(ConnectorResponseData::with_additional_payment_method_data);
1309+
12611310
let url = transaction_response
12621311
.secure_acceptance
12631312
.as_ref()
@@ -1305,6 +1354,7 @@ impl<F, T>
13051354
charges: None,
13061355
}),
13071356
},
1357+
connector_response: connector_response_data,
13081358
..item.data
13091359
})
13101360
}

0 commit comments

Comments
 (0)