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

feat(router): add v2 endpoint retrieve payment aggregate based on merchant profile (#7196)

Aniket Burmanc17eb01e3574
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<Vec<PaymentIntent>, 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<app::AppState>,
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<app::AppState>,
+ req: actix_web::HttpRequest,
+ payload: web::Query<common_utils::types::TimeRange>,
+) -> 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<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
.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<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
.await
}
- #[cfg(all(feature = "v1", feature = "olap"))]
+ #[cfg(feature = "olap")]
#[instrument(skip_all)]
async fn get_intent_status_with_count(
&self,