#[non_exhaustive]pub struct PaymentRequired {
pub x402_version: Version2,
pub error: Option<CompactString>,
pub resource: ResourceInfo,
pub accepts: Vec<PaymentRequirements>,
pub extensions: Extensions,
}Expand description
Body of an HTTP 402 “Payment Required” response.
Contains:
- the x402 version marker,
- an optional human-readable
errorstring for malformed clients, - resource metadata,
- the list of
PaymentRequirementsthe seller will accept, and - an optional
extensionsblock.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.x402_version: Version2Protocol version (always 2).
error: Option<CompactString>Optional error message describing why the request was rejected.
resource: ResourceInfoResource metadata.
accepts: Vec<PaymentRequirements>Accepted payment terms.
extensions: ExtensionsOptional extension block.
Implementations§
Source§impl PaymentRequired
impl PaymentRequired
Sourcepub fn new(resource: ResourceInfo) -> Self
pub fn new(resource: ResourceInfo) -> Self
Constructs a 402 body with the resource block and an empty
accepts list. Use Self::with_accepts to attach payment
requirements and Self::with_error to surface a diagnostic
message to malformed clients.
Sourcepub fn with_accepts(self, accepts: Vec<PaymentRequirements>) -> Self
pub fn with_accepts(self, accepts: Vec<PaymentRequirements>) -> Self
Builder: replaces the accepted payment requirements list.
Sourcepub fn add_accept(self, accept: PaymentRequirements) -> Self
pub fn add_accept(self, accept: PaymentRequirements) -> Self
Builder: appends a single payment requirement to the accepts list.
Sourcepub fn with_error(self, error: impl Into<CompactString>) -> Self
pub fn with_error(self, error: impl Into<CompactString>) -> Self
Builder: attaches a human-readable error message describing why the
request was rejected (e.g. "missing X-PAYMENT header").
Sourcepub fn with_extensions(self, extensions: Extensions) -> Self
pub fn with_extensions(self, extensions: Extensions) -> Self
Builder: replaces the extensions block.
Trait Implementations§
Source§impl Clone for PaymentRequired
impl Clone for PaymentRequired
Source§fn clone(&self) -> PaymentRequired
fn clone(&self) -> PaymentRequired
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PaymentRequired
impl Debug for PaymentRequired
Source§impl<'de> Deserialize<'de> for PaymentRequired
impl<'de> Deserialize<'de> for PaymentRequired
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for PaymentRequired
impl RefUnwindSafe for PaymentRequired
impl Send for PaymentRequired
impl Sync for PaymentRequired
impl Unpin for PaymentRequired
impl UnsafeUnpin for PaymentRequired
impl UnwindSafe for PaymentRequired
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more