Skip to content

feat: Add outgoing webhooks for subscriptions#9859

Merged
likhinbopanna merged 26 commits intomainfrom
subscriptions-outgoing-webhooks
Oct 27, 2025
Merged

feat: Add outgoing webhooks for subscriptions#9859
likhinbopanna merged 26 commits intomainfrom
subscriptions-outgoing-webhooks

Conversation

@Sarthak1799
Copy link
Contributor

@Sarthak1799 Sarthak1799 commented Oct 15, 2025

Type of Change

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

Description

This pull request adds support for subscription-related events and outgoing webhooks throughout the codebase. The changes introduce new types and logic to handle subscription events, such as InvoicePaid, and ensure that outgoing webhooks are triggered for subscription payments. The implementation includes updates to enums, event metadata, webhook handling, and workflow logic.

Subscription Event and Webhook Support

  • Added Subscriptions to EventClass, InvoicePaid to EventType, and mapped InvoicePaid to Stripe's invoice.paid event type. [1] [2] [3] [4]
  • Extended OutgoingWebhookContent, EventObjectType, EventMetadata, and OutgoingWebhookEventContent enums to support subscription details and metadata. [1] [2] [3] [4] [5]
  • Implemented serialization and conversion logic for subscription-related webhook events, including masking and mapping to internal types. [1] [2] [3]
  • Updated workflow logic in invoice_sync.rs to generate subscription responses, trigger outgoing webhooks for successful and failed payments, and refactored handler return types for better state management. [1] [2] [3] [4] [5] [6] [7]
  • Refactored webhook retry workflow to support subscription event types and payloads. [1] [2]

These changes ensure that subscription payments are properly tracked, recorded, and communicated via outgoing webhooks, aligning the subscription flow with other payment-related events.

Additional Changes

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

Motivation and Context

How did you test it?

1. Create customer

Request

curl --location 'http://localhost:8080/customers' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_teL2V5VNBfIVqjeIdHnwoGZ7QIvdCLcVoMf5aYPc87Cb0EVVyg1Q39zdvbC8TCAL' \
--data '{"email":"guest@example.com","name":"John Doe","phone":"999999999","phone_country_code":"+65","description":"First customer","metadata":{"udf1":"value1","new_customer":"true","login_date":"2019-09-10T10:11:12Z"},"billing":{"address":{"line1":"1467","line2":"Harrison Street","line3":"Harrison Street","city":"San Fransico","state":"California","zip":"94122","country":"IN","first_name":"joseph","last_name":"Doe"},"phone":{"number":"123456789","country_code":"+1"}}}'

Response

{
    "customer_id": "cus_Hj2C6Vcz5eKHwFeedY2h",
    "name": "John Doe",
    "email": "guest@example.com",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "First customer",
    "address": null,
    "created_at": "2025-10-15T12:20:22.419Z",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    "default_payment_method_id": null,
    "tax_registration_id": null
}
2. Subscription create and confirm

Request

curl --location 'http://localhost:8080/subscriptions' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'X-Profile-Id: pro_DX9IXGl6PU5aiTqez10m' \
--header 'api-key: dev_teL2V5VNBfIVqjeIdHnwoGZ7QIvdCLcVoMf5aYPc87Cb0EVVyg1Q39zdvbC8TCAL' \
--data '{"item_price_id":"cbdemo_enterprise-suite-monthly","customer_id":"cus_Hj2C6Vcz5eKHwFeedY2h","description":"Hello this is description","merchant_reference_id":"mer_ref_1760530826","shipping":{"address":{"state":"zsaasdas","city":"Banglore","country":"US","line1":"sdsdfsdf","line2":"hsgdbhd","line3":"alsksoe","zip":"571201","first_name":"joseph","last_name":"doe"},"phone":{"number":"123456789","country_code":"+1"}},"billing":{"address":{"line1":"1467","line2":"Harrison Street","line3":"Harrison Street","city":"San Fransico","state":"California","zip":"94122","country":"US","first_name":"joseph","last_name":"Doe"},"phone":{"number":"123456789","country_code":"+1"}},"payment_details":{"payment_method":"card","payment_method_type":"credit","payment_method_data":{"card":{"card_number":"4111111111111111","card_exp_month":"03","card_exp_year":"2030","card_holder_name":"CLBRW dffdg","card_cvc":"737"}},"authentication_type":"no_three_ds","setup_future_usage":"off_session","capture_method":"automatic","return_url":"https://google.com","customer_acceptance":{"acceptance_type":"online","accepted_at":"1963-05-03T04:07:52.723Z","online":{"ip_address":"127.0.0.1","user_agent":"amet irure esse"}}}}'

Response

{
    "id": "sub_XCub97kvC0Sx20LwJRHM",
    "merchant_reference_id": "mer_ref_1760530826",
    "status": "active",
    "plan_id": null,
    "item_price_id": "cbdemo_enterprise-suite-monthly",
    "coupon": null,
    "profile_id": "pro_DX9IXGl6PU5aiTqez10m",
    "payment": {
        "payment_id": "pay_2Qb3qipsMT4URn9Cwvsf",
        "status": "succeeded",
        "amount": 14100,
        "currency": "INR",
        "profile_id": "pro_DX9IXGl6PU5aiTqez10m",
        "connector": "stripe",
        "payment_method_id": "pm_76kFzPQ3dSFPHZV5Azgk",
        "return_url": "https://google.com/",
        "next_action": null,
        "payment_experience": null,
        "error_code": null,
        "error_message": null,
        "payment_method_type": "credit",
        "client_secret": "pay_2Qb3qipsMT4URn9Cwvsf_secret_K4ObnlTW1G4eLbEL21fs",
        "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",
                "origin_zip": null
            },
            "phone": {
                "number": "123456789",
                "country_code": "+1"
            },
            "email": null
        },
        "shipping": {
            "address": {
                "city": "Banglore",
                "country": "US",
                "line1": "sdsdfsdf",
                "line2": "hsgdbhd",
                "line3": "alsksoe",
                "zip": "571201",
                "state": "zsaasdas",
                "first_name": "joseph",
                "last_name": "doe",
                "origin_zip": null
            },
            "phone": {
                "number": "123456789",
                "country_code": "+1"
            },
            "email": null
        },
        "payment_type": null
    },
    "customer_id": "cus_Hj2C6Vcz5eKHwFeedY2h",
    "invoice": {
        "id": "invoice_HpEL01xSvdVbCaTgNhmv",
        "subscription_id": "sub_XCub97kvC0Sx20LwJRHM",
        "merchant_id": "merchant_1760530283",
        "profile_id": "pro_DX9IXGl6PU5aiTqez10m",
        "merchant_connector_id": "mca_Z4EnTngrhohT6ZC8lmfO",
        "payment_intent_id": "pay_2Qb3qipsMT4URn9Cwvsf",
        "payment_method_id": null,
        "customer_id": "cus_Hj2C6Vcz5eKHwFeedY2h",
        "amount": 14100,
        "currency": "INR",
        "status": "payment_pending"
    },
    "billing_processor_subscription_id": "sub_XCub97kvC0Sx20LwJRHM"
}
  1. Webhook received
image

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

@Sarthak1799 Sarthak1799 self-assigned this Oct 15, 2025
@Sarthak1799 Sarthak1799 requested review from a team as code owners October 15, 2025 11:58
@semanticdiff-com
Copy link

semanticdiff-com bot commented Oct 15, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/subscriptions/src/core.rs  90% smaller
  api-reference/v2/openapi_spec_v2.json  67% smaller
  crates/router/src/workflows/invoice_sync.rs  34% smaller
  crates/subscriptions/src/state.rs  32% smaller
  crates/subscriptions/src/workflows/invoice_sync.rs  28% smaller
  crates/openapi/src/openapi.rs  13% smaller
  api-reference/v1/openapi_spec_v1.json  5% smaller
  crates/euclid_wasm/src/lib.rs  1% smaller
  crates/common_enums/src/transformers.rs  1% smaller
  crates/api_models/src/subscription.rs  0% smaller
  crates/api_models/src/webhooks.rs  0% smaller
  crates/common_enums/src/enums.rs  0% smaller
  crates/diesel_models/src/enums.rs  0% smaller
  crates/diesel_models/src/events.rs  0% smaller
  crates/hyperswitch_domain_models/src/router_response_types/subscriptions.rs  0% smaller
  crates/router/src/compatibility/stripe/webhooks.rs  0% smaller
  crates/router/src/core/revenue_recovery/types.rs  0% smaller
  crates/router/src/core/webhooks/outgoing.rs  0% smaller
  crates/router/src/core/webhooks/outgoing_v2.rs  0% smaller
  crates/router/src/events/outgoing_webhook_logs.rs  0% smaller
  crates/router/src/utils.rs  0% smaller
  crates/router/src/workflows/outgoing_webhook_retry.rs  0% smaller
  crates/subscriptions/src/core/subscription_handler.rs  0% smaller
  migrations/2025-10-15-112824_add_invoice_paid_event_type/down.sql Unsupported file format
  migrations/2025-10-15-112824_add_invoice_paid_event_type/up.sql Unsupported file format
  migrations/2025-10-22-094643_drop_duplicate_index_from_invoice_table/down.sql Unsupported file format
  migrations/2025-10-22-094643_drop_duplicate_index_from_invoice_table/up.sql Unsupported file format

@hyperswitch-bot hyperswitch-bot bot added the M-database-changes Metadata: This PR involves database schema changes label Oct 15, 2025
@Sarthak1799 Sarthak1799 linked an issue Oct 15, 2025 that may be closed by this pull request
2 tasks
@Sarthak1799 Sarthak1799 requested a review from a team as a code owner October 15, 2025 19:30
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Oct 22, 2025
@codecov
Copy link

codecov bot commented Oct 24, 2025

Codecov Report

❌ Patch coverage is 0% with 27 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@8a705fd). Learn more about missing BASE report.

Files with missing lines Patch % Lines
crates/api_models/src/subscription.rs 0.00% 11 Missing ⚠️
crates/router/src/core/webhooks/outgoing_v2.rs 0.00% 9 Missing ⚠️
crates/common_enums/src/transformers.rs 0.00% 5 Missing ⚠️
crates/common_enums/src/enums.rs 0.00% 1 Missing ⚠️
crates/router/src/core/revenue_recovery/types.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9859   +/-   ##
=======================================
  Coverage        ?    3.94%           
=======================================
  Files           ?     1223           
  Lines           ?   299317           
  Branches        ?        0           
=======================================
  Hits            ?    11795           
  Misses          ?   287522           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@likhinbopanna likhinbopanna added this pull request to the merge queue Oct 27, 2025
Merged via the queue into main with commit 62035c4 Oct 27, 2025
25 of 27 checks passed
@likhinbopanna likhinbopanna deleted the subscriptions-outgoing-webhooks branch October 27, 2025 10:30
aadityaguptaa pushed a commit that referenced this pull request Nov 10, 2025
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Jagan Elavarasan <jaganelavarasan@gmail.com>
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 M-database-changes Metadata: This PR involves database schema changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add outgoing webhooks support for subscriptions

6 participants