id stringlengths 11 116 | type stringclasses 1
value | granularity stringclasses 4
values | content stringlengths 16 477k | metadata dict |
|---|---|---|---|---|
fn_clm_subscriptions_new_4838608937735488870 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/types/storage/invoice_sync
// Inherent implementation for InvoiceSyncTrackingData
pub fn new(
subscription_id: id_type::SubscriptionId,
invoice_id: id_type::InvoiceId,
merchant_id: id_type::MerchantId,
profile_id: id_type::ProfileId,
customer_id: id_type::CustomerId,
connector_invoice_id: Option<id_type::InvoiceId>,
connector_name: api_enums::Connector,
) -> Self {
Self {
subscription_id,
invoice_id,
merchant_id,
profile_id,
customer_id,
connector_invoice_id,
connector_name,
}
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14463,
"total_crates": null
} |
fn_clm_subscriptions_from_4838608937735488870 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/types/storage/invoice_sync
// Implementation of common_enums::connector_enums::InvoiceStatus for From<InvoiceSyncPaymentStatus>
fn from(value: InvoiceSyncPaymentStatus) -> Self {
match value {
InvoiceSyncPaymentStatus::PaymentSucceeded => Self::InvoicePaid,
InvoiceSyncPaymentStatus::PaymentProcessing => Self::PaymentPending,
InvoiceSyncPaymentStatus::PaymentFailed => Self::PaymentFailed,
}
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2600,
"total_crates": null
} |
fn_clm_subscriptions_new_3874881549435604214 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/subscription_handler
// Implementation of None for SubscriptionHandler<'a>
pub fn new(state: &'a SessionState, merchant_context: &'a MerchantContext) -> Self {
Self {
state,
merchant_context,
}
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14463,
"total_crates": null
} |
fn_clm_subscriptions_foreign_try_from_3874881549435604214 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/subscription_handler
// Implementation of subscription_types::Invoice for ForeignTryFrom<&hyperswitch_domain_models::invoice::Invoice>
fn foreign_try_from(
invoice: &hyperswitch_domain_models::invoice::Invoice,
) -> Result<Self, Self::Error> {
Ok(Self {
id: invoice.id.clone(),
subscription_id: invoice.subscription_id.clone(),
merchant_id: invoice.merchant_id.clone(),
profile_id: invoice.profile_id.clone(),
merchant_connector_id: invoice.merchant_connector_id.clone(),
payment_intent_id: invoice.payment_intent_id.clone(),
payment_method_id: invoice.payment_method_id.clone(),
customer_id: invoice.customer_id.clone(),
amount: invoice.amount,
currency: api_enums::Currency::from_str(invoice.currency.as_str())
.change_context(errors::ApiErrorResponse::InvalidDataValue {
field_name: "currency",
})
.attach_printable(format!(
"unable to parse currency name {currency:?}",
currency = invoice.currency
))?,
status: invoice.status.clone(),
})
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 454,
"total_crates": null
} |
fn_clm_subscriptions_generate_response_3874881549435604214 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/subscription_handler
// Inherent implementation for SubscriptionWithHandler<'_>
pub fn generate_response(
&self,
invoice: &hyperswitch_domain_models::invoice::Invoice,
payment_response: &subscription_types::PaymentResponseData,
status: subscription_response_types::SubscriptionStatus,
) -> errors::SubscriptionResult<subscription_types::ConfirmSubscriptionResponse> {
Ok(subscription_types::ConfirmSubscriptionResponse {
id: self.subscription.id.clone(),
merchant_reference_id: self.subscription.merchant_reference_id.clone(),
status: subscription_types::SubscriptionStatus::from(status),
plan_id: self.subscription.plan_id.clone(),
profile_id: self.subscription.profile_id.to_owned(),
payment: Some(payment_response.clone()),
customer_id: Some(self.subscription.customer_id.clone()),
item_price_id: self.subscription.item_price_id.clone(),
coupon: None,
billing_processor_subscription_id: self.subscription.connector_subscription_id.clone(),
invoice: Some(subscription_types::Invoice::foreign_try_from(invoice)?),
})
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 95,
"total_crates": null
} |
fn_clm_subscriptions_create_subscription_entry_3874881549435604214 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/subscription_handler
// Implementation of None for SubscriptionHandler<'a>
/// Helper function to create a subscription entry in the database.
pub async fn create_subscription_entry(
&self,
subscription_id: common_utils::id_type::SubscriptionId,
customer_id: &common_utils::id_type::CustomerId,
billing_processor: connector_enums::Connector,
merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId,
merchant_reference_id: Option<String>,
profile: &hyperswitch_domain_models::business_profile::Profile,
plan_id: Option<String>,
item_price_id: Option<String>,
) -> errors::SubscriptionResult<SubscriptionWithHandler<'_>> {
let store = self.state.store.clone();
let db = store.as_ref();
let mut subscription = Subscription {
id: subscription_id,
status: SubscriptionStatus::Created.to_string(),
billing_processor: Some(billing_processor.to_string()),
payment_method_id: None,
merchant_connector_id: Some(merchant_connector_id),
client_secret: None,
connector_subscription_id: None,
merchant_id: self
.merchant_context
.get_merchant_account()
.get_id()
.clone(),
customer_id: customer_id.clone(),
metadata: None,
created_at: common_utils::date_time::now(),
modified_at: common_utils::date_time::now(),
profile_id: profile.get_id().clone(),
merchant_reference_id,
plan_id,
item_price_id,
};
subscription.generate_and_set_client_secret();
let key_manager_state = &(self.state).into();
let merchant_key_store = self.merchant_context.get_merchant_key_store();
let new_subscription = db
.insert_subscription_entry(key_manager_state, merchant_key_store, subscription)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("subscriptions: unable to insert subscription entry to database")?;
Ok(SubscriptionWithHandler {
handler: self,
subscription: new_subscription,
merchant_account: self.merchant_context.get_merchant_account().clone(),
})
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 64,
"total_crates": null
} |
fn_clm_subscriptions_find_subscription_3874881549435604214 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/subscription_handler
// Implementation of None for SubscriptionHandler<'a>
pub async fn find_subscription(
&self,
subscription_id: common_utils::id_type::SubscriptionId,
) -> errors::SubscriptionResult<SubscriptionWithHandler<'_>> {
let subscription = self
.state
.store
.find_by_merchant_id_subscription_id(
&(self.state).into(),
self.merchant_context.get_merchant_key_store(),
self.merchant_context.get_merchant_account().get_id(),
subscription_id.get_string_repr().to_string().clone(),
)
.await
.change_context(errors::ApiErrorResponse::GenericNotFoundError {
message: format!(
"subscription not found for id: {}",
subscription_id.get_string_repr()
),
})?;
Ok(SubscriptionWithHandler {
handler: self,
subscription,
merchant_account: self.merchant_context.get_merchant_account().clone(),
})
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 55,
"total_crates": null
} |
fn_clm_subscriptions_create_5690379640970837992 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/billing_processor_handler
// Implementation of None for BillingHandler
pub async fn create(
state: &SessionState,
merchant_account: &hyperswitch_domain_models::merchant_account::MerchantAccount,
key_store: &hyperswitch_domain_models::merchant_key_store::MerchantKeyStore,
profile: hyperswitch_domain_models::business_profile::Profile,
) -> SubscriptionResult<Self> {
let merchant_connector_id = profile.get_billing_processor_id()?;
let billing_processor_mca = state
.store
.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
&(state).into(),
merchant_account.get_id(),
&merchant_connector_id,
key_store,
)
.await
.change_context(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
id: merchant_connector_id.get_string_repr().to_string(),
})?;
let connector_name = billing_processor_mca.connector_name.clone();
let auth_type: hyperswitch_domain_models::router_data::ConnectorAuthType =
MerchantConnectorAccountType::DbVal(Box::new(billing_processor_mca.clone()))
.get_connector_account_details()
.parse_value("ConnectorAuthType")
.change_context(errors::ApiErrorResponse::InvalidDataFormat {
field_name: "connector_account_details".to_string(),
expected_format: "auth_type and api_key".to_string(),
})?;
let connector_enum = state
.connector_converter
.get_connector_enum_by_name(&connector_name)
.change_context(errors::ApiErrorResponse::IncorrectConnectorNameGiven)
.attach_printable(
"invalid connector name received in billing merchant connector account",
)?;
let connector_data = connector_enums::Connector::from_str(connector_name.as_str())
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable(format!("unable to parse connector name {connector_name:?}"))?;
let connector_params =
hyperswitch_domain_models::connector_endpoints::Connectors::get_connector_params(
&state.conf.connectors,
connector_data,
)
.change_context(errors::ApiErrorResponse::ConfigNotFound)
.attach_printable(format!(
"cannot find connector params for this connector {connector_name} in this flow",
))?;
Ok(Self {
auth_type,
connector_enum,
connector_name: connector_data,
connector_params,
connector_metadata: billing_processor_mca.metadata.clone(),
merchant_connector_id,
})
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 120,
"total_crates": null
} |
fn_clm_subscriptions_create_customer_on_connector_5690379640970837992 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/billing_processor_handler
// Implementation of None for BillingHandler
pub async fn create_customer_on_connector(
&self,
state: &SessionState,
customer: hyperswitch_domain_models::customer::Customer,
customer_id: common_utils::id_type::CustomerId,
billing_address: Option<api_models::payments::Address>,
payment_method_data: Option<api_models::payments::PaymentMethodData>,
) -> SubscriptionResult<Option<ConnectorCustomerResponseData>> {
let connector_customer_map = customer.get_connector_customer_map();
if connector_customer_map.contains_key(&self.merchant_connector_id) {
// Customer already exists on the connector, no need to create again
return Ok(None);
}
let customer_req = ConnectorCustomerData {
email: customer.email.clone().map(pii::Email::from),
payment_method_data: payment_method_data.clone().map(|pmd| pmd.into()),
description: None,
phone: None,
name: None,
preprocessing_id: None,
split_payments: None,
setup_future_usage: None,
customer_acceptance: None,
customer_id: Some(customer_id.clone()),
billing_address: billing_address
.as_ref()
.and_then(|add| add.address.clone())
.and_then(|addr| addr.into()),
};
let router_data = self.build_router_data(
state,
customer_req,
SubscriptionCustomerData {
connector_meta_data: self.connector_metadata.clone(),
},
)?;
let connector_integration = self.connector_enum.get_connector_integration();
let response = Box::pin(self.call_connector(
state,
router_data,
"create customer on connector",
connector_integration,
))
.await?;
match response {
Ok(response_data) => match response_data {
PaymentsResponseData::ConnectorCustomerResponse(customer_response) => {
Ok(Some(customer_response))
}
_ => Err(errors::ApiErrorResponse::SubscriptionError {
operation: "Subscription Customer Create".to_string(),
}
.into()),
},
Err(err) => Err(errors::ApiErrorResponse::ExternalConnectorError {
code: err.code,
message: err.message,
connector: self.connector_name.to_string(),
status_code: err.status_code,
reason: err.reason,
}
.into()),
}
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 68,
"total_crates": null
} |
fn_clm_subscriptions_call_connector_5690379640970837992 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/billing_processor_handler
// Implementation of None for BillingHandler
async fn call_connector<F, ResourceCommonData, Req, Resp>(
&self,
state: &SessionState,
router_data: hyperswitch_domain_models::router_data_v2::RouterDataV2<
F,
ResourceCommonData,
Req,
Resp,
>,
operation_name: &str,
connector_integration: connector_integration_interface::BoxedConnectorIntegrationInterface<
F,
ResourceCommonData,
Req,
Resp,
>,
) -> SubscriptionResult<Result<Resp, hyperswitch_domain_models::router_data::ErrorResponse>>
where
F: Clone + std::fmt::Debug + 'static,
Req: Clone + std::fmt::Debug + 'static,
Resp: Clone + std::fmt::Debug + 'static,
ResourceCommonData:
connector_integration_interface::RouterDataConversion<F, Req, Resp> + Clone + 'static,
{
let old_router_data = ResourceCommonData::to_old_router_data(router_data).change_context(
errors::ApiErrorResponse::SubscriptionError {
operation: { operation_name.to_string() },
},
)?;
let router_resp = api_client::execute_connector_processing_step(
state,
connector_integration,
&old_router_data,
CallConnectorAction::Trigger,
None,
None,
)
.await
.change_context(errors::ApiErrorResponse::SubscriptionError {
operation: operation_name.to_string(),
})
.attach_printable(format!(
"Failed while in subscription operation: {operation_name}"
))?;
Ok(router_resp.response)
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 67,
"total_crates": null
} |
fn_clm_subscriptions_record_back_to_billing_processor_5690379640970837992 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/billing_processor_handler
// Implementation of None for BillingHandler
pub async fn record_back_to_billing_processor(
&self,
state: &SessionState,
invoice_id: common_utils::id_type::InvoiceId,
payment_id: common_utils::id_type::PaymentId,
payment_status: common_enums::AttemptStatus,
amount: common_utils::types::MinorUnit,
currency: common_enums::Currency,
payment_method_type: Option<common_enums::PaymentMethodType>,
) -> SubscriptionResult<InvoiceRecordBackResponse> {
let invoice_record_back_req = InvoiceRecordBackRequest {
amount,
currency,
payment_method_type,
attempt_status: payment_status,
merchant_reference_id: common_utils::id_type::PaymentReferenceId::from_str(
invoice_id.get_string_repr(),
)
.change_context(errors::ApiErrorResponse::InvalidDataValue {
field_name: "invoice_id",
})?,
connector_params: self.connector_params.clone(),
connector_transaction_id: Some(common_utils::types::ConnectorTransactionId::TxnId(
payment_id.get_string_repr().to_string(),
)),
};
let router_data = self.build_router_data(
state,
invoice_record_back_req,
InvoiceRecordBackData {
connector_meta_data: self.connector_metadata.clone(),
},
)?;
let connector_integration = self.connector_enum.get_connector_integration();
let response = self
.call_connector(
state,
router_data,
"invoice record back",
connector_integration,
)
.await?;
match response {
Ok(response_data) => Ok(response_data),
Err(err) => Err(errors::ApiErrorResponse::ExternalConnectorError {
code: err.code,
message: err.message,
connector: self.connector_name.to_string(),
status_code: err.status_code,
reason: err.reason,
}
.into()),
}
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 47,
"total_crates": null
} |
fn_clm_subscriptions_create_subscription_on_connector_5690379640970837992 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/billing_processor_handler
// Implementation of None for BillingHandler
pub async fn create_subscription_on_connector(
&self,
state: &SessionState,
subscription: hyperswitch_domain_models::subscription::Subscription,
item_price_id: Option<String>,
billing_address: Option<api_models::payments::Address>,
) -> SubscriptionResult<subscription_response_types::SubscriptionCreateResponse> {
let subscription_item = subscription_request_types::SubscriptionItem {
item_price_id: item_price_id.ok_or(errors::ApiErrorResponse::MissingRequiredField {
field_name: "item_price_id",
})?,
quantity: Some(1),
};
let subscription_req = subscription_request_types::SubscriptionCreateRequest {
subscription_id: subscription.id.to_owned(),
customer_id: subscription.customer_id.to_owned(),
subscription_items: vec![subscription_item],
billing_address: billing_address.ok_or(
errors::ApiErrorResponse::MissingRequiredField {
field_name: "billing",
},
)?,
auto_collection: subscription_request_types::SubscriptionAutoCollection::Off,
connector_params: self.connector_params.clone(),
};
let router_data = self.build_router_data(
state,
subscription_req,
SubscriptionCreateData {
connector_meta_data: self.connector_metadata.clone(),
},
)?;
let connector_integration = self.connector_enum.get_connector_integration();
let response = self
.call_connector(
state,
router_data,
"create subscription on connector",
connector_integration,
)
.await?;
match response {
Ok(response_data) => Ok(response_data),
Err(err) => Err(errors::ApiErrorResponse::ExternalConnectorError {
code: err.code,
message: err.message,
connector: self.connector_name.to_string(),
status_code: err.status_code,
reason: err.reason,
}
.into()),
}
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 46,
"total_crates": null
} |
fn_clm_subscriptions_make_payment_api_call_-4785044522893361185 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/payments_api_client
// Inherent implementation for PaymentsApiClient
/// Generic method to handle payment API calls with different HTTP methods and URL patterns
async fn make_payment_api_call(
state: &SessionState,
method: services::Method,
url: String,
request_body: Option<common_utils::request::RequestContent>,
operation_name: &str,
merchant_id: &str,
profile_id: &str,
) -> errors::SubscriptionResult<subscription_types::PaymentResponseData> {
let subscription_error = errors::ApiErrorResponse::SubscriptionError {
operation: operation_name.to_string(),
};
let headers = Self::get_internal_auth_headers(state, merchant_id, profile_id);
let mut request_builder = services::RequestBuilder::new()
.method(method)
.url(&url)
.headers(headers);
// Add request body only if provided (for POST requests)
if let Some(body) = request_body {
request_builder = request_builder.set_body(body);
}
let request = request_builder.build();
let response = api::call_connector_api(state, request, "Subscription Payments")
.await
.change_context(subscription_error.clone())?;
match response {
Ok(res) => {
let api_response: subscription_types::PaymentResponseData = res
.response
.parse_struct(std::any::type_name::<subscription_types::PaymentResponseData>())
.change_context(subscription_error)?;
Ok(api_response)
}
Err(err) => {
let error_response: ErrorResponse = err
.response
.parse_struct(std::any::type_name::<ErrorResponse>())
.change_context(subscription_error)?;
Err(errors::ApiErrorResponse::ExternalConnectorError {
code: error_response.error.code,
message: error_response.error.message,
connector: "payments_microservice".to_string(),
status_code: err.status_code,
reason: error_response.error.error_type,
}
.into())
}
}
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 60,
"total_crates": null
} |
fn_clm_subscriptions_sync_payment_-4785044522893361185 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/payments_api_client
// Inherent implementation for PaymentsApiClient
pub async fn sync_payment(
state: &SessionState,
payment_id: String,
merchant_id: &str,
profile_id: &str,
) -> errors::SubscriptionResult<subscription_types::PaymentResponseData> {
let base_url = &state.conf.internal_services.payments_base_url;
let url = format!("{}/payments/{}", base_url, payment_id);
Self::make_payment_api_call(
state,
services::Method::Get,
url,
None,
"Sync Payment",
merchant_id,
profile_id,
)
.await
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 41,
"total_crates": null
} |
fn_clm_subscriptions_create_and_confirm_payment_-4785044522893361185 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/payments_api_client
// Inherent implementation for PaymentsApiClient
pub async fn create_and_confirm_payment(
state: &SessionState,
request: subscription_types::CreateAndConfirmPaymentsRequestData,
merchant_id: &str,
profile_id: &str,
) -> errors::SubscriptionResult<subscription_types::PaymentResponseData> {
let base_url = &state.conf.internal_services.payments_base_url;
let url = format!("{}/payments", base_url);
Self::make_payment_api_call(
state,
services::Method::Post,
url,
Some(common_utils::request::RequestContent::Json(Box::new(
request,
))),
"Create And Confirm Payment",
merchant_id,
profile_id,
)
.await
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 30,
"total_crates": null
} |
fn_clm_subscriptions_confirm_payment_-4785044522893361185 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/payments_api_client
// Inherent implementation for PaymentsApiClient
pub async fn confirm_payment(
state: &SessionState,
request: subscription_types::ConfirmPaymentsRequestData,
payment_id: String,
merchant_id: &str,
profile_id: &str,
) -> errors::SubscriptionResult<subscription_types::PaymentResponseData> {
let base_url = &state.conf.internal_services.payments_base_url;
let url = format!("{}/payments/{}/confirm", base_url, payment_id);
Self::make_payment_api_call(
state,
services::Method::Post,
url,
Some(common_utils::request::RequestContent::Json(Box::new(
request,
))),
"Confirm Payment",
merchant_id,
profile_id,
)
.await
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 30,
"total_crates": null
} |
fn_clm_subscriptions_create_mit_payment_-4785044522893361185 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/payments_api_client
// Inherent implementation for PaymentsApiClient
pub async fn create_mit_payment(
state: &SessionState,
request: subscription_types::CreateMitPaymentRequestData,
merchant_id: &str,
profile_id: &str,
) -> errors::SubscriptionResult<subscription_types::PaymentResponseData> {
let base_url = &state.conf.internal_services.payments_base_url;
let url = format!("{}/payments", base_url);
Self::make_payment_api_call(
state,
services::Method::Post,
url,
Some(common_utils::request::RequestContent::Json(Box::new(
request,
))),
"Create MIT Payment",
merchant_id,
profile_id,
)
.await
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 30,
"total_crates": null
} |
fn_clm_subscriptions_new_-8650576453697060373 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/invoice_handler
// Inherent implementation for InvoiceHandler
pub fn new(
subscription: hyperswitch_domain_models::subscription::Subscription,
merchant_account: hyperswitch_domain_models::merchant_account::MerchantAccount,
profile: hyperswitch_domain_models::business_profile::Profile,
merchant_key_store: hyperswitch_domain_models::merchant_key_store::MerchantKeyStore,
) -> Self {
Self {
subscription,
merchant_account,
profile,
merchant_key_store,
}
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14463,
"total_crates": null
} |
fn_clm_subscriptions_create_invoice_entry_-8650576453697060373 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/invoice_handler
// Inherent implementation for InvoiceHandler
pub async fn create_invoice_entry(
&self,
state: &SessionState,
merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId,
payment_intent_id: Option<common_utils::id_type::PaymentId>,
amount: MinorUnit,
currency: common_enums::Currency,
status: connector_enums::InvoiceStatus,
provider_name: connector_enums::Connector,
metadata: Option<pii::SecretSerdeValue>,
connector_invoice_id: Option<common_utils::id_type::InvoiceId>,
) -> errors::SubscriptionResult<hyperswitch_domain_models::invoice::Invoice> {
let invoice_new = hyperswitch_domain_models::invoice::Invoice::to_invoice(
self.subscription.id.to_owned(),
self.subscription.merchant_id.to_owned(),
self.subscription.profile_id.to_owned(),
merchant_connector_id,
payment_intent_id,
self.subscription.payment_method_id.clone(),
self.subscription.customer_id.to_owned(),
amount,
currency.to_string(),
status,
provider_name,
metadata,
connector_invoice_id,
);
let key_manager_state = &(state).into();
let invoice = state
.store
.insert_invoice_entry(key_manager_state, &self.merchant_key_store, invoice_new)
.await
.change_context(errors::ApiErrorResponse::SubscriptionError {
operation: "Create Invoice".to_string(),
})
.attach_printable("invoices: unable to insert invoice entry to database")?;
Ok(invoice)
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 51,
"total_crates": null
} |
fn_clm_subscriptions_create_and_confirm_payment_-8650576453697060373 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/invoice_handler
// Inherent implementation for InvoiceHandler
pub async fn create_and_confirm_payment(
&self,
state: &SessionState,
request: &subscription_types::CreateAndConfirmSubscriptionRequest,
amount: MinorUnit,
currency: common_enums::Currency,
) -> errors::SubscriptionResult<subscription_types::PaymentResponseData> {
let payment_details = &request.payment_details;
let payment_request = subscription_types::CreateAndConfirmPaymentsRequestData {
amount,
currency,
confirm: true,
customer_id: Some(self.subscription.customer_id.clone()),
billing: request.get_billing_address(),
shipping: request.shipping.clone(),
profile_id: Some(self.profile.get_id().clone()),
setup_future_usage: payment_details.setup_future_usage,
return_url: payment_details.return_url.clone(),
capture_method: payment_details.capture_method,
authentication_type: payment_details.authentication_type,
payment_method: payment_details.payment_method,
payment_method_type: payment_details.payment_method_type,
payment_method_data: payment_details.payment_method_data.clone(),
customer_acceptance: payment_details.customer_acceptance.clone(),
payment_type: payment_details.payment_type,
};
payments_api_client::PaymentsApiClient::create_and_confirm_payment(
state,
payment_request,
self.merchant_account.get_id().get_string_repr(),
self.profile.get_id().get_string_repr(),
)
.await
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 50,
"total_crates": null
} |
fn_clm_subscriptions_confirm_payment_-8650576453697060373 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/invoice_handler
// Inherent implementation for InvoiceHandler
pub async fn confirm_payment(
&self,
state: &SessionState,
payment_id: common_utils::id_type::PaymentId,
request: &subscription_types::ConfirmSubscriptionRequest,
) -> errors::SubscriptionResult<subscription_types::PaymentResponseData> {
let payment_details = &request.payment_details;
let cit_payment_request = subscription_types::ConfirmPaymentsRequestData {
billing: request.get_billing_address(),
shipping: request.payment_details.shipping.clone(),
profile_id: Some(self.profile.get_id().clone()),
payment_method: payment_details.payment_method,
payment_method_type: payment_details.payment_method_type,
payment_method_data: payment_details.payment_method_data.clone(),
customer_acceptance: payment_details.customer_acceptance.clone(),
payment_type: payment_details.payment_type,
};
payments_api_client::PaymentsApiClient::confirm_payment(
state,
cit_payment_request,
payment_id.get_string_repr().to_string(),
self.merchant_account.get_id().get_string_repr(),
self.profile.get_id().get_string_repr(),
)
.await
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 50,
"total_crates": null
} |
fn_clm_subscriptions_update_invoice_-8650576453697060373 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/core/invoice_handler
// Inherent implementation for InvoiceHandler
pub async fn update_invoice(
&self,
state: &SessionState,
invoice_id: common_utils::id_type::InvoiceId,
update_request: hyperswitch_domain_models::invoice::InvoiceUpdateRequest,
) -> errors::SubscriptionResult<hyperswitch_domain_models::invoice::Invoice> {
let update_invoice: hyperswitch_domain_models::invoice::InvoiceUpdate =
update_request.into();
let key_manager_state = &(state).into();
state
.store
.update_invoice_entry(
key_manager_state,
&self.merchant_key_store,
invoice_id.get_string_repr().to_string(),
update_invoice,
)
.await
.change_context(errors::ApiErrorResponse::SubscriptionError {
operation: "Invoice Update".to_string(),
})
.attach_printable("invoices: unable to update invoice entry in database")
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 46,
"total_crates": null
} |
fn_clm_subscriptions_finish_process_with_business_status_5222914449581200589 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/workflows/invoice_sync
// Implementation of None for InvoiceSyncHandler<'a>
async fn finish_process_with_business_status(
&self,
process: &ProcessTracker,
business_status: &'static str,
) -> CustomResult<(), router_errors::ApiErrorResponse> {
self.state
.store
.as_scheduler()
.finish_process_with_business_status(process.clone(), business_status)
.await
.change_context(router_errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to update process tracker status")
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 126,
"total_crates": null
} |
fn_clm_subscriptions_create_5222914449581200589 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/workflows/invoice_sync
// Implementation of None for InvoiceSyncHandler<'a>
pub async fn create(
state: &'a SessionState,
tracking_data: storage::invoice_sync::InvoiceSyncTrackingData,
) -> Result<Self, errors::ProcessTrackerError> {
let key_manager_state = &state.into();
let key_store = state
.store
.get_merchant_key_store_by_merchant_id(
key_manager_state,
&tracking_data.merchant_id,
&state.store.get_master_key().to_vec().into(),
)
.await
.attach_printable("Failed to fetch Merchant key store from DB")?;
let merchant_account = state
.store
.find_merchant_account_by_merchant_id(
key_manager_state,
&tracking_data.merchant_id,
&key_store,
)
.await
.attach_printable("Subscriptions: Failed to fetch Merchant Account from DB")?;
let profile = state
.store
.find_business_profile_by_profile_id(
&(state).into(),
&key_store,
&tracking_data.profile_id,
)
.await
.attach_printable("Subscriptions: Failed to fetch Business Profile from DB")?;
let customer = state
.store
.find_customer_by_customer_id_merchant_id(
&(state).into(),
&tracking_data.customer_id,
merchant_account.get_id(),
&key_store,
merchant_account.storage_scheme,
)
.await
.attach_printable("Subscriptions: Failed to fetch Customer from DB")?;
let subscription = state
.store
.find_by_merchant_id_subscription_id(
&state.into(),
&key_store,
merchant_account.get_id(),
tracking_data.subscription_id.get_string_repr().to_string(),
)
.await
.attach_printable("Subscriptions: Failed to fetch subscription from DB")?;
let invoice = state
.store
.find_invoice_by_invoice_id(
&state.into(),
&key_store,
tracking_data.invoice_id.get_string_repr().to_string(),
)
.await
.attach_printable("invoices: unable to get latest invoice from database")?;
Ok(Self {
state,
tracking_data,
key_store,
merchant_account,
customer,
profile,
subscription,
invoice,
})
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 118,
"total_crates": null
} |
fn_clm_subscriptions_perform_billing_processor_record_back_5222914449581200589 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/workflows/invoice_sync
// Implementation of None for InvoiceSyncHandler<'a>
pub async fn perform_billing_processor_record_back(
&self,
payment_response: subscription_types::PaymentResponseData,
payment_status: common_enums::AttemptStatus,
connector_invoice_id: common_utils::id_type::InvoiceId,
invoice_sync_status: storage::invoice_sync::InvoiceSyncPaymentStatus,
) -> CustomResult<(), router_errors::ApiErrorResponse> {
logger::info!("perform_billing_processor_record_back");
let billing_handler = billing::BillingHandler::create(
self.state,
&self.merchant_account,
&self.key_store,
self.profile.clone(),
)
.await
.attach_printable("Failed to create billing handler")?;
let invoice_handler = invoice_handler::InvoiceHandler::new(
self.subscription.clone(),
self.merchant_account.clone(),
self.profile.clone(),
self.key_store.clone(),
);
// TODO: Handle retries here on failure
billing_handler
.record_back_to_billing_processor(
self.state,
connector_invoice_id.clone(),
payment_response.payment_id.to_owned(),
payment_status,
payment_response.amount,
payment_response.currency,
payment_response.payment_method_type,
)
.await
.attach_printable("Failed to record back to billing processor")?;
let update_request = InvoiceUpdateRequest::update_connector_and_status(
connector_invoice_id,
common_enums::connector_enums::InvoiceStatus::from(invoice_sync_status),
);
invoice_handler
.update_invoice(self.state, self.invoice.id.to_owned(), update_request)
.await
.attach_printable("Failed to update invoice in DB")?;
Ok(())
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 55,
"total_crates": null
} |
fn_clm_subscriptions_perform_payments_sync_5222914449581200589 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/workflows/invoice_sync
// Implementation of None for InvoiceSyncHandler<'a>
pub async fn perform_payments_sync(
&self,
) -> CustomResult<subscription_types::PaymentResponseData, router_errors::ApiErrorResponse>
{
logger::info!(
"perform_payments_sync called for invoice_id: {:?} and payment_id: {:?}",
self.invoice.id,
self.invoice.payment_intent_id
);
let payment_id = self.invoice.payment_intent_id.clone().ok_or(
router_errors::ApiErrorResponse::SubscriptionError {
operation: "Invoice_sync: Missing Payment Intent ID in Invoice".to_string(),
},
)?;
let payments_response = payments_api_client::PaymentsApiClient::sync_payment(
self.state,
payment_id.get_string_repr().to_string(),
self.merchant_account.get_id().get_string_repr(),
self.profile.get_id().get_string_repr(),
)
.await
.change_context(router_errors::ApiErrorResponse::SubscriptionError {
operation: "Invoice_sync: Failed to sync payment status from payments microservice"
.to_string(),
})
.attach_printable("Failed to sync payment status from payments microservice")?;
Ok(payments_response)
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 50,
"total_crates": null
} |
fn_clm_subscriptions_transition_workflow_state_5222914449581200589 | clm | function | // Repository: hyperswitch
// Crate: subscriptions
// Module: crates/subscriptions/src/workflows/invoice_sync
// Implementation of None for InvoiceSyncHandler<'a>
pub async fn transition_workflow_state(
&self,
process: ProcessTracker,
payment_response: subscription_types::PaymentResponseData,
connector_invoice_id: Option<common_utils::id_type::InvoiceId>,
) -> CustomResult<(), router_errors::ApiErrorResponse> {
logger::info!(
"transition_workflow_state called with status: {:?}",
payment_response.status
);
let invoice_sync_status =
storage::invoice_sync::InvoiceSyncPaymentStatus::from(payment_response.status);
let (payment_status, status) = match invoice_sync_status {
storage::invoice_sync::InvoiceSyncPaymentStatus::PaymentSucceeded => (common_enums::AttemptStatus::Charged, "succeeded"),
storage::invoice_sync::InvoiceSyncPaymentStatus::PaymentFailed => (common_enums::AttemptStatus::Failure, "failed"),
storage::invoice_sync::InvoiceSyncPaymentStatus::PaymentProcessing => return Err(
router_errors::ApiErrorResponse::SubscriptionError {
operation: "Invoice_sync: Payment in processing state, cannot transition workflow state"
.to_string(),
},
)?,
};
logger::info!("Performing billing processor record back for status: {status}");
Box::pin(self.perform_billing_processor_record_back_if_possible(
payment_response.clone(),
payment_status,
connector_invoice_id,
invoice_sync_status.clone(),
))
.await
.attach_printable(format!(
"Failed to record back {status} status to billing processor"
))?;
self.finish_process_with_business_status(&process, business_status::COMPLETED_BY_PT)
.await
.change_context(router_errors::ApiErrorResponse::SubscriptionError {
operation: "Invoice_sync process_tracker task completion".to_string(),
})
.attach_printable("Failed to update process tracker status")
}
| {
"crate": "subscriptions",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 43,
"total_crates": null
} |
fn_clm_hsdev_get_toml_table_3847895106516478904 | clm | function | // Repository: hyperswitch
// Crate: hsdev
// Module: crates/hsdev/src/main
pub fn get_toml_table<'a>(table_name: &'a str, toml_data: &'a Value) -> &'a Value {
if !table_name.is_empty() {
match toml_data.get(table_name) {
Some(value) => value,
None => {
eprintln!("Unable to find toml table: \"{}\"", &table_name);
std::process::abort()
}
}
} else {
toml_data
}
}
| {
"crate": "hsdev",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 25,
"total_crates": null
} |
fn_clm_hsdev_main_3847895106516478904 | clm | function | // Repository: hyperswitch
// Crate: hsdev
// Module: crates/hsdev/src/main
fn main() {
let args = Args::parse();
let toml_file = &args.toml_file;
let table_name = &args.toml_table;
let toml_contents = match std::fs::read_to_string(toml_file) {
Ok(contents) => contents,
Err(e) => {
eprintln!("Error reading TOML file: {e}");
return;
}
};
let toml_data: Value = match toml_contents.parse() {
Ok(data) => data,
Err(e) => {
eprintln!("Error parsing TOML file: {e}");
return;
}
};
let table = get_toml_table(table_name, &toml_data);
let input = match input_file::InputData::read(table) {
Ok(data) => data,
Err(e) => {
eprintln!("Error loading TOML file: {e}");
return;
}
};
let db_url = input.postgres_url();
println!("Attempting to connect to {db_url}");
let mut conn = match PgConnection::establish(&db_url) {
Ok(value) => value,
Err(_) => {
eprintln!("Unable to establish database connection");
return;
}
};
let migrations = match FileBasedMigrations::find_migrations_directory() {
Ok(value) => value,
Err(_) => {
eprintln!("Could not find migrations directory");
return;
}
};
let mut harness = HarnessWithOutput::write_to_stdout(&mut conn);
match harness.run_pending_migrations(migrations) {
Ok(_) => println!("Successfully ran migrations"),
Err(_) => eprintln!("Couldn't run migrations"),
};
}
| {
"crate": "hsdev",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 20,
"total_crates": null
} |
fn_clm_hsdev_test_input_file_3847895106516478904 | clm | function | // Repository: hyperswitch
// Crate: hsdev
// Module: crates/hsdev/src/main
fn test_input_file() {
let toml_str = r#"username = "db_user"
password = "db_pass"
dbname = "db_name"
host = "localhost"
port = 5432"#;
let toml_value = Value::from_str(toml_str);
assert!(toml_value.is_ok());
let toml_value = toml_value.unwrap();
let toml_table = InputData::read(&toml_value);
assert!(toml_table.is_ok());
let toml_table = toml_table.unwrap();
let db_url = toml_table.postgres_url();
assert_eq!("postgres://db_user:db_pass@localhost:5432/db_name", db_url);
}
| {
"crate": "hsdev",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 6,
"total_crates": null
} |
fn_clm_hsdev_test_given_toml_3847895106516478904 | clm | function | // Repository: hyperswitch
// Crate: hsdev
// Module: crates/hsdev/src/main
fn test_given_toml() {
let toml_str_table = r#"[database]
username = "db_user"
password = "db_pass"
dbname = "db_name"
host = "localhost"
port = 5432"#;
let table_name = "database";
let toml_value = Value::from_str(toml_str_table).unwrap();
let table = get_toml_table(table_name, &toml_value);
assert!(table.is_table());
let table_name = "";
let table = get_toml_table(table_name, &toml_value);
assert!(table.is_table());
}
| {
"crate": "hsdev",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 6,
"total_crates": null
} |
fn_clm_hsdev_read_86779837629964487 | clm | function | // Repository: hyperswitch
// Crate: hsdev
// Module: crates/hsdev/src/input_file
// Inherent implementation for InputData
pub fn read(db_table: &Value) -> Result<Self, toml::de::Error> {
db_table.clone().try_into()
}
| {
"crate": "hsdev",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 37,
"total_crates": null
} |
fn_clm_hsdev_postgres_url_86779837629964487 | clm | function | // Repository: hyperswitch
// Crate: hsdev
// Module: crates/hsdev/src/input_file
// Inherent implementation for InputData
pub fn postgres_url(&self) -> String {
format!(
"postgres://{}:{}@{}:{}/{}",
self.username, self.password, self.host, self.port, self.dbname
)
}
| {
"crate": "hsdev",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 24,
"total_crates": null
} |
fn_clm_euclid_interpreter_vs_jit_vs_vir_interpreter_5857512594998649836 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/benches/backends
fn interpreter_vs_jit_vs_vir_interpreter(c: &mut Criterion) {
let (program, binputs) = get_program_data();
let interp_b = InterpreterBackend::with_program(program.clone()).expect("Interpreter backend");
let vir_interp_b =
VirInterpreterBackend::with_program(program).expect("Vir Interpreter Backend");
c.bench_function("Raw Interpreter Backend", |b| {
b.iter(|| {
interp_b
.execute(binputs.clone())
.expect("Interpreter EXECUTION");
});
});
c.bench_function("Valued Interpreter Backend", |b| {
b.iter(|| {
vir_interp_b
.execute(binputs.clone())
.expect("Vir Interpreter execution");
})
});
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 24,
"total_crates": null
} |
fn_clm_euclid_get_program_data_5857512594998649836 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/benches/backends
fn get_program_data() -> (ast::Program<DummyOutput>, inputs::BackendInput) {
let code1 = r#"
default: ["stripe", "adyen", "checkout"]
stripe_first: ["stripe", "aci"]
{
payment_method = card & amount = 40 {
payment_method = (card, bank_redirect)
amount = (40, 50)
}
}
adyen_first: ["adyen", "checkout"]
{
payment_method = bank_redirect & amount > 60 {
payment_method = (card, bank_redirect)
amount = (40, 50)
}
}
auth_first: ["authorizedotnet", "adyen"]
{
payment_method = wallet
}
"#;
let inp = inputs::BackendInput {
metadata: None,
payment: inputs::PaymentInput {
amount: MinorUnit::new(32),
card_bin: None,
currency: enums::Currency::USD,
authentication_type: Some(enums::AuthenticationType::NoThreeDs),
capture_method: Some(enums::CaptureMethod::Automatic),
business_country: Some(enums::Country::UnitedStatesOfAmerica),
billing_country: Some(enums::Country::France),
business_label: None,
setup_future_usage: None,
},
payment_method: inputs::PaymentMethodInput {
payment_method: Some(enums::PaymentMethod::PayLater),
payment_method_type: Some(enums::PaymentMethodType::Sofort),
card_network: None,
},
mandate: inputs::MandateData {
mandate_acceptance_type: None,
mandate_type: None,
payment_type: None,
},
issuer_data: None,
acquirer_data: None,
customer_device_data: None,
};
let (_, program) = parser::program(code1).expect("Parser");
(program, inp)
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 7,
"total_crates": null
} |
fn_clm_euclid_from_5181847665531414369 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/types
// Implementation of ast::ComparisonType for From<NumValueRefinement>
fn from(value: NumValueRefinement) -> Self {
match value {
NumValueRefinement::NotEqual => Self::NotEqual,
NumValueRefinement::LessThan => Self::LessThan,
NumValueRefinement::GreaterThan => Self::GreaterThan,
NumValueRefinement::GreaterThanEqual => Self::GreaterThanEqual,
NumValueRefinement::LessThanEqual => Self::LessThanEqual,
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2600,
"total_crates": null
} |
fn_clm_euclid_get_key_5181847665531414369 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/types
// Inherent implementation for EuclidValue
pub fn get_key(&self) -> EuclidKey {
match self {
Self::PaymentMethod(_) => EuclidKey::PaymentMethod,
Self::CardBin(_) => EuclidKey::CardBin,
Self::Metadata(_) => EuclidKey::Metadata,
Self::PaymentMethodType(_) => EuclidKey::PaymentMethodType,
Self::MandateType(_) => EuclidKey::MandateType,
Self::PaymentType(_) => EuclidKey::PaymentType,
Self::MandateAcceptanceType(_) => EuclidKey::MandateAcceptanceType,
Self::CardNetwork(_) => EuclidKey::CardNetwork,
Self::AuthenticationType(_) => EuclidKey::AuthenticationType,
Self::CaptureMethod(_) => EuclidKey::CaptureMethod,
Self::PaymentAmount(_) => EuclidKey::PaymentAmount,
Self::PaymentCurrency(_) => EuclidKey::PaymentCurrency,
#[cfg(feature = "payouts")]
Self::PayoutCurrency(_) => EuclidKey::PayoutCurrency,
Self::BusinessCountry(_) => EuclidKey::BusinessCountry,
Self::BillingCountry(_) => EuclidKey::BillingCountry,
Self::BusinessLabel(_) => EuclidKey::BusinessLabel,
Self::SetupFutureUsage(_) => EuclidKey::SetupFutureUsage,
Self::IssuerName(_) => EuclidKey::IssuerName,
Self::IssuerCountry(_) => EuclidKey::IssuerCountry,
Self::AcquirerCountry(_) => EuclidKey::AcquirerCountry,
Self::AcquirerFraudRate(_) => EuclidKey::AcquirerFraudRate,
Self::CustomerDeviceType(_) => EuclidKey::CustomerDeviceType,
Self::CustomerDeviceDisplaySize(_) => EuclidKey::CustomerDeviceDisplaySize,
Self::CustomerDevicePlatform(_) => EuclidKey::CustomerDevicePlatform,
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 90,
"total_crates": null
} |
fn_clm_euclid_get_num_value_5181847665531414369 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/types
// Inherent implementation for EuclidValue
pub fn get_num_value(&self) -> Option<NumValue> {
match self {
Self::PaymentAmount(val) => Some(val.clone()),
_ => None,
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 32,
"total_crates": null
} |
fn_clm_euclid_get_dir_value_for_analysis_5181847665531414369 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/types
// Implementation of DummyOutput for EuclidAnalysable
fn get_dir_value_for_analysis(&self, rule_name: String) -> Vec<(DirValue, Metadata)> {
self.outputs
.iter()
.map(|dummyc| {
let metadata_key = "MetadataKey".to_string();
let metadata_value = dummyc;
(
DirValue::MetaData(MetadataValue {
key: metadata_key.clone(),
value: metadata_value.clone(),
}),
std::collections::HashMap::from_iter([(
"DUMMY_OUTPUT".to_string(),
serde_json::json!({
"rule_name":rule_name,
"Metadata_Key" :metadata_key,
"Metadata_Value" : metadata_value,
}),
)]),
)
})
.collect()
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 29,
"total_crates": null
} |
fn_clm_euclid_key_type_5181847665531414369 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/types
// Inherent implementation for EuclidKey
pub fn key_type(&self) -> DataType {
match self {
Self::PaymentMethod => DataType::EnumVariant,
Self::CardBin => DataType::StrValue,
Self::Metadata => DataType::MetadataValue,
Self::PaymentMethodType => DataType::EnumVariant,
Self::CardNetwork => DataType::EnumVariant,
Self::AuthenticationType => DataType::EnumVariant,
Self::CaptureMethod => DataType::EnumVariant,
Self::PaymentAmount => DataType::Number,
Self::PaymentCurrency => DataType::EnumVariant,
#[cfg(feature = "payouts")]
Self::PayoutCurrency => DataType::EnumVariant,
Self::BusinessCountry => DataType::EnumVariant,
Self::BillingCountry => DataType::EnumVariant,
Self::MandateType => DataType::EnumVariant,
Self::MandateAcceptanceType => DataType::EnumVariant,
Self::PaymentType => DataType::EnumVariant,
Self::BusinessLabel => DataType::StrValue,
Self::SetupFutureUsage => DataType::EnumVariant,
Self::IssuerName => DataType::StrValue,
Self::IssuerCountry => DataType::EnumVariant,
Self::AcquirerCountry => DataType::EnumVariant,
Self::AcquirerFraudRate => DataType::Number,
Self::CustomerDeviceType => DataType::EnumVariant,
Self::CustomerDeviceDisplaySize => DataType::EnumVariant,
Self::CustomerDevicePlatform => DataType::EnumVariant,
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 21,
"total_crates": null
} |
fn_clm_euclid_get_output_-5011542896471737607 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/backend
// Inherent implementation for BackendOutput<O>
pub fn get_output(&self) -> &O {
&self.connector_selection
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 21,
"total_crates": null
} |
fn_clm_euclid_new_4414464518413495379 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/dir
// Inherent implementation for DirKey
pub fn new(kind: DirKeyKind, value: Option<String>) -> Self {
Self { kind, value }
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14463,
"total_crates": null
} |
fn_clm_euclid_get_value_set_4414464518413495379 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/dir
// Inherent implementation for DirKeyKind
pub fn get_value_set(&self) -> Option<Vec<DirValue>> {
match self {
Self::PaymentMethod => Some(
enums::PaymentMethod::iter()
.map(DirValue::PaymentMethod)
.collect(),
),
Self::CardBin => None,
Self::CardType => Some(enums::CardType::iter().map(DirValue::CardType).collect()),
Self::MandateAcceptanceType => Some(
euclid_enums::MandateAcceptanceType::iter()
.map(DirValue::MandateAcceptanceType)
.collect(),
),
Self::PaymentType => Some(
euclid_enums::PaymentType::iter()
.map(DirValue::PaymentType)
.collect(),
),
Self::MandateType => Some(
euclid_enums::MandateType::iter()
.map(DirValue::MandateType)
.collect(),
),
Self::CardNetwork => Some(
enums::CardNetwork::iter()
.map(DirValue::CardNetwork)
.collect(),
),
Self::PayLaterType => Some(
enums::PayLaterType::iter()
.map(DirValue::PayLaterType)
.collect(),
),
Self::MetaData => None,
Self::WalletType => Some(
enums::WalletType::iter()
.map(DirValue::WalletType)
.collect(),
),
Self::UpiType => Some(enums::UpiType::iter().map(DirValue::UpiType).collect()),
Self::VoucherType => Some(
enums::VoucherType::iter()
.map(DirValue::VoucherType)
.collect(),
),
Self::BankTransferType => Some(
enums::BankTransferType::iter()
.map(DirValue::BankTransferType)
.collect(),
),
Self::GiftCardType => Some(
enums::GiftCardType::iter()
.map(DirValue::GiftCardType)
.collect(),
),
Self::BankRedirectType => Some(
enums::BankRedirectType::iter()
.map(DirValue::BankRedirectType)
.collect(),
),
Self::CryptoType => Some(
enums::CryptoType::iter()
.map(DirValue::CryptoType)
.collect(),
),
Self::RewardType => Some(
enums::RewardType::iter()
.map(DirValue::RewardType)
.collect(),
),
Self::PaymentAmount => None,
Self::PaymentCurrency => Some(
enums::PaymentCurrency::iter()
.map(DirValue::PaymentCurrency)
.collect(),
),
Self::AuthenticationType => Some(
enums::AuthenticationType::iter()
.map(DirValue::AuthenticationType)
.collect(),
),
Self::CaptureMethod => Some(
enums::CaptureMethod::iter()
.map(DirValue::CaptureMethod)
.collect(),
),
Self::BankDebitType => Some(
enums::BankDebitType::iter()
.map(DirValue::BankDebitType)
.collect(),
),
Self::BusinessCountry => Some(
enums::Country::iter()
.map(DirValue::BusinessCountry)
.collect(),
),
Self::BillingCountry => Some(
enums::Country::iter()
.map(DirValue::BillingCountry)
.collect(),
),
Self::Connector => Some(
common_enums::RoutableConnectors::iter()
.map(|connector| {
DirValue::Connector(Box::new(ast::ConnectorChoice { connector }))
})
.collect(),
),
Self::BusinessLabel => None,
Self::SetupFutureUsage => Some(
enums::SetupFutureUsage::iter()
.map(DirValue::SetupFutureUsage)
.collect(),
),
Self::CardRedirectType => Some(
enums::CardRedirectType::iter()
.map(DirValue::CardRedirectType)
.collect(),
),
Self::RealTimePaymentType => Some(
enums::RealTimePaymentType::iter()
.map(DirValue::RealTimePaymentType)
.collect(),
),
Self::OpenBankingType => Some(
enums::OpenBankingType::iter()
.map(DirValue::OpenBankingType)
.collect(),
),
Self::MobilePaymentType => Some(
enums::MobilePaymentType::iter()
.map(DirValue::MobilePaymentType)
.collect(),
),
Self::IssuerName => None,
Self::IssuerCountry => Some(
enums::Country::iter()
.map(DirValue::IssuerCountry)
.collect(),
),
Self::CustomerDevicePlatform => Some(
enums::CustomerDevicePlatform::iter()
.map(DirValue::CustomerDevicePlatform)
.collect(),
),
Self::CustomerDeviceType => Some(
enums::CustomerDeviceType::iter()
.map(DirValue::CustomerDeviceType)
.collect(),
),
Self::CustomerDeviceDisplaySize => Some(
enums::CustomerDeviceDisplaySize::iter()
.map(DirValue::CustomerDeviceDisplaySize)
.collect(),
),
Self::AcquirerCountry => Some(
enums::Country::iter()
.map(DirValue::AcquirerCountry)
.collect(),
),
Self::AcquirerFraudRate => None,
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 220,
"total_crates": null
} |
fn_clm_euclid_get_key_4414464518413495379 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/dir
// Inherent implementation for DirValue
pub fn get_key(&self) -> DirKey {
let (kind, data) = match self {
Self::PaymentMethod(_) => (DirKeyKind::PaymentMethod, None),
Self::CardBin(_) => (DirKeyKind::CardBin, None),
Self::RewardType(_) => (DirKeyKind::RewardType, None),
Self::BusinessCountry(_) => (DirKeyKind::BusinessCountry, None),
Self::BillingCountry(_) => (DirKeyKind::BillingCountry, None),
Self::BankTransferType(_) => (DirKeyKind::BankTransferType, None),
Self::UpiType(_) => (DirKeyKind::UpiType, None),
Self::CardType(_) => (DirKeyKind::CardType, None),
Self::CardNetwork(_) => (DirKeyKind::CardNetwork, None),
Self::MetaData(met) => (DirKeyKind::MetaData, Some(met.key.clone())),
Self::PayLaterType(_) => (DirKeyKind::PayLaterType, None),
Self::WalletType(_) => (DirKeyKind::WalletType, None),
Self::BankRedirectType(_) => (DirKeyKind::BankRedirectType, None),
Self::CryptoType(_) => (DirKeyKind::CryptoType, None),
Self::AuthenticationType(_) => (DirKeyKind::AuthenticationType, None),
Self::CaptureMethod(_) => (DirKeyKind::CaptureMethod, None),
Self::PaymentAmount(_) => (DirKeyKind::PaymentAmount, None),
Self::PaymentCurrency(_) => (DirKeyKind::PaymentCurrency, None),
Self::Connector(_) => (DirKeyKind::Connector, None),
Self::BankDebitType(_) => (DirKeyKind::BankDebitType, None),
Self::MandateAcceptanceType(_) => (DirKeyKind::MandateAcceptanceType, None),
Self::MandateType(_) => (DirKeyKind::MandateType, None),
Self::PaymentType(_) => (DirKeyKind::PaymentType, None),
Self::BusinessLabel(_) => (DirKeyKind::BusinessLabel, None),
Self::SetupFutureUsage(_) => (DirKeyKind::SetupFutureUsage, None),
Self::CardRedirectType(_) => (DirKeyKind::CardRedirectType, None),
Self::VoucherType(_) => (DirKeyKind::VoucherType, None),
Self::GiftCardType(_) => (DirKeyKind::GiftCardType, None),
Self::RealTimePaymentType(_) => (DirKeyKind::RealTimePaymentType, None),
Self::OpenBankingType(_) => (DirKeyKind::OpenBankingType, None),
Self::MobilePaymentType(_) => (DirKeyKind::MobilePaymentType, None),
Self::IssuerName(_) => (DirKeyKind::IssuerName, None),
Self::IssuerCountry(_) => (DirKeyKind::IssuerCountry, None),
Self::CustomerDevicePlatform(_) => (DirKeyKind::CustomerDevicePlatform, None),
Self::CustomerDeviceType(_) => (DirKeyKind::CustomerDeviceType, None),
Self::CustomerDeviceDisplaySize(_) => (DirKeyKind::CustomerDeviceDisplaySize, None),
Self::AcquirerCountry(_) => (DirKeyKind::AcquirerCountry, None),
Self::AcquirerFraudRate(_) => (DirKeyKind::AcquirerFraudRate, None),
};
DirKey::new(kind, data)
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 94,
"total_crates": null
} |
fn_clm_euclid_get_num_value_4414464518413495379 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/dir
// Inherent implementation for DirValue
pub fn get_num_value(&self) -> Option<types::NumValue> {
match self {
Self::PaymentAmount(val) => Some(val.clone()),
Self::AcquirerFraudRate(val) => Some(val.clone()),
_ => None,
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 34,
"total_crates": null
} |
fn_clm_euclid_get_type_4414464518413495379 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/dir
// Inherent implementation for DirKeyKind
pub fn get_type(&self) -> types::DataType {
match self {
Self::PaymentMethod => types::DataType::EnumVariant,
Self::CardBin => types::DataType::StrValue,
Self::CardType => types::DataType::EnumVariant,
Self::CardNetwork => types::DataType::EnumVariant,
Self::MetaData => types::DataType::MetadataValue,
Self::MandateType => types::DataType::EnumVariant,
Self::PaymentType => types::DataType::EnumVariant,
Self::MandateAcceptanceType => types::DataType::EnumVariant,
Self::PayLaterType => types::DataType::EnumVariant,
Self::WalletType => types::DataType::EnumVariant,
Self::UpiType => types::DataType::EnumVariant,
Self::VoucherType => types::DataType::EnumVariant,
Self::BankTransferType => types::DataType::EnumVariant,
Self::GiftCardType => types::DataType::EnumVariant,
Self::BankRedirectType => types::DataType::EnumVariant,
Self::CryptoType => types::DataType::EnumVariant,
Self::RewardType => types::DataType::EnumVariant,
Self::PaymentAmount => types::DataType::Number,
Self::PaymentCurrency => types::DataType::EnumVariant,
Self::AuthenticationType => types::DataType::EnumVariant,
Self::CaptureMethod => types::DataType::EnumVariant,
Self::BusinessCountry => types::DataType::EnumVariant,
Self::BillingCountry => types::DataType::EnumVariant,
Self::Connector => types::DataType::EnumVariant,
Self::BankDebitType => types::DataType::EnumVariant,
Self::BusinessLabel => types::DataType::StrValue,
Self::SetupFutureUsage => types::DataType::EnumVariant,
Self::CardRedirectType => types::DataType::EnumVariant,
Self::RealTimePaymentType => types::DataType::EnumVariant,
Self::OpenBankingType => types::DataType::EnumVariant,
Self::MobilePaymentType => types::DataType::EnumVariant,
Self::IssuerName => types::DataType::StrValue,
Self::IssuerCountry => types::DataType::EnumVariant,
Self::CustomerDevicePlatform => types::DataType::EnumVariant,
Self::CustomerDeviceType => types::DataType::EnumVariant,
Self::CustomerDeviceDisplaySize => types::DataType::EnumVariant,
Self::AcquirerCountry => types::DataType::EnumVariant,
Self::AcquirerFraudRate => types::DataType::Number,
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 24,
"total_crates": null
} |
fn_clm_euclid_get_type_1510862836713660992 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/ast
// Inherent implementation for ValueType
pub fn get_type(&self) -> DataType {
match self {
Self::Number(_) => DataType::Number,
Self::StrValue(_) => DataType::StrValue,
Self::MetadataVariant(_) => DataType::MetadataValue,
Self::EnumVariant(_) => DataType::EnumVariant,
Self::NumberComparisonArray(_) => DataType::Number,
Self::NumberArray(_) => DataType::Number,
Self::EnumVariantArray(_) => DataType::EnumVariant,
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 24,
"total_crates": null
} |
fn_clm_euclid_from_-1453935927382562762 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/dir/lowering
// Implementation of global_enums::PaymentMethodType for From<enums::RealTimePaymentType>
fn from(value: enums::RealTimePaymentType) -> Self {
match value {
enums::RealTimePaymentType::Fps => Self::Fps,
enums::RealTimePaymentType::DuitNow => Self::DuitNow,
enums::RealTimePaymentType::PromptPay => Self::PromptPay,
enums::RealTimePaymentType::VietQr => Self::VietQr,
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2600,
"total_crates": null
} |
fn_clm_euclid_lower_value_-1453935927382562762 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/dir/lowering
/// Analyses of the lowering of the DirValues to EuclidValues .
///
/// For example,
/// ```notrust
/// DirValue::PaymentMethod::Cards -> EuclidValue::PaymentMethod::Cards
/// ```notrust
/// This is a function that lowers the Values of the DIR variants into the Value of the VIR variants.
/// The function for each DirValue variant creates a corresponding EuclidValue variants and if there
/// lacks any direct mapping, it return an Error.
fn lower_value(dir_value: dir::DirValue) -> Result<EuclidValue, AnalysisErrorType> {
Ok(match dir_value {
dir::DirValue::PaymentMethod(pm) => EuclidValue::PaymentMethod(pm),
dir::DirValue::CardBin(ci) => EuclidValue::CardBin(ci),
dir::DirValue::CardType(ct) => EuclidValue::PaymentMethodType(ct.into()),
dir::DirValue::CardNetwork(cn) => EuclidValue::CardNetwork(cn),
dir::DirValue::MetaData(md) => EuclidValue::Metadata(md),
dir::DirValue::PayLaterType(plt) => EuclidValue::PaymentMethodType(plt.into()),
dir::DirValue::WalletType(wt) => EuclidValue::PaymentMethodType(wt.into()),
dir::DirValue::UpiType(ut) => EuclidValue::PaymentMethodType(ut.into()),
dir::DirValue::VoucherType(vt) => EuclidValue::PaymentMethodType(vt.into()),
dir::DirValue::BankTransferType(btt) => EuclidValue::PaymentMethodType(btt.into()),
dir::DirValue::GiftCardType(gct) => EuclidValue::PaymentMethodType(gct.into()),
dir::DirValue::CardRedirectType(crt) => EuclidValue::PaymentMethodType(crt.into()),
dir::DirValue::BankRedirectType(brt) => EuclidValue::PaymentMethodType(brt.into()),
dir::DirValue::CryptoType(ct) => EuclidValue::PaymentMethodType(ct.into()),
dir::DirValue::RealTimePaymentType(rtpt) => EuclidValue::PaymentMethodType(rtpt.into()),
dir::DirValue::AuthenticationType(at) => EuclidValue::AuthenticationType(at),
dir::DirValue::CaptureMethod(cm) => EuclidValue::CaptureMethod(cm),
dir::DirValue::PaymentAmount(pa) => EuclidValue::PaymentAmount(pa),
dir::DirValue::PaymentCurrency(pc) => EuclidValue::PaymentCurrency(pc),
dir::DirValue::BusinessCountry(buc) => EuclidValue::BusinessCountry(buc),
dir::DirValue::BillingCountry(bic) => EuclidValue::BillingCountry(bic),
dir::DirValue::MandateAcceptanceType(mat) => EuclidValue::MandateAcceptanceType(mat),
dir::DirValue::MandateType(mt) => EuclidValue::MandateType(mt),
dir::DirValue::PaymentType(pt) => EuclidValue::PaymentType(pt),
dir::DirValue::Connector(_) => Err(AnalysisErrorType::UnsupportedProgramKey(
dir::DirKeyKind::Connector,
))?,
dir::DirValue::BankDebitType(bdt) => EuclidValue::PaymentMethodType(bdt.into()),
dir::DirValue::RewardType(rt) => EuclidValue::PaymentMethodType(rt.into()),
dir::DirValue::BusinessLabel(bl) => EuclidValue::BusinessLabel(bl),
dir::DirValue::SetupFutureUsage(sfu) => EuclidValue::SetupFutureUsage(sfu),
dir::DirValue::OpenBankingType(ob) => EuclidValue::PaymentMethodType(ob.into()),
dir::DirValue::MobilePaymentType(mp) => EuclidValue::PaymentMethodType(mp.into()),
dir::DirValue::IssuerName(str_value) => EuclidValue::IssuerName(str_value),
dir::DirValue::IssuerCountry(country) => EuclidValue::IssuerCountry(country),
dir::DirValue::CustomerDevicePlatform(customer_device_platform) => {
EuclidValue::CustomerDevicePlatform(customer_device_platform)
}
dir::DirValue::CustomerDeviceType(customer_device_type) => {
EuclidValue::CustomerDeviceType(customer_device_type)
}
dir::DirValue::CustomerDeviceDisplaySize(customer_device_display_size) => {
EuclidValue::CustomerDeviceDisplaySize(customer_device_display_size)
}
dir::DirValue::AcquirerCountry(country) => EuclidValue::AcquirerCountry(country),
dir::DirValue::AcquirerFraudRate(num_value) => EuclidValue::AcquirerFraudRate(num_value),
})
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 106,
"total_crates": null
} |
fn_clm_euclid_lower_program_-1453935927382562762 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/dir/lowering
pub fn lower_program<O>(
dir_program: dir::DirProgram<O>,
) -> Result<vir::ValuedProgram<O>, AnalysisError> {
Ok(vir::ValuedProgram {
default_selection: dir_program.default_selection,
rules: dir_program
.rules
.into_iter()
.map(lower_rule)
.collect::<Result<_, _>>()
.map_err(|e| AnalysisError {
error_type: e,
metadata: Default::default(),
})?,
metadata: dir_program.metadata,
})
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 36,
"total_crates": null
} |
fn_clm_euclid_lower_if_statement_-1453935927382562762 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/dir/lowering
fn lower_if_statement(
dir_if_statement: dir::DirIfStatement,
) -> Result<vir::ValuedIfStatement, AnalysisErrorType> {
Ok(vir::ValuedIfStatement {
condition: dir_if_statement
.condition
.into_iter()
.map(lower_comparison)
.collect::<Result<_, _>>()?,
nested: dir_if_statement
.nested
.map(|v| {
v.into_iter()
.map(lower_if_statement)
.collect::<Result<_, _>>()
})
.transpose()?,
})
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 12,
"total_crates": null
} |
fn_clm_euclid_lower_rule_-1453935927382562762 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/dir/lowering
fn lower_rule<O>(dir_rule: dir::DirRule<O>) -> Result<vir::ValuedRule<O>, AnalysisErrorType> {
Ok(vir::ValuedRule {
name: dir_rule.name,
connector_selection: dir_rule.connector_selection,
statements: dir_rule
.statements
.into_iter()
.map(lower_if_statement)
.collect::<Result<_, _>>()?,
})
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 7,
"total_crates": null
} |
fn_clm_euclid_into_dir_value_-2973603351298458977 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/dir/transformers
// Implementation of None for IntoDirValue
fn into_dir_value(self) -> Result<dir::DirValue, AnalysisErrorType> {
match self.0 {
global_enums::PaymentMethodType::Credit => Ok(dirval!(CardType = Credit)),
global_enums::PaymentMethodType::Debit => Ok(dirval!(CardType = Debit)),
#[cfg(feature = "v2")]
global_enums::PaymentMethodType::Card => Ok(dirval!(CardType = Card)),
global_enums::PaymentMethodType::Giropay => Ok(dirval!(BankRedirectType = Giropay)),
global_enums::PaymentMethodType::Ideal => Ok(dirval!(BankRedirectType = Ideal)),
global_enums::PaymentMethodType::Sofort => Ok(dirval!(BankRedirectType = Sofort)),
global_enums::PaymentMethodType::DuitNow => Ok(dirval!(RealTimePaymentType = DuitNow)),
global_enums::PaymentMethodType::Eps => Ok(dirval!(BankRedirectType = Eps)),
global_enums::PaymentMethodType::Fps => Ok(dirval!(RealTimePaymentType = Fps)),
global_enums::PaymentMethodType::Klarna => Ok(dirval!(PayLaterType = Klarna)),
global_enums::PaymentMethodType::Affirm => Ok(dirval!(PayLaterType = Affirm)),
global_enums::PaymentMethodType::AfterpayClearpay => {
Ok(dirval!(PayLaterType = AfterpayClearpay))
}
global_enums::PaymentMethodType::AmazonPay => Ok(dirval!(WalletType = AmazonPay)),
global_enums::PaymentMethodType::Skrill => Ok(dirval!(WalletType = Skrill)),
global_enums::PaymentMethodType::Paysera => Ok(dirval!(WalletType = Paysera)),
global_enums::PaymentMethodType::GooglePay => Ok(dirval!(WalletType = GooglePay)),
global_enums::PaymentMethodType::Bluecode => Ok(dirval!(WalletType = Bluecode)),
global_enums::PaymentMethodType::ApplePay => Ok(dirval!(WalletType = ApplePay)),
global_enums::PaymentMethodType::Paypal => Ok(dirval!(WalletType = Paypal)),
global_enums::PaymentMethodType::RevolutPay => Ok(dirval!(WalletType = RevolutPay)),
global_enums::PaymentMethodType::CryptoCurrency => {
Ok(dirval!(CryptoType = CryptoCurrency))
}
global_enums::PaymentMethodType::Ach => match self.1 {
global_enums::PaymentMethod::BankDebit => Ok(dirval!(BankDebitType = Ach)),
global_enums::PaymentMethod::BankTransfer => Ok(dirval!(BankTransferType = Ach)),
global_enums::PaymentMethod::PayLater
| global_enums::PaymentMethod::Card
| global_enums::PaymentMethod::CardRedirect
| global_enums::PaymentMethod::Wallet
| global_enums::PaymentMethod::BankRedirect
| global_enums::PaymentMethod::Crypto
| global_enums::PaymentMethod::Reward
| global_enums::PaymentMethod::RealTimePayment
| global_enums::PaymentMethod::Upi
| global_enums::PaymentMethod::Voucher
| global_enums::PaymentMethod::OpenBanking
| global_enums::PaymentMethod::MobilePayment
| global_enums::PaymentMethod::GiftCard => Err(AnalysisErrorType::NotSupported),
},
global_enums::PaymentMethodType::Bacs => match self.1 {
global_enums::PaymentMethod::BankDebit => Ok(dirval!(BankDebitType = Bacs)),
global_enums::PaymentMethod::BankTransfer => Ok(dirval!(BankTransferType = Bacs)),
global_enums::PaymentMethod::PayLater
| global_enums::PaymentMethod::Card
| global_enums::PaymentMethod::CardRedirect
| global_enums::PaymentMethod::Wallet
| global_enums::PaymentMethod::BankRedirect
| global_enums::PaymentMethod::Crypto
| global_enums::PaymentMethod::Reward
| global_enums::PaymentMethod::RealTimePayment
| global_enums::PaymentMethod::Upi
| global_enums::PaymentMethod::Voucher
| global_enums::PaymentMethod::OpenBanking
| global_enums::PaymentMethod::MobilePayment
| global_enums::PaymentMethod::GiftCard => Err(AnalysisErrorType::NotSupported),
},
global_enums::PaymentMethodType::Becs => Ok(dirval!(BankDebitType = Becs)),
global_enums::PaymentMethodType::Sepa => Ok(dirval!(BankDebitType = Sepa)),
global_enums::PaymentMethodType::SepaGuarenteedDebit => {
Ok(dirval!(BankDebitType = SepaGuarenteedDebit))
}
global_enums::PaymentMethodType::SepaBankTransfer => {
Ok(dirval!(BankTransferType = SepaBankTransfer))
}
global_enums::PaymentMethodType::AliPay => Ok(dirval!(WalletType = AliPay)),
global_enums::PaymentMethodType::AliPayHk => Ok(dirval!(WalletType = AliPayHk)),
global_enums::PaymentMethodType::BancontactCard => {
Ok(dirval!(BankRedirectType = BancontactCard))
}
global_enums::PaymentMethodType::Blik => Ok(dirval!(BankRedirectType = Blik)),
global_enums::PaymentMethodType::MbWay => Ok(dirval!(WalletType = MbWay)),
global_enums::PaymentMethodType::MobilePay => Ok(dirval!(WalletType = MobilePay)),
global_enums::PaymentMethodType::Cashapp => Ok(dirval!(WalletType = Cashapp)),
global_enums::PaymentMethodType::Multibanco => {
Ok(dirval!(BankTransferType = Multibanco))
}
global_enums::PaymentMethodType::Pix => Ok(dirval!(BankTransferType = Pix)),
global_enums::PaymentMethodType::Pse => Ok(dirval!(BankTransferType = Pse)),
global_enums::PaymentMethodType::Interac => Ok(dirval!(BankRedirectType = Interac)),
global_enums::PaymentMethodType::OnlineBankingCzechRepublic => {
Ok(dirval!(BankRedirectType = OnlineBankingCzechRepublic))
}
global_enums::PaymentMethodType::OnlineBankingFinland => {
Ok(dirval!(BankRedirectType = OnlineBankingFinland))
}
global_enums::PaymentMethodType::OnlineBankingPoland => {
Ok(dirval!(BankRedirectType = OnlineBankingPoland))
}
global_enums::PaymentMethodType::OnlineBankingSlovakia => {
Ok(dirval!(BankRedirectType = OnlineBankingSlovakia))
}
global_enums::PaymentMethodType::Swish => Ok(dirval!(WalletType = Swish)),
global_enums::PaymentMethodType::Trustly => Ok(dirval!(BankRedirectType = Trustly)),
global_enums::PaymentMethodType::Bizum => Ok(dirval!(BankRedirectType = Bizum)),
global_enums::PaymentMethodType::PayBright => Ok(dirval!(PayLaterType = PayBright)),
global_enums::PaymentMethodType::Flexiti => Ok(dirval!(PayLaterType = Flexiti)),
global_enums::PaymentMethodType::Walley => Ok(dirval!(PayLaterType = Walley)),
global_enums::PaymentMethodType::Breadpay => Ok(dirval!(PayLaterType = Breadpay)),
global_enums::PaymentMethodType::Przelewy24 => {
Ok(dirval!(BankRedirectType = Przelewy24))
}
global_enums::PaymentMethodType::PromptPay => {
Ok(dirval!(RealTimePaymentType = PromptPay))
}
global_enums::PaymentMethodType::WeChatPay => Ok(dirval!(WalletType = WeChatPay)),
global_enums::PaymentMethodType::ClassicReward => {
Ok(dirval!(RewardType = ClassicReward))
}
global_enums::PaymentMethodType::Evoucher => Ok(dirval!(RewardType = Evoucher)),
global_enums::PaymentMethodType::UpiCollect => Ok(dirval!(UpiType = UpiCollect)),
global_enums::PaymentMethodType::UpiIntent => Ok(dirval!(UpiType = UpiIntent)),
global_enums::PaymentMethodType::UpiQr => Ok(dirval!(UpiType = UpiQr)),
global_enums::PaymentMethodType::SamsungPay => Ok(dirval!(WalletType = SamsungPay)),
global_enums::PaymentMethodType::GoPay => Ok(dirval!(WalletType = GoPay)),
global_enums::PaymentMethodType::KakaoPay => Ok(dirval!(WalletType = KakaoPay)),
global_enums::PaymentMethodType::Twint => Ok(dirval!(WalletType = Twint)),
global_enums::PaymentMethodType::Gcash => Ok(dirval!(WalletType = Gcash)),
global_enums::PaymentMethodType::Vipps => Ok(dirval!(WalletType = Vipps)),
global_enums::PaymentMethodType::VietQr => Ok(dirval!(RealTimePaymentType = VietQr)),
global_enums::PaymentMethodType::Momo => Ok(dirval!(WalletType = Momo)),
global_enums::PaymentMethodType::Alma => Ok(dirval!(PayLaterType = Alma)),
global_enums::PaymentMethodType::Dana => Ok(dirval!(WalletType = Dana)),
global_enums::PaymentMethodType::OnlineBankingFpx => {
Ok(dirval!(BankRedirectType = OnlineBankingFpx))
}
global_enums::PaymentMethodType::LocalBankRedirect => {
Ok(dirval!(BankRedirectType = LocalBankRedirect))
}
global_enums::PaymentMethodType::OnlineBankingThailand => {
Ok(dirval!(BankRedirectType = OnlineBankingThailand))
}
global_enums::PaymentMethodType::TouchNGo => Ok(dirval!(WalletType = TouchNGo)),
global_enums::PaymentMethodType::Atome => Ok(dirval!(PayLaterType = Atome)),
global_enums::PaymentMethodType::Boleto => Ok(dirval!(VoucherType = Boleto)),
global_enums::PaymentMethodType::Efecty => Ok(dirval!(VoucherType = Efecty)),
global_enums::PaymentMethodType::PagoEfectivo => {
Ok(dirval!(VoucherType = PagoEfectivo))
}
global_enums::PaymentMethodType::RedCompra => Ok(dirval!(VoucherType = RedCompra)),
global_enums::PaymentMethodType::RedPagos => Ok(dirval!(VoucherType = RedPagos)),
global_enums::PaymentMethodType::Alfamart => Ok(dirval!(VoucherType = Alfamart)),
global_enums::PaymentMethodType::BcaBankTransfer => {
Ok(dirval!(BankTransferType = BcaBankTransfer))
}
global_enums::PaymentMethodType::BniVa => Ok(dirval!(BankTransferType = BniVa)),
global_enums::PaymentMethodType::BriVa => Ok(dirval!(BankTransferType = BriVa)),
global_enums::PaymentMethodType::CimbVa => Ok(dirval!(BankTransferType = CimbVa)),
global_enums::PaymentMethodType::DanamonVa => Ok(dirval!(BankTransferType = DanamonVa)),
global_enums::PaymentMethodType::Indomaret => Ok(dirval!(VoucherType = Indomaret)),
global_enums::PaymentMethodType::MandiriVa => Ok(dirval!(BankTransferType = MandiriVa)),
global_enums::PaymentMethodType::LocalBankTransfer => {
Ok(dirval!(BankTransferType = LocalBankTransfer))
}
global_enums::PaymentMethodType::InstantBankTransfer => {
Ok(dirval!(BankTransferType = InstantBankTransfer))
}
global_enums::PaymentMethodType::InstantBankTransferFinland => {
Ok(dirval!(BankTransferType = InstantBankTransferFinland))
}
global_enums::PaymentMethodType::InstantBankTransferPoland => {
Ok(dirval!(BankTransferType = InstantBankTransferPoland))
}
global_enums::PaymentMethodType::PermataBankTransfer => {
Ok(dirval!(BankTransferType = PermataBankTransfer))
}
global_enums::PaymentMethodType::PaySafeCard => Ok(dirval!(GiftCardType = PaySafeCard)),
global_enums::PaymentMethodType::SevenEleven => Ok(dirval!(VoucherType = SevenEleven)),
global_enums::PaymentMethodType::Lawson => Ok(dirval!(VoucherType = Lawson)),
global_enums::PaymentMethodType::MiniStop => Ok(dirval!(VoucherType = MiniStop)),
global_enums::PaymentMethodType::FamilyMart => Ok(dirval!(VoucherType = FamilyMart)),
global_enums::PaymentMethodType::Seicomart => Ok(dirval!(VoucherType = Seicomart)),
global_enums::PaymentMethodType::PayEasy => Ok(dirval!(VoucherType = PayEasy)),
global_enums::PaymentMethodType::Givex => Ok(dirval!(GiftCardType = Givex)),
global_enums::PaymentMethodType::Benefit => Ok(dirval!(CardRedirectType = Benefit)),
global_enums::PaymentMethodType::Knet => Ok(dirval!(CardRedirectType = Knet)),
global_enums::PaymentMethodType::OpenBankingUk => {
Ok(dirval!(BankRedirectType = OpenBankingUk))
}
global_enums::PaymentMethodType::MomoAtm => Ok(dirval!(CardRedirectType = MomoAtm)),
global_enums::PaymentMethodType::Oxxo => Ok(dirval!(VoucherType = Oxxo)),
global_enums::PaymentMethodType::CardRedirect => {
Ok(dirval!(CardRedirectType = CardRedirect))
}
global_enums::PaymentMethodType::Venmo => Ok(dirval!(WalletType = Venmo)),
global_enums::PaymentMethodType::Mifinity => Ok(dirval!(WalletType = Mifinity)),
global_enums::PaymentMethodType::OpenBankingPIS => {
Ok(dirval!(OpenBankingType = OpenBankingPIS))
}
global_enums::PaymentMethodType::Paze => Ok(dirval!(WalletType = Paze)),
global_enums::PaymentMethodType::DirectCarrierBilling => {
Ok(dirval!(MobilePaymentType = DirectCarrierBilling))
}
global_enums::PaymentMethodType::Eft => Ok(dirval!(BankRedirectType = Eft)),
global_enums::PaymentMethodType::IndonesianBankTransfer => {
Ok(dirval!(BankTransferType = IndonesianBankTransfer))
}
global_enums::PaymentMethodType::BhnCardNetwork => {
Ok(dirval!(GiftCardType = BhnCardNetwork))
}
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 35,
"total_crates": null
} |
fn_clm_euclid_lower_comparison_inner_-3108694904030661972 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/ast/lowering
/// lowers the comparison operators for different subtle value types present
/// by throwing required errors for comparisons that can't be performed for a certain value type
/// for example
/// can't have greater/less than operations on enum types
fn lower_comparison_inner<O: EuclidDirFilter>(
comp: ast::Comparison,
) -> Result<Vec<dir::DirValue>, AnalysisErrorType> {
let key_enum = dir::DirKeyKind::from_str(comp.lhs.as_str())
.map_err(|_| AnalysisErrorType::InvalidKey(comp.lhs.clone()))?;
if !O::is_key_allowed(&key_enum) {
return Err(AnalysisErrorType::InvalidKey(key_enum.to_string()));
}
match (&comp.comparison, &comp.value) {
(
ast::ComparisonType::LessThan
| ast::ComparisonType::GreaterThan
| ast::ComparisonType::GreaterThanEqual
| ast::ComparisonType::LessThanEqual,
ast::ValueType::EnumVariant(_),
) => {
Err(AnalysisErrorType::InvalidComparison {
operator: comp.comparison.clone(),
value_type: DataType::EnumVariant,
})?;
}
(
ast::ComparisonType::LessThan
| ast::ComparisonType::GreaterThan
| ast::ComparisonType::GreaterThanEqual
| ast::ComparisonType::LessThanEqual,
ast::ValueType::NumberArray(_),
) => {
Err(AnalysisErrorType::InvalidComparison {
operator: comp.comparison.clone(),
value_type: DataType::Number,
})?;
}
(
ast::ComparisonType::LessThan
| ast::ComparisonType::GreaterThan
| ast::ComparisonType::GreaterThanEqual
| ast::ComparisonType::LessThanEqual,
ast::ValueType::EnumVariantArray(_),
) => {
Err(AnalysisErrorType::InvalidComparison {
operator: comp.comparison.clone(),
value_type: DataType::EnumVariant,
})?;
}
(
ast::ComparisonType::LessThan
| ast::ComparisonType::GreaterThan
| ast::ComparisonType::GreaterThanEqual
| ast::ComparisonType::LessThanEqual,
ast::ValueType::NumberComparisonArray(_),
) => {
Err(AnalysisErrorType::InvalidComparison {
operator: comp.comparison.clone(),
value_type: DataType::Number,
})?;
}
_ => {}
}
let value = comp.value;
let comparison = comp.comparison;
match key_enum {
dir::DirKeyKind::PaymentMethod => lower_enum!(PaymentMethod, value),
dir::DirKeyKind::CardType => lower_enum!(CardType, value),
dir::DirKeyKind::CardNetwork => lower_enum!(CardNetwork, value),
dir::DirKeyKind::PayLaterType => lower_enum!(PayLaterType, value),
dir::DirKeyKind::WalletType => lower_enum!(WalletType, value),
dir::DirKeyKind::BankDebitType => lower_enum!(BankDebitType, value),
dir::DirKeyKind::BankRedirectType => lower_enum!(BankRedirectType, value),
dir::DirKeyKind::CryptoType => lower_enum!(CryptoType, value),
dir::DirKeyKind::PaymentType => lower_enum!(PaymentType, value),
dir::DirKeyKind::MandateType => lower_enum!(MandateType, value),
dir::DirKeyKind::MandateAcceptanceType => lower_enum!(MandateAcceptanceType, value),
dir::DirKeyKind::RewardType => lower_enum!(RewardType, value),
dir::DirKeyKind::PaymentCurrency => lower_enum!(PaymentCurrency, value),
dir::DirKeyKind::AuthenticationType => lower_enum!(AuthenticationType, value),
dir::DirKeyKind::CaptureMethod => lower_enum!(CaptureMethod, value),
dir::DirKeyKind::BusinessCountry => lower_enum!(BusinessCountry, value),
dir::DirKeyKind::BillingCountry => lower_enum!(BillingCountry, value),
dir::DirKeyKind::SetupFutureUsage => lower_enum!(SetupFutureUsage, value),
dir::DirKeyKind::UpiType => lower_enum!(UpiType, value),
dir::DirKeyKind::OpenBankingType => lower_enum!(OpenBankingType, value),
dir::DirKeyKind::VoucherType => lower_enum!(VoucherType, value),
dir::DirKeyKind::GiftCardType => lower_enum!(GiftCardType, value),
dir::DirKeyKind::BankTransferType => lower_enum!(BankTransferType, value),
dir::DirKeyKind::CardRedirectType => lower_enum!(CardRedirectType, value),
dir::DirKeyKind::MobilePaymentType => lower_enum!(MobilePaymentType, value),
dir::DirKeyKind::RealTimePaymentType => lower_enum!(RealTimePaymentType, value),
dir::DirKeyKind::CardBin => {
let validation_closure = |st: &String| -> Result<(), AnalysisErrorType> {
if st.len() == 6 && st.chars().all(|x| x.is_ascii_digit()) {
Ok(())
} else {
Err(AnalysisErrorType::InvalidValue {
key: dir::DirKeyKind::CardBin,
value: st.clone(),
message: Some("Expected 6 digits".to_string()),
})
}
};
lower_str!(CardBin, value, validation_closure)
}
dir::DirKeyKind::BusinessLabel => lower_str!(BusinessLabel, value),
dir::DirKeyKind::MetaData => lower_metadata!(MetaData, value),
dir::DirKeyKind::PaymentAmount => lower_number!(PaymentAmount, value, comparison),
dir::DirKeyKind::Connector => Err(AnalysisErrorType::InvalidKey(
dir::DirKeyKind::Connector.to_string(),
)),
dir::DirKeyKind::IssuerName => lower_str!(IssuerName, value),
dir::DirKeyKind::IssuerCountry => lower_enum!(IssuerCountry, value),
dir::DirKeyKind::CustomerDevicePlatform => lower_enum!(CustomerDevicePlatform, value),
dir::DirKeyKind::CustomerDeviceType => lower_enum!(CustomerDeviceType, value),
dir::DirKeyKind::CustomerDeviceDisplaySize => lower_enum!(CustomerDeviceDisplaySize, value),
dir::DirKeyKind::AcquirerCountry => lower_enum!(AcquirerCountry, value),
dir::DirKeyKind::AcquirerFraudRate => lower_number!(AcquirerFraudRate, value, comparison),
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 40,
"total_crates": null
} |
fn_clm_euclid_lower_program_-3108694904030661972 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/ast/lowering
/// uses the above rules and lowers the whole ast Program into DirProgram by specifying
/// default_selection that is ast ConnectorSelection, a vector of DirRules and clones the metadata
/// whatever comes in the ast_program
pub fn lower_program<O: EuclidDirFilter>(
program: ast::Program<O>,
) -> Result<dir::DirProgram<O>, AnalysisError> {
Ok(dir::DirProgram {
default_selection: program.default_selection,
rules: program
.rules
.into_iter()
.map(lower_rule)
.collect::<Result<_, _>>()?,
metadata: program.metadata,
})
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 32,
"total_crates": null
} |
fn_clm_euclid_lower_rule_-3108694904030661972 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/ast/lowering
/// lowers the rules supplied accordingly to DirRule struct by specifying the rule_name,
/// connector_selection and statements that are a bunch of if statements
pub fn lower_rule<O: EuclidDirFilter>(
rule: ast::Rule<O>,
) -> Result<dir::DirRule<O>, AnalysisError> {
Ok(dir::DirRule {
name: rule.name,
connector_selection: rule.connector_selection,
statements: rule
.statements
.into_iter()
.map(lower_if_statement::<O>)
.collect::<Result<_, _>>()?,
})
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 17,
"total_crates": null
} |
fn_clm_euclid_lower_if_statement_-3108694904030661972 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/ast/lowering
/// lowers the if statement accordingly with a condition and following nested if statements (if
/// present)
fn lower_if_statement<O: EuclidDirFilter>(
stmt: ast::IfStatement,
) -> Result<dir::DirIfStatement, AnalysisError> {
Ok(dir::DirIfStatement {
condition: stmt
.condition
.into_iter()
.map(lower_comparison::<O>)
.collect::<Result<_, _>>()?,
nested: stmt
.nested
.map(|n| n.into_iter().map(lower_if_statement::<O>).collect())
.transpose()?,
})
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14,
"total_crates": null
} |
fn_clm_euclid_lower_comparison_-3108694904030661972 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/ast/lowering
/// returns all the comparison values by matching them appropriately to ComparisonTypes and in turn
/// calls the lower_comparison_inner function
fn lower_comparison<O: EuclidDirFilter>(
comp: ast::Comparison,
) -> Result<dir::DirComparison, AnalysisError> {
let metadata = comp.metadata.clone();
let logic = match &comp.comparison {
ast::ComparisonType::Equal => dir::DirComparisonLogic::PositiveDisjunction,
ast::ComparisonType::NotEqual => dir::DirComparisonLogic::NegativeConjunction,
ast::ComparisonType::LessThan => dir::DirComparisonLogic::PositiveDisjunction,
ast::ComparisonType::LessThanEqual => dir::DirComparisonLogic::PositiveDisjunction,
ast::ComparisonType::GreaterThanEqual => dir::DirComparisonLogic::PositiveDisjunction,
ast::ComparisonType::GreaterThan => dir::DirComparisonLogic::PositiveDisjunction,
};
let values = lower_comparison_inner::<O>(comp).map_err(|etype| AnalysisError {
error_type: etype,
metadata: metadata.clone(),
})?;
Ok(dir::DirComparison {
values,
logic,
metadata,
})
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 6,
"total_crates": null
} |
fn_clm_euclid_skip_ws_-1491936383222166432 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/ast/parser
pub fn skip_ws<'a, F, O>(inner: F) -> impl FnMut(&'a str) -> ParseResult<&'a str, O>
where
F: FnMut(&'a str) -> ParseResult<&'a str, O> + 'a,
{
sequence::preceded(pchar::multispace0, inner)
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 132,
"total_crates": null
} |
fn_clm_euclid_parse_output_-1491936383222166432 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/ast/parser
// Implementation of DummyOutput for EuclidParsable
fn parse_output(input: &str) -> ParseResult<&str, Self> {
let string_w = sequence::delimited(
skip_ws(complete::tag("\"")),
complete::take_while(|c| c != '"'),
skip_ws(complete::tag("\"")),
);
let full_sequence = multi::many0(sequence::preceded(
skip_ws(complete::tag(",")),
sequence::delimited(
skip_ws(complete::tag("\"")),
complete::take_while(|c| c != '"'),
skip_ws(complete::tag("\"")),
),
));
let sequence = sequence::pair(string_w, full_sequence);
error::context(
"dummy_strings",
combinator::map(
sequence::delimited(
skip_ws(complete::tag("[")),
sequence,
skip_ws(complete::tag("]")),
),
|out: (&str, Vec<&str>)| {
let mut first = out.1;
first.insert(0, out.0);
let v = first.iter().map(|s| s.to_string()).collect();
Self { outputs: v }
},
),
)(input)
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 69,
"total_crates": null
} |
fn_clm_euclid_number_array_value_-1491936383222166432 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/ast/parser
pub fn number_array_value(input: &str) -> ParseResult<&str, ast::ValueType> {
fn num_minor_unit(input: &str) -> ParseResult<&str, MinorUnit> {
combinator::map(num_i64, MinorUnit::new)(input)
}
let many_with_comma = multi::many0(sequence::preceded(
skip_ws(complete::tag(",")),
skip_ws(num_minor_unit),
));
let full_sequence = sequence::pair(skip_ws(num_minor_unit), many_with_comma);
error::context(
"number_array_value",
combinator::map(
sequence::delimited(
skip_ws(complete::tag("(")),
full_sequence,
skip_ws(complete::tag(")")),
),
|tup: (MinorUnit, Vec<MinorUnit>)| {
let mut rest = tup.1;
rest.insert(0, tup.0);
ast::ValueType::NumberArray(rest)
},
),
)(input)
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 44,
"total_crates": null
} |
fn_clm_euclid_enum_variant_array_value_-1491936383222166432 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/ast/parser
pub fn enum_variant_array_value(input: &str) -> ParseResult<&str, ast::ValueType> {
let many_with_comma = multi::many0(sequence::preceded(
skip_ws(complete::tag(",")),
skip_ws(enum_value_string),
));
let full_sequence = sequence::pair(skip_ws(enum_value_string), many_with_comma);
error::context(
"enum_variant_array_value",
combinator::map(
sequence::delimited(
skip_ws(complete::tag("(")),
full_sequence,
skip_ws(complete::tag(")")),
),
|tup: (String, Vec<String>)| {
let mut rest = tup.1;
rest.insert(0, tup.0);
ast::ValueType::EnumVariantArray(rest)
},
),
)(input)
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 42,
"total_crates": null
} |
fn_clm_euclid_number_comparison_array_value_-1491936383222166432 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/frontend/ast/parser
pub fn number_comparison_array_value(input: &str) -> ParseResult<&str, ast::ValueType> {
let many_with_comma = multi::many0(sequence::preceded(
skip_ws(complete::tag(",")),
skip_ws(number_comparison),
));
let full_sequence = sequence::pair(skip_ws(number_comparison), many_with_comma);
error::context(
"number_comparison_array_value",
combinator::map(
sequence::delimited(
skip_ws(complete::tag("(")),
full_sequence,
skip_ws(complete::tag(")")),
),
|tup: (ast::NumberComparison, Vec<ast::NumberComparison>)| {
let mut rest = tup.1;
rest.insert(0, tup.0);
ast::ValueType::NumberComparisonArray(rest)
},
),
)(input)
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 42,
"total_crates": null
} |
fn_clm_euclid_execute_-3400062557541798850 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/backend/vir_interpreter
// Implementation of VirInterpreterBackend<O> for EuclidBackend<O>
fn execute(
&self,
input: inputs::BackendInput,
) -> Result<backend::BackendOutput<O>, Self::Error> {
let ctx = types::Context::from_input(input);
Ok(Self::eval_program(&self.program, &ctx))
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 90,
"total_crates": null
} |
fn_clm_euclid_with_program_-3400062557541798850 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/backend/vir_interpreter
// Implementation of VirInterpreterBackend<O> for EuclidBackend<O>
fn with_program(program: ast::Program<O>) -> Result<Self, Self::Error> {
let dir_program = ast::lowering::lower_program(program)
.map_err(types::VirInterpreterError::LoweringError)?;
let vir_program = dir::lowering::lower_program(dir_program)
.map_err(types::VirInterpreterError::LoweringError)?;
Ok(Self {
program: vir_program,
})
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 73,
"total_crates": null
} |
fn_clm_euclid_eval_program_-3400062557541798850 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/backend/vir_interpreter
// Inherent implementation for VirInterpreterBackend<O>
fn eval_program(
program: &vir::ValuedProgram<O>,
ctx: &types::Context,
) -> backend::BackendOutput<O> {
program
.rules
.iter()
.find(|rule| Self::eval_rule(rule, ctx))
.map_or_else(
|| backend::BackendOutput {
connector_selection: program.default_selection.clone(),
rule_name: None,
},
|rule| backend::BackendOutput {
connector_selection: rule.connector_selection.clone(),
rule_name: Some(rule.name.clone()),
},
)
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 28,
"total_crates": null
} |
fn_clm_euclid_eval_comparison_-3400062557541798850 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/backend/vir_interpreter
// Inherent implementation for VirInterpreterBackend<O>
fn eval_comparison(comp: &vir::ValuedComparison, ctx: &types::Context) -> bool {
match &comp.logic {
vir::ValuedComparisonLogic::PositiveDisjunction => {
comp.values.iter().any(|v| ctx.check_presence(v))
}
vir::ValuedComparisonLogic::NegativeConjunction => {
comp.values.iter().all(|v| !ctx.check_presence(v))
}
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 26,
"total_crates": null
} |
fn_clm_euclid_eval_statement_-3400062557541798850 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/backend/vir_interpreter
// Inherent implementation for VirInterpreterBackend<O>
fn eval_statement(stmt: &vir::ValuedIfStatement, ctx: &types::Context) -> bool {
if Self::eval_condition(&stmt.condition, ctx) {
{
stmt.nested.as_ref().is_none_or(|nested_stmts| {
nested_stmts.iter().any(|s| Self::eval_statement(s, ctx))
})
}
} else {
false
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 26,
"total_crates": null
} |
fn_clm_euclid_execute_1342671453287852746 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/backend/interpreter
// Implementation of InterpreterBackend<O> for EuclidBackend<O>
fn execute(&self, input: inputs::BackendInput) -> Result<super::BackendOutput<O>, Self::Error> {
let ctx: types::Context = input.into();
Self::eval_program(&self.program, &ctx)
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 90,
"total_crates": null
} |
fn_clm_euclid_with_program_1342671453287852746 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/backend/interpreter
// Implementation of InterpreterBackend<O> for EuclidBackend<O>
fn with_program(program: ast::Program<O>) -> Result<Self, Self::Error> {
Ok(Self { program })
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 65,
"total_crates": null
} |
fn_clm_euclid_eval_comparison_1342671453287852746 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/backend/interpreter
// Implementation of None for InterpreterBackend<O>
fn eval_comparison(
comparison: &ast::Comparison,
ctx: &types::Context,
) -> Result<bool, types::InterpreterError> {
use ast::{ComparisonType::*, ValueType::*};
let value = ctx
.get(&comparison.lhs)
.ok_or_else(|| types::InterpreterError {
error_type: types::InterpreterErrorType::InvalidKey(comparison.lhs.clone()),
metadata: comparison.metadata.clone(),
})?;
if let Some(val) = value {
match (val, &comparison.comparison, &comparison.value) {
(EnumVariant(e1), Equal, EnumVariant(e2)) => Ok(e1 == e2),
(EnumVariant(e1), NotEqual, EnumVariant(e2)) => Ok(e1 != e2),
(EnumVariant(e), Equal, EnumVariantArray(evec)) => Ok(evec.iter().any(|v| e == v)),
(EnumVariant(e), NotEqual, EnumVariantArray(evec)) => {
Ok(evec.iter().all(|v| e != v))
}
(Number(n1), Equal, Number(n2)) => Ok(n1 == n2),
(Number(n1), NotEqual, Number(n2)) => Ok(n1 != n2),
(Number(n1), LessThanEqual, Number(n2)) => Ok(n1 <= n2),
(Number(n1), GreaterThanEqual, Number(n2)) => Ok(n1 >= n2),
(Number(n1), LessThan, Number(n2)) => Ok(n1 < n2),
(Number(n1), GreaterThan, Number(n2)) => Ok(n1 > n2),
(Number(n), Equal, NumberArray(nvec)) => Ok(nvec.iter().any(|v| v == n)),
(Number(n), NotEqual, NumberArray(nvec)) => Ok(nvec.iter().all(|v| v != n)),
(Number(n), Equal, NumberComparisonArray(ncvec)) => {
Self::eval_number_comparison_array(*n, ncvec)
}
_ => Err(types::InterpreterError {
error_type: types::InterpreterErrorType::InvalidComparison,
metadata: comparison.metadata.clone(),
}),
}
} else {
Ok(false)
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 44,
"total_crates": null
} |
fn_clm_euclid_eval_program_1342671453287852746 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/backend/interpreter
// Implementation of None for InterpreterBackend<O>
fn eval_program(
program: &ast::Program<O>,
ctx: &types::Context,
) -> Result<backend::BackendOutput<O>, types::InterpreterError> {
for rule in &program.rules {
let res = Self::eval_rule(rule, ctx)?;
if res {
return Ok(backend::BackendOutput {
connector_selection: rule.connector_selection.clone(),
rule_name: Some(rule.name.clone()),
});
}
}
Ok(backend::BackendOutput {
connector_selection: program.default_selection.clone(),
rule_name: None,
})
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 22,
"total_crates": null
} |
fn_clm_euclid_eval_if_statement_1342671453287852746 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/backend/interpreter
// Implementation of None for InterpreterBackend<O>
fn eval_if_statement(
stmt: &ast::IfStatement,
ctx: &types::Context,
) -> Result<bool, types::InterpreterError> {
let cond_res = Self::eval_if_condition(&stmt.condition, ctx)?;
if !cond_res {
return Ok(false);
}
if let Some(ref nested) = stmt.nested {
for nested_if in nested {
let res = Self::eval_if_statement(nested_if, ctx)?;
if res {
return Ok(true);
}
}
return Ok(false);
}
Ok(true)
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 18,
"total_crates": null
} |
fn_clm_euclid_from_3162291768115064583 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/backend/interpreter/types
// Implementation of Context for From<inputs::BackendInput>
fn from(input: inputs::BackendInput) -> Self {
let ctx = HashMap::<String, Option<ValueType>>::from_iter([
(
EuclidKey::PaymentMethod.to_string(),
input
.payment_method
.payment_method
.map(|pm| ValueType::EnumVariant(pm.to_string())),
),
(
EuclidKey::PaymentMethodType.to_string(),
input
.payment_method
.payment_method_type
.map(|pt| ValueType::EnumVariant(pt.to_string())),
),
(
EuclidKey::AuthenticationType.to_string(),
input
.payment
.authentication_type
.map(|at| ValueType::EnumVariant(at.to_string())),
),
(
EuclidKey::CaptureMethod.to_string(),
input
.payment
.capture_method
.map(|cm| ValueType::EnumVariant(cm.to_string())),
),
(
EuclidKey::PaymentAmount.to_string(),
Some(ValueType::Number(input.payment.amount)),
),
(
EuclidKey::PaymentCurrency.to_string(),
Some(ValueType::EnumVariant(input.payment.currency.to_string())),
),
]);
Self(ctx)
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2646,
"total_crates": null
} |
fn_clm_euclid_deref_3162291768115064583 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/backend/interpreter/types
// Implementation of Context for Deref
fn deref(&self) -> &Self::Target {
&self.0
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 41,
"total_crates": null
} |
fn_clm_euclid_fmt_3162291768115064583 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/backend/interpreter/types
// Implementation of InterpreterError for fmt::Display
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
InterpreterErrorType::fmt(&self.error_type, f)
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 40,
"total_crates": null
} |
fn_clm_euclid_from_input_6030126670255815637 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/backend/vir_interpreter/types
// Implementation of None for Context
pub fn from_input(input: BackendInput) -> Self {
let payment = input.payment;
let payment_method = input.payment_method;
let meta_data = input.metadata;
let acquirer_data = input.acquirer_data;
let customer_device_data = input.customer_device_data;
let issuer_data = input.issuer_data;
let payment_mandate = input.mandate;
let mut enum_values: FxHashSet<EuclidValue> =
FxHashSet::from_iter([EuclidValue::PaymentCurrency(payment.currency)]);
if let Some(pm) = payment_method.payment_method {
enum_values.insert(EuclidValue::PaymentMethod(pm));
}
if let Some(pmt) = payment_method.payment_method_type {
enum_values.insert(EuclidValue::PaymentMethodType(pmt));
}
if let Some(met) = meta_data {
for (key, value) in met.into_iter() {
enum_values.insert(EuclidValue::Metadata(MetadataValue { key, value }));
}
}
if let Some(card_network) = payment_method.card_network {
enum_values.insert(EuclidValue::CardNetwork(card_network));
}
if let Some(at) = payment.authentication_type {
enum_values.insert(EuclidValue::AuthenticationType(at));
}
if let Some(capture_method) = payment.capture_method {
enum_values.insert(EuclidValue::CaptureMethod(capture_method));
}
if let Some(country) = payment.business_country {
enum_values.insert(EuclidValue::BusinessCountry(country));
}
if let Some(country) = payment.billing_country {
enum_values.insert(EuclidValue::BillingCountry(country));
}
if let Some(card_bin) = payment.card_bin {
enum_values.insert(EuclidValue::CardBin(StrValue { value: card_bin }));
}
if let Some(business_label) = payment.business_label {
enum_values.insert(EuclidValue::BusinessLabel(StrValue {
value: business_label,
}));
}
if let Some(setup_future_usage) = payment.setup_future_usage {
enum_values.insert(EuclidValue::SetupFutureUsage(setup_future_usage));
}
if let Some(payment_type) = payment_mandate.payment_type {
enum_values.insert(EuclidValue::PaymentType(payment_type));
}
if let Some(mandate_type) = payment_mandate.mandate_type {
enum_values.insert(EuclidValue::MandateType(mandate_type));
}
if let Some(mandate_acceptance_type) = payment_mandate.mandate_acceptance_type {
enum_values.insert(EuclidValue::MandateAcceptanceType(mandate_acceptance_type));
}
if let Some(acquirer_country) = acquirer_data.clone().and_then(|data| data.country) {
enum_values.insert(EuclidValue::AcquirerCountry(acquirer_country));
}
// Handle customer device data
if let Some(device_data) = customer_device_data {
if let Some(platform) = device_data.platform {
enum_values.insert(EuclidValue::CustomerDevicePlatform(platform));
}
if let Some(device_type) = device_data.device_type {
enum_values.insert(EuclidValue::CustomerDeviceType(device_type));
}
if let Some(display_size) = device_data.display_size {
enum_values.insert(EuclidValue::CustomerDeviceDisplaySize(display_size));
}
}
// Handle issuer data
if let Some(issuer) = issuer_data {
if let Some(name) = issuer.name {
enum_values.insert(EuclidValue::IssuerName(StrValue { value: name }));
}
if let Some(country) = issuer.country {
enum_values.insert(EuclidValue::IssuerCountry(country));
}
}
let numeric_values: FxHashMap<EuclidKey, EuclidValue> = FxHashMap::from_iter([(
EuclidKey::PaymentAmount,
EuclidValue::PaymentAmount(types::NumValue {
number: payment.amount,
refinement: None,
}),
)]);
Self {
atomic_values: enum_values,
numeric_values,
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 115,
"total_crates": null
} |
fn_clm_euclid_check_presence_6030126670255815637 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/backend/vir_interpreter/types
// Implementation of None for Context
pub fn check_presence(&self, value: &EuclidValue) -> bool {
let key = value.get_key();
match key.key_type() {
types::DataType::MetadataValue => self.atomic_values.contains(value),
types::DataType::StrValue => self.atomic_values.contains(value),
types::DataType::EnumVariant => self.atomic_values.contains(value),
types::DataType::Number => {
let ctx_num_value = self
.numeric_values
.get(&key)
.and_then(|value| value.get_num_value());
value.get_num_value().zip(ctx_num_value).is_some_and(
|(program_value, ctx_value)| {
let program_num = program_value.number;
let ctx_num = ctx_value.number;
match &program_value.refinement {
None => program_num == ctx_num,
Some(NumValueRefinement::NotEqual) => ctx_num != program_num,
Some(NumValueRefinement::GreaterThan) => ctx_num > program_num,
Some(NumValueRefinement::GreaterThanEqual) => ctx_num >= program_num,
Some(NumValueRefinement::LessThanEqual) => ctx_num <= program_num,
Some(NumValueRefinement::LessThan) => ctx_num < program_num,
}
},
)
}
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 49,
"total_crates": null
} |
fn_clm_euclid_new_6759806506003692045 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/state_machine
// Inherent implementation for AnalysisContextManager<'a>
pub fn new<O>(
program: &'a dir::DirProgram<O>,
connector_selection_data: &'a [Vec<(dir::DirValue, Metadata)>],
) -> Self {
let machine = ProgramStateMachine::new(program, connector_selection_data);
let context: types::ConjunctiveContext<'a> = Vec::new();
Self {
context,
machine,
init: false,
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14467,
"total_crates": null
} |
fn_clm_euclid_push_6759806506003692045 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/state_machine
// Inherent implementation for ComparisonStateMachine<'a>
fn push(&self, context: &mut types::ConjunctiveContext<'a>) -> Result<(), StateMachineError> {
match self.logic {
dir::DirComparisonLogic::PositiveDisjunction => {
context.push(types::ContextValue::assertion(
self.values
.get(self.count)
.ok_or(StateMachineError::IndexOutOfBounds(
"in ComparisonStateMachine while pushing",
))?,
self.metadata,
));
}
dir::DirComparisonLogic::NegativeConjunction => {
context.push(types::ContextValue::negation(self.values, self.metadata));
}
}
Ok(())
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 1498,
"total_crates": null
} |
fn_clm_euclid_is_finished_6759806506003692045 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/state_machine
// Inherent implementation for ProgramStateMachine<'a>
pub fn is_finished(&self) -> bool {
self.current_rule_machine
.as_ref()
.is_none_or(|rsm| rsm.is_finished())
&& self.rule_machines.is_empty()
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 47,
"total_crates": null
} |
fn_clm_euclid_advance_6759806506003692045 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/state_machine
// Inherent implementation for AnalysisContextManager<'a>
pub fn advance(&mut self) -> Result<Option<&types::ConjunctiveContext<'a>>, StateMachineError> {
if !self.init {
self.init = true;
self.machine.init(&mut self.context)?;
Ok(Some(&self.context))
} else if self.machine.is_finished() {
Ok(None)
} else {
self.machine.advance(&mut self.context)?;
if self.machine.is_finished() {
Ok(None)
} else {
Ok(Some(&self.context))
}
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 44,
"total_crates": null
} |
fn_clm_euclid_init_6759806506003692045 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/state_machine
// Inherent implementation for ProgramStateMachine<'a>
pub fn init(
&mut self,
context: &mut types::ConjunctiveContext<'a>,
) -> Result<(), StateMachineError> {
if !self.is_init {
if let Some(rsm) = self.current_rule_machine.as_mut() {
rsm.init_next(context)?;
}
self.is_init = true;
}
Ok(())
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 43,
"total_crates": null
} |
fn_clm_euclid_get_key_-1666753747473388764 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/types
// Inherent implementation for CtxValueKind<'_>
pub fn get_key(&self) -> Option<dir::DirKey> {
match self {
Self::Assertion(val) => Some(val.get_key()),
Self::Negation(vals) => vals.first().map(|v| (*v).get_key()),
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 98,
"total_crates": null
} |
fn_clm_euclid_fmt_-1666753747473388764 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/types
// Implementation of AnalysisError for fmt::Display
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.error_type.fmt(f)
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 40,
"total_crates": null
} |
fn_clm_euclid_assertion_-1666753747473388764 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/types
// Inherent implementation for ContextValue<'a>
pub fn assertion(value: &'a dir::DirValue, metadata: &'a Metadata) -> Self {
Self {
value: CtxValueKind::Assertion(value),
metadata,
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 32,
"total_crates": null
} |
fn_clm_euclid_get_assertion_-1666753747473388764 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/types
// Inherent implementation for CtxValueKind<'_>
pub fn get_assertion(&self) -> Option<&dir::DirValue> {
if let Self::Assertion(val) = self {
Some(val)
} else {
None
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 24,
"total_crates": null
} |
fn_clm_euclid_negation_-1666753747473388764 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/types
// Inherent implementation for ContextValue<'a>
pub fn negation(values: &'a [dir::DirValue], metadata: &'a Metadata) -> Self {
Self {
value: CtxValueKind::Negation(values),
metadata,
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 23,
"total_crates": null
} |
fn_clm_euclid_perform_condition_analyses_6834835696342996971 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/analyzer
fn perform_condition_analyses(
context: &types::ConjunctiveContext<'_>,
) -> Result<(), types::AnalysisError> {
let mut assertion_metadata: FxHashMap<&dir::DirValue, &Metadata> = FxHashMap::default();
let mut keywise_assertions: FxHashMap<dir::DirKey, FxHashSet<&dir::DirValue>> =
FxHashMap::default();
let mut negation_metadata: FxHashMap<&dir::DirValue, &Metadata> = FxHashMap::default();
let mut keywise_negation_metadata: FxHashMap<dir::DirKey, Vec<&Metadata>> =
FxHashMap::default();
let mut keywise_negations: FxHashMap<dir::DirKey, FxHashSet<&dir::DirValue>> =
FxHashMap::default();
for ctx_val in context {
let key = if let Some(k) = ctx_val.value.get_key() {
k
} else {
continue;
};
if let dir::DirKeyKind::Connector = key.kind {
continue;
}
if !matches!(key.kind.get_type(), DataType::EnumVariant) {
continue;
}
match ctx_val.value {
types::CtxValueKind::Assertion(val) => {
keywise_assertions
.entry(key.clone())
.or_default()
.insert(val);
assertion_metadata.insert(val, ctx_val.metadata);
}
types::CtxValueKind::Negation(vals) => {
let negation_set = keywise_negations.entry(key.clone()).or_default();
for val in vals {
negation_set.insert(val);
negation_metadata.insert(val, ctx_val.metadata);
}
keywise_negation_metadata
.entry(key.clone())
.or_default()
.push(ctx_val.metadata);
}
}
}
analyze_conflicting_assertions(&keywise_assertions, &assertion_metadata)?;
analyze_exhaustive_negations(&keywise_negations, &keywise_negation_metadata)?;
analyze_negated_assertions(
&keywise_assertions,
&assertion_metadata,
&keywise_negations,
&negation_metadata,
)?;
Ok(())
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 49,
"total_crates": null
} |
fn_clm_euclid_analyze_6834835696342996971 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/analyzer
pub fn analyze<O: EuclidAnalysable + EuclidDirFilter>(
program: ast::Program<O>,
knowledge_graph: Option<&ConstraintGraph<dir::DirValue>>,
) -> Result<vir::ValuedProgram<O>, types::AnalysisError> {
let dir_program = ast::lowering::lower_program(program)?;
let selection_data = state_machine::make_connector_selection_data(&dir_program);
let mut ctx_manager = state_machine::AnalysisContextManager::new(&dir_program, &selection_data);
while let Some(ctx) = ctx_manager.advance().map_err(|err| types::AnalysisError {
metadata: Default::default(),
error_type: types::AnalysisErrorType::StateMachine(err),
})? {
perform_context_analyses(ctx, knowledge_graph.unwrap_or(&truth::ANALYSIS_GRAPH))?;
}
dir::lowering::lower_program(dir_program)
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 45,
"total_crates": null
} |
fn_clm_euclid_analyze_exhaustive_negations_6834835696342996971 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/analyzer
/// Analyses exhaustive negations on the same key in a conjunctive context.
///
/// For example,
/// ```notrust
/// authentication_type /= three_ds && ... && authentication_type /= no_three_ds
/// ```notrust
/// This is a condition that will never evaluate to `true` given any authentication_type
/// since all the possible values authentication_type can take have been negated.
pub fn analyze_exhaustive_negations(
keywise_negations: &FxHashMap<dir::DirKey, FxHashSet<&dir::DirValue>>,
keywise_negation_metadata: &FxHashMap<dir::DirKey, Vec<&Metadata>>,
) -> Result<(), types::AnalysisError> {
for (key, negation_set) in keywise_negations {
let mut value_set = if let Some(set) = key.kind.get_value_set() {
set
} else {
continue;
};
value_set.retain(|val| !negation_set.contains(val));
if value_set.is_empty() {
let error_type = types::AnalysisErrorType::ExhaustiveNegation {
key: key.clone(),
metadata: keywise_negation_metadata
.get(key)
.cloned()
.unwrap_or_default()
.iter()
.copied()
.cloned()
.collect(),
};
Err(types::AnalysisError {
error_type,
metadata: Default::default(),
})?;
}
}
Ok(())
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 39,
"total_crates": null
} |
fn_clm_euclid_analyze_conflicting_assertions_6834835696342996971 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/analyzer
/// Analyses conflicting assertions on the same key in a conjunctive context.
///
/// For example,
/// ```notrust
/// payment_method = card && ... && payment_method = bank_debit
/// ```notrust
/// This is a condition that will never evaluate to `true` given a single
/// payment method and needs to be caught in analysis.
pub fn analyze_conflicting_assertions(
keywise_assertions: &FxHashMap<dir::DirKey, FxHashSet<&dir::DirValue>>,
assertion_metadata: &FxHashMap<&dir::DirValue, &Metadata>,
) -> Result<(), types::AnalysisError> {
for (key, value_set) in keywise_assertions {
if value_set.len() > 1 {
let err_type = types::AnalysisErrorType::ConflictingAssertions {
key: key.clone(),
values: value_set
.iter()
.map(|val| types::ValueData {
value: (*val).clone(),
metadata: assertion_metadata
.get(val)
.map(|meta| (*meta).clone())
.unwrap_or_default(),
})
.collect(),
};
Err(types::AnalysisError {
error_type: err_type,
metadata: Default::default(),
})?;
}
}
Ok(())
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 35,
"total_crates": null
} |
fn_clm_euclid_analyze_negated_assertions_6834835696342996971 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/analyzer
fn analyze_negated_assertions(
keywise_assertions: &FxHashMap<dir::DirKey, FxHashSet<&dir::DirValue>>,
assertion_metadata: &FxHashMap<&dir::DirValue, &Metadata>,
keywise_negations: &FxHashMap<dir::DirKey, FxHashSet<&dir::DirValue>>,
negation_metadata: &FxHashMap<&dir::DirValue, &Metadata>,
) -> Result<(), types::AnalysisError> {
for (key, negation_set) in keywise_negations {
let assertion_set = if let Some(set) = keywise_assertions.get(key) {
set
} else {
continue;
};
let intersection = negation_set & assertion_set;
intersection.iter().next().map_or(Ok(()), |val| {
let error_type = types::AnalysisErrorType::NegatedAssertion {
value: (*val).clone(),
assertion_metadata: assertion_metadata
.get(*val)
.copied()
.cloned()
.unwrap_or_default(),
negation_metadata: negation_metadata
.get(*val)
.copied()
.cloned()
.unwrap_or_default(),
};
Err(types::AnalysisError {
error_type,
metadata: Default::default(),
})
})?;
}
Ok(())
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 31,
"total_crates": null
} |
fn_clm_euclid_insert_-5548497769750923850 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/graph
// Implementation of None for AnalysisContext
pub fn insert(&mut self, value: dir::DirValue) {
self.keywise_values
.entry(value.get_key())
.or_default()
.insert(value);
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 1133,
"total_crates": null
} |
fn_clm_euclid_remove_-5548497769750923850 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/graph
// Implementation of None for AnalysisContext
pub fn remove(&mut self, value: dir::DirValue) {
let set = self.keywise_values.entry(value.get_key()).or_default();
set.remove(&value);
if set.is_empty() {
self.keywise_values.remove(&value.get_key());
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 218,
"total_crates": null
} |
fn_clm_euclid_from_dir_values_-5548497769750923850 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/graph
// Implementation of None for AnalysisContext
pub fn from_dir_values(vals: impl IntoIterator<Item = dir::DirValue>) -> Self {
let mut keywise_values: FxHashMap<dir::DirKey, FxHashSet<dir::DirValue>> =
FxHashMap::default();
for dir_val in vals {
let key = dir_val.get_key();
let set = keywise_values.entry(key).or_default();
set.insert(dir_val);
}
Self { keywise_values }
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 115,
"total_crates": null
} |
fn_clm_euclid_key_value_analysis_-5548497769750923850 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/graph
// Implementation of cgraph::ConstraintGraph<dir::DirValue> for CgraphExt
fn key_value_analysis(
&self,
val: dir::DirValue,
ctx: &AnalysisContext,
memo: &mut cgraph::Memoization<dir::DirValue>,
cycle_map: &mut cgraph::CycleCheck,
domains: Option<&[String]>,
) -> Result<(), cgraph::GraphError<dir::DirValue>> {
self.key_analysis(val.get_key(), ctx, memo, cycle_map, domains)
.and_then(|_| self.value_analysis(val, ctx, memo, cycle_map, domains))
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 103,
"total_crates": null
} |
fn_clm_euclid_viz_-5548497769750923850 | clm | function | // Repository: hyperswitch
// Crate: euclid
// Module: crates/euclid/src/dssa/graph
// Implementation of dir::DirValue for cgraph::NodeViz
fn viz(&self) -> String {
match self {
Self::PaymentMethod(pm) => pm.to_string(),
Self::CardBin(bin) => bin.value.clone(),
Self::CardType(ct) => ct.to_string(),
Self::CardNetwork(cn) => cn.to_string(),
Self::PayLaterType(plt) => plt.to_string(),
Self::WalletType(wt) => wt.to_string(),
Self::UpiType(ut) => ut.to_string(),
Self::BankTransferType(btt) => btt.to_string(),
Self::BankRedirectType(brt) => brt.to_string(),
Self::BankDebitType(bdt) => bdt.to_string(),
Self::CryptoType(ct) => ct.to_string(),
Self::RewardType(rt) => rt.to_string(),
Self::PaymentAmount(amt) => amt.number.to_string(),
Self::PaymentCurrency(curr) => curr.to_string(),
Self::AuthenticationType(at) => at.to_string(),
Self::CaptureMethod(cm) => cm.to_string(),
Self::BusinessCountry(bc) => bc.to_string(),
Self::BillingCountry(bc) => bc.to_string(),
Self::Connector(conn) => conn.connector.to_string(),
Self::MetaData(mv) => format!("[{} = {}]", mv.key, mv.value),
Self::MandateAcceptanceType(mat) => mat.to_string(),
Self::MandateType(mt) => mt.to_string(),
Self::PaymentType(pt) => pt.to_string(),
Self::VoucherType(vt) => vt.to_string(),
Self::GiftCardType(gct) => gct.to_string(),
Self::BusinessLabel(bl) => bl.value.to_string(),
Self::SetupFutureUsage(sfu) => sfu.to_string(),
Self::CardRedirectType(crt) => crt.to_string(),
Self::RealTimePaymentType(rtpt) => rtpt.to_string(),
Self::OpenBankingType(ob) => ob.to_string(),
Self::MobilePaymentType(mpt) => mpt.to_string(),
Self::IssuerName(issuer_name) => issuer_name.value.clone(),
Self::IssuerCountry(issuer_country) => issuer_country.to_string(),
Self::CustomerDevicePlatform(customer_device_platform) => {
customer_device_platform.to_string()
}
Self::CustomerDeviceType(customer_device_type) => customer_device_type.to_string(),
Self::CustomerDeviceDisplaySize(customer_device_display_size) => {
customer_device_display_size.to_string()
}
Self::AcquirerCountry(acquirer_country) => acquirer_country.to_string(),
Self::AcquirerFraudRate(acquirer_fraud_rate) => acquirer_fraud_rate.number.to_string(),
}
}
| {
"crate": "euclid",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 85,
"total_crates": null
} |
fn_clm_api_models_new_-5206725892084843784 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/payment_methods
// Inherent implementation for ResponsePaymentMethodIntermediate
pub fn new(
pm_type: RequestPaymentMethodTypes,
connector: String,
merchant_connector_id: String,
pm: api_enums::PaymentMethod,
) -> Self {
Self {
payment_method_type: pm_type.payment_method_type,
payment_experience: pm_type.payment_experience,
card_networks: pm_type.card_networks,
payment_method: pm,
connector,
merchant_connector_id,
}
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14463,
"total_crates": null
} |
fn_clm_api_models_try_from_-5206725892084843784 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/payment_methods
// Implementation of PaymentMethodMigrate for TryFrom<(
&PaymentMethodRecord,
id_type::MerchantId,
Option<&Vec<id_type::MerchantConnectorAccountId>>,
)>
fn try_from(
item: (
&PaymentMethodRecord,
id_type::MerchantId,
Option<&Vec<id_type::MerchantConnectorAccountId>>,
),
) -> Result<Self, Self::Error> {
let (record, merchant_id, mca_ids) = item;
let billing = record.create_billing();
let connector_mandate_details = if let Some(payment_instrument_id) =
&record.payment_instrument_id
{
let ids = mca_ids.get_required_value("mca_ids")?;
let mandate_map: HashMap<_, _> = ids
.iter()
.map(|mca_id| {
(
mca_id.clone(),
PaymentsMandateReferenceRecord {
connector_mandate_id: payment_instrument_id.peek().to_string(),
payment_method_type: record.payment_method_type,
original_payment_authorized_amount: record.original_transaction_amount,
original_payment_authorized_currency: record
.original_transaction_currency,
},
)
})
.collect();
Some(PaymentsMandateReference(mandate_map))
} else {
None
};
Ok(Self {
merchant_id,
customer_id: Some(record.customer_id.clone()),
card: Some(MigrateCardDetail {
card_number: record
.raw_card_number
.clone()
.unwrap_or_else(|| record.card_number_masked.clone()),
card_exp_month: record.card_expiry_month.clone(),
card_exp_year: record.card_expiry_year.clone(),
card_holder_name: record.name.clone(),
card_network: None,
card_type: None,
card_issuer: None,
card_issuing_country: None,
nick_name: record.nick_name.clone(),
}),
network_token: Some(MigrateNetworkTokenDetail {
network_token_data: MigrateNetworkTokenData {
network_token_number: record.network_token_number.clone().unwrap_or_default(),
network_token_exp_month: record
.network_token_expiry_month
.clone()
.unwrap_or_default(),
network_token_exp_year: record
.network_token_expiry_year
.clone()
.unwrap_or_default(),
card_holder_name: record.name.clone(),
nick_name: record.nick_name.clone(),
card_issuing_country: None,
card_network: None,
card_issuer: None,
card_type: None,
},
network_token_requestor_ref_id: record
.network_token_requestor_ref_id
.clone()
.unwrap_or_default(),
}),
payment_method: record.payment_method,
payment_method_type: record.payment_method_type,
payment_method_issuer: None,
billing,
connector_mandate_details: connector_mandate_details.map(
|payments_mandate_reference| {
CommonMandateReference::from(payments_mandate_reference)
},
),
metadata: None,
payment_method_issuer_code: None,
card_network: None,
#[cfg(feature = "payouts")]
bank_transfer: None,
#[cfg(feature = "payouts")]
wallet: None,
payment_method_data: None,
network_transaction_id: record.original_transaction_id.clone(),
})
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2717,
"total_crates": null
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.