mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-30 09:38:33 +08:00 
			
		
		
		
	feat(connector): [PLACETOPAY] Fix refund request and status mapping (#3894)
This commit is contained in:
		| @ -119,8 +119,8 @@ impl ConnectorValidation for Placetopay { | |||||||
|     ) -> CustomResult<(), errors::ConnectorError> { |     ) -> CustomResult<(), errors::ConnectorError> { | ||||||
|         let capture_method = capture_method.unwrap_or_default(); |         let capture_method = capture_method.unwrap_or_default(); | ||||||
|         match capture_method { |         match capture_method { | ||||||
|             enums::CaptureMethod::Manual => Ok(()), |             enums::CaptureMethod::Automatic => Ok(()), | ||||||
|             enums::CaptureMethod::Automatic |             enums::CaptureMethod::Manual | ||||||
|             | enums::CaptureMethod::ManualMultiple |             | enums::CaptureMethod::ManualMultiple | ||||||
|             | enums::CaptureMethod::Scheduled => Err(utils::construct_not_supported_error_report( |             | enums::CaptureMethod::Scheduled => Err(utils::construct_not_supported_error_report( | ||||||
|                 capture_method, |                 capture_method, | ||||||
| @ -615,7 +615,7 @@ impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponse | |||||||
|     ) -> CustomResult<Option<services::Request>, errors::ConnectorError> { |     ) -> CustomResult<Option<services::Request>, errors::ConnectorError> { | ||||||
|         Ok(Some( |         Ok(Some( | ||||||
|             services::RequestBuilder::new() |             services::RequestBuilder::new() | ||||||
|                 .method(services::Method::Get) |                 .method(services::Method::Post) | ||||||
|                 .url(&types::RefundSyncType::get_url(self, req, connectors)?) |                 .url(&types::RefundSyncType::get_url(self, req, connectors)?) | ||||||
|                 .attach_default_headers() |                 .attach_default_headers() | ||||||
|                 .headers(types::RefundSyncType::get_headers(self, req, connectors)?) |                 .headers(types::RefundSyncType::get_headers(self, req, connectors)?) | ||||||
|  | |||||||
| @ -206,30 +206,43 @@ impl TryFrom<&types::ConnectorAuthType> for PlacetopayAuthType { | |||||||
|  |  | ||||||
| #[derive(Debug, Clone, Deserialize, Serialize)] | #[derive(Debug, Clone, Deserialize, Serialize)] | ||||||
| #[serde(rename_all = "SCREAMING_SNAKE_CASE")] | #[serde(rename_all = "SCREAMING_SNAKE_CASE")] | ||||||
| pub enum PlacetopayStatus { | pub enum PlacetopayTransactionStatus { | ||||||
|     Ok, |     Ok, | ||||||
|     Failed, |     Failed, | ||||||
|     Approved, |     Approved, | ||||||
|  |     // ApprovedPartial, | ||||||
|  |     // PartialExpired, | ||||||
|     Rejected, |     Rejected, | ||||||
|     Pending, |     Pending, | ||||||
|     PendingValidation, |     PendingValidation, | ||||||
|     PendingProcess, |     PendingProcess, | ||||||
|  |     // Refunded, | ||||||
|  |     // Reversed, | ||||||
|  |     Error, | ||||||
|  |     // Unknown, | ||||||
|  |     // Manual, | ||||||
|  |     // Dispute, | ||||||
|  |     //The statuses that are commented out are awaiting clarification on the connector. | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Debug, Deserialize, Serialize)] | #[derive(Debug, Deserialize, Serialize)] | ||||||
| #[serde(rename_all = "camelCase")] | #[serde(rename_all = "camelCase")] | ||||||
| pub struct PlacetopayStatusResponse { | pub struct PlacetopayStatusResponse { | ||||||
|     status: PlacetopayStatus, |     status: PlacetopayTransactionStatus, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl From<PlacetopayStatus> for enums::AttemptStatus { | impl From<PlacetopayTransactionStatus> for enums::AttemptStatus { | ||||||
|     fn from(item: PlacetopayStatus) -> Self { |     fn from(item: PlacetopayTransactionStatus) -> Self { | ||||||
|         match item { |         match item { | ||||||
|             PlacetopayStatus::Approved | PlacetopayStatus::Ok => Self::Authorized, |             PlacetopayTransactionStatus::Approved | PlacetopayTransactionStatus::Ok => { | ||||||
|             PlacetopayStatus::Failed | PlacetopayStatus::Rejected => Self::Failure, |                 Self::Charged | ||||||
|             PlacetopayStatus::Pending |             } | ||||||
|             | PlacetopayStatus::PendingValidation |             PlacetopayTransactionStatus::Failed | ||||||
|             | PlacetopayStatus::PendingProcess => Self::Authorizing, |             | PlacetopayTransactionStatus::Rejected | ||||||
|  |             | PlacetopayTransactionStatus::Error => Self::Failure, | ||||||
|  |             PlacetopayTransactionStatus::Pending | ||||||
|  |             | PlacetopayTransactionStatus::PendingValidation | ||||||
|  |             | PlacetopayTransactionStatus::PendingProcess => Self::Pending, | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -239,6 +252,7 @@ impl From<PlacetopayStatus> for enums::AttemptStatus { | |||||||
| pub struct PlacetopayPaymentsResponse { | pub struct PlacetopayPaymentsResponse { | ||||||
|     status: PlacetopayStatusResponse, |     status: PlacetopayStatusResponse, | ||||||
|     internal_reference: u64, |     internal_reference: u64, | ||||||
|  |     authorization: Option<String>, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl<F, T> | impl<F, T> | ||||||
| @ -263,7 +277,11 @@ impl<F, T> | |||||||
|                 ), |                 ), | ||||||
|                 redirection_data: None, |                 redirection_data: None, | ||||||
|                 mandate_reference: None, |                 mandate_reference: None, | ||||||
|                 connector_metadata: None, |                 connector_metadata: item | ||||||
|  |                     .response | ||||||
|  |                     .authorization | ||||||
|  |                     .clone() | ||||||
|  |                     .map(|authorization| serde_json::json!(authorization)), | ||||||
|                 network_txn_id: None, |                 network_txn_id: None, | ||||||
|                 connector_response_reference_id: None, |                 connector_response_reference_id: None, | ||||||
|                 incremental_authorization_allowed: None, |                 incremental_authorization_allowed: None, | ||||||
| @ -281,55 +299,90 @@ pub struct PlacetopayRefundRequest { | |||||||
|     auth: PlacetopayAuth, |     auth: PlacetopayAuth, | ||||||
|     internal_reference: u64, |     internal_reference: u64, | ||||||
|     action: PlacetopayNextAction, |     action: PlacetopayNextAction, | ||||||
|  |     authorization: Option<String>, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl<F> TryFrom<&types::RefundsRouterData<F>> for PlacetopayRefundRequest { | impl<F> TryFrom<&types::RefundsRouterData<F>> for PlacetopayRefundRequest { | ||||||
|     type Error = error_stack::Report<errors::ConnectorError>; |     type Error = error_stack::Report<errors::ConnectorError>; | ||||||
|     fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> { |     fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> { | ||||||
|         let auth = PlacetopayAuth::try_from(&item.connector_auth_type)?; |         if item.request.refund_amount == item.request.payment_amount { | ||||||
|         let internal_reference = item |             let auth = PlacetopayAuth::try_from(&item.connector_auth_type)?; | ||||||
|             .request |  | ||||||
|             .connector_transaction_id |  | ||||||
|             .parse::<u64>() |  | ||||||
|             .into_report() |  | ||||||
|             .change_context(errors::ConnectorError::RequestEncodingFailed)?; |  | ||||||
|         let action = PlacetopayNextAction::Refund; |  | ||||||
|  |  | ||||||
|         Ok(Self { |             let internal_reference = item | ||||||
|             auth, |                 .request | ||||||
|             internal_reference, |                 .connector_transaction_id | ||||||
|             action, |                 .parse::<u64>() | ||||||
|         }) |                 .into_report() | ||||||
|  |                 .change_context(errors::ConnectorError::RequestEncodingFailed)?; | ||||||
|  |             let action = PlacetopayNextAction::Reverse; | ||||||
|  |             let authorization = match item.request.connector_metadata.clone() { | ||||||
|  |                 Some(metadata) => metadata.as_str().map(|auth| auth.to_string()), | ||||||
|  |                 None => None, | ||||||
|  |             }; | ||||||
|  |             Ok(Self { | ||||||
|  |                 auth, | ||||||
|  |                 internal_reference, | ||||||
|  |                 action, | ||||||
|  |                 authorization, | ||||||
|  |             }) | ||||||
|  |         } else { | ||||||
|  |             Err(errors::ConnectorError::NotSupported { | ||||||
|  |                 message: "Partial Refund".to_string(), | ||||||
|  |                 connector: "placetopay", | ||||||
|  |             } | ||||||
|  |             .into()) | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| impl From<PlacetopayRefundStatus> for enums::RefundStatus { | impl From<PlacetopayRefundStatus> for enums::RefundStatus { | ||||||
|     fn from(item: PlacetopayRefundStatus) -> Self { |     fn from(item: PlacetopayRefundStatus) -> Self { | ||||||
|         match item { |         match item { | ||||||
|             PlacetopayRefundStatus::Refunded => Self::Success, |             PlacetopayRefundStatus::Ok | ||||||
|             PlacetopayRefundStatus::Failed | PlacetopayRefundStatus::Rejected => Self::Failure, |             | PlacetopayRefundStatus::Approved | ||||||
|             PlacetopayRefundStatus::Pending | PlacetopayRefundStatus::PendingProcess => { |             | PlacetopayRefundStatus::Refunded => Self::Success, | ||||||
|                 Self::Pending |             PlacetopayRefundStatus::Failed | ||||||
|             } |             | PlacetopayRefundStatus::Rejected | ||||||
|  |             | PlacetopayRefundStatus::Error => Self::Failure, | ||||||
|  |             PlacetopayRefundStatus::Pending | ||||||
|  |             | PlacetopayRefundStatus::PendingProcess | ||||||
|  |             | PlacetopayRefundStatus::PendingValidation => Self::Pending, | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Debug, Deserialize, Serialize)] | #[derive(Debug, Deserialize, Serialize)] | ||||||
| #[serde(rename_all = "camelCase")] | #[serde(rename_all = "SCREAMING_SNAKE_CASE")] | ||||||
| pub struct PlacetopayRefundResponse { | pub enum PlacetopayRefundStatus { | ||||||
|     status: PlacetopayRefundStatus, |     Ok, | ||||||
|     internal_reference: u64, |     Failed, | ||||||
|  |     Approved, | ||||||
|  |     // ApprovedPartial, | ||||||
|  |     // PartialExpired, | ||||||
|  |     Rejected, | ||||||
|  |     Pending, | ||||||
|  |     PendingValidation, | ||||||
|  |     PendingProcess, | ||||||
|  |     Refunded, | ||||||
|  |     // Reversed, | ||||||
|  |     Error, | ||||||
|  |     // Unknown, | ||||||
|  |     // Manual, | ||||||
|  |     // Dispute, | ||||||
|  |     //The statuses that are commented out are awaiting clarification on the connector. | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Debug, Deserialize, Serialize)] | #[derive(Debug, Deserialize, Serialize)] | ||||||
| #[serde(rename_all = "SCREAMING_SNAKE_CASE")] | #[serde(rename_all = "camelCase")] | ||||||
| pub enum PlacetopayRefundStatus { | pub struct PlacetopayRefundStatusResponse { | ||||||
|     Refunded, |     status: PlacetopayRefundStatus, | ||||||
|     Rejected, | } | ||||||
|     Failed, |  | ||||||
|     Pending, | #[derive(Debug, Deserialize, Serialize)] | ||||||
|     PendingProcess, | #[serde(rename_all = "camelCase")] | ||||||
|  | pub struct PlacetopayRefundResponse { | ||||||
|  |     status: PlacetopayRefundStatusResponse, | ||||||
|  |     internal_reference: u64, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl TryFrom<types::RefundsResponseRouterData<api::Execute, PlacetopayRefundResponse>> | impl TryFrom<types::RefundsResponseRouterData<api::Execute, PlacetopayRefundResponse>> | ||||||
| @ -342,7 +395,7 @@ impl TryFrom<types::RefundsResponseRouterData<api::Execute, PlacetopayRefundResp | |||||||
|         Ok(Self { |         Ok(Self { | ||||||
|             response: Ok(types::RefundsResponseData { |             response: Ok(types::RefundsResponseData { | ||||||
|                 connector_refund_id: item.response.internal_reference.to_string(), |                 connector_refund_id: item.response.internal_reference.to_string(), | ||||||
|                 refund_status: enums::RefundStatus::from(item.response.status), |                 refund_status: enums::RefundStatus::from(item.response.status.status), | ||||||
|             }), |             }), | ||||||
|             ..item.data |             ..item.data | ||||||
|         }) |         }) | ||||||
| @ -383,7 +436,7 @@ impl TryFrom<types::RefundsResponseRouterData<api::RSync, PlacetopayRefundRespon | |||||||
|         Ok(Self { |         Ok(Self { | ||||||
|             response: Ok(types::RefundsResponseData { |             response: Ok(types::RefundsResponseData { | ||||||
|                 connector_refund_id: item.response.internal_reference.to_string(), |                 connector_refund_id: item.response.internal_reference.to_string(), | ||||||
|                 refund_status: enums::RefundStatus::from(item.response.status), |                 refund_status: enums::RefundStatus::from(item.response.status.status), | ||||||
|             }), |             }), | ||||||
|             ..item.data |             ..item.data | ||||||
|         }) |         }) | ||||||
| @ -447,6 +500,7 @@ pub struct PlacetopayNextActionRequest { | |||||||
| #[serde(rename_all = "camelCase")] | #[serde(rename_all = "camelCase")] | ||||||
| pub enum PlacetopayNextAction { | pub enum PlacetopayNextAction { | ||||||
|     Refund, |     Refund, | ||||||
|  |     Reverse, | ||||||
|     Void, |     Void, | ||||||
|     Process, |     Process, | ||||||
|     Checkout, |     Checkout, | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 DEEPANSHU BANSAL
					DEEPANSHU BANSAL