pub struct X402Client { /* private fields */ }Expand description
X402 HTTP client with explicit payment control
This client provides full control over the payment flow, allowing you to decide when and how to handle payment requests.
Implementations§
Source§impl X402Client
impl X402Client
Sourcepub fn new(keypair: Keypair, rpc_url: Option<&str>) -> Self
pub fn new(keypair: Keypair, rpc_url: Option<&str>) -> Self
Create a new X402 client
§Arguments
keypair- Solana keypair for signing transactionsrpc_url- Optional Solana RPC URL (defaults to devnet)
Sourcepub async fn get(&self, url: &str) -> X402Result<Response>
pub async fn get(&self, url: &str) -> X402Result<Response>
Make a GET request
Sourcepub async fn get_with_auth(
&self,
url: &str,
authorization: &PaymentAuthorization,
) -> X402Result<Response>
pub async fn get_with_auth( &self, url: &str, authorization: &PaymentAuthorization, ) -> X402Result<Response>
Make a GET request with payment authorization
Sourcepub async fn post(
&self,
url: &str,
body: Option<String>,
) -> X402Result<Response>
pub async fn post( &self, url: &str, body: Option<String>, ) -> X402Result<Response>
Make a POST request
Sourcepub async fn post_with_auth(
&self,
url: &str,
body: Option<String>,
authorization: &PaymentAuthorization,
) -> X402Result<Response>
pub async fn post_with_auth( &self, url: &str, body: Option<String>, authorization: &PaymentAuthorization, ) -> X402Result<Response>
Make a POST request with payment authorization
Sourcepub fn is_payment_required(&self, response: &Response) -> bool
pub fn is_payment_required(&self, response: &Response) -> bool
Check if a response requires payment (402 status code)
Sourcepub async fn parse_payment_request(
&self,
response: Response,
) -> X402Result<PaymentRequest>
pub async fn parse_payment_request( &self, response: Response, ) -> X402Result<PaymentRequest>
Parse payment request from 402 response
Sourcepub async fn create_payment(
&self,
request: &PaymentRequest,
) -> X402Result<PaymentAuthorization>
pub async fn create_payment( &self, request: &PaymentRequest, ) -> X402Result<PaymentAuthorization>
Create a payment from a payment request
This creates, signs, and broadcasts the payment transaction
Sourcepub async fn verify_payment(
&self,
authorization: &PaymentAuthorization,
expected_amount: &str,
) -> X402Result<bool>
pub async fn verify_payment( &self, authorization: &PaymentAuthorization, expected_amount: &str, ) -> X402Result<bool>
Verify a payment authorization
Auto Trait Implementations§
impl !Freeze for X402Client
impl !RefUnwindSafe for X402Client
impl !UnwindSafe for X402Client
impl Send for X402Client
impl Sync for X402Client
impl Unpin for X402Client
impl UnsafeUnpin for X402Client
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more