Issue:
feat(events): allow listing webhook events and webhook delivery attempts by business profile

## Type of Change

<!-- Put an `x` in the boxes that apply -->

- [ ] Bugfix
- [ ] New feature
- [x] Enhancement
- [ ] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD

## Description

<!-- Describe your changes in detail -->

This PR extends the events list APIs added in #4131 to allow specifying either merchant ID or the business profile ID in the URLs. This PR also includes the corresponding OpenAPI specification changes.

The URLs remain the same as described in #4131, with the only difference being that `{merchant_id}` can now be substituted with `{merchant_or_profile_id}`.

## Motivation and Context

<!--
Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.

If you don't have an issue, we'd recommend starting with one first so the PR
can focus on the implementation (unless it is an obvious bug or documentation fix
that will have little conversation).
-->

This would allow users to list and work with events associated with a specific business profile, which could be useful when users would want to exclude events from other business profiles associated with the same merchant account.

## How did you test it?

<!--
Did you write an integration/unit/API test to verify the code changes?
Or did you test this change manually (provide relevant screenshots)?
-->

1. The three functionalities provided by the endpoints must be unaffected when querying by merchant ID:

   - List events related to a specific object:

     ```shell
     curl -H 'api-key: test_admin' 'http://localhost:8080/events/merchant_1710609960?object_id=pay_9uclJXQboJ0FZPm9Nq2K' 2>/dev/null | jq '.'
     ```

   - Filter events:

     ```shell
     curl -H 'api-key: test_admin' 'http://localhost:8080/events/merchant_1710609960?created_after=2024-03-18T09:00Z&created_before=2024-03-18T11:00Z&limit=2&offset=2' 2>/dev/null | jq '.'
     ```

   - List delivery attempts:

     ```shell
     $ curl -H 'api-key: test_admin' 'http://localhost:8080/events/merchant_1710609960/evt_018e562fcd4571b0b831098bb9ebe230/attempts' 2>/dev/null | jq '.'
     ```

2. The above three functionalities must be unaffected if the merchant ID in the URLs is replaced by the profile ID:

   - List events related to a specific object:

     ```shell
     $ curl -H 'api-key: test_admin' 'http://localhost:8080/events/pro_H7FbvX2pBuJLjlPhkpRa?object_id=pay_9uclJXQboJ0FZPm9Nq2K' 2>/dev/null | jq '.'
     [
       {
         "event_id": "evt_018e484cb6207265a1c715568f889590",
         "merchant_id": "merchant_1710609960",
         "profile_id": "pro_H7FbvX2pBuJLjlPhkpRa",
         "object_id": "pay_9uclJXQboJ0FZPm9Nq2K",
         "event_type": "payment_succeeded",
         "event_class": "payments",
         "is_delivery_successful": true,
         "initial_attempt_id": "evt_018e484cb6207265a1c715568f889590",
         "created": "2024-03-16T17:26:10.720Z"
       }
     ]
     ```

   - Filter events:

     ```shell
     $ curl -H 'api-key: test_admin' 'http://localhost:8080/events/pro_H7FbvX2pBuJLjlPhkpRa?created_after=2024-03-18T09:00Z&created_before=2024-03-18T11:00Z&limit=2&offset=2' 2>/dev/null | jq '.'
     [
       {
         "event_id": "evt_018e50da61a674d6bdbd7150775087f2",
         "merchant_id": "merchant_1710609960",
         "profile_id": "pro_H7FbvX2pBuJLjlPhkpRa",
         "object_id": "pay_WkrmqLjtHqyjWdCYA1Ze",
         "event_type": "payment_succeeded",
         "event_class": "payments",
         "is_delivery_successful": false,
         "initial_attempt_id": "evt_018e50da61a674d6bdbd7150775087f2",
         "created": "2024-03-18T09:17:52.934Z"
       },
       {
         "event_id": "evt_018e50da59e577c6a5e843fe08537a01",
         "merchant_id": "merchant_1710609960",
         "profile_id": "pro_H7FbvX2pBuJLjlPhkpRa",
         "object_id": "pay_ECPc1GBlY8uC4HushNUU",
         "event_type": "payment_succeeded",
         "event_class": "payments",
         "is_delivery_successful": false,
         "initial_attempt_id": "evt_018e50da59e577c6a5e843fe08537a01",
         "created": "2024-03-18T09:17:50.950Z"
       }
     ]
     ```

   - List delivery attempts:

     ```shell
     $ curl -H 'api-key: test_admin' 'http://localhost:8080/events/pro_H7FbvX2pBuJLjlPhkpRa/evt_018e562fcd4571b0b831098bb9ebe230/attempts' 2>/dev/null | jq '.[length-2:]'
     [
       {
         "event_id": "evt_018e563030bc75a7a682fc3281f1d13d",
         "merchant_id": "merchant_1710609960",
         "profile_id": "pro_H7FbvX2pBuJLjlPhkpRa",
         "object_id": "pay_w1nwB6UxMcIgEc3UDPvx",
         "event_type": "payment_succeeded",
         "event_class": "payments",
         "is_delivery_successful": false,
         "initial_attempt_id": "evt_018e562fcd4571b0b831098bb9ebe230",
         "created": "2024-03-19T10:09:42.592Z",
         "request": {
           "body": "{\"merchant_id\":\"merchant_1710609960\",\"event_id\":\"evt_018e562fcd4571b0b831098bb9ebe230\",\"event_type\":\"payment_succeeded\",\"content\":{\"type\":\"payment_details\",\"object\":{\"payment_id\":\"pay_w1nwB6UxMcIgEc3UDPvx\",\"merchant_id\":\"merchant_1710609960\",\"status\":\"succeeded\",\"amount\":6540,\"net_amount\":6540,\"amount_capturable\":0,\"amount_received\":6540,\"connector\":\"stripe\",\"client_secret\":\"pay_w1nwB6UxMcIgEc3UDPvx_secret_ys9LDfhjJE7wiTQkMQru\",\"created\":\"2024-03-19T10:09:15.060Z\",\"currency\":\"USD\",\"customer_id\":\"StripeCustomer\",\"description\":\"Its my first payment request\",\"refunds\":null,\"disputes\":null,\"mandate_id\":null,\"mandate_data\":null,\"setup_future_usage\":null,\"off_session\":null,\"capture_on\":null,\"capture_method\":\"automatic\",\"payment_method\":\"card\",\"payment_method_data\":{\"card\":{\"last4\":\"4242\",\"card_type\":null,\"card_network\":null,\"card_issuer\":null,\"card_issuing_country\":null,\"card_isin\":\"424242\",\"card_extended_bin\":\"42424242\",\"card_exp_month\":\"10\",\"card_exp_year\":\"25\",\"card_holder_name\":\"joseph Doe\"},\"billing\":null},\"payment_token\":null,\"shipping\":{\"address\":{\"city\":\"San Fransico\",\"country\":\"US\",\"line1\":\"1467\",\"line2\":\"Harrison Street\",\"line3\":\"Harrison Street\",\"zip\":\"94122\",\"state\":\"California\",\"first_name\":\"joseph\",\"last_name\":\"Doe\"},\"phone\":{\"number\":\"8056594427\",\"country_code\":\"+91\"},\"email\":null},\"billing\":{\"address\":{\"city\":\"San Fransico\",\"country\":\"US\",\"line1\":\"1467\",\"line2\":\"Harrison Street\",\"line3\":\"Harrison Street\",\"zip\":\"94122\",\"state\":\"California\",\"first_name\":\"joseph\",\"last_name\":\"Doe\"},\"phone\":{\"number\":\"8056594427\",\"country_code\":\"+91\"},\"email\":null},\"order_details\":null,\"email\":\"guest@example.com\",\"name\":\"John Doe\",\"phone\":\"999999999\",\"return_url\":\"https://google.com/\",\"authentication_type\":\"no_three_ds\",\"statement_descriptor_name\":\"joseph\",\"statement_descriptor_suffix\":\"JS\",\"next_action\":null,\"cancellation_reason\":null,\"error_code\":null,\"error_message\":null,\"unified_code\":null,\"unified_message\":null,\"payment_experience\":null,\"payment_method_type\":\"credit\",\"connector_label\":null,\"business_country\":null,\"business_label\":\"default\",\"business_sub_label\":null,\"allowed_payment_method_types\":null,\"ephemeral_key\":{\"customer_id\":\"StripeCustomer\",\"created_at\":1710842955,\"expires\":1710846555,\"secret\":\"epk_ea8a42533ae3472fb32da95c3f616886\"},\"manual_retry_allowed\":false,\"connector_transaction_id\":\"pi_3OvzbcD5R7gDAGff0njPHLCh\",\"frm_message\":null,\"metadata\":{\"udf1\":\"value1\",\"login_date\":\"2019-09-10T10:11:12Z\",\"new_customer\":\"true\"},\"connector_metadata\":null,\"feature_metadata\":null,\"reference_id\":\"pi_3OvzbcD5R7gDAGff0njPHLCh\",\"payment_link\":null,\"profile_id\":\"pro_H7FbvX2pBuJLjlPhkpRa\",\"surcharge_details\":null,\"attempt_count\":1,\"merchant_decision\":null,\"merchant_connector_id\":\"mca_qeS5H2fLkr8GLzN9SNWd\",\"incremental_authorization_allowed\":null,\"authorization_count\":null,\"incremental_authorizations\":null,\"external_authentication_details\":null,\"external_3ds_authentication_attempted\":false,\"expires_on\":\"2024-03-19T10:24:15.060Z\",\"fingerprint\":null,\"payment_method_id\":null,\"payment_method_status\":null}},\"timestamp\":\"2024-03-19T10:09:17.125Z\"}",
           "headers": [
             [
               "content-type",
               "application/json"
             ],
             [
               "X-Webhook-Signature-512",
               "af25f54b7018cc35286451645a3ad0167e28a7fa32417c7411cd655c5db06a4bf1f9f7bd4330f2bed1ef54fedcd5b1fc35b09eb6e50f56b035c90cdf8818df30"
             ]
           ]
         },
         "response": {
           "body": "",
           "headers": [
             [
               "server",
               "mitmproxy 10.2.4"
             ],
             [
               "content-length",
               "0"
             ]
           ],
           "status_code": 404
         },
         "delivery_attempt": "automatic_retry"
       },
       {
         "event_id": "evt_018e562fcd4571b0b831098bb9ebe230",
         "merchant_id": "merchant_1710609960",
         "profile_id": "pro_H7FbvX2pBuJLjlPhkpRa",
         "object_id": "pay_w1nwB6UxMcIgEc3UDPvx",
         "event_type": "payment_succeeded",
         "event_class": "payments",
         "is_delivery_successful": false,
         "initial_attempt_id": "evt_018e562fcd4571b0b831098bb9ebe230",
         "created": "2024-03-19T10:09:17.125Z",
         "request": {
           "body": "{\"merchant_id\":\"merchant_1710609960\",\"event_id\":\"evt_018e562fcd4571b0b831098bb9ebe230\",\"event_type\":\"payment_succeeded\",\"content\":{\"type\":\"payment_details\",\"object\":{\"payment_id\":\"pay_w1nwB6UxMcIgEc3UDPvx\",\"merchant_id\":\"merchant_1710609960\",\"status\":\"succeeded\",\"amount\":6540,\"net_amount\":6540,\"amount_capturable\":0,\"amount_received\":6540,\"connector\":\"stripe\",\"client_secret\":\"pay_w1nwB6UxMcIgEc3UDPvx_secret_ys9LDfhjJE7wiTQkMQru\",\"created\":\"2024-03-19T10:09:15.060Z\",\"currency\":\"USD\",\"customer_id\":\"StripeCustomer\",\"description\":\"Its my first payment request\",\"refunds\":null,\"disputes\":null,\"mandate_id\":null,\"mandate_data\":null,\"setup_future_usage\":null,\"off_session\":null,\"capture_on\":null,\"capture_method\":\"automatic\",\"payment_method\":\"card\",\"payment_method_data\":{\"card\":{\"last4\":\"4242\",\"card_type\":null,\"card_network\":null,\"card_issuer\":null,\"card_issuing_country\":null,\"card_isin\":\"424242\",\"card_extended_bin\":\"42424242\",\"card_exp_month\":\"10\",\"card_exp_year\":\"25\",\"card_holder_name\":\"joseph Doe\"},\"billing\":null},\"payment_token\":null,\"shipping\":{\"address\":{\"city\":\"San Fransico\",\"country\":\"US\",\"line1\":\"1467\",\"line2\":\"Harrison Street\",\"line3\":\"Harrison Street\",\"zip\":\"94122\",\"state\":\"California\",\"first_name\":\"joseph\",\"last_name\":\"Doe\"},\"phone\":{\"number\":\"8056594427\",\"country_code\":\"+91\"},\"email\":null},\"billing\":{\"address\":{\"city\":\"San Fransico\",\"country\":\"US\",\"line1\":\"1467\",\"line2\":\"Harrison Street\",\"line3\":\"Harrison Street\",\"zip\":\"94122\",\"state\":\"California\",\"first_name\":\"joseph\",\"last_name\":\"Doe\"},\"phone\":{\"number\":\"8056594427\",\"country_code\":\"+91\"},\"email\":null},\"order_details\":null,\"email\":\"guest@example.com\",\"name\":\"John Doe\",\"phone\":\"999999999\",\"return_url\":\"https://google.com/\",\"authentication_type\":\"no_three_ds\",\"statement_descriptor_name\":\"joseph\",\"statement_descriptor_suffix\":\"JS\",\"next_action\":null,\"cancellation_reason\":null,\"error_code\":null,\"error_message\":null,\"unified_code\":null,\"unified_message\":null,\"payment_experience\":null,\"payment_method_type\":\"credit\",\"connector_label\":null,\"business_country\":null,\"business_label\":\"default\",\"business_sub_label\":null,\"allowed_payment_method_types\":null,\"ephemeral_key\":{\"customer_id\":\"StripeCustomer\",\"created_at\":1710842955,\"expires\":1710846555,\"secret\":\"epk_ea8a42533ae3472fb32da95c3f616886\"},\"manual_retry_allowed\":false,\"connector_transaction_id\":\"pi_3OvzbcD5R7gDAGff0njPHLCh\",\"frm_message\":null,\"metadata\":{\"udf1\":\"value1\",\"login_date\":\"2019-09-10T10:11:12Z\",\"new_customer\":\"true\"},\"connector_metadata\":null,\"feature_metadata\":null,\"reference_id\":\"pi_3OvzbcD5R7gDAGff0njPHLCh\",\"payment_link\":null,\"profile_id\":\"pro_H7FbvX2pBuJLjlPhkpRa\",\"surcharge_details\":null,\"attempt_count\":1,\"merchant_decision\":null,\"merchant_connector_id\":\"mca_qeS5H2fLkr8GLzN9SNWd\",\"incremental_authorization_allowed\":null,\"authorization_count\":null,\"incremental_authorizations\":null,\"external_authentication_details\":null,\"external_3ds_authentication_attempted\":false,\"expires_on\":\"2024-03-19T10:24:15.060Z\",\"fingerprint\":null,\"payment_method_id\":null,\"payment_method_status\":null}},\"timestamp\":\"2024-03-19T10:09:17.125Z\"}",
           "headers": [
             [
               "content-type",
               "application/json"
             ],
             [
               "X-Webhook-Signature-512",
               "af25f54b7018cc35286451645a3ad0167e28a7fa32417c7411cd655c5db06a4bf1f9f7bd4330f2bed1ef54fedcd5b1fc35b09eb6e50f56b035c90cdf8818df30"
             ]
           ]
         },
         "response": {
           "body": "",
           "headers": [
             [
               "server",
               "mitmproxy 10.2.4"
             ],
             [
               "content-length",
               "0"
             ]
           ],
           "status_code": 404
         },
         "delivery_attempt": "initial_attempt"
       }
     ]
     ```

3. To simulate access from the control center and verifying correct functioning of these APIs:

   1. A user sign in operation can be done, and the JWT token can be temporarily stored.
   2. Replace the `api-key: test_admin` header in the above commands with `Authorization: Bearer <JWT_TOKEN>`.
   3. Try out the APIs specifying both merchant ID and profile ID in the URL, the behavior should be the same.

   I've verified that accessing the APIs using the JWT token, specifying both merchant ID and profile ID works as expected.

## Checklist

<!-- Put an `x` in the boxes that apply -->

- [x] I formatted the code `cargo +nightly fmt --all`
- [x] I addressed lints thrown by `cargo clippy`
- [x] I reviewed the submitted code
- [ ] I added unit tests for my changes where possible
- [ ] I added a [CHANGELOG](/CHANGELOG.md) entry if applicable


Resolution:
<think>
PR Context:
- Title: refactor: use business profile domain models instead of diesel models
- Merged: 2024-08-08T10:37:52Z
- Files changed: 30 files
- Commits: 5 commits

Implementation approach:
## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [ ] Bugfix
- [ ] New feature
- [ ] Enhancement
- [x] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD

## Description
<!-- Describe your changes in detail -->

This PR contains the following changes:

- Updates the `BusinessProfileInterface` trait methods to use and return business profile domain models instead of the corresponding diesel models. As a result of this, almost all of the code in the
</think>

To implement this, you'll need to modify:


**Detailed Implementation:**


**Commit 1:** refactor: use business profile domain models instead of diesel models (#5566)
Files to modify:


**crates/api_models/src/admin.rs**
  Modify existing code

**crates/common_utils/src/types/keymanager.rs**
  Modify existing code

**crates/diesel_models/src/business_profile.rs**
  Remove:
    - function: private::from
    - function: private::from
    - function: private::from
    - struct: pub::BusinessProfileGeneralUpdate
    - struct: pub::BusinessProfileGeneralUpdate
    - enum: pub::BusinessProfileUpdate
    - enum: pub::BusinessProfileUpdate
    - impl: impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal
    - impl: impl From<BusinessProfileNew> for BusinessProfile
    - impl: impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal

**crates/diesel_models/src/query/business_profile.rs**
  Modify existing code

**crates/hyperswitch_domain_models/src/customer.rs**
  Modify existing code

**crates/hyperswitch_domain_models/src/merchant_account.rs**
  Modify existing code

**crates/router/src/connector/braintree/transformers.rs**
  Remove:
    - struct: pub::PsyncInputData

**crates/router/src/core/admin.rs**
  Modify existing code

**crates/router/src/core/authentication.rs**
  Modify existing code

**crates/router/src/core/authentication/transformers.rs**
  Modify existing code

**crates/router/src/core/authentication/utils.rs**
  Modify existing code

**crates/router/src/core/payment_link.rs**
  Modify existing code

**crates/router/src/core/payment_methods.rs**
  Modify existing code

**crates/router/src/core/payment_methods/cards.rs**
  Modify existing code

**crates/router/src/core/payments.rs**
  Modify existing code

**crates/router/src/core/payments/flows.rs**
  Modify existing code

**crates/router/src/core/payments/flows/approve_flow.rs**
  Modify existing code

**crates/router/src/core/payments/flows/authorize_flow.rs**
  Modify existing code

**crates/router/src/core/payments/flows/cancel_flow.rs**
  Modify existing code

**crates/router/src/core/payments/flows/capture_flow.rs**
  Modify existing code

**crates/router/src/core/payments/flows/complete_authorize_flow.rs**
  Modify existing code

**crates/router/src/core/payments/flows/incremental_authorization_flow.rs**
  Modify existing code

**crates/router/src/core/payments/flows/psync_flow.rs**
  Modify existing code

**crates/router/src/core/payments/flows/reject_flow.rs**
  Modify existing code

**crates/router/src/core/payments/flows/session_flow.rs**
  Modify existing code

**crates/router/src/core/payments/flows/setup_mandate_flow.rs**
  Modify existing code

**crates/router/src/core/payments/helpers.rs**
  Modify existing code

**crates/router/src/core/payments/operations.rs**
  Modify existing code

**crates/router/src/core/payments/operations/payment_approve.rs**
  Modify existing code

**crates/router/src/core/payments/operations/payment_cancel.rs**
  Modify existing code

**crates/router/src/core/payments/operations/payment_capture.rs**
  Modify existing code

**crates/router/src/core/payments/operations/payment_complete_authorize.rs**
  Modify existing code

**crates/router/src/core/payments/operations/payment_confirm.rs**
  Modify existing code

**crates/router/src/core/payments/operations/payment_create.rs**
  Modify existing code

**crates/router/src/core/payments/operations/payment_reject.rs**
  Modify existing code

**crates/router/src/core/payments/operations/payment_response.rs**
  Modify existing code

**crates/router/src/core/payments/operations/payment_session.rs**
  Modify existing code

**crates/router/src/core/payments/operations/payment_start.rs**
  Modify existing code

**crates/router/src/core/payments/operations/payment_status.rs**
  Modify existing code

**crates/router/src/core/payments/operations/payment_update.rs**
  Modify existing code

**crates/router/src/core/payments/operations/payments_incremental_authorization.rs**
  Modify existing code

**crates/router/src/core/payments/retry.rs**
  Modify existing code

**crates/router/src/core/payments/routing.rs**
  Modify existing code

**crates/router/src/core/payments/tokenization.rs**
  Modify existing code

**crates/router/src/core/payments/types.rs**
  Modify existing code

**crates/router/src/core/payouts.rs**
  Modify existing code

**crates/router/src/core/payouts/helpers.rs**
  Modify existing code

**crates/router/src/core/payouts/validator.rs**
  Modify existing code

**crates/router/src/core/routing.rs**
  Modify existing code

**crates/router/src/core/routing/helpers.rs**
  Modify existing code

**crates/router/src/core/utils.rs**
  Modify existing code

**crates/router/src/core/webhooks/incoming.rs**
  Modify existing code

**crates/router/src/core/webhooks/outgoing.rs**
  Modify existing code

**crates/router/src/core/webhooks/webhook_events.rs**
  Modify existing code

**crates/router/src/db/business_profile.rs**
  Modify existing code

**crates/router/src/db/kafka_store.rs**
  Modify existing code

**crates/router/src/routes/admin.rs**
  Modify existing code

**crates/router/src/routes/routing.rs**
  Modify existing code

**crates/router/src/routes/webhook_events.rs**
  Modify existing code

**crates/router/src/services/authentication.rs**
  Modify existing code

**crates/router/src/types.rs**
  Modify existing code

**crates/router/src/types/api/admin.rs**
  Add:
    - function: private::foreign_try_from

**crates/router/src/types/domain.rs**
  Remove:
    - mod: private::address
    - mod: pub::merchant_account
  Add:
    - mod: private::merchant_account
    - mod: private::business_profile
    - mod: private::address

**crates/router/src/types/storage/business_profile.rs**
  Modify existing code

**crates/router/src/utils.rs**
  Modify existing code

**crates/router/src/utils/user/sample_data.rs**
  Modify existing code

**crates/router/src/workflows/outgoing_webhook_retry.rs**
  Modify existing code

**crates/router/src/workflows/payment_sync.rs**
  Modify existing code