Skip to main content
The @x402r/sdk package covers the merchant’s post-payment lifecycle: capturing escrowed funds, charging directly, processing refunds, and querying operator state.
Looking for server setup? The Merchant Server Quickstart shows how to accept escrow payments via Express middleware. This page covers the createMerchantClient factory for managing payments after they arrive.

Installation

Setup

payment.capture

Transfer escrowed funds to the receiver. Specify a smaller amount than paymentInfo.maxAmount for a partial capture; the rest stays in escrow.
Parameters Returns Promise<Hash>, the settlement transaction hash.
Always query payment.getAmounts() first to determine the available capturable amount.

payment.voidPayment

Return all escrowed funds to the payer before capture. Full-only: void() empties the authorization in one transaction. For a partial return, capture the share you want to keep first, then void the rest (or let it expire at captureDeadline).
Parameters Returns Promise<Hash>, the void transaction hash.

payment.charge

Non-escrow settlement for subscriptions or session-based payments. Pulls funds directly from the payer via a token collector (no escrow hold).
Parameters Returns Promise<Hash>, the charge transaction hash.

payment.refund

Refund funds the merchant has already captured. Requires a token collector to pull funds from the merchant’s balance.
Parameters Returns Promise<Hash>, the refund transaction hash.
Refunds after capture require the merchant to hold enough token balance and to grant an allowance on the refund collector.

payment.getAmounts

Query the current capturable and refundable amounts for a payment.
Parameters Returns Promise<PaymentAmounts>:

payment.getState

Returns the payment’s lifecycle position as a tuple. The SDK exposes no PaymentState enum.
Parameters Returns Promise<readonly [boolean, bigint, bigint]>, [hasCollectedPayment, capturableAmount, refundableAmount].

operator.getConfig

Retrieve all slot addresses from the PaymentOperator contract.
Returns Promise<OperatorSlots>, see packages/core/src/actions/operator/types.ts. Key fields:

operator.getFeeAddresses

Fetch the fee-related addresses (subset of getConfig with both operator and protocol resolved).
Returns Promise<FeeAddresses>:

operator.calculateFees

Calculate the full fee breakdown for a payment amount.
Parameters Returns Promise<FeeCalculationResult>:

Capture vs refund decision flow

Next steps

Refund Handling

Process incoming refund requests with deny workflows.

forwardToArbiter()

Forward escrow settlements to an arbiter service.

PaymentOperator

Understand the underlying PaymentOperator contract methods.