Skip to content

feat(webhook): Return events list and total_count on list initial delivery attempt call#7243

Merged
Gnanasundari24 merged 16 commits intomainfrom
return-total-events-count
Mar 21, 2025
Merged

feat(webhook): Return events list and total_count on list initial delivery attempt call#7243
Gnanasundari24 merged 16 commits intomainfrom
return-total-events-count

Conversation

@AmeyWale
Copy link
Contributor

@AmeyWale AmeyWale commented Feb 11, 2025

Type of Change

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

Description

Add total_events field to webhook initial delivery attempt response at /events/{merchant_id}. This involves api contract change as we were only returning list of initial delivery attempts, with this getting merged, we will return

{
 "events":[...],
 "total_count":<i64>
}

Additional Changes

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

Motivation and Context

Upon merging this PR, the api will return a new response having events and total_count field when querying initial delivery attempts instead of array of events.

How did you test it?

  • List initial delivery attempts api call
curl --location 'http://localhost:8080/events/merchant_1738922563' \
--header 'Content-Type: application/json' \
--header 'admin_api_key: test_admin' \
--header 'api-key: test_admin' \
--data ''
  • Response from above call
{"events":[{"event_id":"evt_0194eff72c477871b4ddd46276f1f817","merchant_id":"merchant_1738922563","profile_id":"pro_jA0LJ9podhUSLu1H7EKP","object_id":"pay_9WySSsFmMH2tVj6gU5f3","event_type":"payment_succeeded","event_class":"payments","is_delivery_successful":false,"initial_attempt_id":"evt_0194eff72c477871b4ddd46276f1f817","created":"2025-02-10T13:05:40.936Z"},{"event_id":"evt_0194eff71e2d7852b63b6d1e1581c32e","merchant_id":"merchant_1738922563","profile_id":"pro_jA0LJ9podhUSLu1H7EKP","object_id":"pay_Fu9JmwIFkB2oejQsQt4B","event_type":"payment_succeeded","event_class":"payments","is_delivery_successful":false,"initial_attempt_id":"evt_0194eff71e2d7852b63b6d1e1581c32e","created":"2025-02-10T13:05:37.326Z"},{"event_id":"evt_0194eff70d227282a187302c432e446e","merchant_id":"merchant_1738922563","profile_id":"pro_jA0LJ9podhUSLu1H7EKP","object_id":"pay_cQDHrTCuk8zI5rmU4wTa","event_type":"payment_succeeded","event_class":"payments","is_delivery_successful":false,"initial_attempt_id":"evt_0194eff70d227282a187302c432e446e","created":"2025-02-10T13:05:32.963Z"},{"event_id":"evt_0194dfdd52897eb39dd7af9310d8e8d7","merchant_id":"merchant_1738922563","profile_id":"pro_jA0LJ9podhUSLu1H7EKP","object_id":"pay_ORr2AU4XL2hJkXKV1o8B","event_type":"payment_succeeded","event_class":"payments","is_delivery_successful":false,"initial_attempt_id":"evt_0194dfdd52897eb39dd7af9310d8e8d7","created":"2025-02-07T10:03:31.338Z"},{"event_id":"evt_0194dfdd1fbe7a0298c6530bed81d739","merchant_id":"merchant_1738922563","profile_id":"pro_jA0LJ9podhUSLu1H7EKP","object_id":"pay_N5LFrrk9KTAbDmvou3jY","event_type":"payment_succeeded","event_class":"payments","is_delivery_successful":false,"initial_attempt_id":"evt_0194dfdd1fbe7a0298c6530bed81d739","created":"2025-02-07T10:03:18.335Z"},{"event_id":"evt_0194dfdd1d7672e09c6da7a6429d6d32","merchant_id":"merchant_1738922563","profile_id":"pro_jA0LJ9podhUSLu1H7EKP","object_id":"pay_ZJGJwno98a7qEiZugswX","event_type":"payment_succeeded","event_class":"payments","is_delivery_successful":false,"initial_attempt_id":"evt_0194dfdd1d7672e09c6da7a6429d6d32","created":"2025-02-07T10:03:17.751Z"},{"event_id":"evt_0194dfdd1bae733290da71bfca8a6107","merchant_id":"merchant_1738922563","profile_id":"pro_jA0LJ9podhUSLu1H7EKP","object_id":"pay_J3zdj0J13ldoBHAtZmhU","event_type":"payment_succeeded","event_class":"payments","is_delivery_successful":false,"initial_attempt_id":"evt_0194dfdd1bae733290da71bfca8a6107","created":"2025-02-07T10:03:17.295Z"},{"event_id":"evt_0194dfdd19c07312a38d56655d2e021e","merchant_id":"merchant_1738922563","profile_id":"pro_jA0LJ9podhUSLu1H7EKP","object_id":"pay_6DqZUZ7WjGcBusy3I67C","event_type":"payment_succeeded","event_class":"payments","is_delivery_successful":false,"initial_attempt_id":"evt_0194dfdd19c07312a38d56655d2e021e","created":"2025-02-07T10:03:16.801Z"},{"event_id":"evt_0194dfdd16a27af29382a859dce1b236","merchant_id":"merchant_1738922563","profile_id":"pro_jA0LJ9podhUSLu1H7EKP","object_id":"pay_ry337IM2gN01zw9Wt83E","event_type":"payment_succeeded","event_class":"payments","is_delivery_successful":false,"initial_attempt_id":"evt_0194dfdd16a27af29382a859dce1b236","created":"2025-02-07T10:03:16.003Z"},{"event_id":"evt_0194dfdd0f45770086e46b79621f05cb","merchant_id":"merchant_1738922563","profile_id":"pro_jA0LJ9podhUSLu1H7EKP","object_id":"pay_fcK4amsYPri3xFHy5lIW","event_type":"payment_succeeded","event_class":"payments","is_delivery_successful":false,"initial_attempt_id":"evt_0194dfdd0f45770086e46b79621f05cb","created":"2025-02-07T10:03:14.118Z"},{"event_id":"evt_0194dfdd04e27a139fe26c9a3a2f68d2","merchant_id":"merchant_1738922563","profile_id":"pro_jA0LJ9podhUSLu1H7EKP","object_id":"pay_yFVzIkZV8VZ5WaeshtDO","event_type":"payment_succeeded","event_class":"payments","is_delivery_successful":false,"initial_attempt_id":"evt_0194dfdd04e27a139fe26c9a3a2f68d2","created":"2025-02-07T10:03:11.459Z"},{"event_id":"evt_0194dfdced6d7620b6b8a88b4f2425fb","merchant_id":"merchant_1738922563","profile_id":"pro_jA0LJ9podhUSLu1H7EKP","object_id":"pay_icO4WYAeyRkdFZ0s41hX","event_type":"payment_succeeded","event_class":"payments","is_delivery_successful":false,"initial_attempt_id":"evt_0194dfdced6d7620b6b8a88b4f2425fb","created":"2025-02-07T10:03:05.453Z"}],"total_count":12}
  • Call list api with filters like limit, created_before, created_after
curl --location 'http://localhost:8080/events/merchant_1738922563?limit=1&created_before=2025-02-07T10%3A03%3A14.118Z&created_after=2025-01-07T10%3A03%3A14.118Z' \
--header 'Content-Type: application/json' \
--header 'admin_api_key: test_admin' \
--header 'api-key: test_admin' \
--data ''
  • Response from the above call
{"events":[{"event_id":"evt_0194dfdd0f45770086e46b79621f05cb","merchant_id":"merchant_1738922563","profile_id":"pro_jA0LJ9podhUSLu1H7EKP","object_id":"pay_fcK4amsYPri3xFHy5lIW","event_type":"payment_succeeded","event_class":"payments","is_delivery_successful":false,"initial_attempt_id":"evt_0194dfdd0f45770086e46b79621f05cb","created":"2025-02-07T10:03:14.118Z"}],"total_count":3}
  • Call list api with invalid time frame i.e created_after and created_before
curl --location 'http://localhost:8080/events/merchant_1740040892?created_after=2025-02-18T10%3A03%3A14.118Z&created_before=2025-01-07T10%3A03%3A14.118Z' \
--header 'Content-Type: application/json' \
--header 'admin_api_key: test_admin' \
--header 'api-key: test_admin' \
--data ''
  • Response from the above call
{"error":{"type":"invalid_request","message":"Invalid time range provided with `created_after` and `created_before`","code":"IR_06"}}

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

@AmeyWale AmeyWale requested review from a team as code owners February 11, 2025 11:00
@semanticdiff-com
Copy link

semanticdiff-com bot commented Feb 11, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/openapi/src/routes/webhook_events.rs  36% smaller
  crates/router/src/core/webhooks/webhook_events.rs  25% smaller
  crates/router/src/db/events.rs  22% smaller
  crates/diesel_models/src/query/events.rs  15% smaller
  crates/openapi/src/openapi.rs  12% smaller
  api-reference/openapi_spec.json  9% smaller
  crates/router/src/types/api/webhook_events.rs  5% smaller
  crates/api_models/src/webhook_events.rs  1% smaller
  crates/router/src/db/kafka_store.rs  0% smaller

