pub enum WebhookEvent {
Show 17 variants
PaymentAuthorized(PaymentPayload),
PaymentCaptured(PaymentPayload),
PaymentFailed(PaymentPayload),
OrderPaid(OrderPayload),
RefundCreated(RefundPayload),
RefundProcessed(RefundPayload),
RefundFailed(RefundPayload),
SubscriptionAuthenticated(SubscriptionPayload),
SubscriptionActivated(SubscriptionPayload),
SubscriptionCharged(SubscriptionPayload),
SubscriptionCancelled(SubscriptionPayload),
SubscriptionPaused(SubscriptionPayload),
SubscriptionHalted(SubscriptionPayload),
SubscriptionCompleted(SubscriptionPayload),
InvoicePaid(InvoicePayload),
InvoiceExpired(InvoicePayload),
Unknown,
}Expand description
A webhook event, dispatched on its event field.
Unknown catches every event this crate does not
model. You enable events in the Razorpay dashboard independently of this
crate’s version, so an unmodelled event must not break your handler.
Variants§
PaymentAuthorized(PaymentPayload)
A payment was authorized but not yet captured.
PaymentCaptured(PaymentPayload)
A payment was captured — the money is yours.
PaymentFailed(PaymentPayload)
A payment attempt failed.
OrderPaid(OrderPayload)
An order was paid in full.
RefundCreated(RefundPayload)
A refund was created.
RefundProcessed(RefundPayload)
A refund completed.
RefundFailed(RefundPayload)
A refund failed; the money stayed with you.
SubscriptionAuthenticated(SubscriptionPayload)
A subscription was authenticated by the customer.
SubscriptionActivated(SubscriptionPayload)
A subscription became active.
SubscriptionCharged(SubscriptionPayload)
A subscription was charged for a cycle.
SubscriptionCancelled(SubscriptionPayload)
A subscription was cancelled.
SubscriptionPaused(SubscriptionPayload)
A subscription was paused.
SubscriptionHalted(SubscriptionPayload)
A subscription ran out of retries.
SubscriptionCompleted(SubscriptionPayload)
A subscription finished its scheduled cycles.
InvoicePaid(InvoicePayload)
An invoice was paid.
InvoiceExpired(InvoicePayload)
An invoice went past its due date.
Unknown
An event this crate does not model, or one whose payload did not match the shape expected for its type.
Implementations§
Source§impl<'de> WebhookEvent
impl<'de> WebhookEvent
pub fn deserialize<__D>(__deserializer: __D) -> Result<WebhookEvent, __D::Error>where
__D: Deserializer<'de>,
Source§impl WebhookEvent
impl WebhookEvent
Sourcepub fn parse_verified(
raw_body: &str,
signature: &str,
webhook_secret: &str,
) -> Result<Self, RazorpayError>
pub fn parse_verified( raw_body: &str, signature: &str, webhook_secret: &str, ) -> Result<Self, RazorpayError>
Verify raw_body against signature, then parse it.
This is the only entry point that cannot be used in the wrong order. It
returns RazorpayError::SignatureMismatch if the body was not signed by
webhook_secret, and never parses in that case.
raw_body must be the exact bytes of the request. Do not parse and
re-serialize before calling — that changes the digest and always fails.
§Examples
use razorpay_api::resources::WebhookEvent;
use razorpay_api::signature::compute_signature;
let secret = "webhook_secret";
let raw_body = r#"{"event":"payment.captured","payload":{"payment":{"entity":
{"id":"pay_1","amount":50000,"currency":"INR","status":"captured","created_at":1}}}}"#;
let signature = compute_signature(raw_body, secret);
match WebhookEvent::parse_verified(raw_body, &signature, secret)? {
WebhookEvent::PaymentCaptured(p) => {
assert_eq!(p.payment.entity.id, "pay_1");
}
other => panic!("unexpected event: {other:?}"),
}
// A forged body is rejected before parsing.
assert!(WebhookEvent::parse_verified(raw_body, "00", secret).is_err());