From 3fe934c48e15d7a330ef2b15ab729e1b97781cb6 Mon Sep 17 00:00:00 2001 From: Apoorv Dixit Date: Wed, 17 Apr 2024 03:05:55 +0530 Subject: [PATCH 01/10] feat(refunds): update refunds filters --- crates/api_models/src/events/refund.rs | 10 ++++- crates/api_models/src/refunds.rs | 19 ++++++++- crates/common_enums/src/enums.rs | 1 + crates/router/src/core/refunds.rs | 54 ++++++++++++++++++++++++++ crates/router/src/routes/app.rs | 3 +- crates/router/src/routes/lock_utils.rs | 3 +- crates/router/src/routes/refunds.rs | 34 ++++++++++++++++ crates/router_env/src/logger/types.rs | 2 + 8 files changed, 121 insertions(+), 5 deletions(-) diff --git a/crates/api_models/src/events/refund.rs b/crates/api_models/src/events/refund.rs index 424a3191db6..7ab10a23b71 100644 --- a/crates/api_models/src/events/refund.rs +++ b/crates/api_models/src/events/refund.rs @@ -1,8 +1,8 @@ use common_utils::events::{ApiEventMetric, ApiEventsType}; use crate::refunds::{ - RefundListMetaData, RefundListRequest, RefundListResponse, RefundRequest, RefundResponse, - RefundUpdateRequest, RefundsRetrieveRequest, + RefundListFilters, RefundListMetaData, RefundListRequest, RefundListResponse, RefundRequest, + RefundResponse, RefundUpdateRequest, RefundsRetrieveRequest, }; impl ApiEventMetric for RefundRequest { @@ -61,3 +61,9 @@ impl ApiEventMetric for RefundListMetaData { Some(ApiEventsType::ResourceListAPI) } } + +impl ApiEventMetric for RefundListFilters { + fn get_api_event_type(&self) -> Option { + Some(ApiEventsType::ResourceListAPI) + } +} diff --git a/crates/api_models/src/refunds.rs b/crates/api_models/src/refunds.rs index ea28ed56af3..68dee77b381 100644 --- a/crates/api_models/src/refunds.rs +++ b/crates/api_models/src/refunds.rs @@ -1,10 +1,15 @@ +use std::collections::HashMap; + use common_utils::pii; use serde::{Deserialize, Serialize}; use time::PrimitiveDateTime; use utoipa::ToSchema; use super::payments::TimeRange; -use crate::{admin, enums}; +use crate::{ + admin::{self, MerchantConnectorInfo}, + enums, +}; #[derive(Default, Debug, ToSchema, Clone, Deserialize, Serialize)] #[serde(deny_unknown_fields)] @@ -181,6 +186,18 @@ pub struct RefundListMetaData { pub refund_status: Vec, } +#[derive(Clone, Debug, serde::Serialize, ToSchema)] +pub struct RefundListFilters { + /// The list of available connector filters + pub connector: HashMap>, + /// The list of available currency filters + #[schema(value_type = Vec)] + pub currency: Vec, + /// The list of available refund status filters + #[schema(value_type = Vec)] + pub refund_status: Vec, +} + /// The status for refunds #[derive( Debug, diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index 9dbe5f4f4bc..28aff8b4f23 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -1499,6 +1499,7 @@ pub enum PaymentType { PartialEq, strum::Display, strum::EnumString, + strum::EnumIter, serde::Serialize, serde::Deserialize, )] diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs index 2d6cac3f6e0..7b5ec67432b 100644 --- a/crates/router/src/core/refunds.rs +++ b/crates/router/src/core/refunds.rs @@ -1,9 +1,16 @@ pub mod validator; +#[cfg(feature = "olap")] +use std::collections::HashMap; + +#[cfg(feature = "olap")] +use api_models::admin::MerchantConnectorInfo; use common_utils::ext_traits::AsyncExt; use error_stack::{report, ResultExt}; use router_env::{instrument, tracing}; use scheduler::{consumer::types::process_data, utils as process_tracker_utils}; +#[cfg(feature = "olap")] +use strum::IntoEnumIterator; use crate::{ consts, @@ -767,6 +774,53 @@ pub async fn refund_filter_list( Ok(services::ApplicationResponse::Json(filter_list)) } +#[instrument(skip_all)] +#[cfg(feature = "olap")] +pub async fn get_filters_for_refunds( + state: AppState, + merchant_account: domain::MerchantAccount, +) -> RouterResponse { + let merchant_connector_accounts = if let services::ApplicationResponse::Json(data) = + super::admin::list_payment_connectors(state, merchant_account.merchant_id).await? + { + data + } else { + return Err(errors::ApiErrorResponse::InternalServerError.into()); + }; + + let mut connector_map: HashMap> = HashMap::new(); + merchant_connector_accounts + .iter() + .filter_map(|merchant_connector_account| { + merchant_connector_account + .connector_label + .as_ref() + .map(|label| { + let info = MerchantConnectorInfo { + connector_label: label.clone(), + merchant_connector_id: merchant_connector_account + .merchant_connector_id + .clone(), + }; + (merchant_connector_account.connector_name.clone(), info) + }) + }) + .for_each(|(connector_name, info)| { + connector_map + .entry(connector_name.clone()) + .or_default() + .push(info); + }); + + Ok(services::ApplicationResponse::Json( + api_models::refunds::RefundListFilters { + connector: connector_map, + currency: enums::Currency::iter().collect(), + refund_status: enums::RefundStatus::iter().collect(), + }, + )) +} + impl ForeignFrom for api::RefundResponse { fn foreign_from(refund: storage::Refund) -> Self { let refund = refund; diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index 3bc68ff79b5..1e04eb0614d 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -702,7 +702,8 @@ impl Refunds { { route = route .service(web::resource("/list").route(web::post().to(refunds_list))) - .service(web::resource("/filter").route(web::post().to(refunds_filter_list))); + .service(web::resource("/filter").route(web::post().to(refunds_filter_list))) + .service(web::resource("/filter_v2").route(web::get().to(get_refunds_filters))); } #[cfg(feature = "oltp")] { diff --git a/crates/router/src/routes/lock_utils.rs b/crates/router/src/routes/lock_utils.rs index d9887ac0342..3fd60ac276c 100644 --- a/crates/router/src/routes/lock_utils.rs +++ b/crates/router/src/routes/lock_utils.rs @@ -133,7 +133,8 @@ impl From for ApiIdentifier { | Flow::RefundsRetrieve | Flow::RefundsRetrieveForceSync | Flow::RefundsUpdate - | Flow::RefundsList => Self::Refunds, + | Flow::RefundsList + | Flow::RefundsFilters => Self::Refunds, Flow::FrmFulfillment | Flow::IncomingWebhookReceive diff --git a/crates/router/src/routes/refunds.rs b/crates/router/src/routes/refunds.rs index d68c7138213..d90383f11d6 100644 --- a/crates/router/src/routes/refunds.rs +++ b/crates/router/src/routes/refunds.rs @@ -230,6 +230,7 @@ pub async fn refunds_list( ) .await } + /// Refunds - Filter /// /// To list the refunds filters associated with list of connectors, currencies and payment statuses @@ -267,3 +268,36 @@ pub async fn refunds_filter_list( ) .await } + +/// Refunds - Filter V2 +/// +/// To list the refunds filters associated with list of connectors, currencies and payment statuses +#[utoipa::path( + get, + path = "/refunds/filter_v2", + responses( + (status = 200, description = "List of filters", body = RefundListMetaData), + ), + tag = "Refunds", + operation_id = "List all filters for Refunds", + security(("api_key" = [])) +)] +#[instrument(skip_all, fields(flow = ?Flow::RefundsFilters))] +#[cfg(feature = "olap")] +pub async fn get_refunds_filters(state: web::Data, req: HttpRequest) -> HttpResponse { + let flow = Flow::RefundsFilters; + api::server_wrap( + flow, + state, + &req, + (), + |state, auth, _, _| get_filters_for_refunds(state, auth.merchant_account), + auth::auth_type( + &auth::ApiKeyAuth, + &auth::JWTAuth(Permission::RefundRead), + req.headers(), + ), + api_locking::LockAction::NotApplicable, + ) + .await +} diff --git a/crates/router_env/src/logger/types.rs b/crates/router_env/src/logger/types.rs index 240bf379f6c..4daaa4a8ed9 100644 --- a/crates/router_env/src/logger/types.rs +++ b/crates/router_env/src/logger/types.rs @@ -188,6 +188,8 @@ pub enum Flow { RefundsUpdate, /// Refunds list flow. RefundsList, + /// Refunds filters flow + RefundsFilters, // Retrieve forex flow. RetrieveForexFlow, /// Toggles recon service for a merchant. From 47d5636a02617a59ca5da07220c4ff0eec7185f8 Mon Sep 17 00:00:00 2001 From: Apoorv Dixit Date: Mon, 22 Apr 2024 21:56:07 +0530 Subject: [PATCH 02/10] feat(refunds): filter list by amount and merchant connector id --- crates/api_models/src/admin.rs | 2 +- crates/api_models/src/payments.rs | 2 +- crates/api_models/src/refunds.rs | 8 +++- crates/router/src/db/refund.rs | 50 +++++++++++++++++++++++ crates/router/src/types/storage/refund.rs | 43 ++++++++++++++++++- 5 files changed, 100 insertions(+), 5 deletions(-) diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs index 88d584b6a71..f52c84e4859 100644 --- a/crates/api_models/src/admin.rs +++ b/crates/api_models/src/admin.rs @@ -522,7 +522,7 @@ pub struct MerchantConnectorWebhookDetails { pub additional_secret: Option>, } -#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, ToSchema)] pub struct MerchantConnectorInfo { pub connector_label: String, pub merchant_connector_id: String, diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index b85734af8b8..4309f316862 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -3444,7 +3444,7 @@ pub struct PaymentListFiltersV2 { pub authentication_type: Vec, } -#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] +#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)] pub struct AmountFilter { pub start_amount: Option, pub end_amount: Option, diff --git a/crates/api_models/src/refunds.rs b/crates/api_models/src/refunds.rs index 68dee77b381..c0780098727 100644 --- a/crates/api_models/src/refunds.rs +++ b/crates/api_models/src/refunds.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; use time::PrimitiveDateTime; use utoipa::ToSchema; -use super::payments::TimeRange; +use super::payments::{AmountFilter, TimeRange}; use crate::{ admin::{self, MerchantConnectorInfo}, enums, @@ -151,11 +151,15 @@ pub struct RefundListRequest { pub limit: Option, /// The starting point within a list of objects pub offset: Option, - /// The time range for which objects are needed. TimeRange has two fields start_time and end_time from which objects can be filtered as per required scenarios (created_at, time less than, greater than etc). + /// The time range for which objects are needed. TimeRange has two fields start_time and end_time from which objects can be filtered as per required scenarios (created_at, time less than, greater than etc) #[serde(flatten)] pub time_range: Option, + /// The amount to filter reufnds list. Amount takes two option fields start_amount and end_amount from which objects can be filtered as per required scenarios (less_than, greater_than, equal_to and range) + pub amount_filter: Option, /// The list of connectors to filter refunds list pub connector: Option>, + /// The list of merchant connector ids to filter the refunds list for selected label + pub merchant_connector_id: Option>, /// The list of currencies to filter refunds list #[schema(value_type = Option>)] pub currency: Option>, diff --git a/crates/router/src/db/refund.rs b/crates/router/src/db/refund.rs index ca3921d6199..df1130b7af6 100644 --- a/crates/router/src/db/refund.rs +++ b/crates/router/src/db/refund.rs @@ -930,6 +930,7 @@ impl RefundInterface for MockDb { offset: i64, ) -> CustomResult, errors::StorageError> { let mut unique_connectors = HashSet::new(); + let mut unique_merchant_connector_ids = HashSet::new(); let mut unique_currencies = HashSet::new(); let mut unique_statuses = HashSet::new(); @@ -940,6 +941,14 @@ impl RefundInterface for MockDb { }); } + if let Some(merchant_connector_ids) = &refund_details.merchant_connector_id { + merchant_connector_ids + .iter() + .for_each(|unique_merchant_connector_id| { + unique_merchant_connector_ids.insert(unique_merchant_connector_id); + }); + } + if let Some(currencies) = &refund_details.currency { currencies.iter().for_each(|currency| { unique_currencies.insert(currency); @@ -982,9 +991,25 @@ impl RefundInterface for MockDb { range.end_time.unwrap_or_else(common_utils::date_time::now) }) }) + .filter(|refund| { + refund_details + .amount_filter + .as_ref() + .map_or(true, |amount| { + refund.refund_amount >= amount.start_amount.unwrap_or(i64::MIN) + && refund.refund_amount <= amount.end_amount.unwrap_or(i64::MAX) + }) + }) .filter(|refund| { unique_connectors.is_empty() || unique_connectors.contains(&refund.connector) }) + .filter(|refund| { + unique_merchant_connector_ids.is_empty() + || refund + .merchant_connector_id + .as_ref() + .map_or(false, |id| unique_merchant_connector_ids.contains(id)) + }) .filter(|refund| { unique_currencies.is_empty() || unique_currencies.contains(&refund.currency) }) @@ -1054,6 +1079,7 @@ impl RefundInterface for MockDb { _storage_scheme: enums::MerchantStorageScheme, ) -> CustomResult { let mut unique_connectors = HashSet::new(); + let mut unique_merchant_connector_ids = HashSet::new(); let mut unique_currencies = HashSet::new(); let mut unique_statuses = HashSet::new(); @@ -1064,6 +1090,14 @@ impl RefundInterface for MockDb { }); } + if let Some(merchant_connector_ids) = &refund_details.merchant_connector_id { + merchant_connector_ids + .iter() + .for_each(|unique_merchant_connector_id| { + unique_merchant_connector_ids.insert(unique_merchant_connector_id); + }); + } + if let Some(currencies) = &refund_details.currency { currencies.iter().for_each(|currency| { unique_currencies.insert(currency); @@ -1106,9 +1140,25 @@ impl RefundInterface for MockDb { range.end_time.unwrap_or_else(common_utils::date_time::now) }) }) + .filter(|refund| { + refund_details + .amount_filter + .as_ref() + .map_or(true, |amount| { + refund.refund_amount >= amount.start_amount.unwrap_or(i64::MIN) + && refund.refund_amount <= amount.end_amount.unwrap_or(i64::MAX) + }) + }) .filter(|refund| { unique_connectors.is_empty() || unique_connectors.contains(&refund.connector) }) + .filter(|refund| { + unique_merchant_connector_ids.is_empty() + || refund + .merchant_connector_id + .as_ref() + .map_or(false, |id| unique_merchant_connector_ids.contains(id)) + }) .filter(|refund| { unique_currencies.is_empty() || unique_currencies.contains(&refund.currency) }) diff --git a/crates/router/src/types/storage/refund.rs b/crates/router/src/types/storage/refund.rs index 76bdf8655f6..55f4881895c 100644 --- a/crates/router/src/types/storage/refund.rs +++ b/crates/router/src/types/storage/refund.rs @@ -1,3 +1,4 @@ +use api_models::payments::AmountFilter; use async_bb8_diesel::AsyncRunQueryDsl; use common_utils::errors::CustomResult; use diesel::{associations::HasTable, ExpressionMethods, QueryDsl}; @@ -104,10 +105,30 @@ impl RefundDbExt for Refund { } } + filter = match refund_list_details.amount_filter { + Some(AmountFilter { + start_amount: Some(start), + end_amount: Some(end), + }) => filter.filter(dsl::refund_amount.between(start, end)), + Some(AmountFilter { + start_amount: Some(start), + end_amount: None, + }) => filter.filter(dsl::refund_amount.ge(start)), + Some(AmountFilter { + start_amount: None, + end_amount: Some(end), + }) => filter.filter(dsl::refund_amount.le(end)), + _ => filter, + }; + if let Some(connector) = refund_list_details.clone().connector { filter = filter.filter(dsl::connector.eq_any(connector)); } + if let Some(merchant_connector_id) = refund_list_details.clone().merchant_connector_id { + filter = filter.filter(dsl::merchant_connector_id.eq_any(merchant_connector_id)); + } + if let Some(filter_currency) = &refund_list_details.currency { filter = filter.filter(dsl::currency.eq_any(filter_currency.clone())); } @@ -227,10 +248,30 @@ impl RefundDbExt for Refund { } } - if let Some(connector) = refund_list_details.clone().connector { + filter = match refund_list_details.amount_filter { + Some(AmountFilter { + start_amount: Some(start), + end_amount: Some(end), + }) => filter.filter(dsl::refund_amount.between(start, end)), + Some(AmountFilter { + start_amount: Some(start), + end_amount: None, + }) => filter.filter(dsl::refund_amount.ge(start)), + Some(AmountFilter { + start_amount: None, + end_amount: Some(end), + }) => filter.filter(dsl::refund_amount.le(end)), + _ => filter, + }; + + if let Some(connector) = refund_list_details.connector.clone() { filter = filter.filter(dsl::connector.eq_any(connector)); } + if let Some(merchant_connector_id) = refund_list_details.merchant_connector_id.clone() { + filter = filter.filter(dsl::merchant_connector_id.eq_any(merchant_connector_id)) + } + if let Some(filter_currency) = &refund_list_details.currency { filter = filter.filter(dsl::currency.eq_any(filter_currency.clone())); } From 23afdc561bc1831f6cba925e9138a1a227df81c3 Mon Sep 17 00:00:00 2001 From: Apoorv Dixit Date: Mon, 22 Apr 2024 22:21:53 +0530 Subject: [PATCH 03/10] fix: to shema for amount filter --- crates/api_models/src/payments.rs | 2 +- crates/router/src/routes/refunds.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index 4309f316862..cff5c1402f2 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -3444,7 +3444,7 @@ pub struct PaymentListFiltersV2 { pub authentication_type: Vec, } -#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)] +#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)] pub struct AmountFilter { pub start_amount: Option, pub end_amount: Option, diff --git a/crates/router/src/routes/refunds.rs b/crates/router/src/routes/refunds.rs index d90383f11d6..a591d7cca1e 100644 --- a/crates/router/src/routes/refunds.rs +++ b/crates/router/src/routes/refunds.rs @@ -276,7 +276,7 @@ pub async fn refunds_filter_list( get, path = "/refunds/filter_v2", responses( - (status = 200, description = "List of filters", body = RefundListMetaData), + (status = 200, description = "List of static filters", body = RefundListMetaData), ), tag = "Refunds", operation_id = "List all filters for Refunds", From a1351ec51ca47fa85686bc6f95663176a4e2f210 Mon Sep 17 00:00:00 2001 From: Apoorv Dixit Date: Tue, 23 Apr 2024 15:39:14 +0530 Subject: [PATCH 04/10] fix: change openspec api for amount filter --- crates/api_models/src/payments.rs | 2 ++ crates/openapi/src/openapi.rs | 1 + openapi/openapi_spec.json | 33 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index cff5c1402f2..aa14d923784 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -3446,7 +3446,9 @@ pub struct PaymentListFiltersV2 { #[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)] pub struct AmountFilter { + /// The start amount to filter list of transactions which are greater than or equal to the start amount pub start_amount: Option, + /// The end amount to filter list of transactions which are less than or equal to the end amount pub end_amount: Option, } diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs index 972dde7542a..4ac7f5eaf2b 100644 --- a/crates/openapi/src/openapi.rs +++ b/crates/openapi/src/openapi.rs @@ -414,6 +414,7 @@ Never share your secret api keys. Keep them guarded and secure. api_models::refunds::RefundListRequest, api_models::refunds::RefundListResponse, api_models::payments::TimeRange, + api_models::payments::AmountFilter, api_models::mandates::MandateRevokedResponse, api_models::mandates::MandateResponse, api_models::mandates::MandateCardDetails, diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json index f646ba8b8d9..ce344c83d6b 100644 --- a/openapi/openapi_spec.json +++ b/openapi/openapi_spec.json @@ -4911,6 +4911,23 @@ "AliPayRedirection": { "type": "object" }, + "AmountFilter": { + "type": "object", + "properties": { + "start_amount": { + "type": "integer", + "format": "int64", + "description": "The start amount to filter list of transactions which are greater than or equal to the start amount", + "nullable": true + }, + "end_amount": { + "type": "integer", + "format": "int64", + "description": "The end amount to filter list transactions which are less than or equal to the end amount", + "nullable": true + } + } + }, "AmountInfo": { "type": "object", "required": [ @@ -16500,6 +16517,14 @@ "description": "The starting point within a list of objects", "nullable": true }, + "amount_filter": { + "allOf": [ + { + "$ref": "#/components/schemas/AmountFilter" + } + ], + "nullable": true + }, "connector": { "type": "array", "items": { @@ -16508,6 +16533,14 @@ "description": "The list of connectors to filter refunds list", "nullable": true }, + "merchant_connector_id": { + "type": "array", + "items": { + "type": "string" + }, + "description": "The list of merchant connector ids to filter the refunds list for selected label", + "nullable": true + }, "currency": { "type": "array", "items": { From 4d4dbdeac2192f9640aff2fa272875929a39f94b Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Tue, 23 Apr 2024 10:15:16 +0000 Subject: [PATCH 05/10] docs(openapi): re-generate OpenAPI specification --- openapi/openapi_spec.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json index ce344c83d6b..4197b4c34aa 100644 --- a/openapi/openapi_spec.json +++ b/openapi/openapi_spec.json @@ -4923,7 +4923,7 @@ "end_amount": { "type": "integer", "format": "int64", - "description": "The end amount to filter list transactions which are less than or equal to the end amount", + "description": "The end amount to filter list of transactions which are less than or equal to the end amount", "nullable": true } } From 07e18a458f0430d0fe2f6ada0c12da9c56abd8bd Mon Sep 17 00:00:00 2001 From: Apoorv Dixit Date: Wed, 24 Apr 2024 19:10:07 +0530 Subject: [PATCH 06/10] fix: resove PR comments --- crates/router/src/routes/refunds.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/router/src/routes/refunds.rs b/crates/router/src/routes/refunds.rs index a591d7cca1e..a6b48808356 100644 --- a/crates/router/src/routes/refunds.rs +++ b/crates/router/src/routes/refunds.rs @@ -276,7 +276,7 @@ pub async fn refunds_filter_list( get, path = "/refunds/filter_v2", responses( - (status = 200, description = "List of static filters", body = RefundListMetaData), + (status = 200, description = "List of static filters", body = RefundListFilters), ), tag = "Refunds", operation_id = "List all filters for Refunds", From 1641c8278ee27b07e363e110ded508da9bf2bbfe Mon Sep 17 00:00:00 2001 From: Apoorv Dixit Date: Tue, 7 May 2024 12:05:28 +0530 Subject: [PATCH 07/10] fix: resolve review comments --- crates/api_models/src/refunds.rs | 2 +- crates/router/src/core/refunds.rs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/api_models/src/refunds.rs b/crates/api_models/src/refunds.rs index c0780098727..369aa0a6602 100644 --- a/crates/api_models/src/refunds.rs +++ b/crates/api_models/src/refunds.rs @@ -192,7 +192,7 @@ pub struct RefundListMetaData { #[derive(Clone, Debug, serde::Serialize, ToSchema)] pub struct RefundListFilters { - /// The list of available connector filters + /// The map of available connector filters, where the key is the connector name and the value is a list of MerchantConnectorInfo instances pub connector: HashMap>, /// The list of available currency filters #[schema(value_type = Vec)] diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs index 7b5ec67432b..5b9aee52651 100644 --- a/crates/router/src/core/refunds.rs +++ b/crates/router/src/core/refunds.rs @@ -788,8 +788,7 @@ pub async fn get_filters_for_refunds( return Err(errors::ApiErrorResponse::InternalServerError.into()); }; - let mut connector_map: HashMap> = HashMap::new(); - merchant_connector_accounts + let connector_map = merchant_connector_accounts .iter() .filter_map(|merchant_connector_account| { merchant_connector_account @@ -805,12 +804,13 @@ pub async fn get_filters_for_refunds( (merchant_connector_account.connector_name.clone(), info) }) }) - .for_each(|(connector_name, info)| { - connector_map - .entry(connector_name.clone()) - .or_default() - .push(info); - }); + .fold( + HashMap::new(), + |mut map: HashMap>, (connector_name, info)| { + map.entry(connector_name).or_default().push(info); + map + }, + ); Ok(services::ApplicationResponse::Json( api_models::refunds::RefundListFilters { From 8bf601a6e713c6ba01c260e04b7ca6f3385a1f72 Mon Sep 17 00:00:00 2001 From: Apoorv Dixit Date: Mon, 13 May 2024 15:30:24 +0530 Subject: [PATCH 08/10] resolve review comments --- crates/router/src/core/refunds.rs | 21 ++++++++------------- crates/router/src/routes/app.rs | 4 ++-- crates/router/src/types/storage/refund.rs | 4 ++-- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs index 5b9aee52651..2ddc5e1f6c2 100644 --- a/crates/router/src/core/refunds.rs +++ b/crates/router/src/core/refunds.rs @@ -789,20 +789,15 @@ pub async fn get_filters_for_refunds( }; let connector_map = merchant_connector_accounts - .iter() + .into_iter() .filter_map(|merchant_connector_account| { - merchant_connector_account - .connector_label - .as_ref() - .map(|label| { - let info = MerchantConnectorInfo { - connector_label: label.clone(), - merchant_connector_id: merchant_connector_account - .merchant_connector_id - .clone(), - }; - (merchant_connector_account.connector_name.clone(), info) - }) + merchant_connector_account.connector_label.map(|label| { + let info = MerchantConnectorInfo { + connector_label: label, + merchant_connector_id: merchant_connector_account.merchant_connector_id, + }; + (merchant_connector_account.connector_name, info) + }) }) .fold( HashMap::new(), diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index df1b8c29956..2c9f164f8c0 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -318,7 +318,7 @@ impl Payments { .route(web::post().to(payments_list_by_filter)), ) .service(web::resource("/filter").route(web::post().to(get_filters_for_payments))) - .service(web::resource("/filter_v2").route(web::get().to(get_payment_filters))) + .service(web::resource("/filter/v2").route(web::get().to(get_payment_filters))) } #[cfg(feature = "oltp")] { @@ -703,7 +703,7 @@ impl Refunds { route = route .service(web::resource("/list").route(web::post().to(refunds_list))) .service(web::resource("/filter").route(web::post().to(refunds_filter_list))) - .service(web::resource("/filter_v2").route(web::get().to(get_refunds_filters))); + .service(web::resource("/filter/v2").route(web::get().to(get_refunds_filters))); } #[cfg(feature = "oltp")] { diff --git a/crates/router/src/types/storage/refund.rs b/crates/router/src/types/storage/refund.rs index 55f4881895c..75030721ec5 100644 --- a/crates/router/src/types/storage/refund.rs +++ b/crates/router/src/types/storage/refund.rs @@ -121,11 +121,11 @@ impl RefundDbExt for Refund { _ => filter, }; - if let Some(connector) = refund_list_details.clone().connector { + if let Some(connector) = refund_list_details.connector.clone() { filter = filter.filter(dsl::connector.eq_any(connector)); } - if let Some(merchant_connector_id) = refund_list_details.clone().merchant_connector_id { + if let Some(merchant_connector_id) = refund_list_details.merchant_connector_id.clone() { filter = filter.filter(dsl::merchant_connector_id.eq_any(merchant_connector_id)); } From a7b212357d5f7bd94992dc1dfd318b7e6d788fa6 Mon Sep 17 00:00:00 2001 From: Apoorv Dixit Date: Mon, 13 May 2024 15:52:52 +0530 Subject: [PATCH 09/10] fix: change routes for v2 --- crates/router/src/routes/app.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index 005d14821e6..21cc994381e 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -333,7 +333,7 @@ impl Payments { .route(web::post().to(payments_list_by_filter)), ) .service(web::resource("/filter").route(web::post().to(get_filters_for_payments))) - .service(web::resource("/filter/v2").route(web::get().to(get_payment_filters))) + .service(web::resource("/v2/filter").route(web::get().to(get_payment_filters))) } #[cfg(feature = "oltp")] { @@ -717,7 +717,7 @@ impl Refunds { route = route .service(web::resource("/list").route(web::post().to(refunds_list))) .service(web::resource("/filter").route(web::post().to(refunds_filter_list))) - .service(web::resource("/filter/v2").route(web::get().to(get_refunds_filters))); + .service(web::resource("/v2/filter").route(web::get().to(get_refunds_filters))); } #[cfg(feature = "oltp")] { From b9b62cb4fc996df2c07ef74870017e95763f08db Mon Sep 17 00:00:00 2001 From: Apoorv Dixit Date: Mon, 13 May 2024 15:58:53 +0530 Subject: [PATCH 10/10] fix: change route for utoipa --- crates/router/src/routes/refunds.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/router/src/routes/refunds.rs b/crates/router/src/routes/refunds.rs index a6b48808356..3df6c871668 100644 --- a/crates/router/src/routes/refunds.rs +++ b/crates/router/src/routes/refunds.rs @@ -274,7 +274,7 @@ pub async fn refunds_filter_list( /// To list the refunds filters associated with list of connectors, currencies and payment statuses #[utoipa::path( get, - path = "/refunds/filter_v2", + path = "/refunds/v2/filter", responses( (status = 200, description = "List of static filters", body = RefundListFilters), ),