Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Mar 22, 2024

Conversation

SanchithHegde
Copy link
Member

Type of Change

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

Description

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

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?

  1. The three functionalities provided by the endpoints must be unaffected when querying by merchant ID:

    • List events related to a specific object:

      curl -H 'api-key: test_admin' 'https://localhost:8080/events/merchant_1710609960?object_id=pay_9uclJXQboJ0FZPm9Nq2K' 2>/dev/null | jq '.'
    • Filter events:

      curl -H 'api-key: test_admin' 'https://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:

      $ curl -H 'api-key: test_admin' 'https://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:

      $ curl -H 'api-key: test_admin' 'https://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:

      $ curl -H 'api-key: test_admin' 'https://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:

      $ curl -H 'api-key: test_admin' 'https://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\":\"[email protected]\",\"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\":\"[email protected]\",\"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

  • 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
  • I added a CHANGELOG entry if applicable

@SanchithHegde SanchithHegde added A-core Area: Core flows C-feature Category: Feature request or enhancement S-waiting-on-review Status: This PR has been implemented and needs to be reviewed A-webhooks Area: Webhook flows labels Mar 20, 2024
@SanchithHegde SanchithHegde added this to the March 2024 milestone Mar 20, 2024
@SanchithHegde SanchithHegde self-assigned this Mar 20, 2024
@SanchithHegde SanchithHegde requested review from a team as code owners March 20, 2024 21:07
Base automatically changed from add-events-list-apis to main March 21, 2024 13:47
@SanchithHegde SanchithHegde requested review from a team as code owners March 21, 2024 13:47
@SanchithHegde SanchithHegde force-pushed the events-list-apis-allow-profile-id-in-path branch 2 times, most recently from 5ff5ad4 to 64af865 Compare March 21, 2024 13:58
@SanchithHegde SanchithHegde force-pushed the events-list-apis-allow-profile-id-in-path branch from 0aff862 to 70e224f Compare March 21, 2024 14:03
@SanchithHegde SanchithHegde added the M-api-contract-changes Metadata: This PR involves API contract changes label Mar 22, 2024
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Mar 22, 2024
Merged via the queue into main with commit 4c8cdf1 Mar 22, 2024
10 of 12 checks passed
@Gnanasundari24 Gnanasundari24 deleted the events-list-apis-allow-profile-id-in-path branch March 22, 2024 11:46
@SanchithHegde SanchithHegde removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows A-webhooks Area: Webhook flows C-feature Category: Feature request or enhancement M-api-contract-changes Metadata: This PR involves API contract changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants