text stringlengths 70 351k | source stringclasses 4
values |
|---|---|
<|fim_prefix|>
// file: hyperswitch/crates/router/src/types.rs | crate: router
use hyperswitch_domain_models::router_flow_types::{
self,
access_token_auth::AccessTokenAuth,
dispute::{Accept, Defend, Evidence},
files::{Retrieve, Upload},
mandate_revoke::MandateRevoke,
payments::{
Approve, Authorize, AuthorizeSessionToken, Balance, CalculateTax, Capture,
CompleteAuthorize, CreateConnectorCustomer, IncrementalAuthorization, InitPayment, PSync,
PostProcessing, PostSessionTokens, PreProcessing, Reject, SdkSessionUpdate, Session,
SetupMandate, Void,
},
refunds::{Execute, RSync},
webhooks::VerifyWebhookSource,
};
use crate::{
consts,
core::{
errors::{self},
payments::{OperationSessionGetters, PaymentData},
},
services,
types::transformers::{ForeignFrom, ForeignTryFrom},
};
pub type RefundsRouterData<F> = RouterData<F, RefundsData, RefundsResponseData>;
pub type RefundsResponseRouterData<F, R> =
ResponseRouterData<F, R, RefundsData, RefundsResponseData>;
pub type PayoutsRouterData<F> = RouterData<F, PayoutsData, PayoutsResponseData>;
pub type PayoutsResponseRouterData<F, R> =
ResponseRouterData<F, R, PayoutsData, PayoutsResponseData>;
pub type PayoutActionData = Vec<(
storage::Payouts,
storage::PayoutAttempt,
Option<domain::Customer>,
Option<api_models::payments::Address>,
)>;
fn get_amount_capturable<F>(
&self,
_payment_data: &PaymentData<F>,
_attempt_status: common_enums::AttemptStatus,
) -> Option<i64>
where
F: Clone,
{
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/types.rs | crate: router
use hyperswitch_domain_models::router_flow_types::{
self,
access_token_auth::AccessTokenAuth,
dispute::{Accept, Defend, Evidence},
files::{Retrieve, Upload},
mandate_revoke::MandateRevoke,
payments::{
Approve, Authorize, AuthorizeSessionToken, Balance, CalculateTax, Capture,
CompleteAuthorize, CreateConnectorCustomer, IncrementalAuthorization, InitPayment, PSync,
PostProcessing, PostSessionTokens, PreProcessing, Reject, SdkSessionUpdate, Session,
SetupMandate, Void,
},
refunds::{Execute, RSync},
webhooks::VerifyWebhookSource,
};
use crate::{
consts,
core::{
errors::{self},
payments::{OperationSessionGetters, PaymentData},
},
services,
types::transformers::{ForeignFrom, ForeignTryFrom},
};
pub type RefundsRouterData<F> = RouterData<F, RefundsData, RefundsResponseData>;
pub type RefundsResponseRouterData<F, R> =
ResponseRouterData<F, R, RefundsData, RefundsResponseData>;
pub type PayoutsRouterData<F> = RouterData<F, PayoutsData, PayoutsResponseData>;
pub type PayoutsResponseRouterData<F, R> =
ResponseRouterData<F, R, PayoutsData, PayoutsResponseData>;
pub type PayoutActionData = Vec<(
storage::Payouts,
storage::PayoutAttempt,
Option<domain::Customer>,
Option<api_models::payments::Address>,
)>;
fn get_amount_capturable<F>(
&self,
_payment_data: &PaymentData<F>,
attempt_status: common_enums::AttemptStatus,
) -> Option<i64>
where
F: Clone,
{
{
common_enums::IntentStatus::Succeeded
| common_enums::IntentStatus::PartiallyCaptured => Some(0),<|fim_suffix|>
<|fim_middle|>
common_enums::IntentStatus::Processing
| common_enums::IntentStatus::Cancelled
| common_enums::IntentStatus::Failed
| common_enums::IntentStatus::RequiresCustomerAction
| common_enums::IntentStatus::RequiresMerchantAction
| common_enums::IntentStatus::RequiresPaymentMethod
| common_enums::IntentStatus::RequiresConfirmation
| common_enums::IntentStatus::RequiresCapture
| common_enums::IntentStatus::PartiallyCapturedAndCapturable => None,
}
} | ast_fragments |
// file: hyperswitch/crates/router/src/types.rs | crate: router
use hyperswitch_domain_models::router_flow_types::{
self,
access_token_auth::AccessTokenAuth,
dispute::{Accept, Defend, Evidence},
files::{Retrieve, Upload},
mandate_revoke::MandateRevoke,
payments::{
Approve, Authorize, AuthorizeSessionToken, Balance, CalculateTax, Capture,
CompleteAuthorize, CreateConnectorCustomer, IncrementalAuthorization, InitPayment, PSync,
PostProcessing, PostSessionTokens, PreProcessing, Reject, SdkSessionUpdate, Session,
SetupMandate, Void,
},
refunds::{Execute, RSync},
webhooks::VerifyWebhookSource,
};
use crate::{
consts,
core::{
errors::{self},
payments::{OperationSessionGetters, PaymentData},
},
services,
types::transformers::{ForeignFrom, ForeignTryFrom},
};
pub type RefundsRouterData<F> = RouterData<F, RefundsData, RefundsResponseData>;
pub type RefundsResponseRouterData<F, R> =
ResponseRouterData<F, R, RefundsData, RefundsResponseData>;
pub type PayoutsRouterData<F> = RouterData<F, PayoutsData, PayoutsResponseData>;
pub type PayoutsResponseRouterData<F, R> =
ResponseRouterData<F, R, PayoutsData, PayoutsResponseData>;
pub type PayoutActionData = Vec<(
storage::Payouts,
storage::PayoutAttempt,
Option<domain::Customer>,
Option<api_models::payments::Address>,
)>;
fn get_captured_amount<F>(&self, _payment_data: &PaymentData<F>) -> Option<i64>
where
F: Clone,
{
Some(self.amount_to_capture)
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/types.rs | crate: router
use hyperswitch_domain_models::router_flow_types::{
self,
access_token_auth::AccessTokenAuth,
dispute::{Accept, Defend, Evidence},
files::{Retrieve, Upload},
mandate_revoke::MandateRevoke,
payments::{
Approve, Authorize, AuthorizeSessionToken, Balance, CalculateTax, Capture,
CompleteAuthorize, CreateConnectorCustomer, IncrementalAuthorization, InitPayment, PSync,
PostProcessing, PostSessionTokens, PreProcessing, Reject, SdkSessionUpdate, Session,
SetupMandate, Void,
},
refunds::{Execute, RSync},
webhooks::VerifyWebhookSource,
};
use crate::{
consts,
core::{
errors::{self},
payments::{OperationSessionGetters, PaymentData},
},
services,
types::transformers::{ForeignFrom, ForeignTryFrom},
};
pub type RefundsRouterData<F> = RouterData<F, RefundsData, RefundsResponseData>;
pub type RefundsResponseRouterData<F, R> =
ResponseRouterData<F, R, RefundsData, RefundsResponseData>;
pub type PayoutsRouterData<F> = RouterData<F, PayoutsData, PayoutsResponseData>;
pub type PayoutsResponseRouterData<F, R> =
ResponseRouterData<F, R, PayoutsData, PayoutsResponseData>;
pub type PayoutActionData = Vec<(
storage::Payouts,
storage::PayoutAttempt,
Option<domain::Customer>,
Option<api_models::payments::Address>,
)>;
fn get_captured_amount<F>(&self, _payment_data: &PaymentData<F>) -> Option<i64>
where
F: Clone,
{
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/types.rs | crate: router
use hyperswitch_domain_models::router_flow_types::{
self,
access_token_auth::AccessTokenAuth,
dispute::{Accept, Defend, Evidence},
files::{Retrieve, Upload},
mandate_revoke::MandateRevoke,
payments::{
Approve, Authorize, AuthorizeSessionToken, Balance, CalculateTax, Capture,
CompleteAuthorize, CreateConnectorCustomer, IncrementalAuthorization, InitPayment, PSync,
PostProcessing, PostSessionTokens, PreProcessing, Reject, SdkSessionUpdate, Session,
SetupMandate, Void,
},
refunds::{Execute, RSync},
webhooks::VerifyWebhookSource,
};
use crate::{
connector::utils::missing_field_err,
core::utils::IRRELEVANT_CONNECTOR_REQUEST_REFERENCE_ID_IN_PAYOUTS_FLOW,
};
use crate::{
consts,
core::{
errors::{self},
payments::{OperationSessionGetters, PaymentData},
},
services,
types::transformers::{ForeignFrom, ForeignTryFrom},
};
fn get_external_account_account_holder_type(&self) -> Result<String, Self::Error> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/events.rs | crate: router
use std::collections::HashMap;
use error_stack::ResultExt;
use events::{EventsError, Message, MessagingInterface};
use masking::ErasedMaskSerialize;
use time::PrimitiveDateTime;
fn send_message<T>(
&self,
data: T,
metadata: HashMap<String, String>,
timestamp: PrimitiveDateTime,
) -> error_stack::Result<(), EventsError>
where
T: Message<Class = Self::MessageClass> + ErasedMaskSerialize,
{
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/events.rs | crate: router
use storage_impl::{
config::TenantConfig,
errors::{ApplicationError, StorageError, StorageResult},
};
use crate::{
db::KafkaProducer,
services::kafka::{KafkaMessage, KafkaSettings},
};
pub async fn get_event_handler(&self) -> StorageResult<EventsHandler> {
{
Self::Kafka { kafka } => EventsHandler::Kafka(
KafkaProducer::create(kafka)
.await
.change_context(StorageError::InitializationError)?,
),<|fim_suffix|>
<|fim_middle|>
Self::Logs => EventsHandler::Logs(event_logger::EventLogger::default()),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/events.rs | crate: router
use std::collections::HashMap;
use error_stack::ResultExt;
use events::{EventsError, Message, MessagingInterface};
use masking::ErasedMaskSerialize;
use time::PrimitiveDateTime;
fn send_message<T>(
&self,
data: T,
metadata: HashMap<String, String>,
timestamp: PrimitiveDateTime,
) -> error_stack::Result<(), EventsError>
where
T: Message<Class = Self::MessageClass> + ErasedMaskSerialize,
{
{
Self::Kafka(a) => a.send_message(data, metadata, timestamp),<|fim_suffix|>
<|fim_middle|>
Self::Logs(a) => a.send_message(data, metadata, timestamp),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/events.rs | crate: router
use storage_impl::{
config::TenantConfig,
errors::{ApplicationError, StorageError, StorageResult},
};
pub fn add_tenant(&mut self, tenant_config: &dyn TenantConfig) {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/events.rs | crate: router
use router_env::logger;
use crate::{
db::KafkaProducer,
services::kafka::{KafkaMessage, KafkaSettings},
};
pub fn log_event<T: KafkaMessage>(&self, event: &T) {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/events.rs | crate: router
use storage_impl::{
config::TenantConfig,
errors::{ApplicationError, StorageError, StorageResult},
};
use crate::{
db::KafkaProducer,
services::kafka::{KafkaMessage, KafkaSettings},
};
pub fn validate(&self) -> Result<(), ApplicationError> {
{
Self::Kafka { kafka } => kafka.validate(),<|fim_suffix|>
<|fim_middle|>
Self::Logs => Ok(()),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/events.rs | crate: router
use storage_impl::{
config::TenantConfig,
errors::{ApplicationError, StorageError, StorageResult},
};
use crate::{
db::KafkaProducer,
services::kafka::{KafkaMessage, KafkaSettings},
};
pub async fn get_event_handler(&self) -> StorageResult<EventsHandler> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/lib.rs | crate: router
use actix_web::{
body::MessageBody,
dev::{Server, ServerHandle, ServiceFactory, ServiceRequest},
middleware::ErrorHandlers,
};
use http::StatusCode;
use router_env::tracing::Instrument;
use storage_impl::errors::ApplicationResult;
pub use self::env::logger;
pub(crate) use self::macros::*;
use crate::{configs::settings, core::errors};
pub fn get_application_builder(
request_body_limit: usize,
cors: settings::CorsSettings,
) -> actix_web::App<
impl ServiceFactory<
ServiceRequest,
Config = (),
Response = actix_web::dev::ServiceResponse<impl MessageBody>,
Error = actix_web::Error,
InitError = (),
>,
> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/lib.rs | crate: router
use actix_web::{
body::MessageBody,
dev::{Server, ServerHandle, ServiceFactory, ServiceRequest},
middleware::ErrorHandlers,
};
use hyperswitch_interfaces::secrets_interface::secret_state::SecuredSecret;
use routes::{AppState, SessionState};
use storage_impl::errors::ApplicationResult;
use tokio::sync::{mpsc, oneshot};
pub use self::env::logger;
pub(crate) use self::macros::*;
use crate::{configs::settings, core::errors};
pub async fn start_server(conf: settings::Settings<SecuredSecret>) -> ApplicationResult<Server> {
{
None => server_builder.run(),<|fim_suffix|>
<|fim_middle|>
Some(tls_conf) => {
let cert_file =
&mut std::io::BufReader::new(std::fs::File::open(tls_conf.certificate).map_err(
|err| errors::ApplicationError::InvalidConfigurationValueError(err.to_string()),
)?);
let key_file =
&mut std::io::BufReader::new(std::fs::File::open(tls_conf.private_key).map_err(
|err| errors::ApplicationError::InvalidConfigurationValueError(err.to_string()),
)?);
let cert_chain = rustls_pemfile::certs(cert_file)
.collect::<Result<Vec<_>, _>>()
.map_err(|err| {
errors::ApplicationError::InvalidConfigurationValueError(err.to_string())
})?;
let mut keys = rustls_pemfile::pkcs8_private_keys(key_file)
.map(|key| key.map(rustls::pki_types::PrivateKeyDer::Pkcs8))
.collect::<Result<Vec<_>, _>>()
.map_err(|err| {
errors::ApplicationError::InvalidConfigurationValueError(err.to_string())
})?;
// exit if no keys could be parsed
if keys.is_empty() {
return Err(errors::ApplicationError::InvalidConfigurationValueError(
"Could not locate PKCS8 private keys.".into(),
));
}
let config_builder = rustls::ServerConfig::builder().with_no_client_auth();
let config = config_builder
.with_single_cert(cert_chain, keys.remove(0))
.map_err(|err| {
errors::ApplicationError::InvalidConfigurationValueError(err.to_string())
})?;
server_builder
.bind_rustls_0_22(
(tls_conf.host.unwrap_or(server.host).as_str(), tls_conf.port),
config,
)?
.run()
}
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/lib.rs | crate: router
use tokio::sync::{mpsc, oneshot};
pub use self::env::logger;
pub(crate) use self::macros::*;
pub async fn receiver_for_error(rx: oneshot::Receiver<()>, mut server: impl Stop) {
{
Ok(_) => {
logger::error!("The redis server failed ");
server.stop_server().await;
}<|fim_suffix|>
<|fim_middle|>
Err(err) => {
logger::error!("Channel receiver error: {err}");
}
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/lib.rs | crate: router
use actix_web::{
body::MessageBody,
dev::{Server, ServerHandle, ServiceFactory, ServiceRequest},
middleware::ErrorHandlers,
};
use hyperswitch_interfaces::secrets_interface::secret_state::SecuredSecret;
use routes::{AppState, SessionState};
use storage_impl::errors::ApplicationResult;
use tokio::sync::{mpsc, oneshot};
pub use self::env::logger;
pub(crate) use self::macros::*;
use crate::{configs::settings, core::errors};
pub async fn start_server(conf: settings::Settings<SecuredSecret>) -> ApplicationResult<Server> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/lib.rs | crate: router
pub use self::env::logger;
pub(crate) use self::macros::*;
async fn stop_server(&mut self) {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/lib.rs | crate: router
use tokio::sync::{mpsc, oneshot};
pub use self::env::logger;
pub(crate) use self::macros::*;
pub async fn receiver_for_error(rx: oneshot::Receiver<()>, mut server: impl Stop) {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
// file: hyperswitch/crates/router/src/lib.rs | crate: router
use actix_web::{
body::MessageBody,
dev::{Server, ServerHandle, ServiceFactory, ServiceRequest},
middleware::ErrorHandlers,
};
use http::StatusCode;
use hyperswitch_interfaces::secrets_interface::secret_state::SecuredSecret;
use router_env::tracing::Instrument;
use routes::{AppState, SessionState};
use storage_impl::errors::ApplicationResult;
use tokio::sync::{mpsc, oneshot};
pub use self::env::logger;
pub(crate) use self::macros::*;
use crate::{configs::settings, core::errors};
use crate::locale::{_rust_i18n_t, _rust_i18n_try_translate};
pub fn mk_app(
state: AppState,
request_body_limit: usize,
) -> actix_web::App<
impl ServiceFactory<
ServiceRequest,
Config = (),
Response = actix_web::dev::ServiceResponse<impl MessageBody>,
Error = actix_web::Error,
InitError = (),
>,
> {
let mut server_app = get_application_builder(request_body_limit, state.conf.cors.clone());
#[cfg(all(feature = "dummy_connector", feature = "v1"))]
{
use routes::DummyConnector;
server_app = server_app.service(DummyConnector::server(state.clone()));
}
#[cfg(any(feature = "olap", feature = "oltp"))]
{
#[cfg(feature = "olap")]
{
// This is a more specific route as compared to `MerchantConnectorAccount`
// so it is registered before `MerchantConnectorAccount`.
#[cfg(feature = "v1")]
{
server_app = server_app
.service(routes::ProfileNew::server(state.clone()))
.service(routes::Forex::server(state.clone()));
}
server_app = server_app.service(routes::Profile::server(state.clone()));
}
server_app = server_app
.service(routes::Payments::server(state.clone()))
.service(routes::Customers::server(state.clone()))
.service(routes::Configs::server(state.clone()))
.service(routes::MerchantConnectorAccount::server(state.clone()))
.service(routes::RelayWebhooks::server(state.clone()))
.service(routes::Webhooks::server(state.clone()))
.service(routes::Hypersense::server(state.clone()))
.service(routes::Relay::server(state.clone()));
#[cfg(feature = "oltp")]
{
server_app = server_app.service(routes::PaymentMethods::server(state.clone()));
}
#[cfg(all(feature = "v2", feature = "oltp"))]
{
server_app = server_app.service(routes::PaymentMethodSession::server(state.clone()));
}
#[cfg(feature = "v1")]
{
server_app = server_app
.service(routes::Refunds::server(state.clone()))
.service(routes::Mandates::server(state.clone()));
}
}
#[cfg(all(feature = "oltp", any(feature = "v1", feature = "v2"),))]
{
server_app = server_app.service(routes::EphemeralKey::server(state.clone()))
}
#[cfg(all(
feature = "oltp",
any(feature = "v1", feature = "v2"),
not(feature = "customer_v2")
))]
{
server_app = server_app.service(routes::Poll::server(state.clone()))
}
#[cfg(feature = "olap")]
{
server_app = server_app
.service(routes::Organization::server(state.clone()))
.service(routes::MerchantAccount::server(state.clone()))
.service(routes::User::server(state.clone()))
.service(routes::ApiKeys::server(state.clone()))
.service(routes::Routing::server(state.clone()));
#[cfg(feature = "v1")]
{
server_app = server_app
.service(routes::Files::server(state.clone()))
.service(routes::Disputes::server(state.clone()))
.service(routes::Blocklist::server(state.clone()))
.service(routes::Gsm::server(state.clone()))
.service(routes::ApplePayCertificatesMigration::server(state.clone()))
.service(routes::PaymentLink::server(state.clone()))
.service(routes::ConnectorOnboarding::server(state.clone()))
.service(routes::Verify::server(state.clone()))
.service(routes::Analytics::server(state.clone()))
.service(routes::WebhookEvents::server(state.clone()))
.service(routes::FeatureMatrix::server(state.clone()));
}
#[cfg(feature = "v2")]
{
server_app = server_app.service(routes::ProcessTracker::server(state.clone()));
}
}
#[cfg(all(feature = "payouts", feature = "v1"))]
{
server_app = server_app
.service(routes::Payouts::server(state.clone()))
.service(routes::PayoutLink::server(state.clone()));
}
#[cfg(all(
feature = "stripe",
any(feature = "v1", feature = "v2"),
not(feature = "customer_v2")
))]
{
server_app = server_app
.service(routes::StripeApis::server(state.clone()))
.service(routes::Cards::server(state.clone()));
}
#[cfg(all(feature = "recon", feature = "v1"))]
{
server_app = server_app.service(routes::Recon::server(state.clone()));
}
server_app = server_app.service(routes::Cache::server(state.clone()));
server_app = server_app.service(routes::Health::server(state.clone()));
server_app
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/middleware.rs | crate: router
use crate::headers;
fn call(&self, mut req: actix_web::dev::ServiceRequest) -> Self::Future {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/middleware.rs | crate: router
use router_env::{
logger,
tracing::{field::Empty, Instrument},
};
use crate::headers;
fn call(&self, mut req: actix_web::dev::ServiceRequest) -> Self::Future {
{
Ok(value) => {
logger::info!(
"request_id: {request_id}, request_details: {}",
get_request_details_from_value(&value, "")
);
}<|fim_suffix|>
<|fim_middle|>
Err(err) => {
logger::warn!("error while parsing the request in json value: {err}");
}
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/middleware.rs | crate: router
fn get_request_details_from_value(json_value: &serde_json::Value, parent_key: &str) -> String {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/middleware.rs | crate: router
fn get_request_details_from_value(json_value: &serde_json::Value, parent_key: &str) -> String {
{
serde_json::Value::Null => format!("{}: null", parent_key),<|fim_suffix|>
<|fim_middle|>
serde_json::Value::Object(obj) => {
let mut result = String::new();
for (index, (key, value)) in obj.iter().enumerate() {
let child_key = format!("{}[{}]", parent_key, key);
result.push_str(&get_request_details_from_value(value, &child_key));
if index < obj.len() - 1 {
result.push_str(", ");
}
}
result
}
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/middleware.rs | crate: router
fn new_transform(&self, service: S) -> Self::Future {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/middleware.rs | crate: router
use common_utils::consts::TENANT_HEADER;
use futures::StreamExt;
use router_env::{
logger,
tracing::{field::Empty, Instrument},
};
use crate::headers;
/// Middleware for attaching default response headers. Headers with the same key already set in a
/// response will not be overwritten.
pub fn default_response_headers() -> actix_web::middleware::DefaultHeaders {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/middleware.rs | crate: router
use router_env::{
logger,
tracing::{field::Empty, Instrument},
};
use crate::headers;
fn call(&self, req: actix_web::dev::ServiceRequest) -> Self::Future {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
use api_models::{
enums,
payments::{self},
webhooks,
};
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
pub use hyperswitch_connectors::utils::QrImage;
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::core::webhooks as webhooks_core;
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
type Handle<T> = tokio::task::JoinHandle<RouterResult<T>>;
pub async fn trigger_refund_outgoing_webhook(
state: &SessionState,
merchant_account: &domain::MerchantAccount,
refund: &diesel_models::Refund,
profile_id: id_type::ProfileId,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<()> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
use api_models::{
enums,
payments::{self},
webhooks,
};
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
pub use hyperswitch_connectors::utils::QrImage;
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
pub fn add_apple_pay_payment_status_metrics(
payment_attempt_status: enums::AttemptStatus,
apple_pay_flow: Option<domain::ApplePayFlow>,
connector: Option<String>,
merchant_id: id_type::MerchantId,
) {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
pub use hyperswitch_connectors::utils::QrImage;
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
pub fn add_apple_pay_flow_metrics(
apple_pay_flow: &Option<domain::ApplePayFlow>,
connector: Option<String>,
merchant_id: id_type::MerchantId,
) {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
use api_models::{
enums,
payments::{self},
webhooks,
};
use common_utils::types::keymanager::KeyManagerState;
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
use common_utils::{
type_name,
types::keymanager::{Identifier, ToEncryptable},
};
use hyperswitch_domain_models::payments::PaymentIntent;
use hyperswitch_domain_models::type_encryption::{crypto_operation, CryptoOperation};
use masking::{ExposeInterface, SwitchStrategy};
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::types::storage;
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
async fn get_domain_address(
&self,
state: &SessionState,
address_details: payments::AddressDetails,
merchant_id: &id_type::MerchantId,
customer_id: &id_type::CustomerId,
key: &[u8],
storage_scheme: storage::enums::MerchantStorageScheme,
) -> CustomResult<domain::CustomerAddress, common_utils::errors::CryptoError> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
use api_models::{
enums,
payments::{self},
webhooks,
};
use common_utils::types::keymanager::KeyManagerState;
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
use common_utils::{
type_name,
types::keymanager::{Identifier, ToEncryptable},
};
use hyperswitch_domain_models::payments::PaymentIntent;
use hyperswitch_domain_models::type_encryption::{crypto_operation, CryptoOperation};
use masking::{ExposeInterface, SwitchStrategy};
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::types::storage;
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
async fn get_address_update(
&self,
state: &SessionState,
address_details: payments::AddressDetails,
key: &[u8],
storage_scheme: storage::enums::MerchantStorageScheme,
merchant_id: id_type::MerchantId,
) -> CustomResult<storage::AddressUpdate, common_utils::errors::CryptoError> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
use common_utils::types::keymanager::KeyManagerState;
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
use common_utils::{
type_name,
types::keymanager::{Identifier, ToEncryptable},
};
pub use hyperswitch_connectors::utils::QrImage;
use serde_json::Value;
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::types::storage;
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
pub fn handle_json_response_deserialization_failure(
res: types::Response,
connector: &'static str,
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
use api_models::{
enums,
payments::{self},
webhooks,
};
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
pub use hyperswitch_connectors::utils::QrImage;
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::core::webhooks as webhooks_core;
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
pub async fn find_mca_from_authentication_id_type(
state: &SessionState,
authentication_id_type: webhooks::AuthenticationIdType,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantConnectorAccount, errors::ApiErrorResponse> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
use api_models::{
enums,
payments::{self},
webhooks,
};
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
pub use hyperswitch_connectors::utils::QrImage;
use hyperswitch_domain_models::payments::PaymentIntent;
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::core::webhooks as webhooks_core;
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
pub async fn find_payment_intent_from_mandate_id_type(
state: &SessionState,
mandate_id_type: webhooks::MandateIdType,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
) -> CustomResult<PaymentIntent, errors::ApiErrorResponse> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
use api_models::{
enums,
payments::{self},
webhooks,
};
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
pub use hyperswitch_connectors::utils::QrImage;
use hyperswitch_domain_models::payments::PaymentIntent;
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::core::webhooks as webhooks_core;
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
pub async fn find_payment_intent_from_refund_id_type(
state: &SessionState,
refund_id_type: webhooks::RefundIdType,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
connector_name: &str,
) -> CustomResult<PaymentIntent, errors::ApiErrorResponse> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
use api_models::{
enums,
payments::{self},
webhooks,
};
use common_utils::types::keymanager::KeyManagerState;
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
pub use hyperswitch_connectors::utils::QrImage;
use hyperswitch_domain_models::payments::PaymentIntent;
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
pub async fn find_payment_intent_from_payment_id_type(
state: &SessionState,
payment_id_type: payments::PaymentIdType,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
) -> CustomResult<PaymentIntent, errors::ApiErrorResponse> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
logger::warn!(
"Outgoing webhook not sent because of missing event type status mapping"
);
}
}
}
Ok(())
}
type Handle<T> = tokio::task::JoinHandle<RouterResult<T>>;
pub async fn flatten_join_error<T>(handle: Handle<T>) -> RouterResult<T> {
match handle.await {
Ok(Ok(t)) => Ok(t),
Ok(Err(err)) => Err(err),
Err(err) => Err(err)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Join Error"),
}
}
#[cfg(feature = "v1")]
pub async fn trigger_refund_outgoing_webhook(
state: &SessionState,
pub async fn flatten_join_error<T>(handle: Handle<T>) -> RouterResult<T> {
{
Ok(Ok(t)) => Ok(t),<|fim_suffix|>
<|fim_middle|>
Err(err) => Err(err)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Join Error"),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
(
"connector",
connector.to_owned().unwrap_or("null".to_string()),
),
("merchant_id", merchant_id.clone()),
),
),
}
}
}
}
pub fn check_if_pull_mechanism_for_external_3ds_enabled_from_connector_metadata(
metadata: Option<Value>,
) -> bool {
let external_three_ds_connector_metadata: Option<ExternalThreeDSConnectorMetadata> = metadata
.parse_value("ExternalThreeDSConnectorMetadata")
.map_err(|err| logger::warn!(parsing_error=?err,"Error while parsing ExternalThreeDSConnectorMetadata"))
.ok();
external_three_ds_connector_metadata
.and_then(|metadata| metadata.pull_mechanism_for_external_3ds_enabled)
.unwrap_or(true)
}
#[cfg(feature = "v2")]
pub fn check_if_pull_mechanism_for_external_3ds_enabled_from_connector_metadata(
metadata: Option<Value>,
) -> bool {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
use common_utils::types::keymanager::KeyManagerState;
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
use common_utils::{
type_name,
types::keymanager::{Identifier, ToEncryptable},
};
pub use hyperswitch_connectors::utils::QrImage;
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
pub fn get_locale_from_header(headers: &actix_web::http::header::HeaderMap) -> String {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
pub use hyperswitch_connectors::utils::QrImage;
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
type Handle<T> = tokio::task::JoinHandle<RouterResult<T>>;
pub async fn flatten_join_error<T>(handle: Handle<T>) -> RouterResult<T> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
use std::fmt::Debug;
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
pub use hyperswitch_connectors::utils::QrImage;
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
type Handle<T> = tokio::task::JoinHandle<RouterResult<T>>;
pub async fn trigger_payments_webhook<F, Op, D>(
merchant_account: domain::MerchantAccount,
business_profile: domain::Profile,
key_store: &domain::MerchantKeyStore,
payment_data: D,
customer: Option<domain::Customer>,
state: &SessionState,
operation: Op,
) -> RouterResult<()>
where
F: Send + Clone + Sync,
Op: Debug,
D: payments_core::OperationSessionGetters<F>,
{
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
// file: hyperswitch/crates/router/src/utils.rs | crate: router
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
pub use hyperswitch_connectors::utils::QrImage;
use serde_json::Value;
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
pub fn check_if_pull_mechanism_for_external_3ds_enabled_from_connector_metadata(
metadata: Option<Value>,
) -> bool {
let external_three_ds_connector_metadata: Option<ExternalThreeDSConnectorMetadata> = metadata
.parse_value("ExternalThreeDSConnectorMetadata")
.map_err(|err| logger::warn!(parsing_error=?err,"Error while parsing ExternalThreeDSConnectorMetadata"))
.ok();
external_three_ds_connector_metadata
.and_then(|metadata| metadata.pull_mechanism_for_external_3ds_enabled)
.unwrap_or(true)
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
pub use hyperswitch_connectors::utils::QrImage;
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::core::webhooks as webhooks_core;
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
pub fn add_connector_http_status_code_metrics(option_status_code: Option<u16>) {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
pub use hyperswitch_connectors::utils::QrImage;
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
pub fn get_http_status_code_type(
status_code: u16,
) -> CustomResult<String, errors::ApiErrorResponse> {
{
100..=199 => "1xx",<|fim_suffix|>
<|fim_middle|>
_ => Err(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Invalid http status code")?,
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
use std::fmt::Debug;
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
pub use hyperswitch_connectors::utils::QrImage;
pub use self::ext_traits::{OptionExt, ValidateCall};
pub fn get_payout_attempt_id(payout_id: impl std::fmt::Display, attempt_count: i16) -> String {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
use api_models::{
enums,
payments::{self},
webhooks,
};
use common_utils::types::keymanager::KeyManagerState;
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
use common_utils::{
type_name,
types::keymanager::{Identifier, ToEncryptable},
};
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::types::storage;
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
type Handle<T> = tokio::task::JoinHandle<RouterResult<T>>;
fn get_response(self) -> RouterResult<types::Response> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
use api_models::{
enums,
payments::{self},
webhooks,
};
use common_utils::types::keymanager::KeyManagerState;
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
use common_utils::{
type_name,
types::keymanager::{Identifier, ToEncryptable},
};
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::types::storage;
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
type Handle<T> = tokio::task::JoinHandle<RouterResult<T>>;
fn get_error_response(self) -> RouterResult<types::Response> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
use api_models::{
enums,
payments::{self},
webhooks,
};
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
use common_utils::{
type_name,
types::keymanager::{Identifier, ToEncryptable},
};
use serde::de::DeserializeOwned;
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
type Handle<T> = tokio::task::JoinHandle<RouterResult<T>>;
fn get_response_inner<T: DeserializeOwned>(self, type_name: &'static str) -> RouterResult<T> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
pub use hyperswitch_connectors::utils::QrImage;
use uuid::Uuid;
pub use self::ext_traits::{OptionExt, ValidateCall};
pub fn generate_uuid() -> String {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
pub use hyperswitch_connectors::utils::QrImage;
pub use self::ext_traits::{OptionExt, ValidateCall};
pub fn custom_json_error_handler(err: JsonPayloadError, _req: &HttpRequest) -> Error {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
}))
.as_deref()
.unwrap_or("Invalid Json Error"),
)
}
}
impl ResponseError for CustomJsonError {
fn status_code(&self) -> StatusCode {
StatusCode::BAD_REQUEST
}
fn error_response(&self) -> actix_web::HttpResponse<actix_web::body::BoxBody> {
use actix_web::http::header;
actix_web::HttpResponseBuilder::new(self.status_code())
.insert_header((header::CONTENT_TYPE, mime::APPLICATION_JSON))
.body(self.to_string())
}
}
pub fn custom_json_error_handler(err: JsonPayloadError, _req: &HttpRequest) -> Error {
Error::from(CustomJsonError { err })
}
}
fn error_response(&self) -> actix_web::HttpResponse<actix_web::body::BoxBody> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
use api_models::{
enums,
payments::{self},
webhooks,
};
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
pub use hyperswitch_connectors::utils::QrImage;
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::core::webhooks as webhooks_core;
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
pub async fn get_mca_from_object_reference_id(
state: &SessionState,
object_reference_id: webhooks::ObjectReferenceId,
merchant_account: &domain::MerchantAccount,
connector_name: &str,
key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantConnectorAccount, errors::ApiErrorResponse> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
use api_models::{
enums,
payments::{self},
webhooks,
};
use common_utils::types::keymanager::KeyManagerState;
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
pub use hyperswitch_connectors::utils::QrImage;
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::core::webhooks as webhooks_core;
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
pub async fn get_mca_from_payout_attempt(
state: &SessionState,
merchant_account: &domain::MerchantAccount,
payout_id_type: webhooks::PayoutIdType,
connector_name: &str,
key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantConnectorAccount, errors::ApiErrorResponse> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/utils.rs | crate: router
use common_utils::types::keymanager::KeyManagerState;
pub use common_utils::{
crypto::{self, Encryptable},
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
id_type, pii,
validation::validate_email,
};
pub use hyperswitch_connectors::utils::QrImage;
use hyperswitch_domain_models::payments::PaymentIntent;
pub use self::ext_traits::{OptionExt, ValidateCall};
use crate::{
consts,
core::{
authentication::types::ExternalThreeDSConnectorMetadata,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments as payments_core,
},
headers::ACCEPT_LANGUAGE,
logger,
routes::{metrics, SessionState},
services::{self, authentication::get_header_value_by_key},
types::{
self, domain,
transformers::{ForeignFrom, ForeignInto},
},
};
pub async fn get_mca_from_payment_intent(
state: &SessionState,
merchant_account: &domain::MerchantAccount,
payment_intent: PaymentIntent,
key_store: &domain::MerchantKeyStore,
connector_name: &str,
) -> CustomResult<domain::MerchantConnectorAccount, errors::ApiErrorResponse> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/payment_intents.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use api_models::payments as payment_types;
use error_stack::report;
use router_env::Tag;
use router_env::{instrument, tracing, Flow};
use crate::{
compatibility::{stripe::errors, wrap},
core::payments,
routes::{self},
services::{api, authentication as auth},
};
use crate::{
core::api_locking::GetLockingInput, logger, routes::payments::get_or_generate_payment_id,
types::api as api_types,
};
pub async fn payment_intent_list(
state: web::Data<routes::AppState>,
req: HttpRequest,
payload: web::Query<types::StripePaymentListConstraints>,
) -> HttpResponse {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/payment_intents.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use api_models::payments as payment_types;
use error_stack::report;
use router_env::Tag;
use router_env::{instrument, tracing, Flow};
use crate::{
compatibility::{stripe::errors, wrap},
core::payments,
routes::{self},
services::{api, authentication as auth},
};
use crate::{
core::api_locking::GetLockingInput, logger, routes::payments::get_or_generate_payment_id,
types::api as api_types,
};
pub async fn payment_intents_cancel(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
req: HttpRequest,
form_payload: web::Bytes,
path: web::Path<common_utils::id_type::PaymentId>,
) -> HttpResponse {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
// file: hyperswitch/crates/router/src/compatibility/stripe/payment_intents.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use api_models::payments as payment_types;
use error_stack::report;
use router_env::Tag;
use router_env::{instrument, tracing, Flow};
use crate::{
compatibility::{stripe::errors, wrap},
core::payments,
routes::{self},
services::{api, authentication as auth},
};
use crate::{
core::api_locking::GetLockingInput, logger, routes::payments::get_or_generate_payment_id,
types::api as api_types,
};
pub async fn payment_intents_capture(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
req: HttpRequest,
form_payload: web::Bytes,
path: web::Path<common_utils::id_type::PaymentId>,
) -> HttpResponse {
let stripe_payload: payment_types::PaymentsCaptureRequest = match qs_config
.deserialize_bytes(&form_payload)
{
Ok(p) => p,
Err(err) => {
return api::log_and_return_error_response(report!(errors::StripeErrorCode::from(err)))
}
};
tracing::Span::current().record("payment_id", stripe_payload.payment_id.get_string_repr());
logger::info!(tag = ?Tag::CompatibilityLayerRequest, payload = ?stripe_payload);
let payload = payment_types::PaymentsCaptureRequest {
payment_id: path.into_inner(),
..stripe_payload
};
let flow = Flow::PaymentsCapture;
let locking_action = payload.get_locking_input(flow.clone());
Box::pin(wrap::compatibility_api_wrap::<
_,
_,
_,
_,
_,
types::StripePaymentIntentResponse,
errors::StripeErrorCode,
_,
>(
flow,
state.into_inner(),
&req,
payload,
|state, auth: auth::AuthenticationData, payload, req_state| {
payments::payments_core::<
api_types::Capture,
api_types::PaymentsResponse,
_,
_,
_,
payments::PaymentData<api_types::Capture>,
>(
state,
req_state,
auth.merchant_account,
None,
auth.key_store,
payments::PaymentCapture,
payload,
api::AuthFlow::Merchant,
payments::CallConnectorAction::Trigger,
None,
hyperswitch_domain_models::payments::HeaderPayload::default(),
auth.platform_merchant_account,
)
},
&auth::HeaderAuth(auth::ApiKeyAuth),
locking_action,
))
.await
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/payment_intents.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use api_models::payments as payment_types;
use error_stack::report;
use router_env::{instrument, tracing, Flow};
use crate::{
compatibility::{stripe::errors, wrap},
core::payments,
routes::{self},
services::{api, authentication as auth},
};
use crate::{
core::api_locking::GetLockingInput, logger, routes::payments::get_or_generate_payment_id,
types::api as api_types,
};
pub async fn payment_intents_update(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
req: HttpRequest,
form_payload: web::Bytes,
path: web::Path<common_utils::id_type::PaymentId>,
) -> HttpResponse {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/payment_intents.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use api_models::payments as payment_types;
use error_stack::report;
use router_env::{instrument, tracing, Flow};
use crate::{
compatibility::{stripe::errors, wrap},
core::payments,
routes::{self},
services::{api, authentication as auth},
};
use crate::{
core::api_locking::GetLockingInput, logger, routes::payments::get_or_generate_payment_id,
types::api as api_types,
};
pub async fn payment_intents_retrieve_with_gateway_creds(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
req: HttpRequest,
form_payload: web::Bytes,
) -> HttpResponse {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/payment_intents.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use api_models::payments as payment_types;
use error_stack::report;
use router_env::{instrument, tracing, Flow};
use crate::{
compatibility::{stripe::errors, wrap},
core::payments,
routes::{self},
services::{api, authentication as auth},
};
use crate::{
core::api_locking::GetLockingInput, logger, routes::payments::get_or_generate_payment_id,
types::api as api_types,
};
pub async fn payment_intents_retrieve(
state: web::Data<routes::AppState>,
req: HttpRequest,
path: web::Path<common_utils::id_type::PaymentId>,
query_payload: web::Query<types::StripePaymentRetrieveBody>,
) -> HttpResponse {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/payment_intents.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use api_models::payments as payment_types;
use error_stack::report;
use router_env::Tag;
use router_env::{instrument, tracing, Flow};
use crate::{
compatibility::{stripe::errors, wrap},
core::payments,
routes::{self},
services::{api, authentication as auth},
};
use crate::{
core::api_locking::GetLockingInput, logger, routes::payments::get_or_generate_payment_id,
types::api as api_types,
};
pub async fn payment_intents_create(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
req: HttpRequest,
form_payload: web::Bytes,
) -> HttpResponse {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/payment_intents.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use api_models::payments as payment_types;
use error_stack::report;
use router_env::Tag;
use router_env::{instrument, tracing, Flow};
use crate::{
compatibility::{stripe::errors, wrap},
core::payments,
routes::{self},
services::{api, authentication as auth},
};
use crate::{
core::api_locking::GetLockingInput, logger, routes::payments::get_or_generate_payment_id,
types::api as api_types,
};
pub async fn payment_intents_capture(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
req: HttpRequest,
form_payload: web::Bytes,
path: web::Path<common_utils::id_type::PaymentId>,
) -> HttpResponse {
{
Ok(p) => p,<|fim_suffix|>
<|fim_middle|>
Err(err) => {
return api::log_and_return_error_response(report!(errors::StripeErrorCode::from(err)))
}
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/payment_intents.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use api_models::payments as payment_types;
use error_stack::report;
use router_env::{instrument, tracing, Flow};
use crate::{
compatibility::{stripe::errors, wrap},
core::payments,
routes::{self},
services::{api, authentication as auth},
};
use crate::{
core::api_locking::GetLockingInput, logger, routes::payments::get_or_generate_payment_id,
types::api as api_types,
};
pub async fn payment_intents_update(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
req: HttpRequest,
form_payload: web::Bytes,
path: web::Path<common_utils::id_type::PaymentId>,
) -> HttpResponse {
{
Ok(p) => p,<|fim_suffix|>
<|fim_middle|>
Err(err) => {
return api::log_and_return_error_response(report!(errors::StripeErrorCode::from(err)))
}
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/payment_intents.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use api_models::payments as payment_types;
use error_stack::report;
use router_env::Tag;
use router_env::{instrument, tracing, Flow};
use crate::{
compatibility::{stripe::errors, wrap},
core::payments,
routes::{self},
services::{api, authentication as auth},
};
use crate::{
core::api_locking::GetLockingInput, logger, routes::payments::get_or_generate_payment_id,
types::api as api_types,
};
pub async fn payment_intents_confirm(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
req: HttpRequest,
form_payload: web::Bytes,
path: web::Path<common_utils::id_type::PaymentId>,
) -> HttpResponse {
{
Ok(req) => req,<|fim_suffix|>
<|fim_middle|>
Err(err) => return api::log_and_return_error_response(err),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/refunds.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use router_env::{instrument, tracing, Flow, Tag};
use crate::{
compatibility::{stripe::errors, wrap},
core::{api_locking, refunds},
logger, routes,
services::{api, authentication as auth},
types::api::refunds as refund_types,
};
pub async fn refund_update(
state: web::Data<routes::AppState>,
req: HttpRequest,
path: web::Path<String>,
form_payload: web::Form<types::StripeUpdateRefundRequest>,
) -> HttpResponse {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/refunds.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use router_env::{instrument, tracing, Flow, Tag};
use crate::{
compatibility::{stripe::errors, wrap},
core::{api_locking, refunds},
logger, routes,
services::{api, authentication as auth},
types::api::refunds as refund_types,
};
pub async fn refund_retrieve(
state: web::Data<routes::AppState>,
req: HttpRequest,
path: web::Path<String>,
) -> HttpResponse {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/refunds.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use error_stack::report;
use router_env::{instrument, tracing, Flow, Tag};
use crate::{
compatibility::{stripe::errors, wrap},
core::{api_locking, refunds},
logger, routes,
services::{api, authentication as auth},
types::api::refunds as refund_types,
};
pub async fn refund_retrieve_with_gateway_creds(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
req: HttpRequest,
form_payload: web::Bytes,
) -> HttpResponse {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/refunds.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use error_stack::report;
use router_env::{instrument, tracing, Flow, Tag};
use crate::{
compatibility::{stripe::errors, wrap},
core::{api_locking, refunds},
logger, routes,
services::{api, authentication as auth},
types::api::refunds as refund_types,
};
pub async fn refund_create(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
req: HttpRequest,
form_payload: web::Bytes,
) -> HttpResponse {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/refunds.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use error_stack::report;
use router_env::{instrument, tracing, Flow, Tag};
use crate::{
compatibility::{stripe::errors, wrap},
core::{api_locking, refunds},
logger, routes,
services::{api, authentication as auth},
types::api::refunds as refund_types,
};
pub async fn refund_retrieve_with_gateway_creds(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
req: HttpRequest,
form_payload: web::Bytes,
) -> HttpResponse {
{
Ok(payload) => payload,<|fim_suffix|>
<|fim_middle|>
Err(err) => return api::log_and_return_error_response(err),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/refunds.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use error_stack::report;
use router_env::{instrument, tracing, Flow, Tag};
use crate::{
compatibility::{stripe::errors, wrap},
core::{api_locking, refunds},
logger, routes,
services::{api, authentication as auth},
types::api::refunds as refund_types,
};
pub async fn refund_create(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
req: HttpRequest,
form_payload: web::Bytes,
) -> HttpResponse {
{
Ok(p) => p,<|fim_suffix|>
<|fim_middle|>
Err(err) => return api::log_and_return_error_response(err),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/webhooks.rs | crate: router
use api_models::payouts as payout_models;
use api_models::{
enums::{Currency, DisputeStatus, MandateStatus},
webhooks::{self as api},
};
use super::{
payment_intents::types::StripePaymentIntentResponse, refunds::types::StripeRefundResponse,
};
use crate::{
core::{
errors,
webhooks::types::{OutgoingWebhookPayloadWithSignature, OutgoingWebhookType},
},
headers,
services::request::Maskable,
};
fn get_stripe_event_type(event_type: api_models::enums::EventType) -> &'static str {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/webhooks.rs | crate: router
use api_models::payouts as payout_models;
fn from(res: payout_models::PayoutCreateResponse) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/webhooks.rs | crate: router
use api_models::{
enums::{Currency, DisputeStatus, MandateStatus},
webhooks::{self as api},
};
use common_utils::pii::{self, Email};
use common_utils::{crypto::SignMessage, date_time, ext_traits::Encode};
use crate::{
core::{
errors,
webhooks::types::{OutgoingWebhookPayloadWithSignature, OutgoingWebhookType},
},
headers,
services::request::Maskable,
};
fn get_outgoing_webhooks_signature(
&self,
payment_response_hash_key: Option<impl AsRef<[u8]>>,
) -> errors::CustomResult<OutgoingWebhookPayloadWithSignature, errors::WebhooksFlowError> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/webhooks.rs | crate: router
use api_models::{
enums::{Currency, DisputeStatus, MandateStatus},
webhooks::{self as api},
};
use common_utils::{crypto::SignMessage, date_time, ext_traits::Encode};
use router_env::logger;
fn from(value: api::OutgoingWebhook) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/webhooks.rs | crate: router
use api_models::{
enums::{Currency, DisputeStatus, MandateStatus},
webhooks::{self as api},
};
fn from(status: DisputeStatus) -> Self {
{
DisputeStatus::DisputeOpened => Self::WarningNeedsResponse,<|fim_suffix|>
<|fim_middle|>
DisputeStatus::DisputeLost => Self::Lost,
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/webhooks.rs | crate: router
use api_models::payouts as payout_models;
use api_models::{
enums::{Currency, DisputeStatus, MandateStatus},
webhooks::{self as api},
};
fn from(value: api::OutgoingWebhookContent) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
// file: hyperswitch/crates/router/src/compatibility/stripe/webhooks.rs | crate: router
use api_models::{
enums::{Currency, DisputeStatus, MandateStatus},
webhooks::{self as api},
};
use common_utils::{crypto::SignMessage, date_time, ext_traits::Encode};
use router_env::logger;
fn from(value: api::OutgoingWebhook) -> Self {
Self {
id: value.event_id,
stype: get_stripe_event_type(value.event_type),
data: StripeWebhookObject::from(value.content),
object: "event",
// put this conversion it into a function
created: u64::try_from(value.timestamp.assume_utc().unix_timestamp()).unwrap_or_else(
|error| {
logger::error!(
%error,
"incorrect value for `webhook.timestamp` provided {}", value.timestamp
);
// Current timestamp converted to Unix timestamp should have a positive value
// for many years to come
u64::try_from(date_time::now().assume_utc().unix_timestamp())
.unwrap_or_default()
},
),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/webhooks.rs | crate: router
use api_models::{
enums::{Currency, DisputeStatus, MandateStatus},
webhooks::{self as api},
};
fn from(status: DisputeStatus) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/webhooks.rs | crate: router
use api_models::{
enums::{Currency, DisputeStatus, MandateStatus},
webhooks::{self as api},
};
fn from(status: MandateStatus) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/webhooks.rs | crate: router
use api_models::payouts as payout_models;
use api_models::{
enums::{Currency, DisputeStatus, MandateStatus},
webhooks::{self as api},
};
fn from(res: api_models::mandates::MandateResponse) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/webhooks.rs | crate: router
use api_models::payouts as payout_models;
use api_models::{
enums::{Currency, DisputeStatus, MandateStatus},
webhooks::{self as api},
};
fn from(res: api_models::disputes::DisputeResponse) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/webhooks.rs | crate: router
fn from(status: common_enums::PayoutStatus) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/errors.rs | crate: router
fn from(item: serde_qs::Error) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/errors.rs | crate: router
fn from(item: serde_qs::Error) -> Self {
{
serde_qs::Error::Custom(s) => Self::SerdeQsError {
error_message: s,
param: None,
},<|fim_suffix|>
<|fim_middle|>
serde_qs::Error::Utf8(_) => Self::SerdeQsError {
error_message: "Failed to convert utf8 to string".to_owned(),
param: None,
},
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/errors.rs | crate: router
use common_utils::errors::ErrorSwitch;
use hyperswitch_domain_models::errors::api_error_response as errors;
use crate::core::errors::CustomersErrorResponse;
fn status_code(&self) -> reqwest::StatusCode {
{
Self::Unauthorized | Self::PlatformUnauthorizedRequest => StatusCode::UNAUTHORIZED,<|fim_suffix|>
<|fim_middle|>
Self::LockTimeout => StatusCode::LOCKED,
}
} | ast_fragments |
// file: hyperswitch/crates/router/src/compatibility/stripe/errors.rs | crate: router
use common_utils::errors::ErrorSwitch;
use hyperswitch_domain_models::errors::api_error_response as errors;
use crate::core::errors::CustomersErrorResponse;
fn switch(&self) -> StripeErrorCode {
use StripeErrorCode as SC;
match self {
Self::CustomerRedacted => SC::CustomerRedacted,
Self::InternalServerError => SC::InternalServerError,
Self::MandateActive => SC::MandateActive,
Self::CustomerNotFound => SC::CustomerNotFound,
Self::CustomerAlreadyExists => SC::DuplicateCustomer,
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/errors.rs | crate: router
fn switch(&self) -> StripeErrorCode {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/errors.rs | crate: router
use common_utils::errors::ErrorSwitch;
use hyperswitch_domain_models::errors::api_error_response as errors;
use crate::core::errors::CustomersErrorResponse;
fn from(value: errors::ApiErrorResponse) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/setup_intents.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use api_models::payments as payment_types;
use error_stack::report;
use router_env::{instrument, tracing, Flow};
use crate::{
compatibility::{
stripe::{errors, payment_intents::types as stripe_payment_types},
wrap,
},
core::{api_locking, payments},
routes,
services::{api, authentication as auth},
types::api as api_types,
};
pub async fn setup_intents_confirm(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
req: HttpRequest,
form_payload: web::Bytes,
path: web::Path<common_utils::id_type::PaymentId>,
) -> HttpResponse {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/setup_intents.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use api_models::payments as payment_types;
use error_stack::report;
use router_env::{instrument, tracing, Flow};
use crate::{
compatibility::{
stripe::{errors, payment_intents::types as stripe_payment_types},
wrap,
},
core::{api_locking, payments},
routes,
services::{api, authentication as auth},
types::api as api_types,
};
pub async fn setup_intents_update(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
req: HttpRequest,
form_payload: web::Bytes,
path: web::Path<common_utils::id_type::PaymentId>,
) -> HttpResponse {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/setup_intents.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use api_models::payments as payment_types;
use error_stack::report;
use router_env::{instrument, tracing, Flow};
use crate::{
compatibility::{
stripe::{errors, payment_intents::types as stripe_payment_types},
wrap,
},
core::{api_locking, payments},
routes,
services::{api, authentication as auth},
types::api as api_types,
};
pub async fn setup_intents_retrieve(
state: web::Data<routes::AppState>,
req: HttpRequest,
path: web::Path<common_utils::id_type::PaymentId>,
query_payload: web::Query<stripe_payment_types::StripePaymentRetrieveBody>,
) -> HttpResponse {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/setup_intents.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use api_models::payments as payment_types;
use error_stack::report;
use router_env::{instrument, tracing, Flow};
use crate::{
compatibility::{
stripe::{errors, payment_intents::types as stripe_payment_types},
wrap,
},
core::{api_locking, payments},
routes,
services::{api, authentication as auth},
types::api as api_types,
};
pub async fn setup_intents_create(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
req: HttpRequest,
form_payload: web::Bytes,
) -> HttpResponse {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/setup_intents.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use api_models::payments as payment_types;
use error_stack::report;
use router_env::{instrument, tracing, Flow};
use crate::{
compatibility::{
stripe::{errors, payment_intents::types as stripe_payment_types},
wrap,
},
core::{api_locking, payments},
routes,
services::{api, authentication as auth},
types::api as api_types,
};
pub async fn setup_intents_confirm(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
req: HttpRequest,
form_payload: web::Bytes,
path: web::Path<common_utils::id_type::PaymentId>,
) -> HttpResponse {
{
Ok(req) => req,<|fim_suffix|>
<|fim_middle|>
Err(err) => return api::log_and_return_error_response(err),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/setup_intents.rs | crate: router
use actix_web::{web, HttpRequest, HttpResponse};
use api_models::payments as payment_types;
use error_stack::report;
use router_env::{instrument, tracing, Flow};
use crate::{
compatibility::{
stripe::{errors, payment_intents::types as stripe_payment_types},
wrap,
},
core::{api_locking, payments},
routes,
services::{api, authentication as auth},
types::api as api_types,
};
pub async fn setup_intents_retrieve(
state: web::Data<routes::AppState>,
req: HttpRequest,
path: web::Path<common_utils::id_type::PaymentId>,
query_payload: web::Query<stripe_payment_types::StripePaymentRetrieveBody>,
) -> HttpResponse {
{
Ok(auth) => auth,<|fim_suffix|>
<|fim_middle|>
Err(err) => return api::log_and_return_error_response(report!(err)),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/payment_intents/types.rs | crate: router
use api_models::payments;
use crate::{
compatibility::stripe::refunds::types as stripe_refunds,
connector::utils::AddressData,
consts,
core::errors,
pii::{Email, PeekInterface},
types::{
api::{admin, enums as api_enums},
transformers::{ForeignFrom, ForeignTryFrom},
},
};
fn get_pmd_based_on_payment_method_type(
payment_method_type: Option<api_enums::PaymentMethodType>,
billing_details: Option<hyperswitch_domain_models::address::Address>,
) -> Option<payments::PaymentMethodData> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/payment_intents/types.rs | crate: router
use api_models::payments;
use crate::{
compatibility::stripe::refunds::types as stripe_refunds,
connector::utils::AddressData,
consts,
core::errors,
pii::{Email, PeekInterface},
types::{
api::{admin, enums as api_enums},
transformers::{ForeignFrom, ForeignTryFrom},
},
};
pub(crate) fn into_stripe_next_action(
next_action: Option<payments::NextActionData>,
return_url: Option<String>,
) -> Option<StripeNextAction> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/payment_intents/types.rs | crate: router
use api_models::payments;
use common_utils::{
crypto::Encryptable,
date_time,
ext_traits::StringExt,
id_type,
pii::{IpAddress, SecretSerdeValue, UpiVpaMaskingStrategy},
types::MinorUnit,
};
use crate::{
compatibility::stripe::refunds::types as stripe_refunds,
connector::utils::AddressData,
consts,
core::errors,
pii::{Email, PeekInterface},
types::{
api::{admin, enums as api_enums},
transformers::{ForeignFrom, ForeignTryFrom},
},
};
fn foreign_try_from(
(mandate_data, currency): (Option<MandateData>, Option<String>),
) -> errors::RouterResult<Self> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/payment_intents/types.rs | crate: router
use api_models::payments;
use common_utils::{
crypto::Encryptable,
date_time,
ext_traits::StringExt,
id_type,
pii::{IpAddress, SecretSerdeValue, UpiVpaMaskingStrategy},
types::MinorUnit,
};
use crate::{
compatibility::stripe::refunds::types as stripe_refunds,
connector::utils::AddressData,
consts,
core::errors,
pii::{Email, PeekInterface},
types::{
api::{admin, enums as api_enums},
transformers::{ForeignFrom, ForeignTryFrom},
},
};
fn from(resp: payments::PaymentsResponse) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/payment_intents/types.rs | crate: router
use api_models::payments;
use crate::{
compatibility::stripe::refunds::types as stripe_refunds,
connector::utils::AddressData,
consts,
core::errors,
pii::{Email, PeekInterface},
types::{
api::{admin, enums as api_enums},
transformers::{ForeignFrom, ForeignTryFrom},
},
};
pub(crate) fn into_stripe_next_action(
next_action: Option<payments::NextActionData>,
return_url: Option<String>,
) -> Option<StripeNextAction> {
{
payments::NextActionData::RedirectToUrl { redirect_to_url } => {
StripeNextAction::RedirectToUrl {
redirect_to_url: RedirectUrl {
return_url,
url: Some(redirect_to_url),
},
}
}<|fim_suffix|>
<|fim_middle|>
payments::NextActionData::InvokeHiddenIframe { iframe_data } => {
StripeNextAction::InvokeHiddenIframe { iframe_data }
}
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/compatibility/stripe/payment_intents/types.rs | crate: router
use crate::{
compatibility::stripe::refunds::types as stripe_refunds,
connector::utils::AddressData,
consts,
core::errors,
pii::{Email, PeekInterface},
types::{
api::{admin, enums as api_enums},
transformers::{ForeignFrom, ForeignTryFrom},
},
};
fn from(item: api_enums::IntentStatus) -> Self {
{
api_enums::IntentStatus::Succeeded | api_enums::IntentStatus::PartiallyCaptured => {
Self::Succeeded
}<|fim_suffix|>
<|fim_middle|>
api_enums::IntentStatus::Cancelled => Self::Canceled,
}
} | ast_fragments |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.