SubscriptionManager
Subscriptions reuse payment allowlists and fee guardrails from X402FlexRegistry, so keep deployments in sync.
Contract struct
struct Plan {
address token;
uint256 amount;
uint32 interval;
address receiver;
}
Lifecycle
- Create plan – merchant (or backend) calls
createPlan(token, amount, interval, receiver). - Authorize billing – payer signs Permit2/EIP-2612 or grants allowance.
- Subscribe – call
subscribe(planId, user, permitData). - Charge – backend/agent calls
charge(user, planId)after interval elapses. - Cancel – payer or merchant calls
cancel(planId, user).
SDK note
The core SDK exports TypeChain factories for payments contracts. For subscriptions, use the ABI from contracts/subscriptions or your own generated TypeChain bindings until subscription factories are included in the SDK.
Tips
- Reuse collectors across payments and subscriptions to simplify key management.
- Enforce minimum intervals server-side to avoid abuse.
- Persist
referenceDataduring charges to correlate with invoices and x402 sessions.