Skip to content

feat(webhook): add filter by event class and type#7275

Merged
likhinbopanna merged 11 commits intomainfrom
webhook-event-class-type-filter
Apr 11, 2025
Merged

feat(webhook): add filter by event class and type#7275
likhinbopanna merged 11 commits intomainfrom
webhook-event-class-type-filter

Conversation

@Aishwariyaa-Anand
Copy link
Contributor

@Aishwariyaa-Anand Aishwariyaa-Anand commented Feb 17, 2025

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

Webhook events can be filtered based on a list of event classes and event types. This PR also changes the endpoints /events/{merchant_id} and /events/profile/list to POST request.

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

This feature enhances the API by allowing merchants to filter webhook events with a list of event classes and event types. Additionally, validation ensures that only valid event class-event type combinations are used.

How did you test it?

  • List initial delivery attempts
curl --location 'http://localhost:8080/events/merchant_1743589499' \
--header 'Content-Type: application/json' \
--header 'api-key: test_admin' \
--data '{}'
  • Response
{
    "events": [
        {
            "event_id": "evt_0195f62f824f7f53af13fede684998df",
            "merchant_id": "merchant_1743589499",
            "profile_id": "pro_zi0qJ2I57xmpho8jpUYR",
            "object_id": "pay_MvGzXvaQxCJUZZ7EAKIn",
            "event_type": "payment_failed",
            "event_class": "payments",
            "is_delivery_successful": false,
            "initial_attempt_id": "evt_0195f62f824f7f53af13fede684998df",
            "created": "2025-04-02T11:07:43.567Z"
        },
        {
            "event_id": "evt_0195f6099a3e7dc08e246ccc04057684",
            "merchant_id": "merchant_1743589499",
            "profile_id": "pro_zi0qJ2I57xmpho8jpUYR",
            "object_id": "pay_H463bjSirmF62tjviY9Q",
            "event_type": "payment_succeeded",
            "event_class": "payments",
            "is_delivery_successful": false,
            "initial_attempt_id": "evt_0195f6099a3e7dc08e246ccc04057684",
            "created": "2025-04-02T10:26:19.326Z"
        }
    ],
    "total_count": 2
}
  • List initial delivery attempts with filters
curl --location 'http://localhost:8080/events/merchant_1743589499' \
--header 'Content-Type: application/json' \
--header 'api-key: test_admin' \
--data '{
    "created_after": "2025-01-01T00:00:00Z",
    "created_before": "2026-01-31T23:59:59Z",
    "limit": 0,
    "offset": 0,
    "object_id": "{{object_id}}",
    "profile_id": "pro_zi0qJ2I57xmpho8jpUYR",
    "event_classes": ["refunds", "payments"],
    "event_types": ["payment_succeeded"],
    "is_delivered": true
}'
  • Response
{
    "events": [
        {
            "event_id": "evt_0195f6099a3e7dc08e246ccc04057684",
            "merchant_id": "merchant_1743589499",
            "profile_id": "pro_zi0qJ2I57xmpho8jpUYR",
            "object_id": "pay_H463bjSirmF62tjviY9Q",
            "event_type": "payment_succeeded",
            "event_class": "payments",
            "is_delivery_successful": false,
            "initial_attempt_id": "evt_0195f6099a3e7dc08e246ccc04057684",
            "created": "2025-04-02T10:26:19.326Z"
        }
    ],
    "total_count": 1
}
  • List initial delivery attempts using JWT Authentication
curl --location 'http://localhost:8080/events/profile/list' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiZDk1NTcyN2ItYjY1Zi1hNjUwOWVmYmI0NGIiLCJtZXJjaGFudF9pZCI6Im1lcmNoYW50XzE3NDM1ODk0OTkiLCJyb2xlX2lkIjoib3JnX2FkbWluIiwiZXhwIjoxNzQzNjg0NzU0LCJvcmdfaWQiOiJwcm9femtWalRHN1kwY0FVNHJNcjRBM3QiLCJwcm9maWxlX2lkIjoicHJvX3ppMHFKMkk1N3htcGhvOGpwVVlSIiwidGVuYW50X2lkIjoicHVibGljIn0.xhs7FWIU6vuqZ2O0X3e1bt4U6m2BtELJzyxUeONSIPo' \
--header 'Cookie: login_token=eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiZDk1NTcyN2ItYjY1Zi1hNjUwOWVmYmI0NGIiLCJtZXJjaGFudF9pZCI6Im1lcmNoYW50XzE3NDM1ODk0OTkiLCJyb2xlX2lkIjoib3JnX2FkbWluIiwiZXhwIjoxNzQzNjg0NzU0LCJvcmdfaWQiOiJwcm9femtWalRHN1kwY0FVNHJNcjRBM3QiLCJwcm9maWxlX2lkIjoicHJvX3ppMHFKMkk1N3htcGhvOGpwVVlSIiwidGVuYW50X2lkIjoicHVibGljIn0.xhs7FWIU6vuqZ2O0X3e1bt4U6m2BtELJzyxUeONSIPo' \
--data '{
    "limit": 1
}'
  • Response
{
    "events": [
        {
            "event_id": "evt_0195f62f824f7f53af13fede684998df",
            "merchant_id": "merchant_1743589499",
            "profile_id": "pro_zi0qJ2I57xmpho8jpUYR",
            "object_id": "pay_MvGzXvaQxCJUZZ7EAKIn",
            "event_type": "payment_failed",
            "event_class": "payments",
            "is_delivery_successful": false,
            "initial_attempt_id": "evt_0195f62f824f7f53af13fede684998df",
            "created": "2025-04-02T11:07:43.567Z"
        }
    ],
    "total_count": 2
}

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@Aishwariyaa-Anand Aishwariyaa-Anand requested review from a team as code owners February 17, 2025 06:11
@semanticdiff-com
Copy link

semanticdiff-com bot commented Feb 17, 2025

@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Feb 17, 2025
@Aishwariyaa-Anand Aishwariyaa-Anand force-pushed the webhook-event-class-type-filter branch from 4e2d845 to 40790fb Compare April 2, 2025 11:05
@likhinbopanna likhinbopanna added this pull request to the merge queue Apr 11, 2025
Merged via the queue into main with commit 989b2c3 Apr 11, 2025
16 of 20 checks passed
@likhinbopanna likhinbopanna deleted the webhook-event-class-type-filter branch April 11, 2025 10:46
pixincreate added a commit that referenced this pull request Apr 15, 2025
…acilitapay-pix-pmt

* 'main' of github.com:juspay/hyperswitch:
  feat(docker): add webhook notifiers for installation tracking (#7653)
  refactor(customer): refactor customer db with storage utils and move trait to domain_models and impl to storage_model (#7538)
  feat(core): Add support for updating metadata after payment has been authorized (#7776)
  chore(version): 2025.04.14.0
  fix: script for one click docker setup (#7762)
  fix(payment_link): add validation for return_url during payment link creation (#7802)
  chore: address Rust 1.86.0 clippy lints (#7735)
  fix(connector): Add network error message support for payment connectors (#7760)
  feat(webhook): add filter by event class and type (#7275)
  ci(cypress): verify if card fields are populated on updating card info (#7743)
  chore(version): 2025.04.11.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

M-api-contract-changes Metadata: This PR involves API contract changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants