text
stringlengths
70
351k
source
stringclasses
4 values
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payments/flows/session_flow.rs | crate: router use api_models::{admin as admin_types, payments as payment_types}; use common_utils::{ ext_traits::ByteSliceExt, request::RequestContent, types::{AmountConvertor, StringMajorUnitForConnector}, }; use error_stack::{Report, ResultExt}; use hyperswitch_domain_models::payments::PaymentIntentData; use crate::{ consts::PROTOCOL, core::{ errors::{self, ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, PaymentData}, }, headers, logger, routes::{self, app::settings, metrics}, services, types::{ self, api::{self, enums}, domain, }, utils::OptionExt, }; async fn create_applepay_session_token( state: &routes::SessionState, router_data: &types::PaymentsSessionRouterData, connector: &api::ConnectorData, business_profile: &domain::Profile, header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<types::PaymentsSessionRouterData> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payments/flows/cancel_flow.rs | crate: router use crate::{ core::{ errors::{ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, PaymentData}, }, routes::{metrics, SessionState}, services, types::{self, api, domain}, }; async fn construct_router_data<'a>( &self, state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, customer: &Option<domain::Customer>, merchant_connector_account: &helpers::MerchantConnectorAccountType, merchant_recipient_data: Option<types::MerchantRecipientData>, header_payload: Option<hyperswitch_domain_models::payments::HeaderPayload>, ) -> RouterResult<types::PaymentsCancelRouterData> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payments/flows/cancel_flow.rs | crate: router use crate::{ core::{ errors::{ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, PaymentData}, }, routes::{metrics, SessionState}, services, types::{self, api, domain}, }; async fn build_flow_specific_connector_request( &mut self, state: &SessionState, connector: &api::ConnectorData, call_connector_action: payments::CallConnectorAction, ) -> RouterResult<(Option<services::Request>, bool)> { { payments::CallConnectorAction::Trigger => { let connector_integration: services::BoxedPaymentConnectorIntegrationInterface< api::Void, types::PaymentsCancelData, types::PaymentsResponseData, > = connector.connector.get_connector_integration(); connector_integration .build_request(self, &state.conf.connectors) .to_payment_failed_response()? }<|fim_suffix|> <|fim_middle|> _ => None, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payments/flows/cancel_flow.rs | crate: router use crate::{ core::{ errors::{ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, PaymentData}, }, routes::{metrics, SessionState}, services, types::{self, api, domain}, }; async fn construct_router_data<'a>( &self, _state: &SessionState, _connector_id: &str, _merchant_account: &domain::MerchantAccount, _key_store: &domain::MerchantKeyStore, _customer: &Option<domain::Customer>, _merchant_connector_account: &domain::MerchantConnectorAccount, _merchant_recipient_data: Option<types::MerchantRecipientData>, _header_payload: Option<hyperswitch_domain_models::payments::HeaderPayload>, ) -> RouterResult<types::PaymentsCancelRouterData> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payments/flows/reject_flow.rs | crate: router use crate::{ core::{ errors::{ApiErrorResponse, NotImplementedMessage, RouterResult}, payments::{self, access_token, helpers, transformers, PaymentData}, }, routes::SessionState, services, types::{self, api, domain}, }; async fn construct_router_data<'a>( &self, state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, customer: &Option<domain::Customer>, merchant_connector_account: &helpers::MerchantConnectorAccountType, merchant_recipient_data: Option<types::MerchantRecipientData>, header_payload: Option<hyperswitch_domain_models::payments::HeaderPayload>, ) -> RouterResult<types::PaymentsRejectRouterData> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payments/flows/reject_flow.rs | crate: router use crate::{ core::{ errors::{ApiErrorResponse, NotImplementedMessage, RouterResult}, payments::{self, access_token, helpers, transformers, PaymentData}, }, routes::SessionState, services, types::{self, api, domain}, }; async fn construct_router_data<'a>( &self, state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, customer: &Option<domain::Customer>, merchant_connector_account: &domain::MerchantConnectorAccount, merchant_recipient_data: Option<types::MerchantRecipientData>, header_payload: Option<hyperswitch_domain_models::payments::HeaderPayload>, ) -> RouterResult<types::PaymentsRejectRouterData> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/core/payments/flows/reject_flow.rs | crate: router use crate::{ core::{ errors::{ApiErrorResponse, NotImplementedMessage, RouterResult}, payments::{self, access_token, helpers, transformers, PaymentData}, }, routes::SessionState, services, types::{self, api, domain}, }; async fn construct_router_data<'a>( &self, state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, customer: &Option<domain::Customer>, merchant_connector_account: &domain::MerchantConnectorAccount, merchant_recipient_data: Option<types::MerchantRecipientData>, header_payload: Option<hyperswitch_domain_models::payments::HeaderPayload>, ) -> RouterResult<types::PaymentsRejectRouterData> { todo!() }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payments/flows/session_update_flow.rs | crate: router use crate::{ core::{ errors::{ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, Feature, PaymentData}, }, routes::SessionState, services, types::{self, api, domain}, }; async fn construct_router_data<'a>( &self, state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, customer: &Option<domain::Customer>, merchant_connector_account: &helpers::MerchantConnectorAccountType, _merchant_recipient_data: Option<types::MerchantRecipientData>, _header_payload: Option<hyperswitch_domain_models::payments::HeaderPayload>, ) -> RouterResult<types::SdkSessionUpdateRouterData> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payments/flows/session_update_flow.rs | crate: router use crate::{ core::{ errors::{ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, Feature, PaymentData}, }, routes::SessionState, services, types::{self, api, domain}, }; async fn build_flow_specific_connector_request( &mut self, state: &SessionState, connector: &api::ConnectorData, call_connector_action: payments::CallConnectorAction, ) -> RouterResult<(Option<services::Request>, bool)> { { payments::CallConnectorAction::Trigger => { let connector_integration: services::BoxedPaymentConnectorIntegrationInterface< api::SdkSessionUpdate, types::SdkPaymentsSessionUpdateData, types::PaymentsResponseData, > = connector.connector.get_connector_integration(); connector_integration .build_request(self, &state.conf.connectors) .to_payment_failed_response()? }<|fim_suffix|> <|fim_middle|> _ => None, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payments/flows/session_update_flow.rs | crate: router use crate::{ core::{ errors::{ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, Feature, PaymentData}, }, routes::SessionState, services, types::{self, api, domain}, }; async fn construct_router_data<'a>( &self, state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, customer: &Option<domain::Customer>, merchant_connector_account: &domain::MerchantConnectorAccount, _merchant_recipient_data: Option<types::MerchantRecipientData>, _header_payload: Option<hyperswitch_domain_models::payments::HeaderPayload>, ) -> RouterResult<types::SdkSessionUpdateRouterData> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payments/flows/post_session_tokens_flow.rs | crate: router use crate::{ core::{ errors::{ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, Feature, PaymentData}, }, routes::SessionState, services, types::{self, api, domain}, }; async fn construct_router_data<'a>( &self, state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, customer: &Option<domain::Customer>, merchant_connector_account: &helpers::MerchantConnectorAccountType, merchant_recipient_data: Option<types::MerchantRecipientData>, header_payload: Option<hyperswitch_domain_models::payments::HeaderPayload>, ) -> RouterResult<types::PaymentsPostSessionTokensRouterData> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payments/flows/post_session_tokens_flow.rs | crate: router use crate::{ core::{ errors::{ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, Feature, PaymentData}, }, routes::SessionState, services, types::{self, api, domain}, }; async fn build_flow_specific_connector_request( &mut self, state: &SessionState, connector: &api::ConnectorData, call_connector_action: payments::CallConnectorAction, ) -> RouterResult<(Option<services::Request>, bool)> { { payments::CallConnectorAction::Trigger => { let connector_integration: services::BoxedPaymentConnectorIntegrationInterface< api::PostSessionTokens, types::PaymentsPostSessionTokensData, types::PaymentsResponseData, > = connector.connector.get_connector_integration(); connector_integration .build_request(self, &state.conf.connectors) .to_payment_failed_response()? }<|fim_suffix|> <|fim_middle|> _ => None, } }
ast_fragments
// file: hyperswitch/crates/router/src/core/payments/flows/post_session_tokens_flow.rs | crate: router use crate::{ core::{ errors::{ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, Feature, PaymentData}, }, routes::SessionState, services, types::{self, api, domain}, }; async fn get_merchant_recipient_data<'a>( &self, _state: &SessionState, _merchant_account: &domain::MerchantAccount, _key_store: &domain::MerchantKeyStore, _merchant_connector_account: &helpers::MerchantConnectorAccountType, _connector: &api::ConnectorData, ) -> RouterResult<Option<types::MerchantRecipientData>> { Ok(None) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payments/flows/post_session_tokens_flow.rs | crate: router use crate::{ core::{ errors::{ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, Feature, PaymentData}, }, routes::SessionState, services, types::{self, api, domain}, }; async fn construct_router_data<'a>( &self, state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, customer: &Option<domain::Customer>, merchant_connector_account: &domain::MerchantConnectorAccount, merchant_recipient_data: Option<types::MerchantRecipientData>, header_payload: Option<hyperswitch_domain_models::payments::HeaderPayload>, ) -> RouterResult<types::PaymentsPostSessionTokensRouterData> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payments/flows/capture_flow.rs | crate: router use crate::{ core::{ errors::{ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, Feature, PaymentData}, }, routes::SessionState, services, types::{self, api, domain}, }; async fn construct_router_data<'a>( &self, state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, customer: &Option<domain::Customer>, merchant_connector_account: &domain::MerchantConnectorAccount, merchant_recipient_data: Option<types::MerchantRecipientData>, header_payload: Option<hyperswitch_domain_models::payments::HeaderPayload>, ) -> RouterResult< types::RouterData<api::Capture, types::PaymentsCaptureData, types::PaymentsResponseData>, > { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payments/flows/capture_flow.rs | crate: router use crate::{ core::{ errors::{ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, Feature, PaymentData}, }, routes::SessionState, services, types::{self, api, domain}, }; async fn construct_router_data<'a>( &self, state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, customer: &Option<domain::Customer>, merchant_connector_account: &helpers::MerchantConnectorAccountType, merchant_recipient_data: Option<types::MerchantRecipientData>, header_payload: Option<hyperswitch_domain_models::payments::HeaderPayload>, ) -> RouterResult<types::PaymentsCaptureRouterData> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payments/flows/capture_flow.rs | crate: router use crate::{ core::{ errors::{ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, Feature, PaymentData}, }, routes::SessionState, services, types::{self, api, domain}, }; async fn build_flow_specific_connector_request( &mut self, state: &SessionState, connector: &api::ConnectorData, call_connector_action: payments::CallConnectorAction, ) -> RouterResult<(Option<services::Request>, bool)> { { payments::CallConnectorAction::Trigger => { let connector_integration: services::BoxedPaymentConnectorIntegrationInterface< api::Capture, types::PaymentsCaptureData, types::PaymentsResponseData, > = connector.connector.get_connector_integration(); connector_integration .build_request(self, &state.conf.connectors) .to_payment_failed_response()? }<|fim_suffix|> <|fim_middle|> _ => None, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs | crate: router use diesel_models::enums::FraudCheckLastStep; use crate::{ core::{ errors::RouterResult, fraud_check::{ self as frm_core, types::{FrmData, PaymentDetails, PaymentToFrmData}, ConnectorDetailsCore, }, payments, }, errors, routes::app::ReqState, types::{ api::fraud_check as frm_api, domain, fraud_check::{ FraudCheckCheckoutData, FraudCheckResponseData, FraudCheckTransactionData, FrmRequest, FrmResponse, FrmRouterData, }, storage::{ enums::{FraudCheckStatus, FraudCheckType}, fraud_check::{FraudCheckNew, FraudCheckUpdate}, }, ResponseId, }, SessionState, }; async fn pre_payment_frm<'a>( &'a self, state: &'a SessionState, payment_data: &mut D, frm_data: &mut FrmData, merchant_account: &domain::MerchantAccount, customer: &Option<domain::Customer>, key_store: domain::MerchantKeyStore, ) -> RouterResult<FrmRouterData> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs | crate: router use diesel_models::enums::FraudCheckLastStep; use crate::{ core::{ errors::RouterResult, fraud_check::{ self as frm_core, types::{FrmData, PaymentDetails, PaymentToFrmData}, ConnectorDetailsCore, }, payments, }, errors, routes::app::ReqState, types::{ api::fraud_check as frm_api, domain, fraud_check::{ FraudCheckCheckoutData, FraudCheckResponseData, FraudCheckTransactionData, FrmRequest, FrmResponse, FrmRouterData, }, storage::{ enums::{FraudCheckStatus, FraudCheckType}, fraud_check::{FraudCheckNew, FraudCheckUpdate}, }, ResponseId, }, SessionState, }; async fn post_payment_frm<'a>( &'a self, state: &'a SessionState, _req_state: ReqState, payment_data: &mut D, frm_data: &mut FrmData, merchant_account: &domain::MerchantAccount, customer: &Option<domain::Customer>, key_store: domain::MerchantKeyStore, ) -> RouterResult<Option<FrmRouterData>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs | crate: router use common_utils::ext_traits::Encode; use diesel_models::enums::FraudCheckLastStep; use router_env::{instrument, tracing}; use uuid::Uuid; use crate::{ core::{ errors::RouterResult, fraud_check::{ self as frm_core, types::{FrmData, PaymentDetails, PaymentToFrmData}, ConnectorDetailsCore, }, payments, }, errors, routes::app::ReqState, types::{ api::fraud_check as frm_api, domain, fraud_check::{ FraudCheckCheckoutData, FraudCheckResponseData, FraudCheckTransactionData, FrmRequest, FrmResponse, FrmRouterData, }, storage::{ enums::{FraudCheckStatus, FraudCheckType}, fraud_check::{FraudCheckNew, FraudCheckUpdate}, }, ResponseId, }, SessionState, }; async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_data: PaymentToFrmData, frm_connector_details: ConnectorDetailsCore, ) -> RouterResult<Option<FrmData>> { { Ok(fraud_check_value) => { let frm_data = FrmData { payment_intent: payment_data.payment_intent, payment_attempt: payment_data.payment_attempt, merchant_account: payment_data.merchant_account, address: payment_data.address, fraud_check: fraud_check_value, connector_details: payment_data.connector_details, order_details: payment_data.order_details, refund: None, frm_metadata: payment_data.frm_metadata, }; Ok(Some(frm_data)) }<|fim_suffix|> <|fim_middle|> Err(error) => { router_env::logger::error!("inserting into fraud_check table failed {error:?}"); Ok(None) } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs | crate: router } } } #[async_trait] impl<F, D> Domain<F, D> for FraudCheckPre where F: Clone + Send, D: payments::OperationSessionGetters<F> + Send + Sync + Clone, { #[cfg(all(feature = "v2", feature = "customer_v2"))] #[instrument(skip_all)] async fn post_payment_frm<'a>( &'a self, _state: &'a SessionState, _req_state: ReqState, _payment_data: &mut D, _frm_data: &mut FrmData, _merchant_account: &domain::MerchantAccount, _customer: &Option<domain::Customer>, _key_store: domain::MerchantKeyStore, ) -> RouterResult<Option<FrmRouterData>> { todo!() } async fn post_payment_frm<'a>( &'a self, _state: &'a SessionState, _req_state: ReqState, _payment_data: &mut D, _frm_data: &mut FrmData, _merchant_account: &domain::MerchantAccount, _customer: &Option<domain::Customer>, _key_store: domain::MerchantKeyStore, ) -> RouterResult<Option<FrmRouterData>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs | crate: router use crate::{ core::{ errors::RouterResult, fraud_check::{ self as frm_core, types::{FrmData, PaymentDetails, PaymentToFrmData}, ConnectorDetailsCore, }, payments, }, errors, routes::app::ReqState, types::{ api::fraud_check as frm_api, domain, fraud_check::{ FraudCheckCheckoutData, FraudCheckResponseData, FraudCheckTransactionData, FrmRequest, FrmResponse, FrmRouterData, }, storage::{ enums::{FraudCheckStatus, FraudCheckType}, fraud_check::{FraudCheckNew, FraudCheckUpdate}, }, ResponseId, }, SessionState, }; async fn post_payment_frm<'a>( &'a self, _state: &'a SessionState, _req_state: ReqState, _payment_data: &mut D, _frm_data: &mut FrmData, _merchant_account: &domain::MerchantAccount, _customer: &Option<domain::Customer>, _key_store: domain::MerchantKeyStore, ) -> RouterResult<Option<FrmRouterData>> { todo!() }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs | crate: router use crate::{ core::{ errors::RouterResult, fraud_check::{ self as frm_core, types::{FrmData, PaymentDetails, PaymentToFrmData}, ConnectorDetailsCore, }, payments, }, errors, routes::app::ReqState, types::{ api::fraud_check as frm_api, domain, fraud_check::{ FraudCheckCheckoutData, FraudCheckResponseData, FraudCheckTransactionData, FrmRequest, FrmResponse, FrmRouterData, }, storage::{ enums::{FraudCheckStatus, FraudCheckType}, fraud_check::{FraudCheckNew, FraudCheckUpdate}, }, ResponseId, }, SessionState, }; async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_data: PaymentToFrmData, frm_connector_details: ConnectorDetailsCore, ) -> RouterResult<Option<FrmData>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs | crate: router use super::{Domain, FraudCheckOperation, GetTracker, UpdateTracker}; use crate::{ core::{ errors::RouterResult, fraud_check::{ self as frm_core, types::{FrmData, PaymentDetails, PaymentToFrmData}, ConnectorDetailsCore, }, payments, }, errors, routes::app::ReqState, types::{ api::fraud_check as frm_api, domain, fraud_check::{ FraudCheckCheckoutData, FraudCheckResponseData, FraudCheckTransactionData, FrmRequest, FrmResponse, FrmRouterData, }, storage::{ enums::{FraudCheckStatus, FraudCheckType}, fraud_check::{FraudCheckNew, FraudCheckUpdate}, }, ResponseId, }, SessionState, }; fn to_get_tracker(&self) -> RouterResult<&(dyn GetTracker<PaymentToFrmData> + Send + Sync)> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs | crate: router use common_enums::FrmSuggestion; use common_utils::ext_traits::Encode; use crate::{ core::{ errors::RouterResult, fraud_check::{ self as frm_core, types::{FrmData, PaymentDetails, PaymentToFrmData}, ConnectorDetailsCore, }, payments, }, errors, routes::app::ReqState, types::{ api::fraud_check as frm_api, domain, fraud_check::{ FraudCheckCheckoutData, FraudCheckResponseData, FraudCheckTransactionData, FrmRequest, FrmResponse, FrmRouterData, }, storage::{ enums::{FraudCheckStatus, FraudCheckType}, fraud_check::{FraudCheckNew, FraudCheckUpdate}, }, ResponseId, }, SessionState, }; async fn update_tracker<'b>( &'b self, state: &SessionState, _key_store: &domain::MerchantKeyStore, mut frm_data: FrmData, payment_data: &mut D, _frm_suggestion: Option<FrmSuggestion>, frm_router_data: FrmRouterData, ) -> RouterResult<FrmData> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/core/fraud_check/operation/fraud_check_post.rs | crate: router use router_env::{instrument, logger, tracing}; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, fraud_check::{ self as frm_core, types::{FrmData, PaymentDetails, PaymentToFrmData, CANCEL_INITIATED}, ConnectorDetailsCore, FrmConfigsObject, }, payments, }, errors, routes::app::ReqState, services::{self, api}, types::{ api::{ enums::{AttemptStatus, IntentStatus}, fraud_check as frm_api, payments as payment_types, Capture, Void, }, domain, fraud_check::{ FraudCheckResponseData, FraudCheckSaleData, FrmRequest, FrmResponse, FrmRouterData, }, storage::{ enums::{FraudCheckLastStep, FraudCheckStatus, FraudCheckType, MerchantDecision}, fraud_check::{FraudCheckNew, FraudCheckUpdate}, }, ResponseId, }, utils, SessionState, }; async fn post_payment_frm<'a>( &'a self, state: &'a SessionState, _req_state: ReqState, payment_data: &mut D, frm_data: &mut FrmData, merchant_account: &domain::MerchantAccount, customer: &Option<domain::Customer>, key_store: domain::MerchantKeyStore, ) -> RouterResult<Option<FrmRouterData>> { if frm_data.fraud_check.last_step != FraudCheckLastStep::Processing { logger::debug!("post_flow::Sale Skipped"); return Ok(None); } let router_data = frm_core::call_frm_service::<F, frm_api::Sale, _, D>( state, payment_data, &mut frm_data.to_owned(), merchant_account, &key_store, customer, ) .await?; frm_data.fraud_check.last_step = FraudCheckLastStep::CheckoutOrSale; Ok(Some(FrmRouterData { merchant_id: router_data.merchant_id, connector: router_data.connector, payment_id: router_data.payment_id.clone(), attempt_id: router_data.attempt_id, request: FrmRequest::Sale(FraudCheckSaleData { amount: router_data.request.amount, order_details: router_data.request.order_details, currency: router_data.request.currency, email: router_data.request.email, }), response: FrmResponse::Sale(router_data.response), })) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/fraud_check/operation/fraud_check_post.rs | crate: router use common_utils::ext_traits::Encode; use hyperswitch_domain_models::payments::{ payment_attempt::PaymentAttemptUpdate, payment_intent::PaymentIntentUpdate, HeaderPayload, }; use router_env::{instrument, logger, tracing}; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, fraud_check::{ self as frm_core, types::{FrmData, PaymentDetails, PaymentToFrmData, CANCEL_INITIATED}, ConnectorDetailsCore, FrmConfigsObject, }, payments, }, errors, routes::app::ReqState, services::{self, api}, types::{ api::{ enums::{AttemptStatus, IntentStatus}, fraud_check as frm_api, payments as payment_types, Capture, Void, }, domain, fraud_check::{ FraudCheckResponseData, FraudCheckSaleData, FrmRequest, FrmResponse, FrmRouterData, }, storage::{ enums::{FraudCheckLastStep, FraudCheckStatus, FraudCheckType, MerchantDecision}, fraud_check::{FraudCheckNew, FraudCheckUpdate}, }, ResponseId, }, utils, SessionState, }; async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_data: PaymentToFrmData, frm_connector_details: ConnectorDetailsCore, ) -> RouterResult<Option<FrmData>> { { Some(Some(fraud_check)) => Ok(fraud_check),<|fim_suffix|> <|fim_middle|> _ => { db.insert_fraud_check_response(FraudCheckNew { frm_id: utils::generate_id(consts::ID_LENGTH, "frm"), payment_id: payment_data.payment_intent.get_id().to_owned(), merchant_id: payment_data.merchant_account.get_id().clone(), attempt_id: payment_data.payment_attempt.attempt_id.clone(), created_at: common_utils::date_time::now(), frm_name: frm_connector_details.connector_name, frm_transaction_id: None, frm_transaction_type: FraudCheckType::PostFrm, frm_status: FraudCheckStatus::Pending, frm_score: None, frm_reason: None, frm_error: None, payment_details, metadata: None, modified_at: common_utils::date_time::now(), last_step: FraudCheckLastStep::Processing, payment_capture_method: payment_data.payment_attempt.capture_method, }) .await } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/fraud_check/operation/fraud_check_post.rs | crate: router _frm_suggestion: &mut Option<FrmSuggestion>, _key_store: domain::MerchantKeyStore, _payment_data: &mut D, _customer: &Option<domain::Customer>, _should_continue_capture: &mut bool, _platform_merchant_account: Option<&domain::MerchantAccount>, ) -> RouterResult<Option<FrmData>> { todo!() } #[cfg(feature = "v1")] #[instrument(skip_all)] async fn execute_post_tasks( &self, state: &SessionState, req_state: ReqState, frm_data: &mut FrmData, merchant_account: &domain::MerchantAccount, _frm_configs: FrmConfigsObject, frm_suggestion: &mut Option<FrmSuggestion>, key_store: domain::MerchantKeyStore, payment_data: &mut D, customer: &Option<domain::Customer>, _should_continue_capture: &mut bool, platform_merchant_account: Option<&domain::MerchantAccount>, async fn execute_post_tasks( &self, state: &SessionState, req_state: ReqState, frm_data: &mut FrmData, merchant_account: &domain::MerchantAccount, _frm_configs: FrmConfigsObject, frm_suggestion: &mut Option<FrmSuggestion>, key_store: domain::MerchantKeyStore, payment_data: &mut D, customer: &Option<domain::Customer>, _should_continue_capture: &mut bool, platform_merchant_account: Option<&domain::MerchantAccount>, ) -> RouterResult<Option<FrmData>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/fraud_check/operation/fraud_check_post.rs | crate: router use common_enums::{CaptureMethod, FrmSuggestion}; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, fraud_check::{ self as frm_core, types::{FrmData, PaymentDetails, PaymentToFrmData, CANCEL_INITIATED}, ConnectorDetailsCore, FrmConfigsObject, }, payments, }, errors, routes::app::ReqState, services::{self, api}, types::{ api::{ enums::{AttemptStatus, IntentStatus}, fraud_check as frm_api, payments as payment_types, Capture, Void, }, domain, fraud_check::{ FraudCheckResponseData, FraudCheckSaleData, FrmRequest, FrmResponse, FrmRouterData, }, storage::{ enums::{FraudCheckLastStep, FraudCheckStatus, FraudCheckType, MerchantDecision}, fraud_check::{FraudCheckNew, FraudCheckUpdate}, }, ResponseId, }, utils, SessionState, }; async fn execute_post_tasks( &self, _state: &SessionState, _req_state: ReqState, _frm_data: &mut FrmData, _merchant_account: &domain::MerchantAccount, _frm_configs: FrmConfigsObject, _frm_suggestion: &mut Option<FrmSuggestion>, _key_store: domain::MerchantKeyStore, _payment_data: &mut D, _customer: &Option<domain::Customer>, _should_continue_capture: &mut bool, _platform_merchant_account: Option<&domain::MerchantAccount>, ) -> RouterResult<Option<FrmData>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/fraud_check/operation/fraud_check_post.rs | crate: router use super::{Domain, FraudCheckOperation, GetTracker, UpdateTracker}; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, fraud_check::{ self as frm_core, types::{FrmData, PaymentDetails, PaymentToFrmData, CANCEL_INITIATED}, ConnectorDetailsCore, FrmConfigsObject, }, payments, }, errors, routes::app::ReqState, services::{self, api}, types::{ api::{ enums::{AttemptStatus, IntentStatus}, fraud_check as frm_api, payments as payment_types, Capture, Void, }, domain, fraud_check::{ FraudCheckResponseData, FraudCheckSaleData, FrmRequest, FrmResponse, FrmRouterData, }, storage::{ enums::{FraudCheckLastStep, FraudCheckStatus, FraudCheckType, MerchantDecision}, fraud_check::{FraudCheckNew, FraudCheckUpdate}, }, ResponseId, }, utils, SessionState, }; fn to_domain(&self) -> RouterResult<&(dyn Domain<F, D>)> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/core/fraud_check/operation/fraud_check_post.rs | crate: router use super::{Domain, FraudCheckOperation, GetTracker, UpdateTracker}; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, fraud_check::{ self as frm_core, types::{FrmData, PaymentDetails, PaymentToFrmData, CANCEL_INITIATED}, ConnectorDetailsCore, FrmConfigsObject, }, payments, }, errors, routes::app::ReqState, services::{self, api}, types::{ api::{ enums::{AttemptStatus, IntentStatus}, fraud_check as frm_api, payments as payment_types, Capture, Void, }, domain, fraud_check::{ FraudCheckResponseData, FraudCheckSaleData, FrmRequest, FrmResponse, FrmRouterData, }, storage::{ enums::{FraudCheckLastStep, FraudCheckStatus, FraudCheckType, MerchantDecision}, fraud_check::{FraudCheckNew, FraudCheckUpdate}, }, ResponseId, }, utils, SessionState, }; fn to_get_tracker(&self) -> RouterResult<&(dyn GetTracker<PaymentToFrmData> + Send + Sync)> { Ok(*self) }
ast_fragments
// file: hyperswitch/crates/router/src/core/fraud_check/operation/fraud_check_post.rs | crate: router use common_enums::{CaptureMethod, FrmSuggestion}; use hyperswitch_domain_models::payments::{ payment_attempt::PaymentAttemptUpdate, payment_intent::PaymentIntentUpdate, HeaderPayload, }; use router_env::{instrument, logger, tracing}; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, fraud_check::{ self as frm_core, types::{FrmData, PaymentDetails, PaymentToFrmData, CANCEL_INITIATED}, ConnectorDetailsCore, FrmConfigsObject, }, payments, }, errors, routes::app::ReqState, services::{self, api}, types::{ api::{ enums::{AttemptStatus, IntentStatus}, fraud_check as frm_api, payments as payment_types, Capture, Void, }, domain, fraud_check::{ FraudCheckResponseData, FraudCheckSaleData, FrmRequest, FrmResponse, FrmRouterData, }, storage::{ enums::{FraudCheckLastStep, FraudCheckStatus, FraudCheckType, MerchantDecision}, fraud_check::{FraudCheckNew, FraudCheckUpdate}, }, ResponseId, }, utils, SessionState, }; async fn execute_post_tasks( &self, state: &SessionState, req_state: ReqState, frm_data: &mut FrmData, merchant_account: &domain::MerchantAccount, _frm_configs: FrmConfigsObject, frm_suggestion: &mut Option<FrmSuggestion>, key_store: domain::MerchantKeyStore, payment_data: &mut D, customer: &Option<domain::Customer>, _should_continue_capture: &mut bool, platform_merchant_account: Option<&domain::MerchantAccount>, ) -> RouterResult<Option<FrmData>> { if matches!(frm_data.fraud_check.frm_status, FraudCheckStatus::Fraud) && matches!( frm_data.fraud_check.last_step, FraudCheckLastStep::CheckoutOrSale ) { *frm_suggestion = Some(FrmSuggestion::FrmCancelTransaction); let cancel_req = api_models::payments::PaymentsCancelRequest { payment_id: frm_data.payment_intent.get_id().to_owned(), cancellation_reason: frm_data.fraud_check.frm_error.clone(), merchant_connector_details: None, }; let cancel_res = Box::pin(payments::payments_core::< Void, payment_types::PaymentsResponse, _, _, _, payments::PaymentData<Void>, >( state.clone(), req_state.clone(), merchant_account.clone(), None, key_store.clone(), payments::PaymentCancel, cancel_req, api::AuthFlow::Merchant, payments::CallConnectorAction::Trigger, None, HeaderPayload::default(), platform_merchant_account.cloned(), )) .await?; logger::debug!("payment_id : {:?} has been cancelled since it has been found fraudulent by configured frm connector",payment_data.get_payment_attempt().payment_id); if let services::ApplicationResponse::JsonWithHeaders((payments_response, _)) = cancel_res { payment_data.set_payment_intent_status(payments_response.status); } let _router_data = frm_core::call_frm_service::<F, frm_api::RecordReturn, _, D>( state, payment_data, &mut frm_data.to_owned(), merchant_account, &key_store, customer, ) .await?; frm_data.fraud_check.last_step = FraudCheckLastStep::TransactionOrRecordRefund; } else if matches!( frm_data.fraud_check.frm_status, FraudCheckStatus::ManualReview ) { *frm_suggestion = Some(FrmSuggestion::FrmManualReview); } else if matches!(frm_data.fraud_check.frm_status, FraudCheckStatus::Legit) && matches!( frm_data.fraud_check.payment_capture_method, Some(CaptureMethod::Automatic) | Some(CaptureMethod::SequentialAutomatic) ) { let capture_request = api_models::payments::PaymentsCaptureRequest { payment_id: frm_data.payment_intent.get_id().to_owned(), merchant_id: None, amount_to_capture: None, refund_uncaptured_amount: None, statement_descriptor_suffix: None, statement_descriptor_prefix: None, merchant_connector_details: None, }; let capture_response = Box::pin(payments::payments_core::< Capture, payment_types::PaymentsResponse, _, _, _, payments::PaymentData<Capture>, >( state.clone(), req_state.clone(), merchant_account.clone(), None, key_store.clone(), payments::PaymentCapture, capture_request, api::AuthFlow::Merchant, payments::CallConnectorAction::Trigger, None, HeaderPayload::default(), platform_merchant_account.cloned(), )) .await?; logger::debug!("payment_id : {:?} has been captured since it has been found legit by configured frm connector",payment_data.get_payment_attempt().payment_id); if let services::ApplicationResponse::JsonWithHeaders((payments_response, _)) = capture_response { payment_data.set_payment_intent_status(payments_response.status); } }; return Ok(Some(frm_data.to_owned())); }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/fraud_check/operation/fraud_check_post.rs | crate: router use common_enums::{CaptureMethod, FrmSuggestion}; use common_utils::ext_traits::Encode; use hyperswitch_domain_models::payments::{ payment_attempt::PaymentAttemptUpdate, payment_intent::PaymentIntentUpdate, HeaderPayload, }; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, fraud_check::{ self as frm_core, types::{FrmData, PaymentDetails, PaymentToFrmData, CANCEL_INITIATED}, ConnectorDetailsCore, FrmConfigsObject, }, payments, }, errors, routes::app::ReqState, services::{self, api}, types::{ api::{ enums::{AttemptStatus, IntentStatus}, fraud_check as frm_api, payments as payment_types, Capture, Void, }, domain, fraud_check::{ FraudCheckResponseData, FraudCheckSaleData, FrmRequest, FrmResponse, FrmRouterData, }, storage::{ enums::{FraudCheckLastStep, FraudCheckStatus, FraudCheckType, MerchantDecision}, fraud_check::{FraudCheckNew, FraudCheckUpdate}, }, ResponseId, }, utils, SessionState, }; async fn update_tracker<'b>( &'b self, state: &SessionState, key_store: &domain::MerchantKeyStore, mut frm_data: FrmData, payment_data: &mut D, frm_suggestion: Option<FrmSuggestion>, frm_router_data: FrmRouterData, ) -> RouterResult<FrmData> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/core/card_testing_guard/utils.rs | crate: router use hyperswitch_domain_models::{ card_testing_guard_data::CardTestingGuardData, router_request_types::BrowserInformation, }; use crate::{ core::{errors::RouterResult, payments::helpers}, routes::SessionState, services, types::{api, domain}, utils::crypto::{self, SignMessage}, }; pub async fn increment_blocked_count_in_cache( state: &SessionState, card_testing_guard_data: Option<CardTestingGuardData>, ) -> RouterResult<()> { if let Some(card_testing_guard_data) = card_testing_guard_data.clone() { if card_testing_guard_data.is_card_ip_blocking_enabled && !card_testing_guard_data .card_ip_blocking_cache_key .is_empty() { let _ = services::card_testing_guard::increment_blocked_count_in_cache( state, &card_testing_guard_data.card_ip_blocking_cache_key, card_testing_guard_data.card_testing_guard_expiry.into(), ) .await; } if card_testing_guard_data.is_guest_user_card_blocking_enabled && !card_testing_guard_data .guest_user_card_blocking_cache_key .is_empty() { let _ = services::card_testing_guard::increment_blocked_count_in_cache( state, &card_testing_guard_data.guest_user_card_blocking_cache_key, card_testing_guard_data.card_testing_guard_expiry.into(), ) .await; } if card_testing_guard_data.is_customer_id_blocking_enabled && !card_testing_guard_data .customer_id_blocking_cache_key .is_empty() { let _ = services::card_testing_guard::increment_blocked_count_in_cache( state, &card_testing_guard_data.customer_id_blocking_cache_key, card_testing_guard_data.card_testing_guard_expiry.into(), ) .await; } } Ok(()) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/card_testing_guard/utils.rs | crate: router use error_stack::ResultExt; use masking::{PeekInterface, Secret}; use router_env::logger; use super::errors; use crate::{ core::{errors::RouterResult, payments::helpers}, routes::SessionState, services, types::{api, domain}, utils::crypto::{self, SignMessage}, }; pub async fn generate_fingerprint( payment_method_data: Option<&api_models::payments::PaymentMethodData>, business_profile: &domain::Profile, ) -> RouterResult<Secret<String>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/card_testing_guard/utils.rs | crate: router use hyperswitch_domain_models::{ card_testing_guard_data::CardTestingGuardData, router_request_types::BrowserInformation, }; use crate::{ core::{errors::RouterResult, payments::helpers}, routes::SessionState, services, types::{api, domain}, utils::crypto::{self, SignMessage}, }; pub async fn increment_blocked_count_in_cache( state: &SessionState, card_testing_guard_data: Option<CardTestingGuardData>, ) -> RouterResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/card_testing_guard/utils.rs | crate: router use hyperswitch_domain_models::{ card_testing_guard_data::CardTestingGuardData, router_request_types::BrowserInformation, }; use super::errors; use crate::{ core::{errors::RouterResult, payments::helpers}, routes::SessionState, services, types::{api, domain}, utils::crypto::{self, SignMessage}, }; pub async fn validate_card_testing_guard_checks( state: &SessionState, request: &api::PaymentsRequest, payment_method_data: Option<&api_models::payments::PaymentMethodData>, customer_id: &Option<common_utils::id_type::CustomerId>, business_profile: &domain::Profile, ) -> RouterResult<Option<CardTestingGuardData>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/connector_onboarding/paypal.rs | crate: router use api_models::{admin::MerchantConnectorUpdate, connector_onboarding as api}; use common_utils::ext_traits::Encode; use masking::{ExposeInterface, PeekInterface, Secret}; use crate::{ core::{ admin, errors::{ApiErrorResponse, RouterResult}, }, services::{send_request, ApplicationResponse, Request}, types::{self as oss_types, api as oss_api_types, api::connector_onboarding as types}, utils::connector_onboarding as utils, SessionState, }; pub async fn update_mca( state: &SessionState, merchant_id: common_utils::id_type::MerchantId, connector_id: common_utils::id_type::MerchantConnectorAccountId, auth_details: oss_types::ConnectorAuthType, ) -> RouterResult<oss_api_types::MerchantConnectorResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/connector_onboarding/paypal.rs | crate: router use api_models::{admin::MerchantConnectorUpdate, connector_onboarding as api}; use crate::{ core::{ admin, errors::{ApiErrorResponse, RouterResult}, }, services::{send_request, ApplicationResponse, Request}, types::{self as oss_types, api as oss_api_types, api::connector_onboarding as types}, utils::connector_onboarding as utils, SessionState, }; pub async fn sync_merchant_onboarding_status( state: SessionState, tracking_id: String, ) -> RouterResult<api::OnboardingStatus> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/connector_onboarding/paypal.rs | crate: router use api_models::{admin::MerchantConnectorUpdate, connector_onboarding as api}; use common_utils::ext_traits::Encode; use masking::{ExposeInterface, PeekInterface, Secret}; use crate::{ core::{ admin, errors::{ApiErrorResponse, RouterResult}, }, services::{send_request, ApplicationResponse, Request}, types::{self as oss_types, api as oss_api_types, api::connector_onboarding as types}, utils::connector_onboarding as utils, SessionState, }; pub async fn update_mca( state: &SessionState, merchant_id: common_utils::id_type::MerchantId, connector_id: common_utils::id_type::MerchantConnectorAccountId, auth_details: oss_types::ConnectorAuthType, ) -> RouterResult<oss_api_types::MerchantConnectorResponse> { { ApplicationResponse::Json(mca_data) => Ok(mca_data),<|fim_suffix|> <|fim_middle|> _ => Err(ApiErrorResponse::InternalServerError.into()), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/connector_onboarding/paypal.rs | crate: router use crate::{ core::{ admin, errors::{ApiErrorResponse, RouterResult}, }, services::{send_request, ApplicationResponse, Request}, types::{self as oss_types, api as oss_api_types, api::connector_onboarding as types}, utils::connector_onboarding as utils, SessionState, }; async fn find_paypal_merchant_by_tracking_id( state: SessionState, tracking_id: String, access_token: &oss_types::AccessToken, ) -> RouterResult<Option<types::paypal::SellerStatusResponse>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/connector_onboarding/paypal.rs | crate: router use api_models::{admin::MerchantConnectorUpdate, connector_onboarding as api}; use crate::{ core::{ admin, errors::{ApiErrorResponse, RouterResult}, }, services::{send_request, ApplicationResponse, Request}, types::{self as oss_types, api as oss_api_types, api::connector_onboarding as types}, utils::connector_onboarding as utils, SessionState, }; fn merchant_onboarding_status_url(state: SessionState, tracking_id: String) -> String { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/connector_onboarding/paypal.rs | crate: router use crate::{ core::{ admin, errors::{ApiErrorResponse, RouterResult}, }, services::{send_request, ApplicationResponse, Request}, types::{self as oss_types, api as oss_api_types, api::connector_onboarding as types}, utils::connector_onboarding as utils, SessionState, }; pub async fn get_action_url_from_paypal( state: SessionState, tracking_id: String, return_url: String, ) -> RouterResult<String> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/connector_onboarding/paypal.rs | crate: router use crate::{ core::{ admin, errors::{ApiErrorResponse, RouterResult}, }, services::{send_request, ApplicationResponse, Request}, types::{self as oss_types, api as oss_api_types, api::connector_onboarding as types}, utils::connector_onboarding as utils, SessionState, }; async fn build_referral_request( state: SessionState, tracking_id: String, return_url: String, ) -> RouterResult<Request> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/connector_onboarding/paypal.rs | crate: router use crate::{ core::{ admin, errors::{ApiErrorResponse, RouterResult}, }, services::{send_request, ApplicationResponse, Request}, types::{self as oss_types, api as oss_api_types, api::connector_onboarding as types}, utils::connector_onboarding as utils, SessionState, }; fn build_referral_url(state: SessionState) -> String { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/disputes/transformers.rs | crate: router use api_models::disputes::EvidenceType; use crate::{ core::{errors, files::helpers::retrieve_file_and_provider_file_id_from_file_id}, routes::SessionState, types::{ api::{self, DisputeEvidence}, domain, transformers::ForeignFrom, SubmitEvidenceRequestData, }, }; pub fn delete_evidence_file( dispute_evidence: DisputeEvidence, evidence_type: EvidenceType, ) -> DisputeEvidence { { EvidenceType::CancellationPolicy => DisputeEvidence { cancellation_policy: None, ..dispute_evidence }, EvidenceType::CustomerCommunication => DisputeEvidence { customer_communication: None, ..dispute_evidence }, EvidenceType::CustomerSignature => DisputeEvidence { customer_signature: None, ..dispute_evidence },<|fim_suffix|> <|fim_middle|> EvidenceType::InvoiceShowingDistinctTransactions => DisputeEvidence { invoice_showing_distinct_transactions: None, ..dispute_evidence }, EvidenceType::RecurringTransactionAgreement => DisputeEvidence { recurring_transaction_agreement: None, ..dispute_evidence }, EvidenceType::UncategorizedFile => DisputeEvidence { uncategorized_file: None, ..dispute_evidence }, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/disputes/transformers.rs | crate: router use api_models::disputes::EvidenceType; use crate::{ core::{errors, files::helpers::retrieve_file_and_provider_file_id_from_file_id}, routes::SessionState, types::{ api::{self, DisputeEvidence}, domain, transformers::ForeignFrom, SubmitEvidenceRequestData, }, }; pub fn update_dispute_evidence( dispute_evidence: DisputeEvidence, evidence_type: api::EvidenceType, file_id: String, ) -> DisputeEvidence { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/disputes/transformers.rs | crate: router use api_models::disputes::EvidenceType; use crate::{ core::{errors, files::helpers::retrieve_file_and_provider_file_id_from_file_id}, routes::SessionState, types::{ api::{self, DisputeEvidence}, domain, transformers::ForeignFrom, SubmitEvidenceRequestData, }, }; pub fn delete_evidence_file( dispute_evidence: DisputeEvidence, evidence_type: EvidenceType, ) -> DisputeEvidence { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/disputes/transformers.rs | crate: router use api_models::disputes::EvidenceType; use common_utils::errors::CustomResult; use crate::{ core::{errors, files::helpers::retrieve_file_and_provider_file_id_from_file_id}, routes::SessionState, types::{ api::{self, DisputeEvidence}, domain, transformers::ForeignFrom, SubmitEvidenceRequestData, }, }; pub async fn get_dispute_evidence_block( state: &SessionState, merchant_account: &domain::MerchantAccount, evidence_type: EvidenceType, file_id: String, ) -> CustomResult<api_models::disputes::DisputeEvidenceBlock, errors::ApiErrorResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/disputes/transformers.rs | crate: router use api_models::disputes::EvidenceType; use common_utils::errors::CustomResult; use crate::{ core::{errors, files::helpers::retrieve_file_and_provider_file_id_from_file_id}, routes::SessionState, types::{ api::{self, DisputeEvidence}, domain, transformers::ForeignFrom, SubmitEvidenceRequestData, }, }; pub async fn get_dispute_evidence_vec( state: &SessionState, merchant_account: domain::MerchantAccount, dispute_evidence: DisputeEvidence, ) -> CustomResult<Vec<api_models::disputes::DisputeEvidenceBlock>, errors::ApiErrorResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/disputes/transformers.rs | crate: router use api_models::disputes::EvidenceType; use common_utils::errors::CustomResult; use crate::{ core::{errors, files::helpers::retrieve_file_and_provider_file_id_from_file_id}, routes::SessionState, types::{ api::{self, DisputeEvidence}, domain, transformers::ForeignFrom, SubmitEvidenceRequestData, }, }; pub async fn get_evidence_request_data( state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, evidence_request: api_models::disputes::SubmitEvidenceRequest, dispute: &diesel_models::dispute::Dispute, ) -> CustomResult<SubmitEvidenceRequestData, errors::ApiErrorResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/user_role/role.rs | crate: router use std::{cmp, collections::HashSet}; use api_models::user_role::role as role_api; use common_enums::{EntityType, ParentGroup, PermissionGroup}; use diesel_models::role::{ListRolesByEntityPayload, RoleNew, RoleUpdate}; use crate::{ core::errors::{StorageErrorExt, UserErrors, UserResponse}, routes::{app::ReqState, SessionState}, services::{ authentication::{blacklist, UserFromToken}, authorization::{ permission_groups::{ParentGroupExt, PermissionGroupExt}, roles::{self, predefined_roles::PREDEFINED_ROLES}, }, ApplicationResponse, }, types::domain::user::RoleName, utils, }; pub async fn get_parent_info_for_role( state: SessionState, user_from_token: UserFromToken, role: role_api::GetRoleRequest, ) -> UserResponse<role_api::RoleInfoWithParents> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/core/user_role/role.rs | crate: router use api_models::user_role::role as role_api; use diesel_models::role::{ListRolesByEntityPayload, RoleNew, RoleUpdate}; use crate::{ core::errors::{StorageErrorExt, UserErrors, UserResponse}, routes::{app::ReqState, SessionState}, services::{ authentication::{blacklist, UserFromToken}, authorization::{ permission_groups::{ParentGroupExt, PermissionGroupExt}, roles::{self, predefined_roles::PREDEFINED_ROLES}, }, ApplicationResponse, }, types::domain::user::RoleName, utils, }; pub async fn get_role_with_groups( state: SessionState, user_from_token: UserFromToken, role: role_api::GetRoleRequest, ) -> UserResponse<role_api::RoleInfoWithGroupsResponse> { let role_info = roles::RoleInfo::from_role_id_org_id_tenant_id( &state, &role.role_id, &user_from_token.org_id, user_from_token .tenant_id .as_ref() .unwrap_or(&state.tenant.tenant_id), ) .await .to_not_found_response(UserErrors::InvalidRoleId)?; if role_info.is_internal() { return Err(UserErrors::InvalidRoleId.into()); } Ok(ApplicationResponse::Json( role_api::RoleInfoWithGroupsResponse { groups: role_info.get_permission_groups().to_vec(), role_id: role.role_id, role_name: role_info.get_role_name().to_string(), role_scope: role_info.get_scope(), entity_type: role_info.get_entity_type(), }, )) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/user_role/role.rs | crate: router use api_models::user_role::role as role_api; use diesel_models::role::{ListRolesByEntityPayload, RoleNew, RoleUpdate}; use crate::{ core::errors::{StorageErrorExt, UserErrors, UserResponse}, routes::{app::ReqState, SessionState}, services::{ authentication::{blacklist, UserFromToken}, authorization::{ permission_groups::{ParentGroupExt, PermissionGroupExt}, roles::{self, predefined_roles::PREDEFINED_ROLES}, }, ApplicationResponse, }, types::domain::user::RoleName, utils, }; pub async fn get_role_with_groups( state: SessionState, user_from_token: UserFromToken, role: role_api::GetRoleRequest, ) -> UserResponse<role_api::RoleInfoWithGroupsResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/user_role/role.rs | crate: router .iter() .flat_map(|group| group.resources()) .collect::<HashSet<_>>() .into_iter() .collect(); Ok(ApplicationResponse::Json(role_api::GroupsAndResources { groups, resources, })) } pub async fn create_role( state: SessionState, user_from_token: UserFromToken, req: role_api::CreateRoleRequest, _req_state: ReqState, ) -> UserResponse<role_api::RoleInfoWithGroupsResponse> { let now = common_utils::date_time::now(); let user_entity_type = user_from_token .get_role_info_from_db(&state) .await .attach_printable("Invalid role_id in JWT")? .get_entity_type(); pub async fn create_role( state: SessionState, user_from_token: UserFromToken, req: role_api::CreateRoleRequest, _req_state: ReqState, ) -> UserResponse<role_api::RoleInfoWithGroupsResponse> { { EntityType::Organization | EntityType::Tenant => { (user_from_token.org_id, user_from_token.merchant_id, None) }<|fim_suffix|> <|fim_middle|> EntityType::Profile => ( user_from_token.org_id, user_from_token.merchant_id, Some(user_from_token.profile_id), ), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/user_role/role.rs | crate: router use std::{cmp, collections::HashSet}; use api_models::user_role::role as role_api; use crate::{ core::errors::{StorageErrorExt, UserErrors, UserResponse}, routes::{app::ReqState, SessionState}, services::{ authentication::{blacklist, UserFromToken}, authorization::{ permission_groups::{ParentGroupExt, PermissionGroupExt}, roles::{self, predefined_roles::PREDEFINED_ROLES}, }, ApplicationResponse, }, types::domain::user::RoleName, utils, }; pub async fn get_groups_and_resources_for_role_from_token( state: SessionState, user_from_token: UserFromToken, ) -> UserResponse<role_api::GroupsAndResources> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/user_role/role.rs | crate: router use common_enums::{EntityType, ParentGroup, PermissionGroup}; use crate::{ core::errors::{StorageErrorExt, UserErrors, UserResponse}, routes::{app::ReqState, SessionState}, services::{ authentication::{blacklist, UserFromToken}, authorization::{ permission_groups::{ParentGroupExt, PermissionGroupExt}, roles::{self, predefined_roles::PREDEFINED_ROLES}, }, ApplicationResponse, }, types::domain::user::RoleName, utils, }; pub async fn get_role_from_token_with_groups( state: SessionState, user_from_token: UserFromToken, ) -> UserResponse<Vec<PermissionGroup>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/user_role/role.rs | crate: router use api_models::user_role::role as role_api; use common_enums::{EntityType, ParentGroup, PermissionGroup}; use diesel_models::role::{ListRolesByEntityPayload, RoleNew, RoleUpdate}; use crate::{ core::errors::{StorageErrorExt, UserErrors, UserResponse}, routes::{app::ReqState, SessionState}, services::{ authentication::{blacklist, UserFromToken}, authorization::{ permission_groups::{ParentGroupExt, PermissionGroupExt}, roles::{self, predefined_roles::PREDEFINED_ROLES}, }, ApplicationResponse, }, types::domain::user::RoleName, utils, }; pub async fn list_roles_at_entity_level( state: SessionState, user_from_token: UserFromToken, req: role_api::ListRolesAtEntityLevelRequest, check_type: role_api::RoleCheckType, ) -> UserResponse<Vec<role_api::MinimalRoleInfo>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/user_role/role.rs | crate: router use api_models::user_role::role as role_api; use common_enums::{EntityType, ParentGroup, PermissionGroup}; use diesel_models::role::{ListRolesByEntityPayload, RoleNew, RoleUpdate}; use crate::{ core::errors::{StorageErrorExt, UserErrors, UserResponse}, routes::{app::ReqState, SessionState}, services::{ authentication::{blacklist, UserFromToken}, authorization::{ permission_groups::{ParentGroupExt, PermissionGroupExt}, roles::{self, predefined_roles::PREDEFINED_ROLES}, }, ApplicationResponse, }, types::domain::user::RoleName, utils, }; pub async fn list_roles_with_info( state: SessionState, user_from_token: UserFromToken, request: role_api::ListRolesRequest, ) -> UserResponse<Vec<role_api::RoleInfoResponseNew>> { { EntityType::Tenant | EntityType::Organization => state .global_store .generic_list_roles_by_entity_type( ListRolesByEntityPayload::Organization, is_lineage_data_required, tenant_id, user_from_token.org_id, ) .await .change_context(UserErrors::InternalServerError) .attach_printable("Failed to get roles")?,<|fim_suffix|> <|fim_middle|> EntityType::Profile => state .global_store .generic_list_roles_by_entity_type( ListRolesByEntityPayload::Profile( user_from_token.merchant_id, user_from_token.profile_id, ), is_lineage_data_required, tenant_id, user_from_token.org_id, ) .await .change_context(UserErrors::InternalServerError) .attach_printable("Failed to get roles")?, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/user_role/role.rs | crate: router use std::{cmp, collections::HashSet}; use api_models::user_role::role as role_api; use common_enums::{EntityType, ParentGroup, PermissionGroup}; use common_utils::generate_id_with_default_len; use diesel_models::role::{ListRolesByEntityPayload, RoleNew, RoleUpdate}; use error_stack::{report, ResultExt}; use crate::{ core::errors::{StorageErrorExt, UserErrors, UserResponse}, routes::{app::ReqState, SessionState}, services::{ authentication::{blacklist, UserFromToken}, authorization::{ permission_groups::{ParentGroupExt, PermissionGroupExt}, roles::{self, predefined_roles::PREDEFINED_ROLES}, }, ApplicationResponse, }, types::domain::user::RoleName, utils, }; pub async fn update_role( state: SessionState, user_from_token: UserFromToken, req: role_api::UpdateRoleRequest, role_id: &str, ) -> UserResponse<role_api::RoleInfoWithGroupsResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/core/user_role/role.rs | crate: router use std::{cmp, collections::HashSet}; use api_models::user_role::role as role_api; use common_enums::{EntityType, ParentGroup, PermissionGroup}; use common_utils::generate_id_with_default_len; use diesel_models::role::{ListRolesByEntityPayload, RoleNew, RoleUpdate}; use error_stack::{report, ResultExt}; use crate::{ core::errors::{StorageErrorExt, UserErrors, UserResponse}, routes::{app::ReqState, SessionState}, services::{ authentication::{blacklist, UserFromToken}, authorization::{ permission_groups::{ParentGroupExt, PermissionGroupExt}, roles::{self, predefined_roles::PREDEFINED_ROLES}, }, ApplicationResponse, }, types::domain::user::RoleName, utils, }; pub async fn create_role( state: SessionState, user_from_token: UserFromToken, req: role_api::CreateRoleRequest, _req_state: ReqState, ) -> UserResponse<role_api::RoleInfoWithGroupsResponse> { let now = common_utils::date_time::now(); let user_entity_type = user_from_token .get_role_info_from_db(&state) .await .attach_printable("Invalid role_id in JWT")? .get_entity_type(); let role_entity_type = req.entity_type.unwrap_or(EntityType::Merchant); if matches!(role_entity_type, EntityType::Organization) { return Err(report!(UserErrors::InvalidRoleOperation)) .attach_printable("User trying to create org level custom role"); } // TODO: Remove in PR custom-role-write-pr if matches!(role_entity_type, EntityType::Profile) { return Err(report!(UserErrors::InvalidRoleOperation)) .attach_printable("User trying to create profile level custom role"); } let requestor_entity_from_role_scope = EntityType::from(req.role_scope); if requestor_entity_from_role_scope < role_entity_type { return Err(report!(UserErrors::InvalidRoleOperation)).attach_printable(format!( "User is trying to create role of type {} and scope {}", role_entity_type, requestor_entity_from_role_scope )); } let max_from_scope_and_entity = cmp::max(requestor_entity_from_role_scope, role_entity_type); if user_entity_type < max_from_scope_and_entity { return Err(report!(UserErrors::InvalidRoleOperation)).attach_printable(format!( "{} is trying to create of scope {} and of type {}", user_entity_type, requestor_entity_from_role_scope, role_entity_type )); } let role_name = RoleName::new(req.role_name)?; utils::user_role::validate_role_groups(&req.groups)?; utils::user_role::validate_role_name( &state, &role_name, &user_from_token.merchant_id, &user_from_token.org_id, user_from_token .tenant_id .as_ref() .unwrap_or(&state.tenant.tenant_id), &user_from_token.profile_id, &role_entity_type, ) .await?; let (org_id, merchant_id, profile_id) = match role_entity_type { EntityType::Organization | EntityType::Tenant => { (user_from_token.org_id, user_from_token.merchant_id, None) } EntityType::Merchant => (user_from_token.org_id, user_from_token.merchant_id, None), EntityType::Profile => ( user_from_token.org_id, user_from_token.merchant_id, Some(user_from_token.profile_id), ), }; let role = state .global_store .insert_role(RoleNew { role_id: generate_id_with_default_len("role"), role_name: role_name.get_role_name(), merchant_id, org_id, groups: req.groups, scope: req.role_scope, entity_type: role_entity_type, created_by: user_from_token.user_id.clone(), last_modified_by: user_from_token.user_id, created_at: now, last_modified_at: now, profile_id, tenant_id: user_from_token.tenant_id.unwrap_or(state.tenant.tenant_id), }) .await .to_duplicate_response(UserErrors::RoleNameAlreadyExists)?; Ok(ApplicationResponse::Json( role_api::RoleInfoWithGroupsResponse { groups: role.groups, role_id: role.role_id, role_name: role.role_name, role_scope: role.scope, entity_type: role.entity_type, }, )) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/blocklist/utils.rs | crate: router use api_models::blocklist as api_blocklist; use common_utils::errors::CustomResult; use masking::StrongSecret; use super::{errors, transformers::generate_fingerprint, SessionState}; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, payments::PaymentData, }, logger, types::{domain, storage, transformers::ForeignInto}, utils, }; pub async fn generate_payment_fingerprint( state: &SessionState, merchant_id: common_utils::id_type::MerchantId, payment_method_data: Option<domain::PaymentMethodData>, ) -> CustomResult<Option<String>, errors::ApiErrorResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/core/blocklist/utils.rs | crate: router use api_models::blocklist as api_blocklist; use common_enums::MerchantDecision; use common_utils::errors::CustomResult; use super::{errors, transformers::generate_fingerprint, SessionState}; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, payments::PaymentData, }, logger, types::{domain, storage, transformers::ForeignInto}, utils, }; async fn duplicate_check_insert_bin( bin: &str, state: &SessionState, merchant_id: &common_utils::id_type::MerchantId, data_kind: common_enums::BlocklistDataKind, ) -> RouterResult<storage::Blocklist> { let blocklist_entry_result = state .store .find_blocklist_entry_by_merchant_id_fingerprint_id(merchant_id, bin) .await; match blocklist_entry_result { Ok(_) => { return Err(errors::ApiErrorResponse::PreconditionFailed { message: "provided bin is already blocked".to_string(), } .into()); } Err(e) if e.current_context().is_db_not_found() => {} err @ Err(_) => { return err .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("unable to fetch blocklist entry"); } } state .store .insert_blocklist_entry(storage::BlocklistNew { merchant_id: merchant_id.to_owned(), fingerprint_id: bin.to_string(), data_kind, metadata: None, created_at: common_utils::date_time::now(), }) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("error inserting pm blocklist item") }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/blocklist/utils.rs | crate: router use common_utils::errors::CustomResult; use super::{errors, transformers::generate_fingerprint, SessionState}; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, payments::PaymentData, }, logger, types::{domain, storage, transformers::ForeignInto}, utils, }; pub async fn get_merchant_fingerprint_secret( state: &SessionState, merchant_id: &common_utils::id_type::MerchantId, ) -> RouterResult<String> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/core/blocklist/utils.rs | crate: router use api_models::blocklist as api_blocklist; use common_enums::MerchantDecision; use common_utils::errors::CustomResult; use super::{errors, transformers::generate_fingerprint, SessionState}; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, payments::PaymentData, }, logger, types::{domain, storage, transformers::ForeignInto}, utils, }; pub async fn insert_entry_into_blocklist( state: &SessionState, merchant_id: &common_utils::id_type::MerchantId, to_block: api_blocklist::AddToBlocklistRequest, ) -> RouterResult<api_blocklist::AddToBlocklistResponse> { let blocklist_entry = match &to_block { api_blocklist::AddToBlocklistRequest::CardBin(bin) => { validate_card_bin(bin)?; duplicate_check_insert_bin( bin, state, merchant_id, common_enums::BlocklistDataKind::CardBin, ) .await? } api_blocklist::AddToBlocklistRequest::ExtendedCardBin(bin) => { validate_extended_card_bin(bin)?; duplicate_check_insert_bin( bin, state, merchant_id, common_enums::BlocklistDataKind::ExtendedCardBin, ) .await? } api_blocklist::AddToBlocklistRequest::Fingerprint(fingerprint_id) => { let blocklist_entry_result = state .store .find_blocklist_entry_by_merchant_id_fingerprint_id(merchant_id, fingerprint_id) .await; match blocklist_entry_result { Ok(_) => { return Err(errors::ApiErrorResponse::PreconditionFailed { message: "data associated with the given fingerprint is already blocked" .to_string(), } .into()); } // if it is a db not found error, we can proceed as normal Err(inner) if inner.current_context().is_db_not_found() => {} err @ Err(_) => { err.change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("error fetching blocklist entry from table")?; } } state .store .insert_blocklist_entry(storage::BlocklistNew { merchant_id: merchant_id.to_owned(), fingerprint_id: fingerprint_id.clone(), data_kind: api_models::enums::enums::BlocklistDataKind::PaymentMethod, metadata: None, created_at: common_utils::date_time::now(), }) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("failed to add fingerprint to blocklist")? } }; Ok(blocklist_entry.foreign_into()) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/blocklist/utils.rs | crate: router use api_models::blocklist as api_blocklist; use common_utils::errors::CustomResult; use diesel_models::configs; use super::{errors, transformers::generate_fingerprint, SessionState}; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, payments::PaymentData, }, logger, types::{domain, storage, transformers::ForeignInto}, utils, }; pub async fn toggle_blocklist_guard_for_merchant( state: &SessionState, merchant_id: &common_utils::id_type::MerchantId, query: api_blocklist::ToggleBlocklistQuery, ) -> CustomResult<api_blocklist::ToggleBlocklistResponse, errors::ApiErrorResponse> { { Ok(_config) => { let updated_config = configs::ConfigUpdate::Update { config: Some(query.status.to_string()), }; state .store .update_config_by_key(&key, updated_config) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Error enabling the blocklist guard")?; }<|fim_suffix|> <|fim_middle|> Err(error) => { logger::error!(?error); Err(error) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Error enabling the blocklist guard")?; } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/blocklist/utils.rs | crate: router use api_models::blocklist as api_blocklist; use common_enums::MerchantDecision; use common_utils::errors::CustomResult; use super::{errors, transformers::generate_fingerprint, SessionState}; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, payments::PaymentData, }, logger, types::{domain, storage, transformers::ForeignInto}, utils, }; async fn duplicate_check_insert_bin( bin: &str, state: &SessionState, merchant_id: &common_utils::id_type::MerchantId, data_kind: common_enums::BlocklistDataKind, ) -> RouterResult<storage::Blocklist> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/blocklist/utils.rs | crate: router use api_models::blocklist as api_blocklist; use common_enums::MerchantDecision; use common_utils::errors::CustomResult; use super::{errors, transformers::generate_fingerprint, SessionState}; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, payments::PaymentData, }, logger, types::{domain, storage, transformers::ForeignInto}, utils, }; pub async fn insert_entry_into_blocklist( state: &SessionState, merchant_id: &common_utils::id_type::MerchantId, to_block: api_blocklist::AddToBlocklistRequest, ) -> RouterResult<api_blocklist::AddToBlocklistResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/blocklist/utils.rs | crate: router use api_models::blocklist as api_blocklist; use common_utils::errors::CustomResult; use super::{errors, transformers::generate_fingerprint, SessionState}; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, payments::PaymentData, }, logger, types::{domain, storage, transformers::ForeignInto}, utils, }; async fn delete_card_bin_blocklist_entry( state: &SessionState, bin: &str, merchant_id: &common_utils::id_type::MerchantId, ) -> RouterResult<storage::Blocklist> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/blocklist/utils.rs | crate: router use common_utils::errors::CustomResult; use super::{errors, transformers::generate_fingerprint, SessionState}; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, payments::PaymentData, }, logger, types::{domain, storage, transformers::ForeignInto}, utils, }; fn validate_extended_card_bin(bin: &str) -> RouterResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/blocklist/utils.rs | crate: router use common_utils::errors::CustomResult; use super::{errors, transformers::generate_fingerprint, SessionState}; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, payments::PaymentData, }, logger, types::{domain, storage, transformers::ForeignInto}, utils, }; fn validate_card_bin(bin: &str) -> RouterResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/core/blocklist/utils.rs | crate: router use api_models::blocklist as api_blocklist; use common_utils::errors::CustomResult; use super::{errors, transformers::generate_fingerprint, SessionState}; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, payments::PaymentData, }, logger, types::{domain, storage, transformers::ForeignInto}, utils, }; pub async fn list_blocklist_entries_for_merchant( state: &SessionState, merchant_id: &common_utils::id_type::MerchantId, query: api_blocklist::ListBlocklistQuery, ) -> RouterResult<Vec<api_blocklist::BlocklistResponse>> { state .store .list_blocklist_entries_by_merchant_id_data_kind( merchant_id, query.data_kind, query.limit.into(), query.offset.into(), ) .await .to_not_found_response(errors::ApiErrorResponse::GenericNotFoundError { message: "no blocklist records found".to_string(), }) .map(|v| v.into_iter().map(ForeignInto::foreign_into).collect()) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/blocklist/utils.rs | crate: router use api_models::blocklist as api_blocklist; use common_utils::errors::CustomResult; use super::{errors, transformers::generate_fingerprint, SessionState}; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, payments::PaymentData, }, logger, types::{domain, storage, transformers::ForeignInto}, utils, }; pub async fn delete_entry_from_blocklist( state: &SessionState, merchant_id: &common_utils::id_type::MerchantId, request: api_blocklist::DeleteFromBlocklistRequest, ) -> RouterResult<api_blocklist::DeleteFromBlocklistResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/blocklist/utils.rs | crate: router use api_models::blocklist as api_blocklist; use common_enums::MerchantDecision; use common_utils::errors::CustomResult; use masking::StrongSecret; use super::{errors, transformers::generate_fingerprint, SessionState}; use crate::{ consts, core::{ errors::{RouterResult, StorageErrorExt}, payments::PaymentData, }, logger, types::{domain, storage, transformers::ForeignInto}, utils, }; pub async fn validate_data_for_blocklist<F>( state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, payment_data: &mut PaymentData<F>, ) -> CustomResult<bool, errors::ApiErrorResponse> where F: Send + Clone, { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/unified_authentication_service/types.rs | crate: router use api_models::payments; use hyperswitch_domain_models::{ errors::api_error_response::{self as errors, NotImplementedMessage}, router_request_types::{ authentication::MessageCategory, unified_authentication_service::{ UasAuthenticationRequestData, UasPostAuthenticationRequestData, UasPreAuthenticationRequestData, }, BrowserInformation, }, }; use crate::{ core::{ errors::RouterResult, payments::{helpers::MerchantConnectorAccountType, PaymentData}, }, db::domain, routes::SessionState, }; async fn authentication( _state: &SessionState, _business_profile: &domain::Profile, _payment_method: common_enums::PaymentMethod, _payment_method_data: domain::PaymentMethodData, _billing_address: hyperswitch_domain_models::address::Address, _shipping_address: Option<hyperswitch_domain_models::address::Address>, _browser_details: Option<BrowserInformation>, _amount: Option<common_utils::types::MinorUnit>, _currency: Option<common_enums::Currency>, _message_category: MessageCategory, _device_channel: payments::DeviceChannel, _authentication_data: diesel_models::authentication::Authentication, _return_url: Option<String>, _sdk_information: Option<payments::SdkInformation>, _threeds_method_comp_ind: payments::ThreeDsCompletionIndicator, _email: Option<common_utils::pii::Email>, _webhook_url: String, _three_ds_requestor_url: String, _merchant_connector_account: &MerchantConnectorAccountType, _connector_name: &str, _payment_id: common_utils::id_type::PaymentId, ) -> RouterResult<hyperswitch_domain_models::types::UasAuthenticationRouterData> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/unified_authentication_service/types.rs | crate: router use hyperswitch_domain_models::{ errors::api_error_response::{self as errors, NotImplementedMessage}, router_request_types::{ authentication::MessageCategory, unified_authentication_service::{ UasAuthenticationRequestData, UasPostAuthenticationRequestData, UasPreAuthenticationRequestData, }, BrowserInformation, }, }; use crate::{ core::{ errors::RouterResult, payments::{helpers::MerchantConnectorAccountType, PaymentData}, }, db::domain, routes::SessionState, }; async fn post_authentication( _state: &SessionState, _key_store: &domain::MerchantKeyStore, _business_profile: &domain::Profile, _payment_data: &PaymentData<F>, _merchant_connector_account: &MerchantConnectorAccountType, _connector_name: &str, _payment_method: common_enums::PaymentMethod, _authentication: Option<diesel_models::authentication::Authentication>, ) -> RouterResult<hyperswitch_domain_models::types::UasPostAuthenticationRouterData> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/unified_authentication_service/types.rs | crate: router use hyperswitch_domain_models::{ errors::api_error_response::{self as errors, NotImplementedMessage}, router_request_types::{ authentication::MessageCategory, unified_authentication_service::{ UasAuthenticationRequestData, UasPostAuthenticationRequestData, UasPreAuthenticationRequestData, }, BrowserInformation, }, }; use crate::{ core::{ errors::RouterResult, payments::{helpers::MerchantConnectorAccountType, PaymentData}, }, db::domain, routes::SessionState, }; async fn confirmation( _state: &SessionState, _key_store: &domain::MerchantKeyStore, _business_profile: &domain::Profile, _payment_data: &PaymentData<F>, _merchant_connector_account: &MerchantConnectorAccountType, _connector_name: &str, _payment_method: common_enums::PaymentMethod, ) -> RouterResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/core/unified_authentication_service/types.rs | crate: router use hyperswitch_domain_models::{ errors::api_error_response::{self as errors, NotImplementedMessage}, router_request_types::{ authentication::MessageCategory, unified_authentication_service::{ UasAuthenticationRequestData, UasPostAuthenticationRequestData, UasPreAuthenticationRequestData, }, BrowserInformation, }, }; use crate::{ core::{ errors::RouterResult, payments::{helpers::MerchantConnectorAccountType, PaymentData}, }, db::domain, routes::SessionState, }; async fn post_authentication( _state: &SessionState, _key_store: &domain::MerchantKeyStore, _business_profile: &domain::Profile, _payment_data: &PaymentData<F>, _merchant_connector_account: &MerchantConnectorAccountType, _connector_name: &str, _payment_method: common_enums::PaymentMethod, _authentication: Option<diesel_models::authentication::Authentication>, ) -> RouterResult<hyperswitch_domain_models::types::UasPostAuthenticationRouterData> { Err(errors::ApiErrorResponse::NotImplemented { message: NotImplementedMessage::Reason("post_authentication".to_string()), } .into()) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/unified_authentication_service/types.rs | crate: router use hyperswitch_domain_models::{ errors::api_error_response::{self as errors, NotImplementedMessage}, router_request_types::{ authentication::MessageCategory, unified_authentication_service::{ UasAuthenticationRequestData, UasPostAuthenticationRequestData, UasPreAuthenticationRequestData, }, BrowserInformation, }, }; use crate::{ core::{ errors::RouterResult, payments::{helpers::MerchantConnectorAccountType, PaymentData}, }, db::domain, routes::SessionState, }; fn get_post_authentication_request_data( _authentication: Option<diesel_models::authentication::Authentication>, ) -> RouterResult<UasPostAuthenticationRequestData> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/unified_authentication_service/types.rs | crate: router use api_models::payments; use hyperswitch_domain_models::{ errors::api_error_response::{self as errors, NotImplementedMessage}, router_request_types::{ authentication::MessageCategory, unified_authentication_service::{ UasAuthenticationRequestData, UasPostAuthenticationRequestData, UasPreAuthenticationRequestData, }, BrowserInformation, }, }; use crate::{ core::{ errors::RouterResult, payments::{helpers::MerchantConnectorAccountType, PaymentData}, }, db::domain, routes::SessionState, }; fn get_authentication_request_data( _payment_method_data: domain::PaymentMethodData, _billing_address: hyperswitch_domain_models::address::Address, _shipping_address: Option<hyperswitch_domain_models::address::Address>, _browser_details: Option<BrowserInformation>, _amount: Option<common_utils::types::MinorUnit>, _currency: Option<common_enums::Currency>, _message_category: MessageCategory, _device_channel: payments::DeviceChannel, _authentication: diesel_models::authentication::Authentication, _return_url: Option<String>, _sdk_information: Option<payments::SdkInformation>, _threeds_method_comp_ind: payments::ThreeDsCompletionIndicator, _email: Option<common_utils::pii::Email>, _webhook_url: String, _three_ds_requestor_url: String, ) -> RouterResult<UasAuthenticationRequestData> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/unified_authentication_service/types.rs | crate: router use hyperswitch_domain_models::{ errors::api_error_response::{self as errors, NotImplementedMessage}, router_request_types::{ authentication::MessageCategory, unified_authentication_service::{ UasAuthenticationRequestData, UasPostAuthenticationRequestData, UasPreAuthenticationRequestData, }, BrowserInformation, }, }; use crate::{ core::{ errors::RouterResult, payments::{helpers::MerchantConnectorAccountType, PaymentData}, }, db::domain, routes::SessionState, }; async fn pre_authentication( _state: &SessionState, _key_store: &domain::MerchantKeyStore, _business_profile: &domain::Profile, _payment_data: &PaymentData<F>, _merchant_connector_account: &MerchantConnectorAccountType, _connector_name: &str, _authentication_id: &str, _payment_method: common_enums::PaymentMethod, ) -> RouterResult<hyperswitch_domain_models::types::UasPreAuthenticationRouterData> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/unified_authentication_service/types.rs | crate: router use hyperswitch_domain_models::{ errors::api_error_response::{self as errors, NotImplementedMessage}, router_request_types::{ authentication::MessageCategory, unified_authentication_service::{ UasAuthenticationRequestData, UasPostAuthenticationRequestData, UasPreAuthenticationRequestData, }, BrowserInformation, }, }; use crate::{ core::{ errors::RouterResult, payments::{helpers::MerchantConnectorAccountType, PaymentData}, }, db::domain, routes::SessionState, }; fn get_pre_authentication_request_data( _payment_data: &PaymentData<F>, ) -> RouterResult<UasPreAuthenticationRequestData> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/unified_authentication_service/utils.rs | crate: router use std::marker::PhantomData; use common_enums::enums::PaymentMethod; use common_utils::ext_traits::ValueExt; use hyperswitch_domain_models::{ errors::api_error_response::ApiErrorResponse, payment_address::PaymentAddress, router_data::{ConnectorAuthType, ErrorResponse, RouterData}, router_data_v2::UasFlowData, router_request_types::unified_authentication_service::UasAuthenticationResponseData, }; use super::types::{ IRRELEVANT_ATTEMPT_ID_IN_AUTHENTICATION_FLOW, IRRELEVANT_CONNECTOR_REQUEST_REFERENCE_ID_IN_AUTHENTICATION_FLOW, }; use crate::{ core::{ errors::{utils::ConnectorErrorExt, RouterResult}, payments, }, services::{self, execute_connector_processing_step}, types::{api, transformers::ForeignFrom}, SessionState, }; pub fn construct_uas_router_data<F: Clone, Req, Res>( state: &SessionState, authentication_connector_name: String, payment_method: PaymentMethod, merchant_id: common_utils::id_type::MerchantId, address: Option<PaymentAddress>, request_data: Req, merchant_connector_account: &payments::helpers::MerchantConnectorAccountType, authentication_id: Option<String>, payment_id: common_utils::id_type::PaymentId, ) -> RouterResult<RouterData<F, Req, Res>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/unified_authentication_service/utils.rs | crate: router use std::marker::PhantomData; use hyperswitch_domain_models::{ errors::api_error_response::ApiErrorResponse, payment_address::PaymentAddress, router_data::{ConnectorAuthType, ErrorResponse, RouterData}, router_data_v2::UasFlowData, router_request_types::unified_authentication_service::UasAuthenticationResponseData, }; use crate::{ core::{ errors::{utils::ConnectorErrorExt, RouterResult}, payments, }, services::{self, execute_connector_processing_step}, types::{api, transformers::ForeignFrom}, SessionState, }; pub async fn do_auth_connector_call<F, Req, Res>( state: &SessionState, authentication_connector_name: String, router_data: RouterData<F, Req, Res>, ) -> RouterResult<RouterData<F, Req, Res>> where Req: std::fmt::Debug + Clone + 'static, Res: std::fmt::Debug + Clone + 'static, F: std::fmt::Debug + Clone + 'static, dyn api::Connector + Sync: services::api::ConnectorIntegration<F, Req, Res>, dyn api::ConnectorV2 + Sync: services::api::ConnectorIntegrationV2<F, UasFlowData, Req, Res>, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/unified_authentication_service/utils.rs | crate: router use common_enums::enums::PaymentMethod; pub fn get_checkout_event_status_and_reason( attempt_status: common_enums::AttemptStatus, ) -> (Option<String>, Option<String>) { { common_enums::AttemptStatus::Charged | common_enums::AttemptStatus::Authorized => ( Some("02".to_string()), Some("Approval Code received".to_string()), ),<|fim_suffix|> <|fim_middle|> _ => ( Some("03".to_string()), Some("No Approval Code received".to_string()), ), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/unified_authentication_service/utils.rs | crate: router use common_enums::enums::PaymentMethod; pub fn get_checkout_event_status_and_reason( attempt_status: common_enums::AttemptStatus, ) -> (Option<String>, Option<String>) { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/unified_authentication_service/utils.rs | crate: router use common_enums::enums::PaymentMethod; use hyperswitch_domain_models::{ errors::api_error_response::ApiErrorResponse, payment_address::PaymentAddress, router_data::{ConnectorAuthType, ErrorResponse, RouterData}, router_data_v2::UasFlowData, router_request_types::unified_authentication_service::UasAuthenticationResponseData, }; use crate::{ core::{ errors::{utils::ConnectorErrorExt, RouterResult}, payments, }, services::{self, execute_connector_processing_step}, types::{api, transformers::ForeignFrom}, SessionState, }; pub async fn external_authentication_update_trackers<F: Clone, Req>( state: &SessionState, router_data: RouterData<F, Req, UasAuthenticationResponseData>, authentication: diesel_models::authentication::Authentication, acquirer_details: Option< hyperswitch_domain_models::router_request_types::authentication::AcquirerDetails, >, ) -> RouterResult<diesel_models::authentication::Authentication> { { UasAuthenticationResponseData::PreAuthentication { authentication_details, } => Ok( diesel_models::authentication::AuthenticationUpdate::PreAuthenticationUpdate { threeds_server_transaction_id: authentication_details .threeds_server_transaction_id .ok_or(ApiErrorResponse::InternalServerError) .attach_printable( "missing threeds_server_transaction_id in PreAuthentication Details", )?, maximum_supported_3ds_version: authentication_details .maximum_supported_3ds_version .ok_or(ApiErrorResponse::InternalServerError) .attach_printable( "missing maximum_supported_3ds_version in PreAuthentication Details", )?, connector_authentication_id: authentication_details .connector_authentication_id .ok_or(ApiErrorResponse::InternalServerError) .attach_printable( "missing connector_authentication_id in PreAuthentication Details", )?, three_ds_method_data: authentication_details.three_ds_method_data, three_ds_method_url: authentication_details.three_ds_method_url, message_version: authentication_details .message_version .ok_or(ApiErrorResponse::InternalServerError) .attach_printable("missing message_version in PreAuthentication Details")?, connector_metadata: authentication_details.connector_metadata, authentication_status: common_enums::AuthenticationStatus::Pending, acquirer_bin: acquirer_details .as_ref() .map(|acquirer_details| acquirer_details.acquirer_bin.clone()), acquirer_merchant_id: acquirer_details .as_ref() .map(|acquirer_details| acquirer_details.acquirer_merchant_id.clone()), acquirer_country_code: acquirer_details .and_then(|acquirer_details| acquirer_details.acquirer_country_code), directory_server_id: authentication_details.directory_server_id, }, ),<|fim_suffix|> <|fim_middle|> UasAuthenticationResponseData::Confirmation { .. } => Err( ApiErrorResponse::InternalServerError, ) .attach_printable("unexpected api confirmation in external authentication flow."), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/revenue_recovery/types.rs | crate: router pcr_data.key_store.clone(), pcr_data.profile.clone(), operation, req, get_tracker_response, payments::CallConnectorAction::Trigger, hyperswitch_domain_models::payments::HeaderPayload::default(), )) .await?; Ok(payment_data) } pub async fn update_payment_intent_api( state: &SessionState, global_payment_id: id_type::GlobalPaymentId, pcr_data: &storage::revenue_recovery::PcrPaymentData, update_req: PaymentsUpdateIntentRequest, ) -> RouterResult<PaymentIntentData<payments_types::PaymentUpdateIntent>> { // TODO : Use api handler instead of calling payments_intent_operation_core let operation = payments::operations::PaymentUpdateIntent; let (payment_data, _req, customer) = payments::payments_intent_operation_core::< payments_types::PaymentUpdateIntent, _, _, PaymentIntentData<payments_types::PaymentUpdateIntent>, pub async fn update_payment_intent_api( state: &SessionState, global_payment_id: id_type::GlobalPaymentId, pcr_data: &storage::revenue_recovery::PcrPaymentData, update_req: PaymentsUpdateIntentRequest, ) -> RouterResult<PaymentIntentData<payments_types::PaymentUpdateIntent>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/revenue_recovery/types.rs | crate: router use api_models::{ enums as api_enums, mandates::RecurringDetails, payments::{ AmountDetails, FeatureMetadata, PaymentRevenueRecoveryMetadata, PaymentsUpdateIntentRequest, ProxyPaymentsRequest, }, }; use hyperswitch_domain_models::{ business_profile, merchant_connector_account, payments::{ self as domain_payments, payment_attempt, PaymentConfirmData, PaymentIntent, PaymentIntentData, }, router_data_v2::{self, flow_common_types}, router_flow_types, router_request_types::revenue_recovery as revenue_recovery_request, router_response_types::revenue_recovery as revenue_recovery_response, ApiModelToDieselModelConvertor, }; use crate::{ core::{ errors::{self, RouterResult}, payments::{self, helpers, operations::Operation}, revenue_recovery::{self as core_pcr}, }, db::StorageInterface, logger, routes::SessionState, services::{self, connector_integration_interface::RouterDataConversion}, types::{ self, api as api_types, api::payments as payments_types, storage, transformers::ForeignInto, }, workflows::revenue_recovery::get_schedule_time_to_retry_mit_payments, }; async fn call_proxy_api( state: &SessionState, payment_intent: &PaymentIntent, pcr_data: &storage::revenue_recovery::PcrPaymentData, revenue_recovery: &PaymentRevenueRecoveryMetadata, ) -> RouterResult<PaymentConfirmData<payments_types::Authorize>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/core/revenue_recovery/types.rs | crate: router use std::marker::PhantomData; use common_utils::{ self, ext_traits::{OptionExt, ValueExt}, id_type, }; use diesel_models::{enums, process_tracker::business_status, types as diesel_types}; use error_stack::{self, ResultExt}; use hyperswitch_domain_models::{ business_profile, merchant_connector_account, payments::{ self as domain_payments, payment_attempt, PaymentConfirmData, PaymentIntent, PaymentIntentData, }, router_data_v2::{self, flow_common_types}, router_flow_types, router_request_types::revenue_recovery as revenue_recovery_request, router_response_types::revenue_recovery as revenue_recovery_response, ApiModelToDieselModelConvertor, }; use crate::{ core::{ errors::{self, RouterResult}, payments::{self, helpers, operations::Operation}, revenue_recovery::{self as core_pcr}, }, db::StorageInterface, logger, routes::SessionState, services::{self, connector_integration_interface::RouterDataConversion}, types::{ self, api as api_types, api::payments as payments_types, storage, transformers::ForeignInto, }, workflows::revenue_recovery::get_schedule_time_to_retry_mit_payments, }; type RecoveryResult<T> = error_stack::Result<T, errors::RecoveryError>; pub fn construct_recovery_record_back_router_data( &self, state: &SessionState, billing_mca: &merchant_connector_account::MerchantConnectorAccount, payment_attempt: &payment_attempt::PaymentAttempt, payment_intent: &PaymentIntent, ) -> RecoveryResult<hyperswitch_domain_models::types::RevenueRecoveryRecordBackRouterData> { let auth_type: types::ConnectorAuthType = helpers::MerchantConnectorAccountType::DbVal(Box::new(billing_mca.clone())) .get_connector_account_details() .parse_value("ConnectorAuthType") .change_context(errors::RecoveryError::RecordBackToBillingConnectorFailed)?; let merchant_reference_id = payment_intent .merchant_reference_id .clone() .ok_or(errors::RecoveryError::RecordBackToBillingConnectorFailed) .attach_printable( "Merchant reference id not found while recording back to billing connector", )?; let router_data = router_data_v2::RouterDataV2 { flow: PhantomData::<router_flow_types::RecoveryRecordBack>, tenant_id: state.tenant.tenant_id.clone(), resource_common_data: flow_common_types::RevenueRecoveryRecordBackData, connector_auth_type: auth_type, request: revenue_recovery_request::RevenueRecoveryRecordBackRequest { merchant_reference_id, amount: payment_attempt.get_total_amount(), currency: payment_intent.amount_details.currency, payment_method_type: Some(payment_attempt.payment_method_subtype), attempt_status: payment_attempt.status, connector_transaction_id: payment_attempt .connector_payment_id .as_ref() .map(|id| common_utils::types::ConnectorTransactionId::TxnId(id.clone())), }, response: Err(types::ErrorResponse::default()), }; let old_router_data = flow_common_types::RevenueRecoveryRecordBackData::to_old_router_data(router_data) .change_context(errors::RecoveryError::RecordBackToBillingConnectorFailed) .attach_printable("Cannot construct record back router data")?; Ok(old_router_data) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/revenue_recovery/types.rs | crate: router status: enums::ProcessTrackerStatus::Review, business_status: Some(String::from(business_status::EXECUTE_WORKFLOW_COMPLETE)), }; // update the process tracker status as Review db.as_scheduler() .update_process(execute_task_process.clone(), pt_update) .await?; Ok(()) } } } async fn record_back_to_billing_connector( &self, state: &SessionState, payment_attempt: &payment_attempt::PaymentAttempt, payment_intent: &PaymentIntent, billing_mca: &merchant_connector_account::MerchantConnectorAccount, ) -> RecoveryResult<()> { let connector_name = billing_mca.connector_name.to_string(); let connector_data = api_types::ConnectorData::get_connector_by_name( &state.conf.connectors, &connector_name, api_types::GetToken::Connector, Some(billing_mca.get_id()), async fn record_back_to_billing_connector( &self, state: &SessionState, payment_attempt: &payment_attempt::PaymentAttempt, payment_intent: &PaymentIntent, billing_mca: &merchant_connector_account::MerchantConnectorAccount, ) -> RecoveryResult<()> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/revenue_recovery/types.rs | crate: router } #[derive(Debug, Clone)] pub enum Action { SyncPayment(id_type::GlobalAttemptId), RetryPayment(PrimitiveDateTime), TerminalFailure(payment_attempt::PaymentAttempt), SuccessfulPayment(payment_attempt::PaymentAttempt), ReviewPayment, ManualReviewAction, } impl Action { pub async fn execute_payment( state: &SessionState, merchant_id: &id_type::MerchantId, payment_intent: &PaymentIntent, process: &storage::ProcessTracker, pcr_data: &storage::revenue_recovery::PcrPaymentData, revenue_recovery_metadata: &PaymentRevenueRecoveryMetadata, ) -> RecoveryResult<Self> { let db = &*state.store; let response = call_proxy_api(state, payment_intent, pcr_data, revenue_recovery_metadata).await; // handle proxy api's response match response { pub async fn execute_payment( state: &SessionState, merchant_id: &id_type::MerchantId, payment_intent: &PaymentIntent, process: &storage::ProcessTracker, pcr_data: &storage::revenue_recovery::PcrPaymentData, revenue_recovery_metadata: &PaymentRevenueRecoveryMetadata, ) -> RecoveryResult<Self> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/revenue_recovery/types.rs | crate: router }; Ok(()) } } #[derive(Debug, Clone)] pub enum Decision { Execute, Psync(enums::AttemptStatus, id_type::GlobalAttemptId), InvalidDecision, } impl Decision { pub async fn get_decision_based_on_params( state: &SessionState, intent_status: enums::IntentStatus, called_connector: enums::PaymentConnectorTransmission, active_attempt_id: Option<id_type::GlobalAttemptId>, pcr_data: &storage::revenue_recovery::PcrPaymentData, payment_id: &id_type::GlobalPaymentId, ) -> RecoveryResult<Self> { Ok(match (intent_status, called_connector, active_attempt_id) { ( enums::IntentStatus::Failed, enums::PaymentConnectorTransmission::ConnectorCallUnsuccessful, None, pub async fn get_decision_based_on_params( state: &SessionState, intent_status: enums::IntentStatus, called_connector: enums::PaymentConnectorTransmission, active_attempt_id: Option<id_type::GlobalAttemptId>, pcr_data: &storage::revenue_recovery::PcrPaymentData, payment_id: &id_type::GlobalPaymentId, ) -> RecoveryResult<Self> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/revenue_recovery/types.rs | crate: router /// The status of Passive Churn Payments #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] pub enum PcrAttemptStatus { Succeeded, Failed, Processing, InvalidStatus(String), // Cancelled, } impl PcrAttemptStatus { pub(crate) async fn update_pt_status_based_on_attempt_status_for_execute_payment( &self, db: &dyn StorageInterface, execute_task_process: &storage::ProcessTracker, ) -> Result<(), errors::ProcessTrackerError> { match &self { Self::Succeeded | Self::Failed | Self::Processing => { // finish the current execute task db.finish_process_with_business_status( execute_task_process.clone(), business_status::EXECUTE_WORKFLOW_COMPLETE_FOR_PSYNC, ) .await?; pub(crate) async fn update_pt_status_based_on_attempt_status_for_execute_payment( &self, db: &dyn StorageInterface, execute_task_process: &storage::ProcessTracker, ) -> Result<(), errors::ProcessTrackerError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/revenue_recovery/types.rs | crate: router let record_back_response = match response.response { Ok(response) => Ok(response), error @ Err(_) => { router_env::logger::error!(?error); Err(errors::RecoveryError::RecordBackToBillingConnectorFailed) .attach_printable("Failed while recording back to billing connector") } }?; Ok(()) } pub fn construct_recovery_record_back_router_data( &self, state: &SessionState, billing_mca: &merchant_connector_account::MerchantConnectorAccount, payment_attempt: &payment_attempt::PaymentAttempt, payment_intent: &PaymentIntent, ) -> RecoveryResult<hyperswitch_domain_models::types::RevenueRecoveryRecordBackRouterData> { let auth_type: types::ConnectorAuthType = helpers::MerchantConnectorAccountType::DbVal(Box::new(billing_mca.clone())) .get_connector_account_details() .parse_value("ConnectorAuthType") .change_context(errors::RecoveryError::RecordBackToBillingConnectorFailed)?; pub fn construct_recovery_record_back_router_data( &self, state: &SessionState, billing_mca: &merchant_connector_account::MerchantConnectorAccount, payment_attempt: &payment_attempt::PaymentAttempt, payment_intent: &PaymentIntent, ) -> RecoveryResult<hyperswitch_domain_models::types::RevenueRecoveryRecordBackRouterData> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/revenue_recovery/types.rs | crate: router status: enums::ProcessTrackerStatus::Review, business_status: Some(String::from(business_status::EXECUTE_WORKFLOW_COMPLETE)), }; // update the process tracker status as Review db.as_scheduler() .update_process(execute_task_process.clone(), pt_update) .await?; Ok(()) } } } async fn record_back_to_billing_connector( &self, state: &SessionState, payment_attempt: &payment_attempt::PaymentAttempt, payment_intent: &PaymentIntent, billing_mca: &merchant_connector_account::MerchantConnectorAccount, ) -> RecoveryResult<()> { let connector_name = billing_mca.connector_name.to_string(); let connector_data = api_types::ConnectorData::get_connector_by_name( &state.conf.connectors, &connector_name, api_types::GetToken::Connector, Some(billing_mca.get_id()), async fn record_back_to_billing_connector( &self, state: &SessionState, payment_attempt: &payment_attempt::PaymentAttempt, payment_intent: &PaymentIntent, billing_mca: &merchant_connector_account::MerchantConnectorAccount, ) -> RecoveryResult<()> { { Ok(response) => Ok(response),<|fim_suffix|> <|fim_middle|> error @ Err(_) => { router_env::logger::error!(?error); Err(errors::RecoveryError::RecordBackToBillingConnectorFailed) .attach_printable("Failed while recording back to billing connector") } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/revenue_recovery/types.rs | crate: router use common_utils::{ self, ext_traits::{OptionExt, ValueExt}, id_type, }; use hyperswitch_domain_models::{ business_profile, merchant_connector_account, payments::{ self as domain_payments, payment_attempt, PaymentConfirmData, PaymentIntent, PaymentIntentData, }, router_data_v2::{self, flow_common_types}, router_flow_types, router_request_types::revenue_recovery as revenue_recovery_request, router_response_types::revenue_recovery as revenue_recovery_response, ApiModelToDieselModelConvertor, }; use crate::{ core::{ errors::{self, RouterResult}, payments::{self, helpers, operations::Operation}, revenue_recovery::{self as core_pcr}, }, db::StorageInterface, logger, routes::SessionState, services::{self, connector_integration_interface::RouterDataConversion}, types::{ self, api as api_types, api::payments as payments_types, storage, transformers::ForeignInto, }, workflows::revenue_recovery::get_schedule_time_to_retry_mit_payments, }; type RecoveryResult<T> = error_stack::Result<T, errors::RecoveryError>; pub(crate) async fn decide_retry_failure_action( db: &dyn StorageInterface, merchant_id: &id_type::MerchantId, pt: storage::ProcessTracker, payment_attempt: &payment_attempt::PaymentAttempt, ) -> RecoveryResult<Self> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/revenue_recovery/types.rs | crate: router Err(err) => // check for an active attempt being constructed or not { logger::error!(execute_payment_res=?err); match payment_intent.active_attempt_id.clone() { Some(attempt_id) => Ok(Self::SyncPayment(attempt_id)), None => Ok(Self::ReviewPayment), } } } } pub async fn execute_payment_task_response_handler( &self, state: &SessionState, payment_intent: &PaymentIntent, execute_task_process: &storage::ProcessTracker, pcr_data: &storage::revenue_recovery::PcrPaymentData, revenue_recovery_metadata: &mut PaymentRevenueRecoveryMetadata, billing_mca: &merchant_connector_account::MerchantConnectorAccount, ) -> Result<(), errors::ProcessTrackerError> { let db = &*state.store; match self { Self::SyncPayment(attempt_id) => { core_pcr::insert_psync_pcr_task( pub async fn execute_payment_task_response_handler( &self, state: &SessionState, payment_intent: &PaymentIntent, execute_task_process: &storage::ProcessTracker, pcr_data: &storage::revenue_recovery::PcrPaymentData, revenue_recovery_metadata: &mut PaymentRevenueRecoveryMetadata, billing_mca: &merchant_connector_account::MerchantConnectorAccount, ) -> Result<(), errors::ProcessTrackerError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/revenue_recovery/transformers.rs | crate: router use common_enums::AttemptStatus; fn foreign_from(s: AttemptStatus) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/revenue_recovery/transformers.rs | crate: router use common_enums::AttemptStatus; fn foreign_from(s: AttemptStatus) -> Self { { AttemptStatus::Authorized | AttemptStatus::Charged | AttemptStatus::AutoRefunded => { Self::Succeeded }<|fim_suffix|> <|fim_middle|> AttemptStatus::Voided | AttemptStatus::ConfirmationAwaited | AttemptStatus::PartialCharged | AttemptStatus::PartialChargedAndChargeable | AttemptStatus::PaymentMethodAwaited | AttemptStatus::AuthenticationPending | AttemptStatus::DeviceDataCollectionPending | AttemptStatus::Unresolved => Self::InvalidStatus(s.to_string()), } }
ast_fragments