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

refactor(webhook): add jwt authenticated endpoint to list unique webhook events for a profile (#7325)

Aishwariyaa Anand701079908778
diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json
index 3d484a2243..06b56e2add 100644
--- a/api-reference/openapi_spec.json
+++ b/api-reference/openapi_spec.json
@@ -5408,6 +5408,92 @@
]
}
},
+ "/events/profile/list": {
+ "get": {
+ "tags": [
+ "Event"
+ ],
+ "summary": "Events - List",
+ "description": "List all Events associated with a Profile.",
+ "operationId": "List all Events associated with a Profile",
+ "parameters": [
+ {
+ "name": "created_after",
+ "in": "query",
+ "description": "Only include Events created after the specified time. Either only `object_id` must be specified, or one or more of `created_after`, `created_before`, `limit` and `offset` must be specified.",
+ "required": false,
+ "schema": {
+ "type": "string",
+ "format": "date-time",
+ "nullable": true
+ }
+ },
+ {
+ "name": "created_before",
+ "in": "query",
+ "description": "Only include Events created before the specified time. Either only `object_id` must be specified, or one or more of `created_after`, `created_before`, `limit` and `offset` must be specified.",
+ "required": false,
+ "schema": {
+ "type": "string",
+ "format": "date-time",
+ "nullable": true
+ }
+ },
+ {
+ "name": "limit",
+ "in": "query",
+ "description": "The maximum number of Events to include in the response. Either only `object_id` must be specified, or one or more of `created_after`, `created_before`, `limit` and `offset` must be specified.",
+ "required": false,
+ "schema": {
+ "type": "integer",
+ "format": "int64",
+ "nullable": true
+ }
+ },
+ {
+ "name": "offset",
+ "in": "query",
+ "description": "The number of Events to skip when retrieving the list of Events.\n Either only `object_id` must be specified, or one or more of `created_after`, `created_before`, `limit` and `offset` must be specified.",
+ "required": false,
+ "schema": {
+ "type": "integer",
+ "format": "int64",
+ "nullable": true
+ }
+ },
+ {
+ "name": "object_id",
+ "in": "query",
+ "description": "Only include Events associated with the specified object (Payment Intent ID, Refund ID, etc.). Either only `object_id` must be specified, or one or more of `created_after`, `created_before`, `limit` and `offset` must be specified.",
+ "required": false,
+ "schema": {
+ "type": "string",
+ "nullable": true
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "List of Events retrieved successfully",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "array",
+ "items": {
+ "$ref": "#/components/schemas/EventListItemResponse"
+ }
+ }
+ }
+ }
+ }
+ },
+ "security": [
+ {
+ "jwt_key": []
+ }
+ ]
+ }
+ },
"/events/{merchant_id}/{event_id}/attempts": {
"get": {
"tags": [
diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs
index acdf2a8fff..ac1a3c94e8 100644
--- a/crates/openapi/src/openapi.rs
+++ b/crates/openapi/src/openapi.rs
@@ -195,6 +195,7 @@ Never share your secret api keys. Keep them guarded and secure.
// Routes for events
routes::webhook_events::list_initial_webhook_delivery_attempts,
+ routes::webhook_events::list_initial_webhook_delivery_attempts_with_jwtauth,
routes::webhook_events::list_webhook_delivery_attempts,
routes::webhook_events::retry_webhook_delivery_attempt,
diff --git a/crates/openapi/src/routes/webhook_events.rs b/crates/openapi/src/routes/webhook_events.rs
index c65a61768f..605c51340d 100644
--- a/crates/openapi/src/routes/webhook_events.rs
+++ b/crates/openapi/src/routes/webhook_events.rs
@@ -55,6 +55,53 @@
)]
pub fn list_initial_webhook_delivery_attempts() {}
+/// Events - List
+///
+/// List all Events associated with a Profile.
+#[utoipa::path(
+ get,
+ path = "/events/profile/list",
+ params(
+ (
+ "created_after" = Option<PrimitiveDateTime>,
+ Query,
+ description = "Only include Events created after the specified time. \
+ Either only `object_id` must be specified, or one or more of `created_after`, `created_before`, `limit` and `offset` must be specified."
+ ),
+ (
+ "created_before" = Option<PrimitiveDateTime>,
+ Query,
+ description = "Only include Events created before the specified time. \
+ Either only `object_id` must be specified, or one or more of `created_after`, `created_before`, `limit` and `offset` must be specified."
+ ),
+ (
+ "limit" = Option<i64>,
+ Query,
+ description = "The maximum number of Events to include in the response. \
+ Either only `object_id` must be specified, or one or more of `created_after`, `created_before`, `limit` and `offset` must be specified."
+ ),
+ (
+ "offset" = Option<i64>,
+ Query,
+ description = "The number of Events to skip when retrieving the list of Events.
+ Either only `object_id` must be specified, or one or more of `created_after`, `created_before`, `limit` and `offset` must be specified."
+ ),
+ (
+ "object_id" = Option<String>,
+ Query,
+ description = "Only include Events associated with the specified object (Payment Intent ID, Refund ID, etc.). \
+ Either only `object_id` must be specified, or one or more of `created_after`, `created_before`, `limit` and `offset` must be specified."
+ ),
+ ),
+ responses(
+ (status = 200, description = "List of Events retrieved successfully", body = Vec<EventListItemResponse>),
+ ),
+ tag = "Event",
+ operation_id = "List all Events associated with a Profile",
+ security(("jwt_key" = []))
+)]
+pub fn list_initial_webhook_delivery_attempts_with_jwtauth() {}
+
/// Events - Delivery Attempt List
///
/// List all delivery attempts for the specified Event.
diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs
index c4896bed49..58acfa47d3 100644
--- a/crates/router/src/routes/app.rs
+++ b/crates/router/src/routes/app.rs
@@ -2459,21 +2459,24 @@ pub struct WebhookEvents;
#[cfg(all(feature = "olap", feature = "v1"))]
impl WebhookEvents {
pub fn server(config: AppState) -> Scope {
- web::scope("/events/{merchant_id}")
+ web::scope("/events")
.app_data(web::Data::new(config))
+ .service(web::scope("/profile/list").service(web::resource("").route(
+ web::get().to(webhook_events::list_initial_webhook_delivery_attempts_with_jwtauth),
+ )))
.service(
- web::resource("")
- .route(web::get().to(webhook_events::list_initial_webhook_delivery_attempts)),
- )
- .service(
- web::scope("/{event_id}")
- .service(
- web::resource("attempts")
- .route(web::get().to(webhook_events::list_webhook_delivery_attempts)),
- )
+ web::scope("/{merchant_id}")
+ .service(web::resource("").route(
+ web::get().to(webhook_events::list_initial_webhook_delivery_attempts),
+ ))
.service(
- web::resource("retry")
- .route(web::post().to(webhook_events::retry_webhook_delivery_attempt)),
+ web::scope("/{event_id}")
+ .service(web::resource("attempts").route(
+ web::get().to(webhook_events::list_webhook_delivery_attempts),
+ ))
+ .service(web::resource("retry").route(
+ web::post().to(webhook_events::retry_webhook_delivery_attempt),
+ )),
),
)
}
diff --git a/crates/router/src/routes/webhook_events.rs b/crates/router/src/routes/webhook_events.rs
index 08427012ce..405b3f5f85 100644
--- a/crates/router/src/routes/webhook_events.rs
+++ b/crates/router/src/routes/webhook_events.rs
@@ -4,7 +4,11 @@ use router_env::{instrument, tracing, Flow};
use crate::{
core::{api_locking, webhooks::webhook_events},
routes::AppState,
- services::{api, authentication as auth, authorization::permissions::Permission},
+ services::{
+ api,
+ authentication::{self as auth, UserFromToken},
+ authorization::permissions::Permission,
+ },
types::api::webhook_events::{
EventListConstraints, EventListRequestInternal, WebhookDeliveryAttemptListRequestInternal,
WebhookDeliveryRetryRequestInternal,
@@ -52,6 +56,46 @@ pub async fn list_initial_webhook_delivery_attempts(
.await
}
+#[instrument(skip_all, fields(flow = ?Flow::WebhookEventInitialDeliveryAttemptList))]
+pub async fn list_initial_webhook_delivery_attempts_with_jwtauth(
+ state: web::Data<AppState>,
+ req: HttpRequest,
+ query: web::Query<EventListConstraints>,
+) -> impl Responder {
+ let flow = Flow::WebhookEventInitialDeliveryAttemptList;
+ let constraints = query.into_inner();
+
+ let request_internal = EventListRequestInternal {
+ merchant_id: common_utils::id_type::MerchantId::default(),
+ constraints,
+ };
+
+ Box::pin(api::server_wrap(
+ flow,
+ state,
+ &req,
+ request_internal,
+ |state, auth: UserFromToken, mut request_internal, _| {
+ let merchant_id = auth.merchant_id;
+ let profile_id = auth.profile_id;
+
+ request_internal.merchant_id = merchant_id;
+ request_internal.constraints.profile_id = Some(profile_id);
+
+ webhook_events::list_initial_delivery_attempts(
+ state,
+ request_internal.merchant_id,
+ request_internal.constraints,
+ )
+ },
+ &auth::JWTAuth {
+ permission: Permission::ProfileWebhookEventRead,
+ },
+ api_locking::LockAction::NotApplicable,
+ ))
+ .await
+}
+
#[instrument(skip_all, fields(flow = ?Flow::WebhookEventDeliveryAttemptList))]
pub async fn list_webhook_delivery_attempts(
state: web::Data<AppState>,
diff --git a/crates/router/src/services/authorization/permissions.rs b/crates/router/src/services/authorization/permissions.rs
index 5396fff289..37c75de746 100644
--- a/crates/router/src/services/authorization/permissions.rs
+++ b/crates/router/src/services/authorization/permissions.rs
@@ -65,7 +65,7 @@ generate_permissions! {
},
WebhookEvent: {
scopes: [Read, Write],
- entities: [Merchant]
+ entities: [Profile, Merchant]
},
ReconToken: {
scopes: [Read],