Skip to content

Commit

Permalink
feat(payments): add merchant order ref id filter (#6630)
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvdixit88 authored Nov 25, 2024
1 parent 0db3aed commit 57e64c2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
2 changes: 2 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4927,6 +4927,8 @@ pub struct PaymentListFilterConstraints {
pub order: Order,
/// The List of all the card networks to filter payments list
pub card_network: Option<Vec<enums::CardNetwork>>,
/// The identifier for merchant order reference id
pub merchant_order_reference_id: Option<String>,
}

impl PaymentListFilterConstraints {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,7 @@ pub struct PaymentIntentListParams {
pub limit: Option<u32>,
pub order: api_models::payments::Order,
pub card_network: Option<Vec<storage_enums::CardNetwork>>,
pub merchant_order_reference_id: Option<String>,
}

impl From<api_models::payments::PaymentListConstraints> for PaymentIntentFetchConstraints {
Expand Down Expand Up @@ -1036,6 +1037,7 @@ impl From<api_models::payments::PaymentListConstraints> for PaymentIntentFetchCo
limit: Some(std::cmp::min(limit, PAYMENTS_LIST_MAX_LIMIT_V1)),
order: Default::default(),
card_network: None,
merchant_order_reference_id: None,
}))
}
}
Expand All @@ -1061,6 +1063,7 @@ impl From<common_utils::types::TimeRange> for PaymentIntentFetchConstraints {
limit: None,
order: Default::default(),
card_network: None,
merchant_order_reference_id: None,
}))
}
}
Expand All @@ -1084,6 +1087,7 @@ impl From<api_models::payments::PaymentListFilterConstraints> for PaymentIntentF
merchant_connector_id,
order,
card_network,
merchant_order_reference_id,
} = value;
if let Some(payment_intent_id) = payment_id {
Self::Single { payment_intent_id }
Expand All @@ -1107,6 +1111,7 @@ impl From<api_models::payments::PaymentListFilterConstraints> for PaymentIntentF
limit: Some(std::cmp::min(limit, PAYMENTS_LIST_MAX_LIMIT_V2)),
order,
card_network,
merchant_order_reference_id,
}))
}
}
Expand Down
10 changes: 6 additions & 4 deletions crates/router/src/types/storage/dispute.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use async_bb8_diesel::AsyncRunQueryDsl;
use common_utils::errors::CustomResult;
use diesel::{associations::HasTable, ExpressionMethods, QueryDsl};
use diesel::{associations::HasTable, BoolExpressionMethods, ExpressionMethods, QueryDsl};
pub use diesel_models::dispute::{Dispute, DisputeNew, DisputeUpdate};
use diesel_models::{errors, query::generics::db_metrics, schema::dispute::dsl};
use error_stack::ResultExt;
Expand Down Expand Up @@ -43,9 +43,11 @@ impl DisputeDbExt for Dispute {
&dispute_list_constraints.dispute_id,
) {
search_by_payment_or_dispute_id = true;
filter = filter
.filter(dsl::payment_id.eq(payment_id.to_owned()))
.or_filter(dsl::dispute_id.eq(dispute_id.to_owned()));
filter = filter.filter(
dsl::payment_id
.eq(payment_id.to_owned())
.or(dsl::dispute_id.eq(dispute_id.to_owned())),
);
};

if !search_by_payment_or_dispute_id {
Expand Down
17 changes: 11 additions & 6 deletions crates/router/src/types/storage/refund.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use api_models::payments::AmountFilter;
use async_bb8_diesel::AsyncRunQueryDsl;
use common_utils::errors::CustomResult;
use diesel::{associations::HasTable, ExpressionMethods, QueryDsl};
use diesel::{associations::HasTable, BoolExpressionMethods, ExpressionMethods, QueryDsl};
pub use diesel_models::refund::{
Refund, RefundCoreWorkflow, RefundNew, RefundUpdate, RefundUpdateInternal,
};
Expand Down Expand Up @@ -67,8 +67,11 @@ impl RefundDbExt for Refund {
) {
search_by_pay_or_ref_id = true;
filter = filter
.filter(dsl::payment_id.eq(pid.to_owned()))
.or_filter(dsl::refund_id.eq(ref_id.to_owned()))
.filter(
dsl::payment_id
.eq(pid.to_owned())
.or(dsl::refund_id.eq(ref_id.to_owned())),
)
.limit(limit)
.offset(offset);
};
Expand Down Expand Up @@ -228,9 +231,11 @@ impl RefundDbExt for Refund {
&refund_list_details.refund_id,
) {
search_by_pay_or_ref_id = true;
filter = filter
.filter(dsl::payment_id.eq(pid.to_owned()))
.or_filter(dsl::refund_id.eq(ref_id.to_owned()));
filter = filter.filter(
dsl::payment_id
.eq(pid.to_owned())
.or(dsl::refund_id.eq(ref_id.to_owned())),
);
};

if !search_by_pay_or_ref_id {
Expand Down
11 changes: 11 additions & 0 deletions crates/storage_impl/src/payments/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,12 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
query = query.filter(pi_dsl::customer_id.eq(customer_id.clone()));
}

if let Some(merchant_order_reference_id) = &params.merchant_order_reference_id {
query = query.filter(
pi_dsl::merchant_order_reference_id.eq(merchant_order_reference_id.clone()),
)
}

if let Some(profile_id) = &params.profile_id {
query = query.filter(pi_dsl::profile_id.eq_any(profile_id.clone()));
}
Expand Down Expand Up @@ -1041,6 +1047,11 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
if let Some(customer_id) = &params.customer_id {
query = query.filter(pi_dsl::customer_id.eq(customer_id.clone()));
}
if let Some(merchant_order_reference_id) = &params.merchant_order_reference_id {
query = query.filter(
pi_dsl::merchant_order_reference_id.eq(merchant_order_reference_id.clone()),
)
}
if let Some(profile_id) = &params.profile_id {
query = query.filter(pi_dsl::profile_id.eq_any(profile_id.clone()));
}
Expand Down

0 comments on commit 57e64c2

Please sign in to comment.