PaymentExecer — an object that can execute the payment when called.
The PaymentHandler interface
PaymentExecer objects for every requirement it can fulfill. If the handler cannot fulfill any requirement, it returns an empty array.
The PaymentExecer interface
exec() is called, it signs the payment using the associated wallet and returns the payload for the X-PAYMENT header.
How handlers compose
Multiple handlers can be registered simultaneously. The fetch wrapper collects all execers from all handlers and passes them to a payer chooser function.chooseFirstAvailable, picks the first handler that can fulfill a requirement. You can provide a custom chooser to implement logic like balance checking, fee comparison, or chain preference.
Handler selection flow
Built-in handlers
| Package | Handler | Schemes |
|---|---|---|
@faremeter/payment-solana | createPaymentHandler | SOL, SPL tokens |
@faremeter/payment-evm | createPaymentHandler | EIP-3009 USDC |
Building custom handlers
A custom handler follows the same interface. ReturnPaymentExecer objects for requirements you can handle, and an empty array for those you cannot.
Further reading
- Fetch Wrapper — How to register handlers with the fetch wrapper.
- Payment Schemes — The schemes that handlers implement.