From c17eb01e35749343b3bf4fdda51782ea962ee57a Mon Sep 17 00:00:00 2001 From: Aniket Burman <93077964+aniketburman014@users.noreply.github.com> Date: Fri, 14 Feb 2025 18:21:57 +0530 Subject: [PATCH] feat(router): add v2 endpoint retrieve payment aggregate based on merchant profile (#7196) Co-authored-by: Aniket Burman Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> --- .../src/payments/payment_intent.rs | 2 +- crates/router/src/core/payments.rs | 2 +- crates/router/src/db/kafka_store.rs | 3 +- crates/router/src/routes/app.rs | 7 +++++ crates/router/src/routes/payments.rs | 31 ++++++++++++++++++- .../src/mock_db/payment_intent.rs | 2 +- .../src/payments/payment_intent.rs | 4 +-- 7 files changed, 43 insertions(+), 8 deletions(-) diff --git a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs index e20b086016..b2335550cf 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs @@ -102,7 +102,7 @@ pub trait PaymentIntentInterface { storage_scheme: common_enums::MerchantStorageScheme, ) -> error_stack::Result, errors::StorageError>; - #[cfg(all(feature = "v1", feature = "olap"))] + #[cfg(feature = "olap")] async fn get_intent_status_with_count( &self, merchant_id: &id_type::MerchantId, diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs index 57e72a4294..e681c76afb 100644 --- a/crates/router/src/core/payments.rs +++ b/crates/router/src/core/payments.rs @@ -5408,7 +5408,7 @@ pub async fn get_payment_filters( )) } -#[cfg(all(feature = "olap", feature = "v1"))] +#[cfg(feature = "olap")] pub async fn get_aggregates_for_payments( state: SessionState, merchant: domain::MerchantAccount, diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rs index d4a1fee092..d21c345b5f 100644 --- a/crates/router/src/db/kafka_store.rs +++ b/crates/router/src/db/kafka_store.rs @@ -1876,8 +1876,7 @@ impl PaymentIntentInterface for KafkaStore { ) .await } - - #[cfg(all(feature = "olap", feature = "v1"))] + #[cfg(feature = "olap")] async fn get_intent_status_with_count( &self, merchant_id: &id_type::MerchantId, diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index ee1e06af93..3da65e968b 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -571,6 +571,13 @@ impl Payments { .service( web::resource("/create-intent") .route(web::post().to(payments::payments_create_intent)), + ) + .service( + web::resource("/aggregate").route(web::get().to(payments::get_payments_aggregates)), + ) + .service( + web::resource("/profile/aggregate") + .route(web::get().to(payments::get_payments_aggregates_profile)), ); route = diff --git a/crates/router/src/routes/payments.rs b/crates/router/src/routes/payments.rs index b55ab207f4..dd15079efe 100644 --- a/crates/router/src/routes/payments.rs +++ b/crates/router/src/routes/payments.rs @@ -1407,7 +1407,7 @@ pub async fn get_payment_filters_profile( } #[instrument(skip_all, fields(flow = ?Flow::PaymentsAggregate))] -#[cfg(all(feature = "olap", feature = "v1"))] +#[cfg(feature = "olap")] pub async fn get_payments_aggregates( state: web::Data, req: actix_web::HttpRequest, @@ -2228,6 +2228,35 @@ pub async fn get_payments_aggregates_profile( )) .await } +#[instrument(skip_all, fields(flow = ?Flow::PaymentsAggregate))] +#[cfg(all(feature = "olap", feature = "v2"))] +pub async fn get_payments_aggregates_profile( + state: web::Data, + req: actix_web::HttpRequest, + payload: web::Query, +) -> impl Responder { + let flow = Flow::PaymentsAggregate; + let payload = payload.into_inner(); + Box::pin(api::server_wrap( + flow, + state, + &req, + payload, + |state, auth: auth::AuthenticationData, req, _| { + payments::get_aggregates_for_payments( + state, + auth.merchant_account, + Some(vec![auth.profile.get_id().clone()]), + req, + ) + }, + &auth::JWTAuth { + permission: Permission::ProfilePaymentRead, + }, + api_locking::LockAction::NotApplicable, + )) + .await +} #[cfg(feature = "v2")] /// A private module to hold internal types to be used in route handlers. diff --git a/crates/storage_impl/src/mock_db/payment_intent.rs b/crates/storage_impl/src/mock_db/payment_intent.rs index 0766d397bb..6a46702e52 100644 --- a/crates/storage_impl/src/mock_db/payment_intent.rs +++ b/crates/storage_impl/src/mock_db/payment_intent.rs @@ -41,7 +41,7 @@ impl PaymentIntentInterface for MockDb { Err(StorageError::MockDbError)? } - #[cfg(all(feature = "v1", feature = "olap"))] + #[cfg(feature = "olap")] async fn get_intent_status_with_count( &self, _merchant_id: &common_utils::id_type::MerchantId, diff --git a/crates/storage_impl/src/payments/payment_intent.rs b/crates/storage_impl/src/payments/payment_intent.rs index a515898006..b64d1aee36 100644 --- a/crates/storage_impl/src/payments/payment_intent.rs +++ b/crates/storage_impl/src/payments/payment_intent.rs @@ -412,7 +412,7 @@ impl PaymentIntentInterface for KVRouterStore { .await } - #[cfg(all(feature = "v1", feature = "olap"))] + #[cfg(feature = "olap")] async fn get_intent_status_with_count( &self, merchant_id: &common_utils::id_type::MerchantId, @@ -829,7 +829,7 @@ impl PaymentIntentInterface for crate::RouterStore { .await } - #[cfg(all(feature = "v1", feature = "olap"))] + #[cfg(feature = "olap")] #[instrument(skip_all)] async fn get_intent_status_with_count( &self,