@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Feb 11, 2025
@AmeyWale AmeyWale changed the title Return total events count feat(webhooks): Return events list and total_events count on list initial delivery attempt call Feb 11, 2025
@AmeyWale AmeyWale changed the title feat(webhooks): Return events list and total_events count on list initial delivery attempt call feat(webhook): Return events list and total_events count on list initial delivery attempt call Feb 11, 2025
@hyperswitch-bot hyperswitch-bot bot removed the M-api-contract-changes Metadata: This PR involves API contract changes label Feb 11, 2025
@AmeyWale AmeyWale force-pushed the return-total-events-count branch from b959162 to 0bfbf89 Compare February 11, 2025 12:34
@AmeyWale AmeyWale changed the title feat(webhook): Return events list and total_events count on list initial delivery attempt call feat(webhook): Return events list and total_count on list initial delivery attempt call Feb 11, 2025
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Feb 11, 2025
@AmeyWale AmeyWale self-assigned this Feb 11, 2025
@AmeyWale AmeyWale force-pushed the return-total-events-count branch 2 times, most recently from 1454760 to 02e1b35 Compare February 20, 2025 12:01
@hyperswitch-bot hyperswitch-bot bot added M-database-changes Metadata: This PR involves database schema changes and removed M-database-changes Metadata: This PR involves database schema changes labels Feb 27, 2025
SanchithHegde
SanchithHegde previously approved these changes Feb 27, 2025
@AmeyWale AmeyWale requested review from a team as code owners March 10, 2025 11:07
@AmeyWale AmeyWale force-pushed the return-total-events-count branch from 0d0d58e to 9a81544 Compare March 10, 2025 11:13
@AmeyWale AmeyWale removed request for a team March 10, 2025 11:14
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Mar 21, 2025
Merged via the queue into main with commit 4d57f5e Mar 21, 2025
17 of 23 checks passed
@Gnanasundari24 Gnanasundari24 deleted the return-total-events-count branch March 21, 2025 14:42
pixincreate added a commit that referenced this pull request Mar 24, 2025
…lobalpay-fixes

* 'main' of github.com:juspay/hyperswitch:
  feat(connector): [Recurly] Add record back support for recurly [V2] (#7544)
  refactor(webhook): add jwt authenticated endpoint to list unique webhook events for a profile (#7325)
  feat(core): Add three_ds_requestor_app_url in business_profile (#7589)
  feat(refunds): Add refunds diesel model support in V2 API (#7503)
  fix(connector): [globalpay] address 5xx due to deserialization issue when `account_name` is not passed (#7540)
  chore: update production endpoint url for globalPay (#7588)
  feat(connector): [Stripebilling] add record back support for stripebilling (#7561)
  feat(router): Make payment_method_subtype optional in payment_attempt [V2] (#7568)
  fix(connector): RSync voided status mapping in AuthorizeDotNet (#7566)
  chore(version): 2025.03.24.0
  feat(connector): [Coingate] implement refunds  (#7513)
  feat(connectors): [Redsys] add Psync and Rsync support (#7586)
  refactor(connector): [BRAINTREE] Pass email in payment requests (#7591)
  feat(webhook): Return events list and total_count on list initial delivery attempt call (#7243)
  refactor(router): make error_type generic in domain_models inorder to avoid conversion of errors in storage_impl (#7537)
  feat(router): [V2] Return connector customer reference IDs in `CustomerResponse` (#7319)
  feat: core changes for extended authorization (#6766)
  feat(coingate): Add Payment webhooks (#7489)
  refactor(dynamic_routing): change insert operation to upsert for dynamic_routing_stats (#7398)
  feat(connectors): [Redsys] add 3D secure card payment support, including transaction capture, cancellation, and refunds (#7508)
pixincreate added a commit that referenced this pull request Mar 27, 2025
…e-status-check

* 'main' of github.com:juspay/hyperswitch: (74 commits)
  chore(version): 2025.03.26.0
  feat(connector): [Coingate] add wasm changes for coingate metadata (#7632)
  feat(connector): [TRUSTPAY]  implement Banktransfer PaymentMethod (#7575)
  feat(connector): [BANKOFAMERICA] Implement Samsung Pay (#6888)
  fix(connector):  add Nomupay in payout_connector_list for all environment (#7521)
  chore(version): 2025.03.25.0
  feat(connector): [Recurly] Add record back support for recurly [V2] (#7544)
  refactor(webhook): add jwt authenticated endpoint to list unique webhook events for a profile (#7325)
  feat(core): Add three_ds_requestor_app_url in business_profile (#7589)
  feat(refunds): Add refunds diesel model support in V2 API (#7503)
  fix(connector): [globalpay] address 5xx due to deserialization issue when `account_name` is not passed (#7540)
  chore: update production endpoint url for globalPay (#7588)
  feat(connector): [Stripebilling] add record back support for stripebilling (#7561)
  feat(router): Make payment_method_subtype optional in payment_attempt [V2] (#7568)
  fix(connector): RSync voided status mapping in AuthorizeDotNet (#7566)
  chore(version): 2025.03.24.0
  feat(connector): [Coingate] implement refunds  (#7513)
  feat(connectors): [Redsys] add Psync and Rsync support (#7586)
  refactor(connector): [BRAINTREE] Pass email in payment requests (#7591)
  feat(webhook): Return events list and total_count on list initial delivery attempt call (#7243)
  ...
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