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