mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	fix: move connector_refund_id to request (#445)
				
					
				
			This commit is contained in:
		| @ -467,16 +467,17 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for AuthorizedotnetCreateSyncReque | |||||||
|  |  | ||||||
|     fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> { |     fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> { | ||||||
|         let transaction_id = item |         let transaction_id = item | ||||||
|             .response |             .request | ||||||
|             .as_ref() |             .connector_refund_id | ||||||
|             .map(|refund_response_data| refund_response_data.connector_refund_id.clone()) |             .clone() | ||||||
|             .ok(); |             .get_required_value("connector_refund_id") | ||||||
|  |             .change_context(errors::ConnectorError::MissingConnectorRefundID)?; | ||||||
|         let merchant_authentication = MerchantAuthentication::try_from(&item.connector_auth_type)?; |         let merchant_authentication = MerchantAuthentication::try_from(&item.connector_auth_type)?; | ||||||
|  |  | ||||||
|         let payload = Self { |         let payload = Self { | ||||||
|             get_transaction_details_request: TransactionDetails { |             get_transaction_details_request: TransactionDetails { | ||||||
|                 merchant_authentication, |                 merchant_authentication, | ||||||
|                 transaction_id, |                 transaction_id: Some(transaction_id), | ||||||
|             }, |             }, | ||||||
|         }; |         }; | ||||||
|         Ok(payload) |         Ok(payload) | ||||||
|  | |||||||
| @ -675,12 +675,11 @@ impl services::ConnectorIntegration<api::RSync, types::RefundsData, types::Refun | |||||||
|         res: types::Response, |         res: types::Response, | ||||||
|     ) -> CustomResult<types::RefundsRouterData<api::RSync>, errors::ConnectorError> { |     ) -> CustomResult<types::RefundsRouterData<api::RSync>, errors::ConnectorError> { | ||||||
|         let refund_action_id = data |         let refund_action_id = data | ||||||
|             .response |             .request | ||||||
|  |             .connector_refund_id | ||||||
|             .clone() |             .clone() | ||||||
|             .ok() |             .get_required_value("connector_refund_id") | ||||||
|             .get_required_value("response") |             .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; | ||||||
|             .change_context(errors::ConnectorError::ResponseDeserializationFailed)? |  | ||||||
|             .connector_refund_id; |  | ||||||
|  |  | ||||||
|         let response: Vec<checkout::ActionResponse> = res |         let response: Vec<checkout::ActionResponse> = res | ||||||
|             .response |             .response | ||||||
|  | |||||||
| @ -445,12 +445,11 @@ impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponse | |||||||
|         connectors: &settings::Connectors, |         connectors: &settings::Connectors, | ||||||
|     ) -> CustomResult<String, errors::ConnectorError> { |     ) -> CustomResult<String, errors::ConnectorError> { | ||||||
|         let refund_id = req |         let refund_id = req | ||||||
|             .response |             .request | ||||||
|  |             .connector_refund_id | ||||||
|             .clone() |             .clone() | ||||||
|             .ok() |             .get_required_value("connector_refund_id") | ||||||
|             .get_required_value("response") |             .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; | ||||||
|             .change_context(errors::ConnectorError::ResponseDeserializationFailed)? |  | ||||||
|             .connector_refund_id; |  | ||||||
|         Ok(format!( |         Ok(format!( | ||||||
|             "{}refunds/{}", |             "{}refunds/{}", | ||||||
|             self.base_url(connectors), |             self.base_url(connectors), | ||||||
|  | |||||||
| @ -779,13 +779,11 @@ impl services::ConnectorIntegration<api::RSync, types::RefundsData, types::Refun | |||||||
|         connectors: &settings::Connectors, |         connectors: &settings::Connectors, | ||||||
|     ) -> CustomResult<String, errors::ConnectorError> { |     ) -> CustomResult<String, errors::ConnectorError> { | ||||||
|         let id = req |         let id = req | ||||||
|             .response |             .request | ||||||
|             .as_ref() |  | ||||||
|             .ok() |  | ||||||
|             .get_required_value("response") |  | ||||||
|             .change_context(errors::ConnectorError::FailedToObtainIntegrationUrl)? |  | ||||||
|             .connector_refund_id |             .connector_refund_id | ||||||
|             .clone(); |             .clone() | ||||||
|  |             .get_required_value("connector_refund_id") | ||||||
|  |             .change_context(errors::ConnectorError::FailedToObtainIntegrationUrl)?; | ||||||
|         Ok(format!("{}v1/refunds/{}", self.base_url(connectors), id)) |         Ok(format!("{}v1/refunds/{}", self.base_url(connectors), id)) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | |||||||
| @ -601,13 +601,11 @@ impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponse | |||||||
|         connectors: &Connectors, |         connectors: &Connectors, | ||||||
|     ) -> CustomResult<String, errors::ConnectorError> { |     ) -> CustomResult<String, errors::ConnectorError> { | ||||||
|         let refund_id = req |         let refund_id = req | ||||||
|             .response |             .request | ||||||
|             .as_ref() |  | ||||||
|             .ok() |  | ||||||
|             .get_required_value("response") |  | ||||||
|             .change_context(errors::ConnectorError::FailedToObtainIntegrationUrl)? |  | ||||||
|             .connector_refund_id |             .connector_refund_id | ||||||
|             .clone(); |             .clone() | ||||||
|  |             .get_required_value("connector_refund_id") | ||||||
|  |             .change_context(errors::ConnectorError::FailedToObtainIntegrationUrl)?; | ||||||
|         let base_url = self.base_url(connectors); |         let base_url = self.base_url(connectors); | ||||||
|         let auth: worldline::AuthType = worldline::AuthType::try_from(&req.connector_auth_type)?; |         let auth: worldline::AuthType = worldline::AuthType::try_from(&req.connector_auth_type)?; | ||||||
|         let merchant_account_id = auth.merchant_account_id; |         let merchant_account_id = auth.merchant_account_id; | ||||||
|  | |||||||
| @ -237,6 +237,8 @@ pub enum ConnectorError { | |||||||
|     NotImplemented(String), |     NotImplemented(String), | ||||||
|     #[error("Missing connector transaction ID")] |     #[error("Missing connector transaction ID")] | ||||||
|     MissingConnectorTransactionID, |     MissingConnectorTransactionID, | ||||||
|  |     #[error("Missing connector refund ID")] | ||||||
|  |     MissingConnectorRefundID, | ||||||
|     #[error("Webhooks not implemented for this connector")] |     #[error("Webhooks not implemented for this connector")] | ||||||
|     WebhooksNotImplemented, |     WebhooksNotImplemented, | ||||||
|     #[error("Failed to decode webhook event body")] |     #[error("Failed to decode webhook event body")] | ||||||
|  | |||||||
| @ -295,10 +295,12 @@ pub async fn sync_refund_with_gateway( | |||||||
|  |  | ||||||
|     logger::debug!(refund_retrieve_router_data=?router_data); |     logger::debug!(refund_retrieve_router_data=?router_data); | ||||||
|  |  | ||||||
|  |     if add_access_token_result.connector_supports_access_token { | ||||||
|         match add_access_token_result.access_token_result { |         match add_access_token_result.access_token_result { | ||||||
|             Ok(access_token) => router_data.access_token = access_token, |             Ok(access_token) => router_data.access_token = access_token, | ||||||
|             Err(connector_error) => router_data.response = Err(connector_error), |             Err(connector_error) => router_data.response = Err(connector_error), | ||||||
|         } |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     let router_data_res = if !(add_access_token_result.connector_supports_access_token |     let router_data_res = if !(add_access_token_result.connector_supports_access_token | ||||||
|         && router_data.access_token.is_none()) |         && router_data.access_token.is_none()) | ||||||
|  | |||||||
| @ -74,6 +74,7 @@ pub async fn construct_refund_router_data<'a, F>( | |||||||
|             amount, |             amount, | ||||||
|             connector_metadata: payment_attempt.connector_metadata.clone(), |             connector_metadata: payment_attempt.connector_metadata.clone(), | ||||||
|             reason: refund.refund_reason.clone(), |             reason: refund.refund_reason.clone(), | ||||||
|  |             connector_refund_id: refund.connector_refund_id.clone(), | ||||||
|         }, |         }, | ||||||
|  |  | ||||||
|         response: Ok(types::RefundsResponseData { |         response: Ok(types::RefundsResponseData { | ||||||
|  | |||||||
| @ -217,6 +217,8 @@ impl ResponseId { | |||||||
| pub struct RefundsData { | pub struct RefundsData { | ||||||
|     pub refund_id: String, |     pub refund_id: String, | ||||||
|     pub connector_transaction_id: String, |     pub connector_transaction_id: String, | ||||||
|  |  | ||||||
|  |     pub connector_refund_id: Option<String>, | ||||||
|     pub currency: storage_enums::Currency, |     pub currency: storage_enums::Currency, | ||||||
|     /// Amount for the payment against which this refund is issued |     /// Amount for the payment against which this refund is issued | ||||||
|     pub amount: i64, |     pub amount: i64, | ||||||
|  | |||||||
| @ -87,6 +87,7 @@ fn construct_refund_router_data<F>() -> types::RefundsRouterData<F> { | |||||||
|             refund_amount: 100, |             refund_amount: 100, | ||||||
|             connector_metadata: None, |             connector_metadata: None, | ||||||
|             reason: None, |             reason: None, | ||||||
|  |             connector_refund_id: None, | ||||||
|         }, |         }, | ||||||
|         payment_method_id: None, |         payment_method_id: None, | ||||||
|         response: Err(types::ErrorResponse::default()), |         response: Err(types::ErrorResponse::default()), | ||||||
|  | |||||||
| @ -87,6 +87,7 @@ fn construct_refund_router_data<F>() -> types::RefundsRouterData<F> { | |||||||
|             refund_amount: 1, |             refund_amount: 1, | ||||||
|             connector_metadata: None, |             connector_metadata: None, | ||||||
|             reason: None, |             reason: None, | ||||||
|  |             connector_refund_id: None, | ||||||
|         }, |         }, | ||||||
|         response: Err(types::ErrorResponse::default()), |         response: Err(types::ErrorResponse::default()), | ||||||
|         payment_method_id: None, |         payment_method_id: None, | ||||||
|  | |||||||
| @ -84,6 +84,7 @@ fn construct_refund_router_data<F>() -> types::RefundsRouterData<F> { | |||||||
|             refund_amount: 10, |             refund_amount: 10, | ||||||
|             connector_metadata: None, |             connector_metadata: None, | ||||||
|             reason: None, |             reason: None, | ||||||
|  |             connector_refund_id: None, | ||||||
|         }, |         }, | ||||||
|         response: Err(types::ErrorResponse::default()), |         response: Err(types::ErrorResponse::default()), | ||||||
|         payment_method_id: None, |         payment_method_id: None, | ||||||
|  | |||||||
| @ -144,6 +144,7 @@ pub trait ConnectorActions: Connector { | |||||||
|                 connector_transaction_id: transaction_id, |                 connector_transaction_id: transaction_id, | ||||||
|                 refund_amount: 100, |                 refund_amount: 100, | ||||||
|                 connector_metadata: None, |                 connector_metadata: None, | ||||||
|  |                 connector_refund_id: None, | ||||||
|                 reason: Some("Customer returned product".to_string()), |                 reason: Some("Customer returned product".to_string()), | ||||||
|             }), |             }), | ||||||
|             payment_info, |             payment_info, | ||||||
| @ -167,6 +168,7 @@ pub trait ConnectorActions: Connector { | |||||||
|                 refund_amount: 100, |                 refund_amount: 100, | ||||||
|                 connector_metadata: None, |                 connector_metadata: None, | ||||||
|                 reason: None, |                 reason: None, | ||||||
|  |                 connector_refund_id: None, | ||||||
|             }), |             }), | ||||||
|             payment_info, |             payment_info, | ||||||
|         ); |         ); | ||||||
| @ -335,6 +337,7 @@ impl Default for PaymentRefundType { | |||||||
|             refund_amount: 100, |             refund_amount: 100, | ||||||
|             connector_metadata: None, |             connector_metadata: None, | ||||||
|             reason: None, |             reason: None, | ||||||
|  |             connector_refund_id: None, | ||||||
|         }; |         }; | ||||||
|         Self(data) |         Self(data) | ||||||
|     } |     } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Nishant Joshi
					Nishant Joshi