text
stringlengths
70
351k
source
stringclasses
4 values
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/admin.rs | crate: router use actix_web::{web, HttpRequest, HttpResponse}; use router_env::{instrument, tracing, Flow}; use super::app::AppState; use crate::{ core::{admin::*, api_locking}, services::{api, authentication as auth, authorization::permissions::Permission}, types::api::admin, }; pub async fn connector_create( state: web::Data<AppState>, req: HttpRequest, path: web::Path<common_utils::id_type::MerchantId>, json_payload: web::Json<admin::MerchantConnectorCreate>, ) -> HttpResponse { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/admin.rs | crate: router use actix_web::{web, HttpRequest, HttpResponse}; use router_env::{instrument, tracing, Flow}; use super::app::AppState; use crate::{ core::{admin::*, api_locking}, services::{api, authentication as auth, authorization::permissions::Permission}, types::api::admin, }; pub async fn merchant_account_create( state: web::Data<AppState>, req: HttpRequest, json_payload: web::Json<api_models::admin::MerchantAccountCreateWithoutOrgId>, ) -> HttpResponse { { Ok(org_id) => org_id,<|fim_suffix|> <|fim_middle|> Err(e) => return api::log_and_return_error_response(e), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/admin.rs | crate: router use actix_web::{web, HttpRequest, HttpResponse}; use router_env::{instrument, tracing, Flow}; use super::app::AppState; use crate::{ core::{admin::*, api_locking}, services::{api, authentication as auth, authorization::permissions::Permission}, types::api::admin, }; pub async fn merchant_account_enable_platform_account( state: web::Data<AppState>, req: HttpRequest, path: web::Path<common_utils::id_type::MerchantId>, ) -> HttpResponse { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/admin.rs | crate: router use actix_web::{web, HttpRequest, HttpResponse}; use router_env::{instrument, tracing, Flow}; use super::app::AppState; use crate::{ core::{admin::*, api_locking}, services::{api, authentication as auth, authorization::permissions::Permission}, types::api::admin, }; pub async fn merchant_account_transfer_keys( state: web::Data<AppState>, req: HttpRequest, payload: web::Json<api_models::admin::MerchantKeyTransferRequest>, ) -> HttpResponse { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/admin.rs | crate: router use actix_web::{web, HttpRequest, HttpResponse}; use router_env::{instrument, tracing, Flow}; use super::app::AppState; use crate::{ core::{admin::*, api_locking}, services::{api, authentication as auth, authorization::permissions::Permission}, types::api::admin, }; pub async fn merchant_account_kv_status( state: web::Data<AppState>, req: HttpRequest, path: web::Path<common_utils::id_type::MerchantId>, ) -> HttpResponse { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/admin.rs | crate: router use actix_web::{web, HttpRequest, HttpResponse}; use router_env::{instrument, tracing, Flow}; use super::app::AppState; use crate::{ core::{admin::*, api_locking}, services::{api, authentication as auth, authorization::permissions::Permission}, types::api::admin, }; pub async fn merchant_account_toggle_all_kv( state: web::Data<AppState>, req: HttpRequest, json_payload: web::Json<admin::ToggleAllKVRequest>, ) -> HttpResponse { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/admin.rs | crate: router use actix_web::{web, HttpRequest, HttpResponse}; use router_env::{instrument, tracing, Flow}; use super::app::AppState; use crate::{ core::{admin::*, api_locking}, services::{api, authentication as auth, authorization::permissions::Permission}, types::api::admin, }; pub async fn merchant_account_toggle_kv( state: web::Data<AppState>, req: HttpRequest, path: web::Path<common_utils::id_type::MerchantId>, json_payload: web::Json<admin::ToggleKVRequest>, ) -> HttpResponse { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/admin.rs | crate: router use actix_web::{web, HttpRequest, HttpResponse}; use router_env::{instrument, tracing, Flow}; use super::app::AppState; use crate::{ core::{admin::*, api_locking}, services::{api, authentication as auth, authorization::permissions::Permission}, types::api::admin, }; pub async fn delete_merchant_account( state: web::Data<AppState>, req: HttpRequest, mid: web::Path<common_utils::id_type::MerchantId>, ) -> HttpResponse { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/admin.rs | crate: router use actix_web::{web, HttpRequest, HttpResponse}; use router_env::{instrument, tracing, Flow}; use super::app::AppState; use crate::{ core::{admin::*, api_locking}, services::{api, authentication as auth, authorization::permissions::Permission}, types::api::admin, }; pub async fn merchant_account_list( state: web::Data<AppState>, req: HttpRequest, query_params: web::Query<api_models::admin::MerchantAccountListRequest>, ) -> HttpResponse { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/admin.rs | crate: router use actix_web::{web, HttpRequest, HttpResponse}; use router_env::{instrument, tracing, Flow}; use super::app::AppState; use crate::{ core::{admin::*, api_locking}, services::{api, authentication as auth, authorization::permissions::Permission}, types::api::admin, }; pub async fn merchant_account_create( state: web::Data<AppState>, req: HttpRequest, json_payload: web::Json<admin::MerchantAccountCreate>, ) -> HttpResponse { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/admin.rs | crate: router use actix_web::{web, HttpRequest, HttpResponse}; use router_env::{instrument, tracing, Flow}; use super::app::AppState; use crate::{ core::{admin::*, api_locking}, services::{api, authentication as auth, authorization::permissions::Permission}, types::api::admin, }; pub async fn organization_create( state: web::Data<AppState>, req: HttpRequest, json_payload: web::Json<admin::OrganizationCreateRequest>, ) -> HttpResponse { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/pm_auth.rs | crate: router use actix_web::{web, HttpRequest, Responder}; use api_models as api_types; use router_env::{instrument, tracing, types::Flow}; use crate::{ core::api_locking, routes::AppState, services::api, types::transformers::ForeignTryFrom, }; pub async fn exchange_token( state: web::Data<AppState>, req: HttpRequest, json_payload: web::Json<api_types::pm_auth::ExchangeTokenCreateRequest>, ) -> impl Responder { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/pm_auth.rs | crate: router use actix_web::{web, HttpRequest, Responder}; use api_models as api_types; use router_env::{instrument, tracing, types::Flow}; use crate::{ core::api_locking, routes::AppState, services::api, types::transformers::ForeignTryFrom, }; pub async fn link_token_create( state: web::Data<AppState>, req: HttpRequest, json_payload: web::Json<api_types::pm_auth::LinkTokenCreateRequest>, ) -> impl Responder { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/pm_auth.rs | crate: router use actix_web::{web, HttpRequest, Responder}; use api_models as api_types; use router_env::{instrument, tracing, types::Flow}; use crate::{ core::api_locking, routes::AppState, services::api, types::transformers::ForeignTryFrom, }; pub async fn link_token_create( state: web::Data<AppState>, req: HttpRequest, json_payload: web::Json<api_types::pm_auth::LinkTokenCreateRequest>, ) -> impl Responder { { Ok(headers) => headers,<|fim_suffix|> <|fim_middle|> Err(err) => { return api::log_and_return_error_response(err); } } }
ast_fragments
// file: hyperswitch/crates/router/src/routes/dummy_connector/core.rs | crate: router use app::SessionState; use common_utils::generate_id_with_default_len; use super::{errors, types, utils}; use crate::{ routes::{app, dummy_connector::consts}, services::api, utils::OptionExt, }; pub async fn refund_payment( state: SessionState, req: types::DummyConnectorRefundRequest, ) -> types::DummyConnectorResponse<types::DummyConnectorRefundResponse> { utils::tokio_mock_sleep( state.conf.dummy_connector.refund_duration, state.conf.dummy_connector.refund_tolerance, ) .await; let payment_id = req .payment_id .get_required_value("payment_id") .change_context(errors::DummyConnectorErrors::MissingRequiredField { field_name: "payment_id", })?; let mut payment_data = utils::get_payment_data_from_payment_id(&state, payment_id.get_string_repr().to_owned()) .await?; payment_data.is_eligible_for_refund(req.amount)?; let refund_id = generate_id_with_default_len(consts::REFUND_ID_PREFIX); payment_data.eligible_amount -= req.amount; utils::store_data_in_redis( &state, payment_id.get_string_repr().to_owned(), payment_data.to_owned(), state.conf.dummy_connector.payment_ttl, ) .await?; let refund_data = types::DummyConnectorRefundResponse::new( types::DummyConnectorStatus::Succeeded, refund_id.to_owned(), payment_data.currency, common_utils::date_time::now(), payment_data.amount, req.amount, ); utils::store_data_in_redis( &state, refund_id, refund_data.to_owned(), state.conf.dummy_connector.refund_ttl, ) .await?; Ok(api::ApplicationResponse::Json(refund_data)) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/core.rs | crate: router use app::SessionState; use super::{errors, types, utils}; use crate::{ routes::{app, dummy_connector::consts}, services::api, utils::OptionExt, }; pub async fn payment_complete( state: SessionState, req: types::DummyConnectorPaymentCompleteRequest, ) -> types::DummyConnectorResponse<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/core.rs | crate: router use app::SessionState; use super::{errors, types, utils}; use crate::{ routes::{app, dummy_connector::consts}, services::api, utils::OptionExt, }; pub async fn payment_authorize( state: SessionState, req: types::DummyConnectorPaymentConfirmRequest, ) -> types::DummyConnectorResponse<String> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/core.rs | crate: router use app::SessionState; use super::{errors, types, utils}; use crate::{ routes::{app, dummy_connector::consts}, services::api, utils::OptionExt, }; pub async fn payment( state: SessionState, req: types::DummyConnectorPaymentRequest, ) -> types::DummyConnectorResponse<types::DummyConnectorPaymentResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/core.rs | crate: router use app::SessionState; use common_utils::generate_id_with_default_len; use super::{errors, types, utils}; use crate::{ routes::{app, dummy_connector::consts}, services::api, utils::OptionExt, }; pub async fn refund_payment( state: SessionState, req: types::DummyConnectorRefundRequest, ) -> types::DummyConnectorResponse<types::DummyConnectorRefundResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/core.rs | crate: router use app::SessionState; use super::{errors, types, utils}; use crate::{ routes::{app, dummy_connector::consts}, services::api, utils::OptionExt, }; pub async fn refund_data( state: SessionState, req: types::DummyConnectorRefundRetrieveRequest, ) -> types::DummyConnectorResponse<types::DummyConnectorRefundResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/core.rs | crate: router use app::SessionState; use super::{errors, types, utils}; use crate::{ routes::{app, dummy_connector::consts}, services::api, utils::OptionExt, }; pub async fn payment_data( state: SessionState, req: types::DummyConnectorPaymentRetrieveRequest, ) -> types::DummyConnectorResponse<types::DummyConnectorPaymentResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/types.rs | crate: router fn get_image_link(&self, base_url: &str) -> String { { Self::GooglePay => "GOOGLE_PAY.svg",<|fim_suffix|> <|fim_middle|> Self::AliPayHK => "ALIPAY.svg", } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/types.rs | crate: router fn get_name(&self) -> &'static str { { Self::GooglePay => "Google Pay",<|fim_suffix|> <|fim_middle|> Self::AliPayHK => "Alipay HK", } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/types.rs | crate: router use api_models::enums::Currency; use time::PrimitiveDateTime; pub type DummyConnectorResponse<T> = CustomResult<services::ApplicationResponse<T>, DummyConnectorErrors>; pub type DummyConnectorResult<T> = CustomResult<T, DummyConnectorErrors>; pub fn new( status: DummyConnectorStatus, id: String, currency: Currency, created: PrimitiveDateTime, payment_amount: i64, refund_amount: i64, ) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/types.rs | crate: router fn from(value: DummyConnectorPaymentData) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/types.rs | crate: router use error_stack::report; use super::{consts, errors::DummyConnectorErrors}; pub type DummyConnectorResponse<T> = CustomResult<services::ApplicationResponse<T>, DummyConnectorErrors>; pub type DummyConnectorResult<T> = CustomResult<T, DummyConnectorErrors>; pub fn is_eligible_for_refund(&self, refund_amount: i64) -> DummyConnectorResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/types.rs | crate: router fn get_image_link(&self, base_url: &str) -> String { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/types.rs | crate: router fn get_name(&self) -> &'static str { { Self::Klarna => "Klarna",<|fim_suffix|> <|fim_middle|> Self::AfterPayClearPay => "Afterpay Clearpay", } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/types.rs | crate: router fn get_name(&self) -> &'static str { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/types.rs | crate: router fn get_name(&self) -> &'static str { { Self::Card => "3D Secure",<|fim_suffix|> <|fim_middle|> Self::PayLater(pay_later) => pay_later.get_name(), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/types.rs | crate: router fn from(value: DummyConnectorPaymentMethodData) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/types.rs | crate: router pub type DummyConnectorResponse<T> = CustomResult<services::ApplicationResponse<T>, DummyConnectorErrors>; pub type DummyConnectorResult<T> = CustomResult<T, DummyConnectorErrors>; pub fn build_payment_data( self, status: DummyConnectorStatus, next_action: Option<DummyConnectorNextAction>, return_url: Option<String>, ) -> DummyConnectorPaymentData { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/types.rs | crate: router use common_utils::{errors::CustomResult, generate_id_with_default_len}; use super::{consts, errors::DummyConnectorErrors}; fn from(payment_request: DummyConnectorPaymentRequest) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/types.rs | crate: router pub type DummyConnectorResponse<T> = CustomResult<services::ApplicationResponse<T>, DummyConnectorErrors>; pub type DummyConnectorResult<T> = CustomResult<T, DummyConnectorErrors>; pub fn get_connector_image_link(self, base_url: &str) -> String { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/dummy_connector/errors.rs | crate: router fn switch(&self) -> api_models::errors::types::ApiErrorResponse { { Self::InternalServerError => { AER::InternalServerError(ApiError::new("DC", 0, self.error_message(), None)) }<|fim_suffix|> <|fim_middle|> Self::PaymentDeclined { message: _ } => { AER::BadRequest(ApiError::new("DC", 8, self.error_message(), None)) } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/disputes/utils.rs | crate: router use actix_multipart::{Field, Multipart}; use actix_web::web::Bytes; use common_utils::{errors::CustomResult, ext_traits::StringExt, fp_utils}; use crate::{ core::{errors, files::helpers}, types::api::{disputes, files}, utils::OptionExt, }; pub async fn get_attach_evidence_request( mut payload: Multipart, ) -> CustomResult<disputes::AttachEvidenceRequest, errors::ApiErrorResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/disputes/utils.rs | crate: router use actix_multipart::{Field, Multipart}; use actix_web::web::Bytes; use common_utils::{errors::CustomResult, ext_traits::StringExt, fp_utils}; use crate::{ core::{errors, files::helpers}, types::api::{disputes, files}, utils::OptionExt, }; pub async fn get_attach_evidence_request( mut payload: Multipart, ) -> CustomResult<disputes::AttachEvidenceRequest, errors::ApiErrorResponse> { { Some("file") => { file_name = content_disposition.get_filename().map(String::from); //Collect the file content and throw error if something fails let mut file_data = Vec::new(); let mut stream = field.into_stream(); while let Some(chunk) = stream.next().await { match chunk { Ok(bytes) => file_data.push(bytes), Err(err) => Err(errors::ApiErrorResponse::InternalServerError) .attach_printable_lazy(|| format!("File parsing error: {err}"))?, } } file_content = Some(file_data) }<|fim_suffix|> <|fim_middle|> _ => (), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/disputes/utils.rs | crate: router use actix_multipart::{Field, Multipart}; use common_utils::{errors::CustomResult, ext_traits::StringExt, fp_utils}; use crate::{ core::{errors, files::helpers}, types::api::{disputes, files}, utils::OptionExt, }; pub async fn parse_evidence_type( field: &mut Field, ) -> CustomResult<Option<disputes::EvidenceType>, errors::ApiErrorResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/files/transformers.rs | crate: router use actix_multipart::Multipart; use actix_web::web::Bytes; use common_utils::errors::CustomResult; use crate::{ core::{errors, files::helpers}, types::api::files::{self, CreateFileRequest}, utils::OptionExt, }; pub async fn get_create_file_request( mut payload: Multipart, ) -> CustomResult<CreateFileRequest, errors::ApiErrorResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/routes/files/transformers.rs | crate: router use actix_multipart::Multipart; use actix_web::web::Bytes; use common_utils::errors::CustomResult; use crate::{ core::{errors, files::helpers}, types::api::files::{self, CreateFileRequest}, utils::OptionExt, }; pub async fn get_create_file_request( mut payload: Multipart, ) -> CustomResult<CreateFileRequest, errors::ApiErrorResponse> { { Some(valid_file_content) => valid_file_content.concat().to_vec(),<|fim_suffix|> <|fim_middle|> None => Err(errors::ApiErrorResponse::MissingFile) .attach_printable("Missing / Invalid file in the request")?, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/consts/opensearch.rs | crate: router use api_models::analytics::search::SearchIndex; pub const fn get_search_indexes() -> [SearchIndex; 8] { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/consts/opensearch.rs | crate: router use api_models::analytics::search::SearchIndex; pub const fn get_search_indexes() -> [SearchIndex; 8] { [ SearchIndex::PaymentAttempts, SearchIndex::PaymentIntents, SearchIndex::Refunds, SearchIndex::Disputes, SearchIndex::SessionizerPaymentAttempts, SearchIndex::SessionizerPaymentIntents, SearchIndex::SessionizerRefunds, SearchIndex::SessionizerDisputes, ] }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/openidconnect.rs | crate: router use oidc::TokenResponse; use openidconnect::{self as oidc, core as oidc_core}; use storage_impl::errors::ApiClientError; use crate::{ consts, core::errors::{UserErrors, UserResult}, routes::SessionState, services::api::client, types::domain::user::UserEmail, }; async fn get_oidc_reqwest_client( state: &SessionState, request: oidc::HttpRequest, ) -> Result<oidc::HttpResponse, ApiClientError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/openidconnect.rs | crate: router use masking::{ExposeInterface, Secret}; use oidc::TokenResponse; use openidconnect::{self as oidc, core as oidc_core}; use crate::{ consts, core::errors::{UserErrors, UserResult}, routes::SessionState, services::api::client, types::domain::user::UserEmail, }; pub async fn get_user_email_from_oidc_provider( state: &SessionState, redirect_url: String, redirect_state: Secret<String>, base_url: Secret<String>, client_id: Secret<String>, authorization_code: Secret<String>, client_secret: Secret<String>, ) -> UserResult<UserEmail> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/openidconnect.rs | crate: router use masking::{ExposeInterface, Secret}; use oidc::TokenResponse; use openidconnect::{self as oidc, core as oidc_core}; use crate::{ consts, core::errors::{UserErrors, UserResult}, routes::SessionState, services::api::client, types::domain::user::UserEmail, }; pub async fn get_authorization_url( state: SessionState, redirect_url: String, redirect_state: Secret<String>, base_url: Secret<String>, client_id: Secret<String>, ) -> UserResult<url::Url> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/openidconnect.rs | crate: router use masking::{ExposeInterface, Secret}; use oidc::TokenResponse; use openidconnect::{self as oidc, core as oidc_core}; use crate::{ consts, core::errors::{UserErrors, UserResult}, routes::SessionState, services::api::client, types::domain::user::UserEmail, }; async fn get_nonce_from_redis( state: &SessionState, redirect_state: &Secret<String>, ) -> UserResult<oidc::Nonce> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/openidconnect.rs | crate: router use redis_interface::RedisConnectionPool; use crate::{ consts, core::errors::{UserErrors, UserResult}, routes::SessionState, services::api::client, types::domain::user::UserEmail, }; fn get_redis_connection(state: &SessionState) -> UserResult<std::sync::Arc<RedisConnectionPool>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/openidconnect.rs | crate: router use crate::{ consts, core::errors::{UserErrors, UserResult}, routes::SessionState, services::api::client, types::domain::user::UserEmail, }; fn get_oidc_redis_key(csrf: &str) -> String { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/services/openidconnect.rs | crate: router use masking::{ExposeInterface, Secret}; use oidc::TokenResponse; use openidconnect::{self as oidc, core as oidc_core}; use crate::{ consts, core::errors::{UserErrors, UserResult}, routes::SessionState, services::api::client, types::domain::user::UserEmail, }; async fn get_nonce_from_redis( state: &SessionState, redirect_state: &Secret<String>, ) -> UserResult<oidc::Nonce> { let redis_connection = get_redis_connection(state)?; let redirect_state = redirect_state.clone().expose(); let key = get_oidc_redis_key(&redirect_state); redis_connection .get_key::<Option<String>>(&key.into()) .await .change_context(UserErrors::InternalServerError) .attach_printable("Error Fetching CSRF from redis")? .map(oidc::Nonce::new) .ok_or(UserErrors::SSOFailed) .attach_printable("Cannot find csrf in redis. Csrf invalid or expired") }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/openidconnect.rs | crate: router use masking::{ExposeInterface, Secret}; use oidc::TokenResponse; use openidconnect::{self as oidc, core as oidc_core}; use crate::{ consts, core::errors::{UserErrors, UserResult}, routes::SessionState, services::api::client, types::domain::user::UserEmail, }; fn get_oidc_core_client( discovery_document: oidc_core::CoreProviderMetadata, client_id: Secret<String>, client_secret: Option<Secret<String>>, redirect_url: String, ) -> UserResult<oidc_core::CoreClient> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/openidconnect.rs | crate: router use masking::{ExposeInterface, Secret}; use oidc::TokenResponse; use openidconnect::{self as oidc, core as oidc_core}; use crate::{ consts, core::errors::{UserErrors, UserResult}, routes::SessionState, services::api::client, types::domain::user::UserEmail, }; async fn get_discovery_document( base_url: Secret<String>, state: &SessionState, ) -> UserResult<oidc_core::CoreProviderMetadata> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/encryption.rs | crate: router use std::str; use error_stack::{report, ResultExt}; use josekit::{jwe, jws}; use crate::{ core::errors::{self, CustomResult}, utils, }; pub async fn decrypt_jwe( jwt: &str, key_ids: KeyIdCheck<'_>, private_key: impl AsRef<[u8]>, alg: jwe::alg::rsaes::RsaesJweAlgorithm, ) -> CustomResult<String, errors::EncryptionError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/encryption.rs | crate: router use std::str; use josekit::{jwe, jws}; use crate::{ core::errors::{self, CustomResult}, utils, }; pub async fn encrypt_jwe( payload: &[u8], public_key: impl AsRef<[u8]>, algorithm: EncryptionAlgorithm, key_id: Option<&str>, ) -> CustomResult<String, errors::EncryptionError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/encryption.rs | crate: router use josekit::{jwe, jws}; async fn test_jws() { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/encryption.rs | crate: router use josekit::{jwe, jws}; async fn test_jwe() { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/encryption.rs | crate: router use josekit::{jwe, jws}; use crate::{ core::errors::{self, CustomResult}, utils, }; pub fn verify_sign( jws_body: String, key: impl AsRef<[u8]>, ) -> CustomResult<String, errors::EncryptionError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/encryption.rs | crate: router use std::str; use josekit::{jwe, jws}; use crate::{ core::errors::{self, CustomResult}, utils, }; pub async fn jws_sign_payload( payload: &[u8], kid: &str, private_key: impl AsRef<[u8]>, ) -> CustomResult<String, errors::EncryptionError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/services/encryption.rs | crate: router use std::str; use josekit::{jwe, jws}; use crate::{ core::errors::{self, CustomResult}, utils, }; pub async fn encrypt_jwe( payload: &[u8], public_key: impl AsRef<[u8]>, algorithm: EncryptionAlgorithm, key_id: Option<&str>, ) -> CustomResult<String, errors::EncryptionError> { let alg = jwe::RSA_OAEP_256; let mut src_header = jwe::JweHeader::new(); let enc_str = algorithm.as_ref(); src_header.set_content_encryption(enc_str); src_header.set_token_type("JWT"); if let Some(key_id) = key_id { src_header.set_key_id(key_id); } let encrypter = alg .encrypter_from_pem(public_key) .change_context(errors::EncryptionError) .attach_printable("Error getting JweEncryptor")?; jwe::serialize_compact(payload, &src_header, &encrypter) .change_context(errors::EncryptionError) .attach_printable("Error getting jwt string") }
ast_fragments
// file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use std::{collections::HashMap, sync::Arc}; use error_stack::{report, ResultExt}; use events::{EventsError, Message, MessagingInterface}; use rdkafka::{ config::FromClientConfig, message::{Header, OwnedHeaders}, producer::{BaseRecord, DefaultProducerContext, Producer, ThreadedProducer}, }; use serde_json::Value; use crate::{events::EventType, services::kafka::fraud_check_event::KafkaFraudCheckEvent}; use time::{OffsetDateTime, PrimitiveDateTime}; use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; use crate::{services::kafka::fraud_check::KafkaFraudCheck, types::storage::Dispute}; pub type MQResult<T> = CustomResult<T, KafkaError>; fn send_message<T>( &self, data: T, metadata: HashMap<String, String>, timestamp: PrimitiveDateTime, ) -> error_stack::Result<(), EventsError> where T: Message<Class = Self::MessageClass> + masking::ErasedMaskSerialize, { let topic = self.get_topic(data.get_message_class()); let json_data = data .masked_serialize() .and_then(|mut value| { if let Value::Object(ref mut map) = value { if let Some(db_name) = self.ckh_database_name.clone() { map.insert("clickhouse_database".to_string(), Value::String(db_name)); } } serde_json::to_vec(&value) }) .change_context(EventsError::SerializationError)?; let mut headers = OwnedHeaders::new(); for (k, v) in metadata.iter() { headers = headers.insert(Header { key: k.as_str(), value: Some(v), }); } headers = headers.insert(Header { key: "clickhouse_database", value: self.ckh_database_name.as_ref(), }); self.producer .0 .send( BaseRecord::to(topic) .key(&data.identifier()) .payload(&json_data) .headers(headers) .timestamp( (timestamp.assume_utc().unix_timestamp_nanos() / 1_000_000) .to_i64() .unwrap_or_else(|| { // kafka producer accepts milliseconds // try converting nanos to millis if that fails convert seconds to millis timestamp.assume_utc().unix_timestamp() * 1_000 }), ), ) .map_err(|(error, record)| report!(error).attach_printable(format!("{record:?}"))) .change_context(KafkaError::GenericError) .change_context(EventsError::PublishError) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; use crate::{services::kafka::fraud_check::KafkaFraudCheck, types::storage::Dispute}; pub type MQResult<T> = CustomResult<T, KafkaError>; use crate::db::kafka_store::TenantID; pub async fn log_dispute( &self, dispute: &Dispute, old_dispute: Option<Dispute>, tenant_id: TenantID, ) -> MQResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use diesel_models::{authentication::Authentication, refund::Refund}; use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; pub type MQResult<T> = CustomResult<T, KafkaError>; use crate::db::kafka_store::TenantID; pub async fn log_refund( &self, refund: &Refund, old_refund: Option<Refund>, tenant_id: TenantID, ) -> MQResult<()> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use hyperswitch_domain_models::payments::{payment_attempt::PaymentAttempt, PaymentIntent}; use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; pub type MQResult<T> = CustomResult<T, KafkaError>; use crate::db::kafka_store::TenantID; pub async fn log_payment_intent( &self, intent: &PaymentIntent, old_intent: Option<PaymentIntent>, tenant_id: TenantID, ) -> MQResult<()> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use diesel_models::{authentication::Authentication, refund::Refund}; use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; pub type MQResult<T> = CustomResult<T, KafkaError>; use crate::db::kafka_store::TenantID; pub async fn log_authentication( &self, authentication: &Authentication, old_authentication: Option<Authentication>, tenant_id: TenantID, ) -> MQResult<()> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use hyperswitch_domain_models::payments::{payment_attempt::PaymentAttempt, PaymentIntent}; use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; pub type MQResult<T> = CustomResult<T, KafkaError>; use crate::db::kafka_store::TenantID; pub async fn log_payment_attempt( &self, attempt: &PaymentAttempt, old_attempt: Option<PaymentAttempt>, tenant_id: TenantID, ) -> MQResult<()> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use diesel_models::fraud_check::FraudCheck; use crate::{events::EventType, services::kafka::fraud_check_event::KafkaFraudCheckEvent}; use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; use crate::{services::kafka::fraud_check::KafkaFraudCheck, types::storage::Dispute}; pub type MQResult<T> = CustomResult<T, KafkaError>; use crate::db::kafka_store::TenantID; pub async fn log_fraud_check( &self, attempt: &FraudCheck, old_attempt: Option<FraudCheck>, tenant_id: TenantID, ) -> MQResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router match self.0.flush(rdkafka::util::Timeout::After( std::time::Duration::from_secs(5), )) { Ok(_) => router_env::logger::info!("Kafka events flush Successful"), Err(error) => router_env::logger::error!("Failed to flush Kafka Events {error:?}"), } } } impl MessagingInterface for KafkaProducer { type MessageClass = EventType; fn send_message<T>( &self, data: T, metadata: HashMap<String, String>, timestamp: PrimitiveDateTime, ) -> error_stack::Result<(), EventsError> where T: Message<Class = Self::MessageClass> + masking::ErasedMaskSerialize, { let topic = self.get_topic(data.get_message_class()); let json_data = data .masked_serialize() .and_then(|mut value| { fn send_message<T>( &self, data: T, metadata: HashMap<String, String>, timestamp: PrimitiveDateTime, ) -> error_stack::Result<(), EventsError> where T: Message<Class = Self::MessageClass> + masking::ErasedMaskSerialize, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use diesel_models::fraud_check::FraudCheck; use crate::{events::EventType, services::kafka::fraud_check_event::KafkaFraudCheckEvent}; use diesel_models::{authentication::Authentication, refund::Refund}; use hyperswitch_domain_models::payments::{payment_attempt::PaymentAttempt, PaymentIntent}; use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; use crate::{services::kafka::fraud_check::KafkaFraudCheck, types::storage::Dispute}; pub type MQResult<T> = CustomResult<T, KafkaError>; pub fn get_topic(&self, event: EventType) -> &str { { EventType::FraudCheck => &self.fraud_check_analytics_topic,<|fim_suffix|> <|fim_middle|> EventType::Authentication => &self.authentication_analytics_topic, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use diesel_models::fraud_check::FraudCheck; use crate::{events::EventType, services::kafka::fraud_check_event::KafkaFraudCheckEvent}; use diesel_models::{authentication::Authentication, refund::Refund}; use hyperswitch_domain_models::payments::{payment_attempt::PaymentAttempt, PaymentIntent}; use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; use crate::{services::kafka::fraud_check::KafkaFraudCheck, types::storage::Dispute}; pub type MQResult<T> = CustomResult<T, KafkaError>; pub fn get_topic(&self, event: EventType) -> &str { { EventType::FraudCheck => &self.fraud_check_analytics_topic, EventType::ApiLogs => &self.api_logs_topic, EventType::PaymentAttempt => &self.attempt_analytics_topic,<|fim_suffix|> <|fim_middle|> #[cfg(feature = "payouts")] EventType::Payout => &self.payout_analytics_topic, EventType::Consolidated => &self.consolidated_events_topic, EventType::Authentication => &self.authentication_analytics_topic, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; pub type MQResult<T> = CustomResult<T, KafkaError>; use crate::db::kafka_store::TenantID; pub async fn log_payout_delete( &self, delete_old_payout: &KafkaPayout<'_>, tenant_id: TenantID, ) -> MQResult<()> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; pub type MQResult<T> = CustomResult<T, KafkaError>; use crate::db::kafka_store::TenantID; pub async fn log_payout( &self, payout: &KafkaPayout<'_>, old_payout: Option<KafkaPayout<'_>>, tenant_id: TenantID, ) -> MQResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; use crate::{services::kafka::fraud_check::KafkaFraudCheck, types::storage::Dispute}; pub type MQResult<T> = CustomResult<T, KafkaError>; use crate::db::kafka_store::TenantID; pub async fn log_dispute_delete( &self, delete_old_dispute: &Dispute, tenant_id: TenantID, ) -> MQResult<()> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use diesel_models::{authentication::Authentication, refund::Refund}; use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; pub type MQResult<T> = CustomResult<T, KafkaError>; use crate::db::kafka_store::TenantID; pub async fn log_refund_delete( &self, delete_old_refund: &Refund, tenant_id: TenantID, ) -> MQResult<()> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use hyperswitch_domain_models::payments::{payment_attempt::PaymentAttempt, PaymentIntent}; use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; pub type MQResult<T> = CustomResult<T, KafkaError>; use crate::db::kafka_store::TenantID; pub async fn log_payment_intent_delete( &self, delete_old_intent: &PaymentIntent, tenant_id: TenantID, ) -> MQResult<()> { self.log_event(&KafkaEvent::old( &KafkaPaymentIntent::from_storage(delete_old_intent), tenant_id.clone(), self.ckh_database_name.clone(), )) .attach_printable_lazy(|| { format!("Failed to add negative intent event {delete_old_intent:?}") }) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use hyperswitch_domain_models::payments::{payment_attempt::PaymentAttempt, PaymentIntent}; use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; pub type MQResult<T> = CustomResult<T, KafkaError>; use crate::db::kafka_store::TenantID; pub async fn log_payment_attempt_delete( &self, delete_old_attempt: &PaymentAttempt, tenant_id: TenantID, ) -> MQResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use error_stack::{report, ResultExt}; use rdkafka::{ config::FromClientConfig, message::{Header, OwnedHeaders}, producer::{BaseRecord, DefaultProducerContext, Producer, ThreadedProducer}, }; use crate::{events::EventType, services::kafka::fraud_check_event::KafkaFraudCheckEvent}; use time::{OffsetDateTime, PrimitiveDateTime}; use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; use crate::{services::kafka::fraud_check::KafkaFraudCheck, types::storage::Dispute}; pub type MQResult<T> = CustomResult<T, KafkaError>; pub fn log_event<T: KafkaMessage>(&self, event: &T) -> MQResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use std::{collections::HashMap, sync::Arc}; use rdkafka::{ config::FromClientConfig, message::{Header, OwnedHeaders}, producer::{BaseRecord, DefaultProducerContext, Producer, ThreadedProducer}, }; pub type MQResult<T> = CustomResult<T, KafkaError>; pub async fn create(conf: &KafkaSettings) -> MQResult<Self> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use storage_impl::config::TenantConfig; use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; pub type MQResult<T> = CustomResult<T, KafkaError>; pub fn set_tenancy(&mut self, tenant_config: &dyn TenantConfig) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use crate::{events::EventType, services::kafka::fraud_check_event::KafkaFraudCheckEvent}; use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; fn event_type(&self) -> EventType { EventType::Consolidated }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router pub type MQResult<T> = CustomResult<T, KafkaError>; use crate::db::kafka_store::TenantID; fn new(event: &'a T, tenant_id: TenantID) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; fn creation_timestamp(&self) -> Option<i64> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use crate::{events::EventType, services::kafka::fraud_check_event::KafkaFraudCheckEvent}; use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; fn event_type(&self) -> EventType { self.event.event_type() }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router pub type MQResult<T> = CustomResult<T, KafkaError>; use crate::db::kafka_store::TenantID; fn old(event: &'a T, tenant_id: TenantID, clickhouse_database: Option<String>) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router pub type MQResult<T> = CustomResult<T, KafkaError>; use crate::db::kafka_store::TenantID; fn new(event: &'a T, tenant_id: TenantID, clickhouse_database: Option<String>) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use serde_json::Value; use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; pub type MQResult<T> = CustomResult<T, KafkaError>; fn value(&self) -> MQResult<Vec<u8>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/kafka.rs | crate: router use std::{collections::HashMap, sync::Arc}; use common_utils::errors::CustomResult; use error_stack::{report, ResultExt}; use events::{EventsError, Message, MessagingInterface}; use num_traits::ToPrimitive; use rdkafka::{ config::FromClientConfig, message::{Header, OwnedHeaders}, producer::{BaseRecord, DefaultProducerContext, Producer, ThreadedProducer}, }; use serde_json::Value; use storage_impl::config::TenantConfig; use diesel_models::fraud_check::FraudCheck; use crate::{events::EventType, services::kafka::fraud_check_event::KafkaFraudCheckEvent}; use diesel_models::{authentication::Authentication, refund::Refund}; use hyperswitch_domain_models::payments::{payment_attempt::PaymentAttempt, PaymentIntent}; use serde::Serialize; use time::{OffsetDateTime, PrimitiveDateTime}; use self::payout::KafkaPayout; use self::{ authentication::KafkaAuthentication, authentication_event::KafkaAuthenticationEvent, dispute::KafkaDispute, dispute_event::KafkaDisputeEvent, payment_attempt::KafkaPaymentAttempt, payment_attempt_event::KafkaPaymentAttemptEvent, payment_intent::KafkaPaymentIntent, payment_intent_event::KafkaPaymentIntentEvent, refund::KafkaRefund, refund_event::KafkaRefundEvent, }; use crate::{services::kafka::fraud_check::KafkaFraudCheck, types::storage::Dispute}; pub type MQResult<T> = CustomResult<T, KafkaError>; use crate::db::kafka_store::TenantID; pub fn validate(&self) -> Result<(), crate::core::errors::ApplicationError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use std::str::FromStr; use common_utils::{date_time, fp_utils, id_type}; use router_env::logger; use super::authorization::{self, permissions::Permission}; use super::jwt; use crate::configs::Settings; use crate::consts; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub async fn new_token( user_id: String, merchant_id: id_type::MerchantId, settings: &Settings, org_id: id_type::OrganizationId, profile_id: id_type::ProfileId, tenant_id: Option<id_type::TenantId>, role_info: authorization::roles::RoleInfo, ) -> UserResult<String> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; async fn authenticate_and_fetch( &self, request_headers: &HeaderMap, state: &A, ) -> RouterResult<(UserFromTokenWithRoleInfo, AuthenticationType)> { let payload = parse_jwt_payload::<A, AuthToken>(request_headers, state).await?; if payload.check_in_blacklist(state).await? { return Err(errors::ApiErrorResponse::InvalidJwtToken.into()); } authorization::check_tenant( payload.tenant_id.clone(), &state.session_state().tenant.tenant_id, )?; let role_info = authorization::get_role_info(state, &payload).await?; authorization::check_permission(self.permission, &role_info)?; let user = UserFromToken { user_id: payload.user_id.clone(), merchant_id: payload.merchant_id.clone(), org_id: payload.org_id, role_id: payload.role_id, profile_id: payload.profile_id, tenant_id: payload.tenant_id, }; Ok(( UserFromTokenWithRoleInfo { user, role_info }, AuthenticationType::MerchantJwt { merchant_id: payload.merchant_id, user_id: Some(payload.user_id), }, )) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use common_utils::{date_time, fp_utils, id_type}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; async fn get_connected_merchant_account<A>( state: &A, connected_merchant_id: id_type::MerchantId, platform_org_id: id_type::OrganizationId, ) -> RouterResult<domain::MerchantAccount> where A: SessionStateInfo + Sync, { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; async fn authenticate_and_fetch( &self, request_headers: &HeaderMap, state: &A, ) -> RouterResult<(AuthenticationDataWithUser, AuthenticationType)> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub async fn get_ephemeral_or_other_auth<T>( headers: &HeaderMap, is_merchant_flow: bool, payload: Option<&impl ClientSecretFetch>, ) -> RouterResult<( Box<dyn AuthenticateAndFetch<AuthenticationData, T>>, api::AuthFlow, bool, )> where T: SessionStateInfo + Sync + Send, ApiKeyAuth: AuthenticateAndFetch<AuthenticationData, T>, PublishableKeyAuth: AuthenticateAndFetch<AuthenticationData, T>, EphemeralKeyAuth: AuthenticateAndFetch<AuthenticationData, T>, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub fn check_client_secret_and_get_auth<T>( headers: &HeaderMap, payload: &impl ClientSecretFetch, ) -> RouterResult<( Box<dyn AuthenticateAndFetch<AuthenticationData, T>>, api::AuthFlow, )> where T: SessionStateInfo + Sync + Send, ApiKeyAuth: AuthenticateAndFetch<AuthenticationData, T>, PublishableKeyAuth: AuthenticateAndFetch<AuthenticationData, T>, { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); async fn authenticate_and_fetch( &self, request_headers: &HeaderMap, state: &A, ) -> RouterResult<(AuthenticationData, AuthenticationType)> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; async fn authenticate_and_fetch( &self, request_headers: &HeaderMap, state: &A, ) -> RouterResult<(UserFromToken, AuthenticationType)> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); async fn authenticate_and_fetch( &self, request_headers: &HeaderMap, state: &A, ) -> RouterResult<(AuthenticationDataWithUserId, AuthenticationType)> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use router_env::logger; use serde::Serialize; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub async fn parse_jwt_payload<A, T>(headers: &HeaderMap, state: &A) -> RouterResult<T> where T: serde::de::DeserializeOwned, A: SessionStateInfo + Sync, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use common_utils::{date_time, fp_utils, id_type}; use error_stack::{report, ResultExt}; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; async fn authenticate_and_fetch( &self, request_headers: &HeaderMap, state: &A, ) -> RouterResult<((), AuthenticationType)> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; async fn authenticate_and_fetch( &self, request_headers: &HeaderMap, state: &A, ) -> RouterResult<(AuthenticationDataWithMultipleProfiles, AuthenticationType)> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); async fn authenticate_and_fetch( &self, _request_headers: &HeaderMap, state: &A, ) -> RouterResult<(AuthenticationData, AuthenticationType)> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); async fn authenticate_and_fetch( &self, request_headers: &HeaderMap, state: &A, ) -> RouterResult<(AuthenticationData, AuthenticationType)> { if state.conf().platform.enabled { throw_error_if_platform_merchant_authentication_required(request_headers)?; } let key_manager_state = &(&state.session_state()).into(); let key_store = state .store() .get_merchant_key_store_by_merchant_id( key_manager_state, &self.merchant_id, &state.store().get_master_key().to_vec().into(), ) .await .to_not_found_response(errors::ApiErrorResponse::Unauthorized)?; let profile = state .store() .find_business_profile_by_merchant_id_profile_id( key_manager_state, &key_store, &self.merchant_id, &self.profile_id, ) .await .to_not_found_response(errors::ApiErrorResponse::Unauthorized)?; let merchant = state .store() .find_merchant_account_by_merchant_id(key_manager_state, &self.merchant_id, &key_store) .await .to_not_found_response(errors::ApiErrorResponse::Unauthorized)?; let auth = AuthenticationData { merchant_account: merchant, key_store, profile, platform_merchant_account: None, }; Ok(( auth.clone(), AuthenticationType::MerchantId { merchant_id: auth.merchant_account.get_id().clone(), }, )) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use common_utils::{date_time, fp_utils, id_type}; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; async fn authenticate_and_fetch( &self, request_headers: &HeaderMap, state: &A, ) -> RouterResult<(AuthenticationDataWithoutProfile, AuthenticationType)> { <|fim_suffix|> <|fim_middle|> }
ast_fragments