Class X402PaymentHandler
A System.Net.Http.DelegatingHandler that automatically pays HTTP 402 challenges using the XRPL x402 protocol.
On a 402 response the handler selects the matching PaymentRequirement, enforces configured
amount caps and allowlists, signs the payment via IX402Signer, and retries the original request
with the PAYMENT-SIGNATURE header attached.
Inheritance
Namespace: Xrpl.X402
Assembly: Xrpl.X402.dll
Syntax
public sealed class X402PaymentHandler : DelegatingHandler
Constructors
| Edit this page View SourceX402PaymentHandler(IX402Signer, X402ClientOptions)
Initializes a new instance of X402PaymentHandler.
Declaration
public X402PaymentHandler(IX402Signer signer, X402ClientOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| IX402Signer | signer | Signer that autofills and locally signs XRPL payment transactions. |
| X402ClientOptions | options | Client options controlling network selection, amount caps, and allowlists. |
Methods
| Edit this page View SourceSendAsync(HttpRequestMessage, CancellationToken)
Sends the request; if a 402 Payment Required response is received, negotiates and pays the challenge, then retries the request with the payment proof attached.
Declaration
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpRequestMessage | request | The HTTP request to send. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<HttpResponseMessage> | The final System.Net.Http.HttpResponseMessage after any payment negotiation. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| X402PaymentException | Thrown when the challenge is malformed, no acceptable requirement is found, a policy cap is exceeded, or the server returns 402 again after payment (anti double-pay guard). |