payment

package
v0.13.0-go Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package payment implements the x402 micropayment protocol for DOSRouter. x402 enables pay-per-request LLM access without API keys or accounts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatPaymentInfo

func FormatPaymentInfo(pr PaymentRequired) string

FormatPaymentInfo returns a human-readable payment summary.

func IsPaymentRequired

func IsPaymentRequired(resp *http.Response) bool

IsPaymentRequired checks if a response is a 402 payment required.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client handles x402 payment flows.

func New

func New(w *wallet.Wallet) *Client

New creates a new payment client.

func (*Client) HandlePaymentRequired

func (c *Client) HandlePaymentRequired(resp *http.Response, originalReq *http.Request, model string) (*PaymentResult, error)

HandlePaymentRequired processes a 402 response by signing and submitting payment.

func (*Client) WrapRequest

func (c *Client) WrapRequest(req *http.Request, model string) bool

WrapRequest adds payment headers to an outgoing request if pre-auth is cached. Returns true if payment headers were added.

type PaymentRequired

type PaymentRequired struct {
	Amount       float64 `json:"amount"`
	Currency     string  `json:"currency"`
	PayTo        string  `json:"payTo"`
	Network      string  `json:"network"`
	Description  string  `json:"description"`
	ExpiresAt    string  `json:"expiresAt,omitempty"`
	PaymentToken string  `json:"paymentToken,omitempty"` // Token to include after payment
}

PaymentRequired represents a 402 response from the upstream server.

type PaymentResult

type PaymentResult struct {
	Success bool    `json:"success"`
	TxHash  string  `json:"txHash,omitempty"`
	Cost    float64 `json:"cost"`
	Error   string  `json:"error,omitempty"`
}

PaymentResult is the outcome of a payment attempt.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL