mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 12:15:40 +08:00
feat(router): add profile id and extra filters in lists (#2379)
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
use api_models::enums::{Connector, PaymentMethod};
|
||||
use api_models::enums::{AuthenticationType, Connector, PaymentMethod, PaymentMethodType};
|
||||
use common_utils::errors::CustomResult;
|
||||
use data_models::{
|
||||
errors::StorageError,
|
||||
@ -39,7 +39,9 @@ impl PaymentAttemptInterface for MockDb {
|
||||
_merchant_id: &str,
|
||||
_active_attempt_ids: &[String],
|
||||
_connector: Option<Vec<Connector>>,
|
||||
_payment_methods: Option<Vec<PaymentMethod>>,
|
||||
_payment_method: Option<Vec<PaymentMethod>>,
|
||||
_payment_method_type: Option<Vec<PaymentMethodType>>,
|
||||
_authentication_type: Option<Vec<AuthenticationType>>,
|
||||
_storage_scheme: MerchantStorageScheme,
|
||||
) -> CustomResult<i64, StorageError> {
|
||||
Err(StorageError::MockDbError)?
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use api_models::enums::{Connector, PaymentMethod};
|
||||
use api_models::enums::{AuthenticationType, Connector, PaymentMethod, PaymentMethodType};
|
||||
use common_utils::errors::CustomResult;
|
||||
use data_models::{
|
||||
errors,
|
||||
@ -176,11 +176,20 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
|
||||
er.change_context(new_err)
|
||||
})
|
||||
.map(
|
||||
|(connector, currency, status, payment_method)| PaymentListFilters {
|
||||
|(
|
||||
connector,
|
||||
currency,
|
||||
status,
|
||||
payment_method,
|
||||
payment_method_type,
|
||||
authentication_type,
|
||||
)| PaymentListFilters {
|
||||
connector,
|
||||
currency,
|
||||
status,
|
||||
payment_method,
|
||||
payment_method_type,
|
||||
authentication_type,
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -248,7 +257,9 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
|
||||
merchant_id: &str,
|
||||
active_attempt_ids: &[String],
|
||||
connector: Option<Vec<Connector>>,
|
||||
payment_methods: Option<Vec<PaymentMethod>>,
|
||||
payment_method: Option<Vec<PaymentMethod>>,
|
||||
payment_method_type: Option<Vec<PaymentMethodType>>,
|
||||
authentication_type: Option<Vec<AuthenticationType>>,
|
||||
_storage_scheme: MerchantStorageScheme,
|
||||
) -> CustomResult<i64, errors::StorageError> {
|
||||
let conn = self
|
||||
@ -269,7 +280,9 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
|
||||
merchant_id,
|
||||
active_attempt_ids,
|
||||
connector_strings,
|
||||
payment_methods,
|
||||
payment_method,
|
||||
payment_method_type,
|
||||
authentication_type,
|
||||
)
|
||||
.await
|
||||
.map_err(|er| {
|
||||
@ -826,7 +839,9 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
|
||||
merchant_id: &str,
|
||||
active_attempt_ids: &[String],
|
||||
connector: Option<Vec<Connector>>,
|
||||
payment_methods: Option<Vec<PaymentMethod>>,
|
||||
payment_method: Option<Vec<PaymentMethod>>,
|
||||
payment_method_type: Option<Vec<PaymentMethodType>>,
|
||||
authentication_type: Option<Vec<AuthenticationType>>,
|
||||
storage_scheme: MerchantStorageScheme,
|
||||
) -> CustomResult<i64, errors::StorageError> {
|
||||
self.router_store
|
||||
@ -834,7 +849,9 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
|
||||
merchant_id,
|
||||
active_attempt_ids,
|
||||
connector,
|
||||
payment_methods,
|
||||
payment_method,
|
||||
payment_method_type,
|
||||
authentication_type,
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
|
||||
@ -366,29 +366,20 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
|
||||
PaymentIntentFetchConstraints::Single { payment_intent_id } => {
|
||||
query = query.filter(pi_dsl::payment_id.eq(payment_intent_id.to_owned()));
|
||||
}
|
||||
PaymentIntentFetchConstraints::List {
|
||||
offset,
|
||||
starting_at,
|
||||
ending_at,
|
||||
connector: _,
|
||||
currency,
|
||||
status,
|
||||
payment_methods: _,
|
||||
customer_id,
|
||||
starting_after_id,
|
||||
ending_before_id,
|
||||
limit,
|
||||
} => {
|
||||
if let Some(limit) = limit {
|
||||
query = query.limit((*limit).into());
|
||||
};
|
||||
|
||||
if let Some(customer_id) = customer_id {
|
||||
query = query.filter(pi_dsl::customer_id.eq(customer_id.clone()));
|
||||
PaymentIntentFetchConstraints::List(params) => {
|
||||
if let Some(limit) = params.limit {
|
||||
query = query.limit(limit.into());
|
||||
}
|
||||
|
||||
query = match (starting_at, starting_after_id) {
|
||||
(Some(starting_at), _) => query.filter(pi_dsl::created_at.ge(*starting_at)),
|
||||
if let Some(customer_id) = ¶ms.customer_id {
|
||||
query = query.filter(pi_dsl::customer_id.eq(customer_id.clone()));
|
||||
}
|
||||
if let Some(profile_id) = ¶ms.profile_id {
|
||||
query = query.filter(pi_dsl::profile_id.eq(profile_id.clone()));
|
||||
}
|
||||
|
||||
query = match (params.starting_at, ¶ms.starting_after_id) {
|
||||
(Some(starting_at), _) => query.filter(pi_dsl::created_at.ge(starting_at)),
|
||||
(None, Some(starting_after_id)) => {
|
||||
// TODO: Fetch partial columns for this query since we only need some columns
|
||||
let starting_at = self
|
||||
@ -404,8 +395,8 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
|
||||
(None, None) => query,
|
||||
};
|
||||
|
||||
query = match (ending_at, ending_before_id) {
|
||||
(Some(ending_at), _) => query.filter(pi_dsl::created_at.le(*ending_at)),
|
||||
query = match (params.ending_at, ¶ms.ending_before_id) {
|
||||
(Some(ending_at), _) => query.filter(pi_dsl::created_at.le(ending_at)),
|
||||
(None, Some(ending_before_id)) => {
|
||||
// TODO: Fetch partial columns for this query since we only need some columns
|
||||
let ending_at = self
|
||||
@ -420,17 +411,26 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
|
||||
}
|
||||
(None, None) => query,
|
||||
};
|
||||
query = query.offset((*offset).into());
|
||||
|
||||
query = match currency {
|
||||
query = query.offset(params.offset.into());
|
||||
|
||||
query = match ¶ms.currency {
|
||||
Some(currency) => query.filter(pi_dsl::currency.eq_any(currency.clone())),
|
||||
None => query,
|
||||
};
|
||||
|
||||
query = match status {
|
||||
query = match ¶ms.status {
|
||||
Some(status) => query.filter(pi_dsl::status.eq_any(status.clone())),
|
||||
None => query,
|
||||
};
|
||||
|
||||
if let Some(currency) = ¶ms.currency {
|
||||
query = query.filter(pi_dsl::currency.eq_any(currency.clone()));
|
||||
}
|
||||
|
||||
if let Some(status) = ¶ms.status {
|
||||
query = query.filter(pi_dsl::status.eq_any(status.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -490,29 +490,21 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
|
||||
PaymentIntentFetchConstraints::Single { payment_intent_id } => {
|
||||
query.filter(pi_dsl::payment_id.eq(payment_intent_id.to_owned()))
|
||||
}
|
||||
PaymentIntentFetchConstraints::List {
|
||||
offset,
|
||||
starting_at,
|
||||
ending_at,
|
||||
connector,
|
||||
currency,
|
||||
status,
|
||||
payment_methods,
|
||||
customer_id,
|
||||
starting_after_id,
|
||||
ending_before_id,
|
||||
limit,
|
||||
} => {
|
||||
if let Some(limit) = limit {
|
||||
query = query.limit((*limit).into());
|
||||
PaymentIntentFetchConstraints::List(params) => {
|
||||
if let Some(limit) = params.limit {
|
||||
query = query.limit(limit.into());
|
||||
}
|
||||
|
||||
if let Some(customer_id) = customer_id {
|
||||
if let Some(customer_id) = ¶ms.customer_id {
|
||||
query = query.filter(pi_dsl::customer_id.eq(customer_id.clone()));
|
||||
}
|
||||
|
||||
query = match (starting_at, starting_after_id) {
|
||||
(Some(starting_at), _) => query.filter(pi_dsl::created_at.ge(*starting_at)),
|
||||
if let Some(profile_id) = ¶ms.profile_id {
|
||||
query = query.filter(pi_dsl::profile_id.eq(profile_id.clone()));
|
||||
}
|
||||
|
||||
query = match (params.starting_at, ¶ms.starting_after_id) {
|
||||
(Some(starting_at), _) => query.filter(pi_dsl::created_at.ge(starting_at)),
|
||||
(None, Some(starting_after_id)) => {
|
||||
// TODO: Fetch partial columns for this query since we only need some columns
|
||||
let starting_at = self
|
||||
@ -528,8 +520,8 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
|
||||
(None, None) => query,
|
||||
};
|
||||
|
||||
query = match (ending_at, ending_before_id) {
|
||||
(Some(ending_at), _) => query.filter(pi_dsl::created_at.le(*ending_at)),
|
||||
query = match (params.ending_at, ¶ms.ending_before_id) {
|
||||
(Some(ending_at), _) => query.filter(pi_dsl::created_at.le(ending_at)),
|
||||
(None, Some(ending_before_id)) => {
|
||||
// TODO: Fetch partial columns for this query since we only need some columns
|
||||
let ending_at = self
|
||||
@ -545,14 +537,14 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
|
||||
(None, None) => query,
|
||||
};
|
||||
|
||||
query = query.offset((*offset).into());
|
||||
query = query.offset(params.offset.into());
|
||||
|
||||
query = match currency {
|
||||
Some(currency) => query.filter(pi_dsl::currency.eq_any(currency.clone())),
|
||||
None => query,
|
||||
};
|
||||
if let Some(currency) = ¶ms.currency {
|
||||
query = query.filter(pi_dsl::currency.eq_any(currency.clone()));
|
||||
}
|
||||
|
||||
let connectors = connector
|
||||
let connectors = params
|
||||
.connector
|
||||
.as_ref()
|
||||
.map(|c| c.iter().map(|c| c.to_string()).collect::<Vec<String>>());
|
||||
|
||||
@ -561,18 +553,30 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
|
||||
None => query,
|
||||
};
|
||||
|
||||
query = match status {
|
||||
query = match ¶ms.status {
|
||||
Some(status) => query.filter(pi_dsl::status.eq_any(status.clone())),
|
||||
None => query,
|
||||
};
|
||||
|
||||
query = match payment_methods {
|
||||
Some(payment_methods) => {
|
||||
query.filter(pa_dsl::payment_method.eq_any(payment_methods.clone()))
|
||||
query = match ¶ms.payment_method {
|
||||
Some(payment_method) => {
|
||||
query.filter(pa_dsl::payment_method.eq_any(payment_method.clone()))
|
||||
}
|
||||
None => query,
|
||||
};
|
||||
|
||||
query = match ¶ms.payment_method_type {
|
||||
Some(payment_method_type) => query
|
||||
.filter(pa_dsl::payment_method_type.eq_any(payment_method_type.clone())),
|
||||
None => query,
|
||||
};
|
||||
|
||||
query = match ¶ms.authentication_type {
|
||||
Some(authentication_type) => query
|
||||
.filter(pa_dsl::authentication_type.eq_any(authentication_type.clone())),
|
||||
None => query,
|
||||
};
|
||||
|
||||
query
|
||||
}
|
||||
};
|
||||
@ -620,34 +624,30 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
|
||||
PaymentIntentFetchConstraints::Single { payment_intent_id } => {
|
||||
query.filter(pi_dsl::payment_id.eq(payment_intent_id.to_owned()))
|
||||
}
|
||||
PaymentIntentFetchConstraints::List {
|
||||
starting_at,
|
||||
ending_at,
|
||||
currency,
|
||||
status,
|
||||
customer_id,
|
||||
..
|
||||
} => {
|
||||
if let Some(customer_id) = customer_id {
|
||||
PaymentIntentFetchConstraints::List(params) => {
|
||||
if let Some(customer_id) = ¶ms.customer_id {
|
||||
query = query.filter(pi_dsl::customer_id.eq(customer_id.clone()));
|
||||
}
|
||||
if let Some(profile_id) = ¶ms.profile_id {
|
||||
query = query.filter(pi_dsl::profile_id.eq(profile_id.clone()));
|
||||
}
|
||||
|
||||
query = match starting_at {
|
||||
Some(starting_at) => query.filter(pi_dsl::created_at.ge(*starting_at)),
|
||||
query = match params.starting_at {
|
||||
Some(starting_at) => query.filter(pi_dsl::created_at.ge(starting_at)),
|
||||
None => query,
|
||||
};
|
||||
|
||||
query = match ending_at {
|
||||
Some(ending_at) => query.filter(pi_dsl::created_at.le(*ending_at)),
|
||||
query = match params.ending_at {
|
||||
Some(ending_at) => query.filter(pi_dsl::created_at.le(ending_at)),
|
||||
None => query,
|
||||
};
|
||||
|
||||
query = match currency {
|
||||
query = match ¶ms.currency {
|
||||
Some(currency) => query.filter(pi_dsl::currency.eq_any(currency.clone())),
|
||||
None => query,
|
||||
};
|
||||
|
||||
query = match status {
|
||||
query = match ¶ms.status {
|
||||
Some(status) => query.filter(pi_dsl::status.eq_any(status.clone())),
|
||||
None => query,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user