@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 thanpaymentInfo.maxAmount for a partial capture; the rest stays in escrow.
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).
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).
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.
Returns
Promise<Hash>, the refund transaction hash.
payment.getAmounts
Query the current capturable and refundable amounts for a payment.
Returns
Promise<PaymentAmounts>:
payment.getState
Returns the payment’s lifecycle position as a tuple. The SDK exposes noPaymentState enum.
Returns
Promise<readonly [boolean, bigint, bigint]>, [hasCollectedPayment, capturableAmount, refundableAmount].
operator.getConfig
Retrieve all slot addresses from the PaymentOperator contract.Promise<OperatorSlots>, see packages/core/src/actions/operator/types.ts. Key fields:
operator.getFeeAddresses
Fetch the fee-related addresses (subset ofgetConfig with both operator and protocol resolved).
Promise<FeeAddresses>:
operator.calculateFees
Calculate the full fee breakdown for a payment amount.
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.
