Payment Models

Detailed documentation for payment models in the core package.

PaymentRequest

The PaymentRequest class represents a payment request from a server.

Properties

class PaymentRequest {
  maxAmountRequired: string;    // Maximum payment amount required
  assetType: string;            // Asset type (e.g., "SPL")
  assetAddress: string;         // Token mint address or "native" for SOL
  paymentAddress: string;       // Recipient wallet address
  network: string;              // Blockchain network identifier
  expiresAt: Date;              // Payment request expiration time
  nonce: string;                // Unique nonce for this request
  paymentId: string;            // Unique payment identifier
  resource: string;             // Resource path being requested
  description?: string;         // Optional description
}

Creating a Payment Request

Methods

isExpired()

Check if the payment request has expired:

toDict()

Convert to dictionary format:

toJSON()

Convert to JSON string:

fromDict()

Create from dictionary:

Validation

The PaymentRequest constructor validates all fields using Zod schemas:

PaymentAuthorization

The PaymentAuthorization class represents proof of payment.

Properties

Creating a Payment Authorization

Methods

toHeaderValue()

Convert to header value (base64-encoded JSON):

fromHeader()

Create from header value:

toDict()

Convert to dictionary:

toJSON()

Convert to JSON string:

Validation

The PaymentAuthorization constructor validates all fields:

Usage Examples

Creating Payment Request on Server

Parsing Payment Authorization on Server

Validating Payment Authorization

Type Definitions

Next Steps

Last updated