Skip to content

Commit 989b2c3

Browse files
Aishwariyaa-AnandAishwariyaa Anandhyperswitch-bot[bot]
authored
feat(webhook): add filter by event class and type (#7275)
Co-authored-by: Aishwariyaa Anand <[email protected]> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
1 parent e677b13 commit 989b2c3

File tree

12 files changed

+346
-219
lines changed

12 files changed

+346
-219
lines changed

api-reference/openapi_spec.json

+128-134
Original file line numberDiff line numberDiff line change
@@ -5307,7 +5307,7 @@
53075307
}
53085308
},
53095309
"/events/{merchant_id}": {
5310-
"get": {
5310+
"post": {
53115311
"tags": [
53125312
"Event"
53135313
],
@@ -5323,82 +5323,39 @@
53235323
"schema": {
53245324
"type": "string"
53255325
}
5326-
},
5327-
{
5328-
"name": "created_after",
5329-
"in": "query",
5330-
"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.",
5331-
"required": false,
5332-
"schema": {
5333-
"type": "string",
5334-
"format": "date-time",
5335-
"nullable": true
5336-
}
5337-
},
5338-
{
5339-
"name": "created_before",
5340-
"in": "query",
5341-
"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.",
5342-
"required": false,
5343-
"schema": {
5344-
"type": "string",
5345-
"format": "date-time",
5346-
"nullable": true
5347-
}
5348-
},
5349-
{
5350-
"name": "limit",
5351-
"in": "query",
5352-
"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.",
5353-
"required": false,
5354-
"schema": {
5355-
"type": "integer",
5356-
"format": "int64",
5357-
"nullable": true
5358-
}
5359-
},
5360-
{
5361-
"name": "offset",
5362-
"in": "query",
5363-
"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.",
5364-
"required": false,
5365-
"schema": {
5366-
"type": "integer",
5367-
"format": "int64",
5368-
"nullable": true
5369-
}
5370-
},
5371-
{
5372-
"name": "object_id",
5373-
"in": "query",
5374-
"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.",
5375-
"required": false,
5376-
"schema": {
5377-
"type": "string",
5378-
"nullable": true
5379-
}
5380-
},
5381-
{
5382-
"name": "profile_id",
5383-
"in": "query",
5384-
"description": "Only include Events associated with the Profile identified by the specified Profile ID.",
5385-
"required": false,
5386-
"schema": {
5387-
"type": "string",
5388-
"nullable": true
5389-
}
5390-
},
5391-
{
5392-
"name": "is_delivered",
5393-
"in": "query",
5394-
"description": "Only include Events which are ultimately delivered to the merchant.",
5395-
"required": false,
5396-
"schema": {
5397-
"type": "boolean",
5398-
"nullable": true
5399-
}
54005326
}
54015327
],
5328+
"requestBody": {
5329+
"description": "The constraints that can be applied when listing Events.",
5330+
"content": {
5331+
"application/json": {
5332+
"schema": {
5333+
"$ref": "#/components/schemas/EventListConstraints"
5334+
},
5335+
"examples": {
5336+
"example": {
5337+
"value": {
5338+
"created_after": "2023-01-01T00:00:00",
5339+
"created_before": "2023-01-31T23:59:59",
5340+
"event_classes": [
5341+
"payments",
5342+
"refunds"
5343+
],
5344+
"event_types": [
5345+
"payment_succeeded"
5346+
],
5347+
"is_delivered": true,
5348+
"limit": 5,
5349+
"object_id": "{{object_id}}",
5350+
"offset": 0,
5351+
"profile_id": "{{profile_id}}"
5352+
}
5353+
}
5354+
}
5355+
}
5356+
},
5357+
"required": true
5358+
},
54025359
"responses": {
54035360
"200": {
54045361
"description": "List of Events retrieved successfully",
@@ -5419,79 +5376,51 @@
54195376
}
54205377
},
54215378
"/events/profile/list": {
5422-
"get": {
5379+
"post": {
54235380
"tags": [
54245381
"Event"
54255382
],
54265383
"summary": "Events - List",
54275384
"description": "List all Events associated with a Profile.",
54285385
"operationId": "List all Events associated with a Profile",
5429-
"parameters": [
5430-
{
5431-
"name": "created_after",
5432-
"in": "query",
5433-
"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.",
5434-
"required": false,
5435-
"schema": {
5436-
"type": "string",
5437-
"format": "date-time",
5438-
"nullable": true
5439-
}
5440-
},
5441-
{
5442-
"name": "created_before",
5443-
"in": "query",
5444-
"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.",
5445-
"required": false,
5446-
"schema": {
5447-
"type": "string",
5448-
"format": "date-time",
5449-
"nullable": true
5450-
}
5451-
},
5452-
{
5453-
"name": "limit",
5454-
"in": "query",
5455-
"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.",
5456-
"required": false,
5457-
"schema": {
5458-
"type": "integer",
5459-
"format": "int64",
5460-
"nullable": true
5461-
}
5462-
},
5463-
{
5464-
"name": "offset",
5465-
"in": "query",
5466-
"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.",
5467-
"required": false,
5468-
"schema": {
5469-
"type": "integer",
5470-
"format": "int64",
5471-
"nullable": true
5386+
"requestBody": {
5387+
"description": "The constraints that can be applied when listing Events.",
5388+
"content": {
5389+
"application/json": {
5390+
"schema": {
5391+
"$ref": "#/components/schemas/EventListConstraints"
5392+
},
5393+
"examples": {
5394+
"example": {
5395+
"value": {
5396+
"created_after": "2023-01-01T00:00:00",
5397+
"created_before": "2023-01-31T23:59:59",
5398+
"event_classes": [
5399+
"payments",
5400+
"refunds"
5401+
],
5402+
"event_types": [
5403+
"payment_succeeded"
5404+
],
5405+
"is_delivered": true,
5406+
"limit": 5,
5407+
"object_id": "{{object_id}}",
5408+
"offset": 0,
5409+
"profile_id": "{{profile_id}}"
5410+
}
5411+
}
5412+
}
54725413
}
54735414
},
5474-
{
5475-
"name": "object_id",
5476-
"in": "query",
5477-
"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.",
5478-
"required": false,
5479-
"schema": {
5480-
"type": "string",
5481-
"nullable": true
5482-
}
5483-
}
5484-
],
5415+
"required": true
5416+
},
54855417
"responses": {
54865418
"200": {
54875419
"description": "List of Events retrieved successfully",
54885420
"content": {
54895421
"application/json": {
54905422
"schema": {
5491-
"type": "array",
5492-
"items": {
5493-
"$ref": "#/components/schemas/EventListItemResponse"
5494-
}
5423+
"$ref": "#/components/schemas/TotalEventsResponse"
54955424
}
54965425
}
54975426
}
@@ -12025,6 +11954,71 @@
1202511954
"payouts"
1202611955
]
1202711956
},
11957+
"EventListConstraints": {
11958+
"type": "object",
11959+
"description": "The constraints to apply when filtering events.",
11960+
"properties": {
11961+
"created_after": {
11962+
"type": "string",
11963+
"format": "date-time",
11964+
"description": "Filter events created after the specified time.",
11965+
"nullable": true
11966+
},
11967+
"created_before": {
11968+
"type": "string",
11969+
"format": "date-time",
11970+
"description": "Filter events created before the specified time.",
11971+
"nullable": true
11972+
},
11973+
"limit": {
11974+
"type": "integer",
11975+
"format": "int32",
11976+
"description": "Include at most the specified number of events.",
11977+
"nullable": true,
11978+
"minimum": 0
11979+
},
11980+
"offset": {
11981+
"type": "integer",
11982+
"format": "int32",
11983+
"description": "Include events after the specified offset.",
11984+
"nullable": true,
11985+
"minimum": 0
11986+
},
11987+
"object_id": {
11988+
"type": "string",
11989+
"description": "Filter all events associated with the specified object identifier (Payment Intent ID,\nRefund ID, etc.)",
11990+
"nullable": true
11991+
},
11992+
"profile_id": {
11993+
"type": "string",
11994+
"description": "Filter all events associated with the specified business profile ID.",
11995+
"nullable": true
11996+
},
11997+
"event_classes": {
11998+
"type": "array",
11999+
"items": {
12000+
"$ref": "#/components/schemas/EventClass"
12001+
},
12002+
"description": "Filter events by their class.",
12003+
"uniqueItems": true,
12004+
"nullable": true
12005+
},
12006+
"event_types": {
12007+
"type": "array",
12008+
"items": {
12009+
"$ref": "#/components/schemas/EventType"
12010+
},
12011+
"description": "Filter events by their type.",
12012+
"uniqueItems": true,
12013+
"nullable": true
12014+
},
12015+
"is_delivered": {
12016+
"type": "boolean",
12017+
"description": "Filter all events by `is_overall_delivery_successful` field of the event.",
12018+
"nullable": true
12019+
}
12020+
}
12021+
},
1202812022
"EventListItemResponse": {
1202912023
"type": "object",
1203012024
"description": "The response body for each item when listing events.",

crates/api_models/src/webhook_events.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::collections::HashSet;
2+
13
use common_enums::{EventClass, EventType, WebhookDeliveryAttempt};
24
use masking::Secret;
35
use serde::{Deserialize, Serialize};
@@ -29,6 +31,11 @@ pub struct EventListConstraints {
2931
#[schema(value_type = Option<String>)]
3032
pub profile_id: Option<common_utils::id_type::ProfileId>,
3133

34+
/// Filter events by their class.
35+
pub event_classes: Option<HashSet<EventClass>>,
36+
37+
/// Filter events by their type.
38+
pub event_types: Option<HashSet<EventType>>,
3239
/// Filter all events by `is_overall_delivery_successful` field of the event.
3340
pub is_delivered: Option<bool>,
3441
}
@@ -40,6 +47,8 @@ pub enum EventListConstraintsInternal {
4047
created_before: Option<PrimitiveDateTime>,
4148
limit: Option<i64>,
4249
offset: Option<i64>,
50+
event_classes: Option<HashSet<EventClass>>,
51+
event_types: Option<HashSet<EventType>>,
4352
is_delivered: Option<bool>,
4453
},
4554
ObjectIdFilter {

0 commit comments

Comments
 (0)