-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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(webhook): Add is_delivered filter to list initial attempts endpoint #7344
base: return-total-events-count
Are you sure you want to change the base?
Conversation
// Filter all events by overall_delivery_status. | ||
pub is_delivered: Option<bool>, |
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 make this a documentation comment instead.
And update the documentation comment to reflect the current field name, in case you think we actually need to reference the field name here.
@@ -68,7 +72,7 @@ pub struct EventListItemResponse { | |||
/// Specifies the class of event (the type of object: Payment, Refund, etc.) | |||
pub event_class: EventClass, | |||
|
|||
/// Indicates whether the webhook delivery attempt was successful. | |||
/// Indicates whether the webhook was ultimately delivery. |
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.
Nit:
/// Indicates whether the webhook was ultimately delivery. | |
/// Indicates whether the webhook was ultimately delivered. |
@@ -0,0 +1,2 @@ | |||
-- Your SQL goes here | |||
ALTER TABLE events ADD COLUMN IF NOT EXISTS is_overall_delivery_successful BOOLEAN NOT NULL DEFAULT FALSE; |
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.
Why is this column non-nullable? Why can't the old data have null values?
let parent_update = domain::EventUpdate::ParentUpdate { | ||
is_overall_delivery_successful: status_code.is_success(), | ||
}; | ||
|
||
let parent_event_id = current_event.initial_attempt_id.clone(); | ||
let delivery_attempt = current_event.delivery_attempt; | ||
|
||
if let Some(( | ||
parent_event_id, | ||
enums::WebhookDeliveryAttempt::InitialAttempt | ||
| enums::WebhookDeliveryAttempt::AutomaticRetry, | ||
)) = parent_event_id.zip(delivery_attempt) | ||
{ | ||
state | ||
.store | ||
.update_event_by_merchant_id_event_id( | ||
key_manager_state, | ||
merchant_id, | ||
parent_event_id.as_str(), | ||
parent_update, | ||
&merchant_key_store, | ||
) | ||
.await | ||
.change_context(errors::WebhooksFlowError::WebhookEventUpdationFailed) | ||
.attach_printable("Failed to update parent event")?; | ||
} |
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.
Can we extract updating of the initial attempt to a different function, and call it in trigger_webhook_to_merchant()
? We'd prefer to keep the update_event_in_storage()
function responsible for updating only the current event that we're working with.
Ideally, we'd want to keep a function to have only one responsibility...
let parent_update = domain::EventUpdate::ParentUpdate { | ||
is_overall_delivery_successful: status_code.is_success(), | ||
}; |
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.
Once we've extracted it to a separate function, let's name this enum variant to indicate which field is being updated, rather than which event is being updated: something along the lines of OverallDeliveryStatusUpdate
.
/// Reference to the object type for which the webhook was created. | ||
pub primary_object_type: EventObjectType, |
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.
/// Reference to the object type for which the webhook was created. | |
pub primary_object_type: EventObjectType, | |
/// Type of the object for which the webhook was created. | |
pub primary_object_type: EventObjectType, |
/// Merchant identifier to which the webhook was sent. | ||
pub merchant_id: Option<common_utils::id_type::MerchantId>, | ||
|
||
/// Business Profile identifier to which the webhook was sent. | ||
pub business_profile_id: Option<common_utils::id_type::ProfileId>, |
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.
These actually are the identifiers of the merchant account and business profile the object is associated with.
Type of Change
Description
This PR features addition of new filter called
is_delivered
which will allow merchants to filter out webhook events based on the fact that if a particular event was ultimately delivered or not.The
is_delivery_successful
field now takes data fromis_overall_delivery_successful
column of the events table and notis_webhook_notified
to represent the eventual delivery of the event.Additional Changes
Motivation and Context
Upon merging this PR, the merchants would be able to filter webhook events based on ultimate delivery status.
How did you test it?
is_delivered
havingfalse
value.is_delivered
filter havingtrue
value.Checklist
cargo +nightly fmt --all
cargo clippy