Quick Start for Facilitators
1. Install the Package
npm install @x402/extensions
2. Add the Refund Hook
import { settleWithRefundHelper } from '@x402/extensions/refund'
facilitator.onBeforeSettle(async (context) => {
const result = await settleWithRefundHelper(
context.paymentPayload,
context.paymentRequirements,
facilitator.signer,
ESCROW_FACTORY_ADDRESS
)
return result ? { abort: true } : null
})
What Happens Under the Hood
- Detects refund-enabled payments by checking for
extra._x402_refund_merchantPayoutinpaymentRequirements - Extracts the DepositRelay address from
paymentRequirements.payTo(set by the merchant'swithRefund()) - Gets the merchant payout address from
paymentRequirements.extra._x402_refund_merchantPayout - Queries EscrowFactory using merchant payout address to get the escrow contract address for the merchant
- Calls DepositRelay.executeDeposit() to route the payment through escrow
The helper automatically detects refund-enabled payments and routes them correctly.