Skip to main content

WebhookEvent

Enum WebhookEvent 

Source
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

Source

pub fn deserialize<__D>(__deserializer: __D) -> Result<WebhookEvent, __D::Error>
where __D: Deserializer<'de>,

Source§

impl WebhookEvent

Source

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());

Trait Implementations§

Source§

impl Clone for WebhookEvent

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WebhookEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for WebhookEvent

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for WebhookEvent

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for WebhookEvent

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more