mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 18:17:13 +08:00 
			
		
		
		
	fix(connector): [Authorizedotnet]fix error deserialization incase of authentication failure (#2600)
Signed-off-by: chikke srujan <121822803+srujanchikke@users.noreply.github.com>
This commit is contained in:
		| @ -883,30 +883,31 @@ fn get_error_response( | ||||
|         .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; | ||||
|  | ||||
|     match response.transaction_response { | ||||
|         Some(transaction_response) => Ok({ | ||||
|             transaction_response | ||||
|                 .errors | ||||
|                 .and_then(|errors| { | ||||
|                     errors.into_iter().next().map(|error| types::ErrorResponse { | ||||
|                         code: error.error_code, | ||||
|                         message: error.error_text, | ||||
|                         reason: None, | ||||
|                         status_code, | ||||
|                     }) | ||||
|                 }) | ||||
|                 .unwrap_or_else(|| types::ErrorResponse { | ||||
|                     code: consts::NO_ERROR_CODE.to_string(), | ||||
|                     message: consts::NO_ERROR_MESSAGE.to_string(), | ||||
|                     reason: None, | ||||
|         Some(authorizedotnet::TransactionResponse::AuthorizedotnetTransactionResponse( | ||||
|             payment_response, | ||||
|         )) => Ok(payment_response | ||||
|             .errors | ||||
|             .and_then(|errors| { | ||||
|                 errors.into_iter().next().map(|error| types::ErrorResponse { | ||||
|                     code: error.error_code, | ||||
|                     message: error.error_text.to_owned(), | ||||
|                     reason: Some(error.error_text), | ||||
|                     status_code, | ||||
|                 }) | ||||
|         }), | ||||
|         None => { | ||||
|             }) | ||||
|             .unwrap_or_else(|| types::ErrorResponse { | ||||
|                 code: consts::NO_ERROR_CODE.to_string(), // authorizedotnet sends 200 in case of bad request so this are hard coded to NO_ERROR_CODE and NO_ERROR_MESSAGE | ||||
|                 message: consts::NO_ERROR_MESSAGE.to_string(), | ||||
|                 reason: None, | ||||
|                 status_code, | ||||
|             })), | ||||
|         Some(authorizedotnet::TransactionResponse::AuthorizedotnetTransactionResponseError(_)) | ||||
|         | None => { | ||||
|             let message = &response.messages.message[0].text; | ||||
|             Ok(types::ErrorResponse { | ||||
|                 code: consts::NO_ERROR_CODE.to_string(), | ||||
|                 message: message.to_string(), | ||||
|                 reason: None, | ||||
|                 reason: Some(message.to_string()), | ||||
|                 status_code, | ||||
|             }) | ||||
|         } | ||||
|  | ||||
| @ -453,9 +453,22 @@ pub struct ErrorMessage { | ||||
|     pub error_text: String, | ||||
| } | ||||
|  | ||||
| #[derive(Debug, Clone, Deserialize)] | ||||
| #[serde(untagged)] | ||||
| pub enum TransactionResponse { | ||||
|     AuthorizedotnetTransactionResponse(Box<AuthorizedotnetTransactionResponse>), | ||||
|     AuthorizedotnetTransactionResponseError(Box<AuthorizedotnetTransactionResponseError>), | ||||
| } | ||||
|  | ||||
| #[derive(Debug, Clone, Deserialize)] | ||||
| #[serde(rename_all = "PascalCase")] | ||||
| pub struct AuthorizedotnetTransactionResponseError { | ||||
|     _supplemental_data_qualification_indicator: i64, | ||||
| } | ||||
|  | ||||
| #[derive(Debug, Clone, Deserialize)] | ||||
| #[serde(rename_all = "camelCase")] | ||||
| pub struct TransactionResponse { | ||||
| pub struct AuthorizedotnetTransactionResponse { | ||||
|     response_code: AuthorizedotnetPaymentStatus, | ||||
|     #[serde(rename = "transId")] | ||||
|     transaction_id: String, | ||||
| @ -550,7 +563,7 @@ impl<F, T> | ||||
|         >, | ||||
|     ) -> Result<Self, Self::Error> { | ||||
|         match &item.response.transaction_response { | ||||
|             Some(transaction_response) => { | ||||
|             Some(TransactionResponse::AuthorizedotnetTransactionResponse(transaction_response)) => { | ||||
|                 let status = enums::AttemptStatus::from(transaction_response.response_code.clone()); | ||||
|                 let error = transaction_response.errors.as_ref().and_then(|errors| { | ||||
|                     errors.iter().next().map(|error| types::ErrorResponse { | ||||
| @ -598,11 +611,13 @@ impl<F, T> | ||||
|                     ..item.data | ||||
|                 }) | ||||
|             } | ||||
|             None => Ok(Self { | ||||
|                 status: enums::AttemptStatus::Failure, | ||||
|                 response: Err(get_err_response(item.http_code, item.response.messages)), | ||||
|                 ..item.data | ||||
|             }), | ||||
|             Some(TransactionResponse::AuthorizedotnetTransactionResponseError(_)) | None => { | ||||
|                 Ok(Self { | ||||
|                     status: enums::AttemptStatus::Failure, | ||||
|                     response: Err(get_err_response(item.http_code, item.response.messages)), | ||||
|                     ..item.data | ||||
|                 }) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 chikke srujan
					chikke srujan