Skip to main content

ErrorKind

Enum ErrorKind 

Source
#[non_exhaustive]
pub enum ErrorKind { Auth, InvalidRequest, Declined, NotFound, RateLimited, Transport, Malformed, Untrusted, Unsupported, Provider, }
Expand description

What went wrong, in terms a caller can branch on without knowing the provider.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Auth

Credentials were missing, wrong, or not allowed to do this.

§

InvalidRequest

The request was rejected before it reached the card network.

§

Declined

The bank or the network refused the payment.

§

NotFound

The payment was not found, or no longer exists.

§

RateLimited

The provider asked us to slow down.

§

Transport

The request never got a usable answer: DNS, TLS, timeout, socket.

§

Malformed

The provider answered, but with something this crate cannot read.

§

Untrusted

The answer could not be shown to have come from the provider.

A signature that does not match, or one that is missing where the provider always sends it. Not a transport failure and not a decline: it means the message may not be theirs, and it must never be acted on.

§

Unsupported

The provider does not offer what was asked of it.

§

Provider

The provider failed on its own side.

Implementations§

Source§

impl ErrorKind

Source

pub const fn is_retryable(self) -> bool

Whether replaying the same request unchanged could plausibly succeed.

§This does not mean the retry is safe

It says the failure was not a verdict. It says nothing about whether the first attempt took the money — a timeout is exactly the case where nobody knows.

Replaying a charge is safe only where the provider offers idempotency, and not every one does:

replaying a charge
Stripesafe — ChargeRequest::idempotency_key is sent as Idempotency-Key
iyziconot documented safe — it refuses an idempotency key, and does not say what a reused orderId does
PayTRnot documented safe — no idempotency mechanism is documented for opening a payment
Molliesafe — ChargeRequest::idempotency_key is sent as Idempotency-Key, and Mollie replays the first answer for an hour
PayPalsafe — ChargeRequest::idempotency_key is sent as PayPal-Request-Id, and PayPal returns the first answer for a repeated key

Where it is not safe, read the payment back before sending it again. Reading is always safe — but which call reads it back depends on what you still have. A charge that answered and then failed later leaves a Charge::id, and Provider::charge_status takes it. A charge whose answer never arrived leaves nothing but the order reference, and that is Provider::lookup — which is exactly the timeout case, and exactly the two providers whose replay is not documented as safe: iyzico and PayTR can both be asked.

Replaying a capture is a narrower question, because a capture takes money rather than opening a request for it. Provider::capture carries its own idempotency, and what a timeout means depends on whether one was sent:

replaying a capture, with a keyreplaying a capture, without one
Stripesafe — sent as Idempotency-Key, same as a chargenot safe — a second PaymentIntent capture can take the funds twice
iyzicon/a — a key is refused outright, because iyzico accepts nonenot safeclassic’s capture is /payment/postauth, and iyzico documents no idempotency mechanism for it
PayTRn/a — no capture step; the hosted form takes the money as it goesn/a
Molliesafe — sent as Idempotency-Key on the captures endpoint, answered from the cache for an hournot safe — a second capture against the same authorisation can take the funds twice
PayPalsafe — sent as PayPal-Request-Id, same as opening an ordernot safe, and PayPal documents it — a second capture of the same order can take the funds twice

Where it is not safe, this table’s answer does not change: read the payment back with Provider::charge_status rather than sending Provider::capture again. A capture whose outcome is_retryable does not resolve is read back, never resent — with a key, resending is safe but reading is still simpler and costs nothing extra.

Trait Implementations§

Source§

impl Clone for ErrorKind

Source§

fn clone(&self) -> ErrorKind

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 Copy for ErrorKind

Source§

impl Debug for ErrorKind

Source§

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

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

impl Display for ErrorKind

Source§

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

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

impl Eq for ErrorKind

Source§

impl Hash for ErrorKind

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ErrorKind

Source§

fn eq(&self, other: &ErrorKind) -> 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 ErrorKind

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.