text
stringlengths
70
351k
source
stringclasses
4 values
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/webhooks.rs | crate: api_models use crate::payouts; pub type MerchantWebhookConfig = std::collections::HashSet<IncomingWebhookEvent>; fn from(evt: IncomingWebhookEvent) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/webhooks.rs | crate: api_models use common_utils::custom_serde; use crate::payouts; use crate::{disputes, enums as api_enums, mandates, payments, refunds}; pub type MerchantWebhookConfig = std::collections::HashSet<IncomingWebhookEvent>; pub fn get_connector_transaction_id_as_string( self, ) -> Result<String, common_utils::errors::ValidationError> { { Self::PaymentId( payments::PaymentIdType::ConnectorTransactionId(id) ) => Ok(id),<|fim_suffix|> <|fim_middle|> Self::InvoiceId(_) => Err( common_utils::errors::ValidationError::IncorrectValueProvided { field_name: "PaymentId is required but received InvoiceId", }, ) } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/webhooks.rs | crate: api_models use crate::payouts; pub type MerchantWebhookConfig = std::collections::HashSet<IncomingWebhookEvent>; fn from(evt: IncomingWebhookEvent) -> Self { { IncomingWebhookEvent::PaymentIntentFailure | IncomingWebhookEvent::PaymentIntentSuccess | IncomingWebhookEvent::PaymentIntentProcessing | IncomingWebhookEvent::PaymentActionRequired | IncomingWebhookEvent::PaymentIntentPartiallyFunded | IncomingWebhookEvent::PaymentIntentCancelled | IncomingWebhookEvent::PaymentIntentCancelFailure | IncomingWebhookEvent::PaymentIntentAuthorizationSuccess | IncomingWebhookEvent::PaymentIntentAuthorizationFailure | IncomingWebhookEvent::PaymentIntentCaptureSuccess | IncomingWebhookEvent::PaymentIntentCaptureFailure => Self::Payment,<|fim_suffix|> <|fim_middle|> #[cfg(all(feature = "revenue_recovery", feature = "v2"))] IncomingWebhookEvent::RecoveryInvoiceCancel | IncomingWebhookEvent::RecoveryPaymentFailure | IncomingWebhookEvent::RecoveryPaymentPending | IncomingWebhookEvent::RecoveryPaymentSuccess => Self::Recovery, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/webhooks.rs | crate: api_models pub type MerchantWebhookConfig = std::collections::HashSet<IncomingWebhookEvent>; pub fn is_recovery_transaction_event(&self) -> bool { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/webhooks.rs | crate: api_models use common_utils::custom_serde; use crate::payouts; pub type MerchantWebhookConfig = std::collections::HashSet<IncomingWebhookEvent>; pub fn get_payment_id(&self) -> Option<common_utils::id_type::GlobalPaymentId> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/webhooks.rs | crate: api_models use common_utils::custom_serde; use crate::payouts; pub type MerchantWebhookConfig = std::collections::HashSet<IncomingWebhookEvent>; pub fn get_payment_id(&self) -> Option<common_utils::id_type::PaymentId> { { Self::Payment { payment_id, .. } | Self::Refund { payment_id, .. } | Self::Dispute { payment_id, .. } => Some(payment_id.to_owned()),<|fim_suffix|> <|fim_middle|> Self::Relay { .. } => None, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/api_keys.rs | crate: api_models fn from(expiration: ApiKeyExpiration) -> Self { { ApiKeyExpiration::Never => None,<|fim_suffix|> <|fim_middle|> ApiKeyExpiration::DateTime(date_time) => Some(date_time), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/api_keys.rs | crate: api_models fn test_null() { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/api_keys.rs | crate: api_models use time::PrimitiveDateTime; fn test_deserialization() { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/api_keys.rs | crate: api_models use time::PrimitiveDateTime; fn test_serialization() { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/api_keys.rs | crate: api_models use common_utils::custom_serde; use masking::StrongSecret; use serde::{Deserialize, Serialize}; use time::PrimitiveDateTime; use utoipa::ToSchema; fn schema() -> ( &'a str, utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>, ) { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/api_keys.rs | crate: api_models use serde::{Deserialize, Serialize}; pub fn deserialize<'de, D>(deserializer: D) -> Result<(), D::Error> where D: serde::Deserializer<'de>, { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/api_keys.rs | crate: api_models use serde::{Deserialize, Serialize}; fn visit_str<E: serde::de::Error>(self, value: &str) -> Result<Self::Value, E> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/api_keys.rs | crate: api_models fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/api_keys.rs | crate: api_models use serde::{Deserialize, Serialize}; pub fn serialize<S>(serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/api_keys.rs | crate: api_models use time::PrimitiveDateTime; fn from(date_time: Option<PrimitiveDateTime>) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/api_keys.rs | crate: api_models fn from(expiration: ApiKeyExpiration) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/analytics.rs | crate: api_models use self::{ active_payments::ActivePaymentsMetrics, api_event::{ApiEventDimensions, ApiEventMetrics}, auth_events::{AuthEventDimensions, AuthEventFilters, AuthEventMetrics}, disputes::{DisputeDimensions, DisputeMetrics}, frm::{FrmDimensions, FrmMetrics}, payment_intents::{PaymentIntentDimensions, PaymentIntentMetrics}, payments::{PaymentDimensions, PaymentDistributions, PaymentMetrics}, refunds::{RefundDimensions, RefundDistributions, RefundMetrics}, sdk_events::{SdkEventDimensions, SdkEventMetrics}, }; fn into(self) -> u64 { { Self::Top5 => 5,<|fim_suffix|> <|fim_middle|> Self::Top10 => 10, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/analytics.rs | crate: api_models use self::{ active_payments::ActivePaymentsMetrics, api_event::{ApiEventDimensions, ApiEventMetrics}, auth_events::{AuthEventDimensions, AuthEventFilters, AuthEventMetrics}, disputes::{DisputeDimensions, DisputeMetrics}, frm::{FrmDimensions, FrmMetrics}, payment_intents::{PaymentIntentDimensions, PaymentIntentMetrics}, payments::{PaymentDimensions, PaymentDistributions, PaymentMetrics}, refunds::{RefundDimensions, RefundDistributions, RefundMetrics}, sdk_events::{SdkEventDimensions, SdkEventMetrics}, }; fn into(self) -> u64 { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/analytics.rs | crate: api_models pub use common_utils::types::TimeRange; use self::{ active_payments::ActivePaymentsMetrics, api_event::{ApiEventDimensions, ApiEventMetrics}, auth_events::{AuthEventDimensions, AuthEventFilters, AuthEventMetrics}, disputes::{DisputeDimensions, DisputeMetrics}, frm::{FrmDimensions, FrmMetrics}, payment_intents::{PaymentIntentDimensions, PaymentIntentMetrics}, payments::{PaymentDimensions, PaymentDistributions, PaymentMetrics}, refunds::{RefundDimensions, RefundDistributions, RefundMetrics}, sdk_events::{SdkEventDimensions, SdkEventMetrics}, }; pub fn requires_forex_functionality(&self) -> bool { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/health_check.rs | crate: api_models fn from(value: HealthState) -> Self { { HealthState::Running => Some(true),<|fim_suffix|> <|fim_middle|> HealthState::NotApplicable => None, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/health_check.rs | crate: api_models fn from(value: HealthState) -> Self { { HealthState::Running => true,<|fim_suffix|> <|fim_middle|> HealthState::Error | HealthState::NotApplicable => false, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/health_check.rs | crate: api_models fn from(value: HealthState) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; use masking::{PeekInterface, Secret}; pub fn get_frm_config_as_secret(&self) -> Option<Vec<Secret<serde_json::Value>>> { { Some(frm_value) => { let configs_for_frm_value: Vec<Secret<serde_json::Value>> = frm_value .iter() .map(|config| config.encode_to_value().map(Secret::new)) .collect::<Result<Vec<_>, _>>() .ok()?; Some(configs_for_frm_value) }<|fim_suffix|> <|fim_middle|> None => None, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; pub fn get_connector_label(&self, profile_name: String) -> String { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; pub fn validate(&self) -> Result<(), &str> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use std::collections::{HashMap, HashSet}; use masking::{PeekInterface, Secret}; pub fn from_headers(headers: HashMap<String, Secret<String>>) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models fn mask_value(value: &str) -> String { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; use crate::{ consts::{MAX_ORDER_FULFILLMENT_EXPIRY, MIN_ORDER_FULFILLMENT_EXPIRY}, enums as api_enums, payment_methods, }; pub fn get_payment_method_type( &self, ) -> Option<&Vec<payment_methods::RequestPaymentMethodTypes>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; use masking::{PeekInterface, Secret}; pub fn get_frm_config_as_secret(&self) -> Option<Vec<Secret<serde_json::Value>>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; pub fn get_connector_name(&self) -> common_enums::connector_enums::Connector { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; pub fn to_merchant_connector_info(&self, connector_label: &String) -> MerchantConnectorInfo { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; pub fn get_connector_name(&self) -> String { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; pub fn new( connector_label: String, merchant_connector_id: id_type::MerchantConnectorAccountId, ) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; use crate::{ consts::{MAX_ORDER_FULFILLMENT_EXPIRY, MIN_ORDER_FULFILLMENT_EXPIRY}, enums as api_enums, payment_methods, }; pub fn get_transaction_type(&self) -> api_enums::TransactionType { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; pub fn get_connector_label(&self, profile_name: String) -> String { { Some(connector_label) => connector_label,<|fim_suffix|> <|fim_middle|> None => format!("{}_{}", self.connector_name, profile_name), } }
ast_fragments
// file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; use masking::{PeekInterface, Secret}; pub fn get_frm_config_as_secret(&self) -> Option<Vec<Secret<serde_json::Value>>> { match self.frm_configs.as_ref() { Some(frm_value) => { let configs_for_frm_value: Vec<Secret<serde_json::Value>> = frm_value .iter() .map(|config| config.encode_to_value().map(Secret::new)) .collect::<Result<Vec<_>, _>>() .ok()?; Some(configs_for_frm_value) } None => None, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; use masking::{PeekInterface, Secret}; pub fn get_metadata_as_secret( &self, ) -> CustomResult<Option<pii::SecretSerdeValue>, errors::ParsingError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; use masking::{PeekInterface, Secret}; pub fn get_merchant_details_as_secret( &self, ) -> CustomResult<Option<pii::SecretSerdeValue>, errors::ParsingError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; pub fn get_enable_payment_response_hash(&self) -> bool { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; use crate::routing; pub fn parse_routing_algorithm(&self) -> CustomResult<(), errors::ParsingError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; pub fn get_webhook_details_as_value( &self, ) -> CustomResult<Option<serde_json::Value>, errors::ParsingError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; pub fn get_pm_link_config_as_value( &self, ) -> CustomResult<Option<serde_json::Value>, errors::ParsingError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; pub fn get_primary_details_as_value( &self, ) -> CustomResult<Option<serde_json::Value>, errors::ParsingError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; pub fn get_primary_details_as_value( &self, ) -> CustomResult<serde_json::Value, errors::ParsingError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; pub fn get_merchant_reference_id(&self) -> id_type::MerchantId { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/admin.rs | crate: api_models use common_utils::{ consts, crypto::Encryptable, errors::{self, CustomResult}, ext_traits::Encode, id_type, link_utils, pii, }; use common_utils::{crypto::OptionalEncryptableName, ext_traits::ValueExt}; pub fn get_payment_response_hash_key(&self) -> Option<String> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/payments/trait_impls.rs | crate: api_models use common_enums::enums; use common_utils::errors; use crate::payments; fn validate_field_and_get( &self, request: &payments::PaymentsRequest, ) -> errors::CustomResult<Self, errors::ValidationError> where Self: Sized, { { Some(enums::CaptureMethod::Automatic) | Some(enums::CaptureMethod::Scheduled) | Some(enums::CaptureMethod::SequentialAutomatic) | None => Err(error_stack::report!(errors::ValidationError::InvalidValue { message: "request_extended_authorization must be sent only if capture method is manual or manual_multiple".to_string() })),<|fim_suffix|> <|fim_middle|> Some(enums::CaptureMethod::Manual) | Some(enums::CaptureMethod::ManualMultiple) => Ok(*self) } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/payments/trait_impls.rs | crate: api_models use common_enums::enums; use common_utils::errors; use crate::payments; fn validate_field_and_get( &self, request: &payments::PaymentsRequest, ) -> errors::CustomResult<Self, errors::ValidationError> where Self: Sized, { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/errors/types.rs | crate: api_models pub(crate) fn error_type(&self) -> &'static str { { Self::Unauthorized(_) | Self::ForbiddenCommonResource(_) | Self::ForbiddenPrivateResource(_) | Self::Conflict(_) | Self::Gone(_) | Self::Unprocessable(_) | Self::NotImplemented(_) | Self::MethodNotAllowed(_) | Self::NotFound(_) | Self::BadRequest(_) => "invalid_request",<|fim_suffix|> <|fim_middle|> Self::ConnectorError(_, _) => "connector", } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/errors/types.rs | crate: api_models pub(crate) fn error_type(&self) -> &'static str { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/errors/types.rs | crate: api_models pub fn get_internal_error_mut(&mut self) -> &mut ApiError { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/errors/types.rs | crate: api_models pub(crate) fn get_internal_error(&self) -> &ApiError { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/errors/types.rs | crate: api_models use std::borrow::Cow; fn from(value: &'a ApiErrorResponse) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/errors/types.rs | crate: api_models pub fn new( sub_code: &'static str, error_identifier: u16, error_message: impl ToString, extra: Option<Extra>, ) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/analytics/refunds.rs | crate: api_models fn from(value: RefundDimensions) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/analytics/refunds.rs | crate: api_models use crate::enums::{Currency, RefundStatus}; use super::{ForexMetric, NameDescription, TimeRange}; pub fn new( currency: Option<Currency>, refund_status: Option<String>, connector: Option<String>, refund_type: Option<String>, profile_id: Option<String>, refund_reason: Option<String>, refund_error_message: Option<String>, normalized_time_range: TimeRange, ) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/api_models/src/analytics/refunds.rs | crate: api_models fn from(value: RefundDimensions) -> Self { Self { name: value.to_string(), desc: String::new(), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/analytics/refunds.rs | crate: api_models fn from(value: RefundMetrics) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/analytics/auth_events.rs | crate: api_models fn from(value: AuthEventDimensions) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/api_models/src/analytics/auth_events.rs | crate: api_models use std::{ collections::hash_map::DefaultHasher, hash::{Hash, Hasher}, }; fn hash<H: Hasher>(&self, state: &mut H) { self.authentication_status.hash(state); self.trans_status.hash(state); self.authentication_type.hash(state); self.authentication_connector.hash(state); self.message_version.hash(state); self.acs_reference_number.hash(state); self.error_message.hash(state); self.time_bucket.hash(state); }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/analytics/auth_events.rs | crate: api_models use common_enums::{ AuthenticationConnectors, AuthenticationStatus, DecoupledAuthenticationType, TransactionStatus, }; use super::{NameDescription, TimeRange}; pub fn new( authentication_status: Option<AuthenticationStatus>, trans_status: Option<TransactionStatus>, authentication_type: Option<DecoupledAuthenticationType>, error_message: Option<String>, authentication_connector: Option<AuthenticationConnectors>, message_version: Option<String>, acs_reference_number: Option<String>, normalized_time_range: TimeRange, ) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/api_models/src/analytics/auth_events.rs | crate: api_models fn from(value: AuthEventDimensions) -> Self { Self { name: value.to_string(), desc: String::new(), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/api_models/src/analytics/auth_events.rs | crate: api_models fn from(value: AuthEventMetrics) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/formatter.rs | crate: router_env use std::{ collections::{HashMap, HashSet}, fmt, io::Write, }; use serde::ser::{SerializeMap, Serializer}; use serde_json::{ser::Formatter, Value}; use tracing::{Event, Metadata, Subscriber}; use tracing_subscriber::{ fmt::MakeWriter, layer::Context, registry::{LookupSpan, SpanRef}, Layer, }; use crate::Storage; /// Serialize entries of span. fn span_serialize<S>( &self, span: &SpanRef<'_, S>, ty: RecordType, ) -> Result<Vec<u8>, std::io::Error> where S: Subscriber + for<'a> LookupSpan<'a>, { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/formatter.rs | crate: router_env use std::{ collections::{HashMap, HashSet}, fmt, io::Write, }; use config::ConfigError; use serde_json::{ser::Formatter, Value}; use tracing_subscriber::{ fmt::MakeWriter, layer::Context, registry::{LookupSpan, SpanRef}, Layer, }; use crate::Storage; /// Construct of `FormattingLayer with implicit default entries. pub fn new_with_implicit_entries( service: &str, dst_writer: W, default_fields: HashMap<String, Value>, formatter: F, ) -> error_stack::Result<Self, ConfigError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/formatter.rs | crate: router_env use std::{ collections::{HashMap, HashSet}, fmt, io::Write, }; use serde::ser::{SerializeMap, Serializer}; use serde_json::{ser::Formatter, Value}; use time::format_description::well_known::Iso8601; use tracing::{Event, Metadata, Subscriber}; use tracing_subscriber::{ fmt::MakeWriter, layer::Context, registry::{LookupSpan, SpanRef}, Layer, }; use crate::Storage; /// Serialize common for both span and event entries. fn common_serialize<S>( &self, map_serializer: &mut impl SerializeMap<Error = serde_json::Error>, metadata: &Metadata<'_>, span: Option<&SpanRef<'_, S>>, storage: &Storage<'_>, name: &str, ) -> Result<(), std::io::Error> where S: Subscriber + for<'a> LookupSpan<'a>, { {let is_extra = |s: &str| !IMPLICIT_KEYS.contains(s);let is_extra_implicit = |s: &str| is_extra(s) && EXTRA_IMPLICIT_KEYS.contains(s);<|fim_suffix|> <|fim_middle|> map_serializer.serialize_entry("extra", &extra)?;Ok(())}}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/formatter.rs | crate: router_env use std::{ collections::{HashMap, HashSet}, fmt, io::Write, }; use config::ConfigError; /// /// A `name` will be attached to all records during formatting. /// A `dst_writer` to forward all records. /// /// ## Example /// ```rust /// let formatting_layer = router_env::FormattingLayer::new("my_service", std::io::stdout, serde_json::ser::CompactFormatter); /// ``` pub fn new( service: &str, dst_writer: W, formatter: F, ) -> error_stack::Result<Self, ConfigError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/formatter.rs | crate: router_env use tracing::{Event, Metadata, Subscriber}; use tracing_subscriber::{ fmt::MakeWriter, layer::Context, registry::{LookupSpan, SpanRef}, Layer, }; fn on_close(&self, id: tracing::Id, ctx: Context<'_, S>) { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/formatter.rs | crate: router_env use tracing::{Event, Metadata, Subscriber}; use tracing_subscriber::{ fmt::MakeWriter, layer::Context, registry::{LookupSpan, SpanRef}, Layer, }; fn on_enter(&self, id: &tracing::Id, ctx: Context<'_, S>) { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/formatter.rs | crate: router_env use std::{ collections::{HashMap, HashSet}, fmt, io::Write, }; use tracing::{Event, Metadata, Subscriber}; use tracing_subscriber::{ fmt::MakeWriter, layer::Context, registry::{LookupSpan, SpanRef}, Layer, }; fn on_event(&self, event: &Event<'_>, ctx: Context<'_, S>) { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/formatter.rs | crate: router_env use serde_json::{ser::Formatter, Value}; use tracing::{Event, Metadata, Subscriber}; use tracing_subscriber::{ fmt::MakeWriter, layer::Context, registry::{LookupSpan, SpanRef}, Layer, }; use crate::Storage; /// Format message of an event. /// /// Examples: "[FN_WITHOUT_COLON - EVENT] Message" fn event_message<S>(span: Option<&SpanRef<'_, S>>, event: &Event<'_>, storage: &mut Storage<'_>) where S: Subscriber + for<'a> LookupSpan<'a>, { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/formatter.rs | crate: router_env use tracing::{Event, Metadata, Subscriber}; use tracing_subscriber::{ fmt::MakeWriter, layer::Context, registry::{LookupSpan, SpanRef}, Layer, }; /// Format message of a span. /// /// Example: "[FN_WITHOUT_COLON - START]" fn span_message<S>(span: &SpanRef<'_, S>, ty: RecordType) -> String where S: Subscriber + for<'a> LookupSpan<'a>, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/formatter.rs | crate: router_env use std::{ collections::{HashMap, HashSet}, fmt, io::Write, }; use serde::ser::{SerializeMap, Serializer}; use serde_json::{ser::Formatter, Value}; use tracing::{Event, Metadata, Subscriber}; use tracing_subscriber::{ fmt::MakeWriter, layer::Context, registry::{LookupSpan, SpanRef}, Layer, }; use crate::Storage; /// Serialize event into a buffer of bytes using parent span. pub fn event_serialize<S>( &self, span: Option<&SpanRef<'_, S>>, event: &Event<'_>, ) -> std::io::Result<Vec<u8>> where S: Subscriber + for<'a> LookupSpan<'a>, { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/formatter.rs | crate: router_env use std::{ collections::{HashMap, HashSet}, fmt, io::Write, }; /// Flush memory buffer into an output stream trailing it with next line. /// /// Should be done by single `write_all` call to avoid fragmentation of log because of mutlithreading. fn flush(&self, mut buffer: Vec<u8>) -> Result<(), std::io::Error> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/formatter.rs | crate: router_env use std::{ collections::{HashMap, HashSet}, fmt, io::Write, }; use config::ConfigError; /// Constructor of `FormattingLayer`. /// /// A `name` will be attached to all records during formatting. /// A `dst_writer` to forward all records. /// /// ## Example /// ```rust /// let formatting_layer = router_env::FormattingLayer::new("my_service", std::io::stdout, serde_json::ser::CompactFormatter); /// ``` pub fn new( service: &str, dst_writer: W, formatter: F, ) -> error_stack::Result<Self, ConfigError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/formatter.rs | crate: router_env use std::{ collections::{HashMap, HashSet}, fmt, io::Write, }; use serde::ser::{SerializeMap, Serializer}; use serde_json::{ser::Formatter, Value}; use time::format_description::well_known::Iso8601; use tracing::{Event, Metadata, Subscriber}; use tracing_subscriber::{ fmt::MakeWriter, layer::Context, registry::{LookupSpan, SpanRef}, Layer, }; use crate::Storage; /// Serialize common for both span and event entries. fn common_serialize<S>( &self, map_serializer: &mut impl SerializeMap<Error = serde_json::Error>, metadata: &Metadata<'_>, span: Option<&SpanRef<'_, S>>, storage: &Storage<'_>, name: &str, ) -> Result<(), std::io::Error> where S: Subscriber + for<'a> LookupSpan<'a>, { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/storage.rs | crate: router_env use std::{collections::HashMap, fmt, time::Instant}; use tracing::{ field::{Field, Visit}, span::{Attributes, Record}, Id, Subscriber, }; use tracing_subscriber::{layer::Context, Layer}; /// On close create an entry about how long did it take. fn on_close(&self, span: Id, ctx: Context<'_, S>) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/storage.rs | crate: router_env use std::{collections::HashMap, fmt, time::Instant}; use tracing::{ field::{Field, Visit}, span::{Attributes, Record}, Id, Subscriber, }; /// Otherwise. fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) { { name if name.starts_with("log.") => (),<|fim_suffix|> <|fim_middle|> name => { self.record_value(name, serde_json::Value::from(format!("{value:?}"))); } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/storage.rs | crate: router_env use std::{collections::HashMap, fmt, time::Instant}; use tracing::{ field::{Field, Visit}, span::{Attributes, Record}, Id, Subscriber, }; use tracing_subscriber::{layer::Context, Layer}; /// On enter store time. fn on_enter(&self, span: &Id, ctx: Context<'_, S>) { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/storage.rs | crate: router_env use tracing::{ field::{Field, Visit}, span::{Attributes, Record}, Id, Subscriber, }; use tracing_subscriber::{layer::Context, Layer}; /// On additional key value pairs store it. fn on_record(&self, span: &Id, values: &Record<'_>, ctx: Context<'_, S>) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/storage.rs | crate: router_env use tracing::{ field::{Field, Visit}, span::{Attributes, Record}, Id, Subscriber, }; use tracing_subscriber::{layer::Context, Layer}; /// On new span. fn on_new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/storage.rs | crate: router_env use std::{collections::HashMap, fmt, time::Instant}; use tracing::{ field::{Field, Visit}, span::{Attributes, Record}, Id, Subscriber, }; /// Otherwise. fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/storage.rs | crate: router_env use tracing::{ field::{Field, Visit}, span::{Attributes, Record}, Id, Subscriber, }; /// A string. fn record_str(&mut self, field: &Field, value: &str) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/storage.rs | crate: router_env use tracing::{ field::{Field, Visit}, span::{Attributes, Record}, Id, Subscriber, }; /// A boolean. fn record_bool(&mut self, field: &Field, value: bool) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/storage.rs | crate: router_env use tracing::{ field::{Field, Visit}, span::{Attributes, Record}, Id, Subscriber, }; /// A 64-bit floating point. fn record_f64(&mut self, field: &Field, value: f64) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/storage.rs | crate: router_env use tracing::{ field::{Field, Visit}, span::{Attributes, Record}, Id, Subscriber, }; /// A u64. fn record_u64(&mut self, field: &Field, value: u64) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/storage.rs | crate: router_env use tracing::{ field::{Field, Visit}, span::{Attributes, Record}, Id, Subscriber, }; /// A i64. fn record_i64(&mut self, field: &Field, value: i64) { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/storage.rs | crate: router_env use tracing::{ field::{Field, Visit}, span::{Attributes, Record}, Id, Subscriber, }; pub fn record_value(&mut self, key: &'a str, value: serde_json::Value) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/storage.rs | crate: router_env /// Default constructor. pub fn new() -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/setup.rs | crate: router_env use std::time::Duration; use ::config::ConfigError; use tracing_subscriber::{fmt, prelude::*, util::SubscriberInitExt, EnvFilter, Layer}; use crate::{config, FormattingLayer, StorageSubscription}; fn get_envfilter( filtering_directive: Option<&String>, default_log_level: config::Level, filter_log_level: config::Level, crates_to_filter: impl AsRef<[&'static str]>, ) -> EnvFilter { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/setup.rs | crate: router_env use std::time::Duration; use ::config::ConfigError; use serde_json::ser::{CompactFormatter, PrettyFormatter}; use tracing_appender::non_blocking::WorkerGuard; use tracing_subscriber::{fmt, prelude::*, util::SubscriberInitExt, EnvFilter, Layer}; use crate::{config, FormattingLayer, StorageSubscription}; fn setup_metrics_pipeline(config: &config::LogTelemetry) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/setup.rs | crate: router_env use std::time::Duration; use ::config::ConfigError; use serde_json::ser::{CompactFormatter, PrettyFormatter}; use tracing_appender::non_blocking::WorkerGuard; use tracing_subscriber::{fmt, prelude::*, util::SubscriberInitExt, EnvFilter, Layer}; use crate::{config, FormattingLayer, StorageSubscription}; fn setup_tracing_pipeline( config: &config::LogTelemetry, service_name: &str, ) -> Option< tracing_opentelemetry::OpenTelemetryLayer< tracing_subscriber::Registry, opentelemetry_sdk::trace::Tracer, >, > { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/setup.rs | crate: router_env use std::time::Duration; use ::config::ConfigError; use serde_json::ser::{CompactFormatter, PrettyFormatter}; use tracing_appender::non_blocking::WorkerGuard; use tracing_subscriber::{fmt, prelude::*, util::SubscriberInitExt, EnvFilter, Layer}; use crate::{config, FormattingLayer, StorageSubscription}; fn should_sample( &self, parent_context: Option<&opentelemetry::Context>, trace_id: opentelemetry::trace::TraceId, name: &str, span_kind: &opentelemetry::trace::SpanKind, attributes: &[opentelemetry::KeyValue], links: &[opentelemetry::trace::Link], ) -> opentelemetry::trace::SamplingResult { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/setup.rs | crate: router_env /// Should the provided url be traced fn should_trace_url(&self, url: &str) -> bool { { Some(clauses) => clauses.iter().all(|cur| cur.compare_url(url)),<|fim_suffix|> <|fim_middle|> None => self.default, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/setup.rs | crate: router_env fn from(value: String) -> Self { { url if url.starts_with('*') => Self::EndsWith(url.trim_start_matches('*').to_string()),<|fim_suffix|> <|fim_middle|> url => Self::Match(url), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/setup.rs | crate: router_env /// Should the provided url be traced fn should_trace_url(&self, url: &str) -> bool { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router_env/src/logger/setup.rs | crate: router_env fn compare_url(&self, url: &str) -> bool { match self { Self::Match(value) => url == value, Self::EndsWith(end) => url.ends_with(end), } }
ast_fragments
// file: hyperswitch/crates/router_env/src/logger/setup.rs | crate: router_env use std::time::Duration; use ::config::ConfigError; use crate::{config, FormattingLayer, StorageSubscription}; fn get_opentelemetry_exporter_config( config: &config::LogTelemetry, ) -> opentelemetry_otlp::ExportConfig { let mut exporter_config = opentelemetry_otlp::ExportConfig { protocol: opentelemetry_otlp::Protocol::Grpc, endpoint: config.otel_exporter_otlp_endpoint.clone(), ..Default::default() }; if let Some(timeout) = config.otel_exporter_otlp_timeout { exporter_config.timeout = Duration::from_millis(timeout); } exporter_config }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router_env/src/logger/setup.rs | crate: router_env use std::time::Duration; use ::config::ConfigError; use serde_json::ser::{CompactFormatter, PrettyFormatter}; use tracing_appender::non_blocking::WorkerGuard; use tracing_subscriber::{fmt, prelude::*, util::SubscriberInitExt, EnvFilter, Layer}; use crate::{config, FormattingLayer, StorageSubscription}; pub fn setup( config: &config::Log, service_name: &str, crates_to_filter: impl AsRef<[&'static str]>, ) -> error_stack::Result<TelemetryGuard, ConfigError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments