-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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(core): Support for multiple outgoing webhooks added #7578
base: main
Are you sure you want to change the base?
Conversation
@@ -52,7 +52,7 @@ pub struct MerchantAccountCreate { | |||
pub return_url: Option<url::Url>, | |||
|
|||
/// Webhook related details | |||
pub webhook_details: Option<WebhookDetails>, | |||
pub webhook_details: Option<Vec<Option<WebhookDetails>>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two options here, which seem redundant. Is there any specific reason to do so?
///The password for Webhook login | ||
#[schema(value_type = Option<String>, max_length = 255, example = "ekart@123")] | ||
pub webhook_password: Option<Secret<String>>, | ||
pub webhook_endpoint_id: Option<id_type::WebhookEndpointId>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this change backwards compatible?
@@ -239,6 +239,13 @@ pub fn generate_profile_id_of_default_length() -> id_type::ProfileId { | |||
id_type::ProfileId::generate() | |||
} | |||
|
|||
/// Generate a profile id with default length, with prefix as `pro` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change the doc comment
#[serde(rename_all = "snake_case")] | ||
#[strum(serialize_all = "snake_case")] | ||
pub enum OutgoingWebhookEndpointStatus { | ||
Active, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please provide description to these enums. What is the difference between inactive and deprecated? if once made as deprecated, it cannot be made active?
Type of Change
Description
In the current system, merchants can configure only one webhook endpoint per profile. This PR introduces support for configuring multiple webhook endpoints based on the event_type. These changes include modifications to the database schema and alterations in the webhook triggering logic.
Database Schema Changes
The webhook_details column in the business_profile table is being updated from a JSON object to an array of JSON objects. This will allow each business profile to store multiple webhook endpoints that can be associated with different event types.
Old Schema (Single webhook configuration):
{
"webhook_url": "https://example.com/webhook",
"events": ["payment_succeeded"]
}
New Schema (Multiple webhook configurations):
[
{
"webhook_url": "https://example1.com/webhook",
"events": ["payment_succeeded", "order_created"]
},
{
"webhook_url": "https://example2.com/webhook",
"events": ["payment_failed"]
}
]
2. Merchant Account Schema Update:
The merchant_account table might also include the webhook_details field to store webhook configurations for the merchant, allowing the use of multiple endpoints for different events.
The database migrations will need to reflect these changes to handle an array of webhook configurations instead of a single configuration.
Event Handling Logic
Triggering the First Webhook: When an event (e.g., a payment) occurs, the first webhook endpoint is triggered. This is determined by matching the event_type against the webhook configurations stored in the business_profile. The first matching webhook endpoint is used to trigger the webhook request.
Process Tracker for Remaining Webhooks: For the remaining webhook endpoints, even though they won't be triggered immediately, the system will log these events in the process tracker for future attempts. This is useful for retrying failed webhook calls or ensuring that the webhooks are eventually delivered.
Webhook Retry Handling: Each webhook delivery attempt, whether initial or retry, will be recorded in the process_tracker. This ensures that failed webhook deliveries are retried.
Additional Changes
Motivation and Context
How did you test it?
Response
Response
Checklist
cargo +nightly fmt --all
cargo clippy