@@ -11,7 +11,10 @@ use common_utils::{
11
11
use error_stack:: ResultExt ;
12
12
use hyperswitch_domain_models:: {
13
13
payment_method_data:: { Card , PaymentMethodData , WalletData } ,
14
- router_data:: { ConnectorAuthType , ErrorResponse , RouterData } ,
14
+ router_data:: {
15
+ AdditionalPaymentMethodConnectorResponse , ConnectorAuthType , ConnectorResponseData ,
16
+ ErrorResponse , RouterData ,
17
+ } ,
15
18
router_flow_types:: RSync ,
16
19
router_request_types:: ResponseId ,
17
20
router_response_types:: {
@@ -1138,6 +1141,7 @@ pub struct AuthorizedotnetTransactionResponse {
1138
1141
pub ( super ) account_number : Option < Secret < String > > ,
1139
1142
pub ( super ) errors : Option < Vec < ErrorMessage > > ,
1140
1143
secure_acceptance : Option < SecureAcceptance > ,
1144
+ avs_result_code : Option < String > ,
1141
1145
}
1142
1146
1143
1147
#[ derive( Debug , Clone , Deserialize , Serialize ) ]
@@ -1216,6 +1220,48 @@ impl From<AuthorizedotnetVoidStatus> for enums::AttemptStatus {
1216
1220
}
1217
1221
}
1218
1222
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
+
1219
1265
impl < F , T >
1220
1266
ForeignTryFrom < (
1221
1267
ResponseRouterData < F , AuthorizedotnetPaymentsResponse , T , PaymentsResponseData > ,
@@ -1258,6 +1304,11 @@ impl<F, T>
1258
1304
. change_context ( errors:: ConnectorError :: MissingRequiredField {
1259
1305
field_name : "connector_metadata" ,
1260
1306
} ) ?;
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
+
1261
1312
let url = transaction_response
1262
1313
. secure_acceptance
1263
1314
. as_ref ( )
@@ -1305,6 +1356,7 @@ impl<F, T>
1305
1356
charges : None ,
1306
1357
} ) ,
1307
1358
} ,
1359
+ connector_response : connector_response_data,
1308
1360
..item. data
1309
1361
} )
1310
1362
}
0 commit comments