Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(payouts): populate total_count in payout list and filter responses (#11907)

spritianeja0343c075dfd458
diff --git a/crates/diesel_models/src/query/payouts.rs b/crates/diesel_models/src/query/payouts.rs
index e7d06d05ff..dcb9d8e120 100644
--- a/crates/diesel_models/src/query/payouts.rs
+++ b/crates/diesel_models/src/query/payouts.rs
@@ -93,10 +93,12 @@ impl Payouts {
.await
}
+ #[allow(clippy::too_many_arguments)]
pub async fn get_total_count_of_payouts(
conn: &PgPooledConn,
merchant_id: &common_utils::id_type::MerchantId,
active_payout_ids: &[common_utils::id_type::PayoutId],
+ profile_id_list: Option<Vec<common_utils::id_type::ProfileId>>,
connector: Option<Vec<String>>,
currency: Option<Vec<enums::Currency>>,
status: Option<Vec<enums::PayoutStatus>>,
@@ -121,6 +123,9 @@ impl Payouts {
if let Some(payout_type) = payout_type {
filter = filter.filter(dsl::payout_type.eq_any(payout_type));
}
+ if let Some(profile_id_list) = profile_id_list {
+ filter = filter.filter(dsl::profile_id.eq_any(profile_id_list));
+ }
router_env::logger::debug!(query = %debug_query::<Pg, _>(&filter).to_string());
db_metrics::track_database_call::<<Self as HasTable>::Table, _, _>(
diff --git a/crates/hyperswitch_domain_models/src/payouts/payouts.rs b/crates/hyperswitch_domain_models/src/payouts/payouts.rs
index 190c198f30..ce5fd0edd2 100644
--- a/crates/hyperswitch_domain_models/src/payouts/payouts.rs
+++ b/crates/hyperswitch_domain_models/src/payouts/payouts.rs
@@ -77,6 +77,7 @@ pub trait PayoutsInterface {
&self,
_merchant_id: &id_type::MerchantId,
_active_payout_ids: &[id_type::PayoutId],
+ _profile_id_list: Option<Vec<id_type::ProfileId>>,
_connector: Option<Vec<api_models::enums::PayoutConnectors>>,
_currency: Option<Vec<storage_enums::Currency>>,
_status: Option<Vec<storage_enums::PayoutStatus>>,
diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rs
index 4937b8c360..09407d6992 100644
--- a/crates/router/src/core/payouts.rs
+++ b/crates/router/src/core/payouts.rs
@@ -832,7 +832,8 @@ pub async fn payouts_list_core(
)
.await
.to_not_found_response(errors::ApiErrorResponse::PayoutNotFound)?;
- let payouts = core_utils::filter_objects_based_on_profile_id_list(profile_id_list, payouts);
+ let payouts =
+ core_utils::filter_objects_based_on_profile_id_list(profile_id_list.clone(), payouts);
let mut pi_pa_tuple_vec = PayoutActionData::new();
@@ -925,11 +926,32 @@ pub async fn payouts_list_core(
.map(ForeignFrom::foreign_from)
.collect();
+ let constraints = constraints.into();
+ let active_payout_ids = db
+ .filter_active_payout_ids_by_constraints(merchant_id, &constraints)
+ .await
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to filter active payout ids based on the constraints")?;
+
+ let total_count = db
+ .get_total_count_of_filtered_payouts(
+ merchant_id,
+ &active_payout_ids,
+ profile_id_list,
+ None,
+ None,
+ None,
+ None,
+ )
+ .await
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to get total count of filtered payouts")?;
+
Ok(services::ApplicationResponse::Json(
api::PayoutListResponse {
size: data.len(),
data,
- total_count: None,
+ total_count: Some(total_count),
},
))
}
@@ -958,7 +980,7 @@ pub async fn payouts_filtered_list_core(
)
.await
.to_not_found_response(errors::ApiErrorResponse::PayoutNotFound)?;
- let list = core_utils::filter_objects_based_on_profile_id_list(profile_id_list, list);
+ let list = core_utils::filter_objects_based_on_profile_id_list(profile_id_list.clone(), list);
let data: Vec<api::PayoutCreateResponse> =
join_all(list.into_iter().map(|(p, pa, customer, address)| async {
let customer: Option<domain::Customer> = customer
@@ -1027,6 +1049,7 @@ pub async fn payouts_filtered_list_core(
.get_total_count_of_filtered_payouts(
platform.get_processor().get_account().get_id(),
&active_payout_ids,
+ profile_id_list,
filters.connector.clone(),
filters.currency.clone(),
filters.status.clone(),
diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rs
index 44c4d8336f..89ecbbf97a 100644
--- a/crates/router/src/db/kafka_store.rs
+++ b/crates/router/src/db/kafka_store.rs
@@ -2588,6 +2588,7 @@ impl PayoutsInterface for KafkaStore {
&self,
merchant_id: &id_type::MerchantId,
active_payout_ids: &[id_type::PayoutId],
+ profile_id_list: Option<Vec<id_type::ProfileId>>,
connector: Option<Vec<api_models::enums::PayoutConnectors>>,
currency: Option<Vec<enums::Currency>>,
status: Option<Vec<enums::PayoutStatus>>,
@@ -2597,6 +2598,7 @@ impl PayoutsInterface for KafkaStore {
.get_total_count_of_filtered_payouts(
merchant_id,
active_payout_ids,
+ profile_id_list,
connector,
currency,
status,
diff --git a/crates/storage_impl/src/mock_db/payouts.rs b/crates/storage_impl/src/mock_db/payouts.rs
index f836dc71f0..3e493f9e3c 100644
--- a/crates/storage_impl/src/mock_db/payouts.rs
+++ b/crates/storage_impl/src/mock_db/payouts.rs
@@ -96,6 +96,7 @@ impl PayoutsInterface for MockDb {
&self,
_merchant_id: &common_utils::id_type::MerchantId,
_active_payout_ids: &[common_utils::id_type::PayoutId],
+ _profile_id_list: Option<Vec<common_utils::id_type::ProfileId>>,
_connector: Option<Vec<api_models::enums::PayoutConnectors>>,
_currency: Option<Vec<storage_enums::Currency>>,
_status: Option<Vec<storage_enums::PayoutStatus>>,
diff --git a/crates/storage_impl/src/payouts/payouts.rs b/crates/storage_impl/src/payouts/payouts.rs
index 2bae4b43f0..2dcc5f25fc 100644
--- a/crates/storage_impl/src/payouts/payouts.rs
+++ b/crates/storage_impl/src/payouts/payouts.rs
@@ -358,6 +358,7 @@ impl<T: DatabaseStore> PayoutsInterface for KVRouterStore<T> {
&self,
merchant_id: &common_utils::id_type::MerchantId,
active_payout_ids: &[common_utils::id_type::PayoutId],
+ profile_id_list: Option<Vec<common_utils::id_type::ProfileId>>,
connector: Option<Vec<PayoutConnectors>>,
currency: Option<Vec<storage_enums::Currency>>,
status: Option<Vec<storage_enums::PayoutStatus>>,
@@ -367,6 +368,7 @@ impl<T: DatabaseStore> PayoutsInterface for KVRouterStore<T> {
.get_total_count_of_filtered_payouts(
merchant_id,
active_payout_ids,
+ profile_id_list,
connector,
currency,
status,
@@ -781,6 +783,7 @@ impl<T: DatabaseStore> PayoutsInterface for crate::RouterStore<T> {
&self,
merchant_id: &common_utils::id_type::MerchantId,
active_payout_ids: &[common_utils::id_type::PayoutId],
+ profile_id_list: Option<Vec<common_utils::id_type::ProfileId>>,
connector: Option<Vec<PayoutConnectors>>,
currency: Option<Vec<storage_enums::Currency>>,
status: Option<Vec<storage_enums::PayoutStatus>>,
@@ -802,6 +805,7 @@ impl<T: DatabaseStore> PayoutsInterface for crate::RouterStore<T> {
&conn,
merchant_id,
active_payout_ids,
+ profile_id_list,
connector_strings,
currency,
status,