mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	feat(events): add extracted fields based on req/res types (#2795)
This commit is contained in:
		
							
								
								
									
										35
									
								
								crates/api_models/src/events/customer.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								crates/api_models/src/events/customer.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,35 @@ | ||||
| use common_utils::events::{ApiEventMetric, ApiEventsType}; | ||||
|  | ||||
| use crate::customers::{CustomerDeleteResponse, CustomerId, CustomerRequest, CustomerResponse}; | ||||
|  | ||||
| impl ApiEventMetric for CustomerDeleteResponse { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Customer { | ||||
|             customer_id: self.customer_id.clone(), | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for CustomerRequest { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Customer { | ||||
|             customer_id: self.customer_id.clone(), | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for CustomerResponse { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Customer { | ||||
|             customer_id: self.customer_id.clone(), | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for CustomerId { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Customer { | ||||
|             customer_id: self.customer_id.clone(), | ||||
|         }) | ||||
|     } | ||||
| } | ||||
							
								
								
									
										151
									
								
								crates/api_models/src/events/payment.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										151
									
								
								crates/api_models/src/events/payment.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,151 @@ | ||||
| use common_utils::events::{ApiEventMetric, ApiEventsType}; | ||||
|  | ||||
| use crate::{ | ||||
|     payment_methods::{ | ||||
|         CustomerPaymentMethodsListResponse, PaymentMethodDeleteResponse, PaymentMethodListRequest, | ||||
|         PaymentMethodResponse, PaymentMethodUpdate, | ||||
|     }, | ||||
|     payments::{ | ||||
|         PaymentIdType, PaymentListConstraints, PaymentListFilterConstraints, PaymentListFilters, | ||||
|         PaymentListResponse, PaymentListResponseV2, PaymentsApproveRequest, PaymentsCancelRequest, | ||||
|         PaymentsCaptureRequest, PaymentsRejectRequest, PaymentsRequest, PaymentsResponse, | ||||
|         PaymentsRetrieveRequest, PaymentsStartRequest, RedirectionResponse, | ||||
|     }, | ||||
| }; | ||||
| impl ApiEventMetric for PaymentsRetrieveRequest { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         match self.resource_id { | ||||
|             PaymentIdType::PaymentIntentId(ref id) => Some(ApiEventsType::Payment { | ||||
|                 payment_id: id.clone(), | ||||
|             }), | ||||
|             _ => None, | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for PaymentsStartRequest { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Payment { | ||||
|             payment_id: self.payment_id.clone(), | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for PaymentsCaptureRequest { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Payment { | ||||
|             payment_id: self.payment_id.to_owned(), | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for PaymentsCancelRequest { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Payment { | ||||
|             payment_id: self.payment_id.clone(), | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for PaymentsApproveRequest { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Payment { | ||||
|             payment_id: self.payment_id.clone(), | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for PaymentsRejectRequest { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Payment { | ||||
|             payment_id: self.payment_id.clone(), | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for PaymentsRequest { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         match self.payment_id { | ||||
|             Some(PaymentIdType::PaymentIntentId(ref id)) => Some(ApiEventsType::Payment { | ||||
|                 payment_id: id.clone(), | ||||
|             }), | ||||
|             _ => None, | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for PaymentsResponse { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         self.payment_id | ||||
|             .clone() | ||||
|             .map(|payment_id| ApiEventsType::Payment { payment_id }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for PaymentMethodResponse { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::PaymentMethod { | ||||
|             payment_method_id: self.payment_method_id.clone(), | ||||
|             payment_method: Some(self.payment_method), | ||||
|             payment_method_type: self.payment_method_type, | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for PaymentMethodUpdate {} | ||||
|  | ||||
| impl ApiEventMetric for PaymentMethodDeleteResponse { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::PaymentMethod { | ||||
|             payment_method_id: self.payment_method_id.clone(), | ||||
|             payment_method: None, | ||||
|             payment_method_type: None, | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for CustomerPaymentMethodsListResponse {} | ||||
|  | ||||
| impl ApiEventMetric for PaymentMethodListRequest { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::PaymentMethodList { | ||||
|             payment_id: self | ||||
|                 .client_secret | ||||
|                 .as_ref() | ||||
|                 .and_then(|cs| cs.rsplit_once("_secret_")) | ||||
|                 .map(|(pid, _)| pid.to_string()), | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for PaymentListFilterConstraints { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::ResourceListAPI) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for PaymentListFilters { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::ResourceListAPI) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for PaymentListConstraints { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::ResourceListAPI) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for PaymentListResponse { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::ResourceListAPI) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for PaymentListResponseV2 { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::ResourceListAPI) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for RedirectionResponse {} | ||||
							
								
								
									
										29
									
								
								crates/api_models/src/events/payouts.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								crates/api_models/src/events/payouts.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,29 @@ | ||||
| use common_utils::events::{ApiEventMetric, ApiEventsType}; | ||||
|  | ||||
| use crate::payouts::{ | ||||
|     PayoutActionRequest, PayoutCreateRequest, PayoutCreateResponse, PayoutRetrieveRequest, | ||||
| }; | ||||
|  | ||||
| impl ApiEventMetric for PayoutRetrieveRequest { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Payout) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for PayoutCreateRequest { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Payout) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for PayoutCreateResponse { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Payout) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for PayoutActionRequest { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Payout) | ||||
|     } | ||||
| } | ||||
							
								
								
									
										63
									
								
								crates/api_models/src/events/refund.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								crates/api_models/src/events/refund.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,63 @@ | ||||
| use common_utils::events::{ApiEventMetric, ApiEventsType}; | ||||
|  | ||||
| use crate::refunds::{ | ||||
|     RefundListMetaData, RefundListRequest, RefundListResponse, RefundRequest, RefundResponse, | ||||
|     RefundUpdateRequest, RefundsRetrieveRequest, | ||||
| }; | ||||
|  | ||||
| impl ApiEventMetric for RefundRequest { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         let payment_id = self.payment_id.clone(); | ||||
|         self.refund_id | ||||
|             .clone() | ||||
|             .map(|refund_id| ApiEventsType::Refund { | ||||
|                 payment_id: Some(payment_id), | ||||
|                 refund_id, | ||||
|             }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for RefundResponse { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Refund { | ||||
|             payment_id: Some(self.payment_id.clone()), | ||||
|             refund_id: self.refund_id.clone(), | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for RefundsRetrieveRequest { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Refund { | ||||
|             payment_id: None, | ||||
|             refund_id: self.refund_id.clone(), | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for RefundUpdateRequest { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Refund { | ||||
|             payment_id: None, | ||||
|             refund_id: self.refund_id.clone(), | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for RefundListRequest { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::ResourceListAPI) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for RefundListResponse { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::ResourceListAPI) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for RefundListMetaData { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::ResourceListAPI) | ||||
|     } | ||||
| } | ||||
							
								
								
									
										58
									
								
								crates/api_models/src/events/routing.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								crates/api_models/src/events/routing.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,58 @@ | ||||
| use common_utils::events::{ApiEventMetric, ApiEventsType}; | ||||
|  | ||||
| use crate::routing::{ | ||||
|     LinkedRoutingConfigRetrieveResponse, MerchantRoutingAlgorithm, RoutingAlgorithmId, | ||||
|     RoutingConfigRequest, RoutingDictionaryRecord, RoutingKind, | ||||
| }; | ||||
| #[cfg(feature = "business_profile_routing")] | ||||
| use crate::routing::{RoutingRetrieveLinkQuery, RoutingRetrieveQuery}; | ||||
|  | ||||
| impl ApiEventMetric for RoutingKind { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Routing) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for MerchantRoutingAlgorithm { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Routing) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for RoutingAlgorithmId { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Routing) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for RoutingDictionaryRecord { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Routing) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for LinkedRoutingConfigRetrieveResponse { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Routing) | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[cfg(feature = "business_profile_routing")] | ||||
| impl ApiEventMetric for RoutingRetrieveQuery { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Routing) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ApiEventMetric for RoutingConfigRequest { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Routing) | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[cfg(feature = "business_profile_routing")] | ||||
| impl ApiEventMetric for RoutingRetrieveLinkQuery { | ||||
|     fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||||
|         Some(ApiEventsType::Routing) | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sampras Lopes
					Sampras Lopes