diff --git a/src/resources/webhook_events.rs b/src/resources/webhook_events.rs index 656ab9c7f..92725edd1 100644 --- a/src/resources/webhook_events.rs +++ b/src/resources/webhook_events.rs @@ -485,6 +485,8 @@ pub struct Webhook { #[cfg(feature = "webhook-events")] impl Webhook { + /// Construct an event from a webhook payload and signature. + /// /// # Errors /// /// This function will return a WebhookError if: @@ -495,6 +497,27 @@ impl Webhook { Self { current_timestamp: Utc::now().timestamp() }.do_construct_event(payload, sig, secret) } + /// Construct an event from a webhook payload and signature, verifying its signature + /// using the provided timestamp. + /// + /// This is helpful for replaying requests in tests and should be avoided otherwise + /// in production use. + /// + /// # Errors + /// + /// This function will return a WebhookError if: + /// - the provided signature is invalid + /// - the provided secret is invalid + /// - the signature timestamp is older than 5 minutes from the provided timestamp + pub fn construct_event_with_timestamp( + payload: &str, + sig: &str, + secret: &str, + timestamp: i64, + ) -> Result { + Self { current_timestamp: timestamp }.do_construct_event(payload, sig, secret) + } + fn do_construct_event( self, payload: &str,