{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "autumn-billing",
  "type": "registry:block",
  "title": "Autumn Billing",
  "description": "Autumn billing adapter for plan attach, checkout redirects, usage billing, and plan changes.",
  "dependencies": [
    "autumn-js"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "https://stackfoundry.dev/r/billing-core.json",
    "https://stackfoundry.dev/r/usage-metering.json"
  ],
  "files": [
    {
      "path": "apps/web/src/lib/autumn/billing.ts",
      "type": "registry:file",
      "target": "apps/web/src/lib/autumn/billing.ts",
      "content": "import \"server-only\";\n\nimport { Autumn } from \"autumn-js\";\n\ntype AttachAutumnPlanInput = {\n  customerId: string;\n  planId: string;\n  featureQuantities?: Record<string, number>;\n  checkoutSessionParams?: Record<string, unknown>;\n};\n\nfunction requireEnv(key: string) {\n  const value = process.env[key];\n  if (!value) throw new Error(`${key} is required.`);\n  return value;\n}\n\nfunction getAutumn() {\n  return new Autumn({ secretKey: requireEnv(\"AUTUMN_SECRET_KEY\") });\n}\n\nexport async function attachAutumnPlan(input: AttachAutumnPlanInput) {\n  return getAutumn().billing.attach({\n    customerId: input.customerId,\n    planId: input.planId,\n    featureQuantities: input.featureQuantities,\n    checkoutSessionParams: input.checkoutSessionParams,\n  });\n}\n"
    },
    {
      "path": "apps/web/src/app/(console)/admin/providers/autumn-billing/page.tsx",
      "type": "registry:page",
      "target": "apps/web/src/app/(console)/admin/providers/autumn-billing/page.tsx",
      "content": "const deployChecks = [\n  \"Create Autumn products, plans, and features before wiring production actions\",\n  \"Set AUTUMN_SECRET_KEY in preview and production environments\",\n  \"Validate checkout redirects and saved-payment flows against sandbox customers\",\n  \"Keep plan ids and price decisions in server-owned configuration\",\n];\n\nexport default function AutumnBillingPage() {\n  return (\n    <main className=\"flex flex-col gap-6 p-6\">\n      <div>\n        <h1 className=\"text-2xl font-semibold\">Autumn Billing</h1>\n        <p className=\"text-muted-foreground\">\n          Optional Autumn adapter for plan attach, checkout redirects, usage billing, and plan changes.\n        </p>\n      </div>\n      <div className=\"grid gap-3\">\n        {deployChecks.map((check) => (\n          <div key={check} className=\"rounded-lg border p-4 text-sm\">\n            {check}\n          </div>\n        ))}\n      </div>\n    </main>\n  );\n}\n"
    }
  ],
  "maintenanceSkills": [
    {
      "name": "autumn-billing",
      "target": ".stackfoundry/skills/autumn-billing/SKILL.md",
      "content": "---\nname: autumn-billing\ndescription: Maintain the optional Autumn Billing adapter installed by StackFoundry.\n---\n\n# Autumn Billing Maintenance Instructions\n\n- Treat Autumn as an optional provider adapter. Keep `billing-core` and `usage-metering` as the source-owned default path.\n- Keep Autumn product, plan, and feature ids in server-owned configuration.\n- Validate client-selected plan ids against local allowlists before calling `billing.attach`.\n- Verify checkout redirects, saved-payment plan changes, upgrades, downgrades, and cancellation state mapping in sandbox.\n- Keep `module.json`, `docs.md`, and `tests/checklist.md` aligned when env vars, dependencies, or target files change.\n- Do not introduce provider lock-in outside the adapter boundary.\n\n## Shared Skills\n\nWhen provider, framework, or database behavior changes, load the installed shared skill before editing implementation details:\n\n- `.stackfoundry/skills/autumn/SKILL.md` (source: `registry/skills/autumn/SKILL.md`)\n- `.stackfoundry/skills/nextjs/SKILL.md` (source: `registry/skills/nextjs/SKILL.md`)\n\nKeep this module skill focused on ownership, installed files, env vars, deployment checks, and module-specific invariants.\n\n"
    },
    {
      "name": "autumn",
      "target": ".stackfoundry/skills/autumn/SKILL.md",
      "content": "---\nname: autumn\ndescription: Autumn billing and entitlement guidance for installed modules.\n---\n\n# Autumn Guidance\n\n## Installed Location\n\n- Installed target: `.stackfoundry/skills/autumn/SKILL.md`\n- Registry source: `registry/skills/autumn/SKILL.md`\n\nAgents maintaining an installed module should load this shared skill from the installed target when provider, framework, database, SDK, or platform behavior is involved. Keep provider-specific API details here instead of duplicating them inside module maintenance skills.\n\n- Keep provider keys server-only.\n- Document entitlement names and metered features.\n- Verify checks before gating user actions.\n- Test plan changes, overages, and credit behavior.\n"
    },
    {
      "name": "nextjs",
      "target": ".stackfoundry/skills/nextjs/SKILL.md",
      "content": "---\nname: nextjs\ndescription: Maintain Next.js App Router code installed by StackFoundry modules.\n---\n\n# Next.js Operating Instructions\n\n## Installed Location\n\n- Installed target: `.stackfoundry/skills/nextjs/SKILL.md`\n- Registry source: `registry/skills/nextjs/SKILL.md`\n\nAgents maintaining an installed module should load this shared skill from the installed target when provider, framework, database, SDK, or platform behavior is involved. Keep provider-specific API details here instead of duplicating them inside module maintenance skills.\n\n- Keep server-only data access out of Client Components.\n- Put route handlers under `app/api` and UI routes under the relevant App Router segment.\n- Prefer Server Components for data loading and add `\"use client\"` only for interactivity.\n- Keep public environment variables prefixed with `NEXT_PUBLIC_`; keep secrets server-only.\n- Re-run typecheck and build after changing route handlers, layouts, or shared app configuration.\n"
    }
  ],
  "envVars": {
    "AUTUMN_SECRET_KEY": ""
  },
  "docs": "# Autumn Billing\n\nOptional Autumn adapter for plan attach, checkout redirects, usage billing, overages, and plan changes.\n\nAutumn should sit beside the source-owned billing modules, not replace them by default. Use `billing-core` and `usage-metering` for local product state, then map plan ids and usage features into Autumn when the app chooses Autumn for hosted billing logic.\n\n## Official Docs\n\n- [Autumn Docs](https://docs.useautumn.com)\n- [Autumn API Reference](https://docs.useautumn.com/api-reference)\n\n## Owns\n\n- `apps/web/src/lib/autumn/billing.ts`\n- `apps/web/src/app/(console)/admin/providers/autumn-billing/page.tsx`\n\n## Dependencies\n\n- `autumn-js`\n- `registry:billing-core`\n- `registry:usage-metering`\n\n## Environment\n\n- `AUTUMN_SECRET_KEY`\n\n## Provider Notes\n\n- Autumn's `billing.attach` flow attaches a customer to a plan and may return a `paymentUrl` for hosted checkout.\n- Keep plan ids in server-owned configuration. Do not trust plan ids, prices, or feature quantities from client input without validation.\n- Model products, plans, usage features, included amounts, and overages in Autumn before promoting this adapter.\n\n## Maintenance\n\n- Keep this module focused on the Autumn boundary.\n- Update local billing mappings when Autumn product, plan, or feature ids change.\n- Verify sandbox checkout, upgrade, downgrade, saved-payment, and cancellation paths before marking stable.\n",
  "meta": {
    "category": "billing",
    "env": [
      "AUTUMN_SECRET_KEY"
    ],
    "status": "ready",
    "maturity": "ready",
    "recommendedFor": []
  }
}
