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: EventIdWhat 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: EventKindWhat 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: ProviderIdWhich provider sent it.
raw: RawThe delivery’s own body, kept whole.