feat: enable payment and refund filter at DB query level (#5827)

This commit is contained in:
Hrithikesh
2024-09-09 13:23:47 +05:30
committed by GitHub
parent aa2f5d1475
commit 21352cf875
14 changed files with 268 additions and 60 deletions

View File

@ -2940,15 +2940,13 @@ pub async fn list_payments(
let db = state.store.as_ref();
let payment_intents = helpers::filter_by_constraints(
&state,
&constraints,
&(constraints, profile_id_list).try_into()?,
merchant_id,
&key_store,
merchant.storage_scheme,
)
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
let payment_intents =
utils::filter_objects_based_on_profile_id_list(profile_id_list, payment_intents);
let collected_futures = payment_intents.into_iter().map(|pi| {
async {
@ -3011,25 +3009,25 @@ pub async fn apply_filters_on_payments(
) -> RouterResponse<api::PaymentListResponseV2> {
let limit = &constraints.limit;
helpers::validate_payment_list_request_for_joins(*limit)?;
let db = state.store.as_ref();
let db: &dyn StorageInterface = state.store.as_ref();
let pi_fetch_constraints = (constraints.clone(), profile_id_list.clone()).try_into()?;
let list: Vec<(storage::PaymentIntent, storage::PaymentAttempt)> = db
.get_filtered_payment_intents_attempt(
&(&state).into(),
merchant.get_id(),
&constraints.clone().into(),
&pi_fetch_constraints,
&merchant_key_store,
merchant.storage_scheme,
)
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
let list = utils::filter_objects_based_on_profile_id_list(profile_id_list, list);
let data: Vec<api::PaymentsResponse> =
list.into_iter().map(ForeignFrom::foreign_from).collect();
let active_attempt_ids = db
.get_filtered_active_attempt_ids_for_total_count(
merchant.get_id(),
&constraints.clone().into(),
&pi_fetch_constraints,
merchant.storage_scheme,
)
.await
@ -3044,6 +3042,7 @@ pub async fn apply_filters_on_payments(
constraints.payment_method_type,
constraints.authentication_type,
constraints.merchant_connector_id,
pi_fetch_constraints.get_profile_id_list(),
merchant.storage_scheme,
)
.await

View File

@ -26,7 +26,10 @@ use hyperswitch_domain_models::payments::payment_intent::CustomerData;
use hyperswitch_domain_models::{
mandates::MandateData,
payment_method_data::GetPaymentMethodType,
payments::{payment_attempt::PaymentAttempt, PaymentIntent},
payments::{
payment_attempt::PaymentAttempt, payment_intent::PaymentIntentFetchConstraints,
PaymentIntent,
},
router_data::KlarnaSdkResponse,
};
use hyperswitch_interfaces::integrity::{CheckIntegrity, FlowIntegrity, GetIntegrityObject};
@ -2538,7 +2541,7 @@ where
#[cfg(feature = "olap")]
pub(super) async fn filter_by_constraints(
state: &SessionState,
constraints: &api::PaymentListConstraints,
constraints: &PaymentIntentFetchConstraints,
merchant_id: &id_type::MerchantId,
key_store: &domain::MerchantKeyStore,
storage_scheme: storage_enums::MerchantStorageScheme,
@ -2548,7 +2551,7 @@ pub(super) async fn filter_by_constraints(
.filter_payment_intent_by_constraints(
&(state).into(),
merchant_id,
&constraints.clone().into(),
constraints,
key_store,
storage_scheme,
)

View File

@ -869,7 +869,7 @@ pub async fn validate_and_create_refund(
pub async fn refund_list(
state: SessionState,
merchant_account: domain::MerchantAccount,
_profile_id_list: Option<Vec<common_utils::id_type::ProfileId>>,
profile_id_list: Option<Vec<common_utils::id_type::ProfileId>>,
req: api_models::refunds::RefundListRequest,
) -> RouterResponse<api_models::refunds::RefundListResponse> {
let db = state.store;
@ -879,7 +879,7 @@ pub async fn refund_list(
let refund_list = db
.filter_refund_by_constraints(
merchant_account.get_id(),
&req,
&(req.clone(), profile_id_list.clone()).try_into()?,
merchant_account.storage_scheme,
limit,
offset,
@ -895,7 +895,7 @@ pub async fn refund_list(
let total_count = db
.get_total_count_of_refunds(
merchant_account.get_id(),
&req,
&(req, profile_id_list).try_into()?,
merchant_account.storage_scheme,
)
.await