Skip to main content

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

  1. Create plan – merchant (or backend) calls createPlan(token, amount, interval, receiver).
  2. Authorize billing – payer signs Permit2/EIP-2612 or grants allowance.
  3. Subscribe – call subscribe(planId, user, permitData).
  4. Charge – backend/agent calls charge(user, planId) after interval elapses.
  5. 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 referenceData during charges to correlate with invoices and x402 sessions.