mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	fix(globalpay): fix globalpay error handling (#464)
This commit is contained in:
		| @ -226,7 +226,7 @@ impl TryFrom<&types::ConnectorAuthType> for CybersourceAuthType { | ||||
|     } | ||||
| } | ||||
| #[derive(Debug, Default, Clone, Deserialize, Eq, PartialEq)] | ||||
| #[serde(rename_all = "UPPERCASE")] | ||||
| #[serde(rename_all = "SCREAMING_SNAKE_CASE")] | ||||
| pub enum CybersourcePaymentStatus { | ||||
|     Authorized, | ||||
|     Succeeded, | ||||
| @ -235,6 +235,7 @@ pub enum CybersourcePaymentStatus { | ||||
|     Reversed, | ||||
|     Pending, | ||||
|     Declined, | ||||
|     AuthorizedPendingReview, | ||||
|     Transmitted, | ||||
|     #[default] | ||||
|     Processing, | ||||
| @ -243,7 +244,8 @@ pub enum CybersourcePaymentStatus { | ||||
| impl From<CybersourcePaymentStatus> for enums::AttemptStatus { | ||||
|     fn from(item: CybersourcePaymentStatus) -> Self { | ||||
|         match item { | ||||
|             CybersourcePaymentStatus::Authorized => Self::Authorized, | ||||
|             CybersourcePaymentStatus::Authorized | ||||
|             | CybersourcePaymentStatus::AuthorizedPendingReview => Self::Authorized, | ||||
|             CybersourcePaymentStatus::Succeeded | CybersourcePaymentStatus::Transmitted => { | ||||
|                 Self::Charged | ||||
|             } | ||||
|  | ||||
| @ -344,7 +344,7 @@ pub enum FingerprintPresenceIndicator { | ||||
| } | ||||
|  | ||||
| /// Indicates where a transaction is in its lifecycle. | ||||
| #[derive(Debug, Serialize, Deserialize)] | ||||
| #[derive(Clone, Copy, Debug, Serialize, Deserialize)] | ||||
| #[serde(rename_all = "SCREAMING_SNAKE_CASE")] | ||||
| pub enum GlobalpayPaymentStatus { | ||||
|     /// A Transaction has been successfully authorized and captured. The funding | ||||
|  | ||||
| @ -9,8 +9,9 @@ use super::{ | ||||
| }; | ||||
| use crate::{ | ||||
|     connector::utils::{self, CardData, PaymentsRequestData}, | ||||
|     consts, | ||||
|     core::errors, | ||||
|     types::{self, api, storage::enums}, | ||||
|     types::{self, api, storage::enums, ErrorResponse}, | ||||
| }; | ||||
|  | ||||
| impl TryFrom<&types::PaymentsAuthorizeRouterData> for GlobalpayPaymentsRequest { | ||||
| @ -149,6 +150,28 @@ impl From<GlobalpayPaymentStatus> for enums::RefundStatus { | ||||
|     } | ||||
| } | ||||
|  | ||||
| fn get_payment_response( | ||||
|     status: enums::AttemptStatus, | ||||
|     response: GlobalpayPaymentsResponse, | ||||
| ) -> Result<types::PaymentsResponseData, ErrorResponse> { | ||||
|     match status { | ||||
|         enums::AttemptStatus::Failure => Err(ErrorResponse { | ||||
|             message: response | ||||
|                 .payment_method | ||||
|                 .and_then(|pm| pm.message) | ||||
|                 .unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()), | ||||
|             ..Default::default() | ||||
|         }), | ||||
|         _ => Ok(types::PaymentsResponseData::TransactionResponse { | ||||
|             resource_id: types::ResponseId::ConnectorTransactionId(response.id), | ||||
|             redirection_data: None, | ||||
|             redirect: false, | ||||
|             mandate_reference: None, | ||||
|             connector_metadata: None, | ||||
|         }), | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl<F, T> | ||||
|     TryFrom<types::ResponseRouterData<F, GlobalpayPaymentsResponse, T, types::PaymentsResponseData>> | ||||
|     for types::RouterData<F, T, types::PaymentsResponseData> | ||||
| @ -162,15 +185,10 @@ impl<F, T> | ||||
|             types::PaymentsResponseData, | ||||
|         >, | ||||
|     ) -> Result<Self, Self::Error> { | ||||
|         let status = enums::AttemptStatus::from(item.response.status); | ||||
|         Ok(Self { | ||||
|             status: enums::AttemptStatus::from(item.response.status), | ||||
|             response: Ok(types::PaymentsResponseData::TransactionResponse { | ||||
|                 resource_id: types::ResponseId::ConnectorTransactionId(item.response.id), | ||||
|                 redirection_data: None, | ||||
|                 redirect: false, | ||||
|                 mandate_reference: None, | ||||
|                 connector_metadata: None, | ||||
|             }), | ||||
|             status, | ||||
|             response: get_payment_response(status, item.response), | ||||
|             ..item.data | ||||
|         }) | ||||
|     } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Jagan
					Jagan