Skip to main content

Event

Struct Event 

Source
pub struct Event {
    pub id: EventId,
    pub kind: EventKind,
    pub payment: Option<PaymentId>,
    pub amount: Option<Money>,
    pub provider: ProviderId,
    pub raw: Raw,
}
Expand description

What a provider told us happened, once it has been shown to be theirs.

Every field is public and the struct is open, for the same reason Charge is: an adapter in someone else’s repository has to be able to build one.

§Why this is not an enum of Charge and Refund

It was the other candidate, and it asks each adapter to build a whole charge out of a delivery. Stripe’s webhook carries a PaymentIntent and can; PayTR’s notice signs three fields and cannot say what currency they are in; Mollie’s carries an identifier and nothing else at all. The shape that survives all three is this one — what happened, to which payment, and the body for everything else — and what the caller does next is read the payment back, which is a call they already have.

Fields§

§id: EventId

What the caller writes into a unique index before acting on this.

The second delivery of an event collides with the first instead of shipping the order twice, which is the whole reason this field is not optional — a delivery nothing identifies is one nothing can deduplicate.

Read Id::source before trusting it. Stripe and PayPal issue an identifier for the delivery itself; PayTR and Mollie issue none, so kasapay composes one out of the fields the provider did send and says which they were. A composed key is unique exactly as far as those fields are, and no further — two deliveries that differ only in a field the provider did not sign are one key.

§kind: EventKind

What happened.

§payment: Option<PaymentId>

The payment it happened to, where the delivery names one.

None for a delivery about something that is not a payment — a dispute opening, a payout landing — which arrives as EventKind::Other and is a normal thing to receive.

§amount: Option<Money>

The amount the delivery carried, where it carried one that can be trusted.

None is not “zero” and not “the provider sent nothing”. PayTR’s notice carries an amount whose currency is outside the hash, so the figure is a number without a unit and is left here rather than guessed at; it is on Event::raw with everything else.

§provider: ProviderId

Which provider sent it.

§raw: Raw

The delivery’s own body, kept whole.

Trait Implementations§

Source§

impl Clone for Event

Source§

fn clone(&self) -> Event

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 Event

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Event

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnsafeUnpin for Event

§

impl UnwindSafe for Event

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.