Skip to main content

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

  1. Detects refund-enabled payments by checking for extra._x402_refund_merchantPayout in paymentRequirements
  2. Extracts the DepositRelay address from paymentRequirements.payTo (set by the merchant's withRefund())
  3. Gets the merchant payout address from paymentRequirements.extra._x402_refund_merchantPayout
  4. Queries EscrowFactory using merchant payout address to get the escrow contract address for the merchant
  5. Calls DepositRelay.executeDeposit() to route the payment through escrow

The helper automatically detects refund-enabled payments and routes them correctly.