Agent skill · software engineering · aiskillstore
credits-handler
Manage the credit system (allocation, purchasing, usage). Use when adding credit types, configuring pricing, or building credit UI.
Why this skill is useful
Provides specific implementation patterns and configurations for managing a credit system that the AI wouldn't reliably generate on its own.
What it needs
About 3k tokens when loaded. Last updated 2026-08-07. 405 stars on the source repository.
What this skill does
Credits Handler This skill guides you through the entire credit system, from backend configuration to frontend UI implementation. 1. Configuration All credit configuration lives in src/lib/credits/config.ts. Adding a New Credit Type 1. Define the Type: Add the new type to creditTypeSchema enum. 2. Configure Pricing & Metadata: Add an entry to creditsConfig. 3. Plan Allocations (Optional): Define how many credits are given when subscribing to a plan in onPlanChangeCredits. 2. UI Implementation: Buying Credits To let users purchase credits, use the useBuyCredits hook. This hook handles price calculation (factoring in plan discounts) and generating checkout URLs. Key Hook: useBuyCredits Location: src/lib/credits/useBuyCredits.ts Usage Example: Building a Pricing Card Here is a pattern for creating a credit purchase UI, similar to src/components/website/website-credits-section.tsx. 3. UI Implementation: Displaying Credits To show the user's current balance, use the useCredits hook. Key Hook: useCredits Location: src/lib/users/useCredits.ts Return Data Structure Usage Example 4. Core Operations (Backend) These functions are used in API routes and webhooks. Allocating Credits (e.g., on Plan Change) Use allocatePlanCredits to give users credits when they subscribe/upgrade. File: src/lib/credits/allocatePlanCredits.ts Input: userId, planId, paymentId (for idempotency). Behavior: Checks onPlanChangeCredits config and adds credits if applicable. Adding/Deducting Credits To manually manipulate balances, use helpers from src/lib/credits/recalculate.ts (e.g., addCredits, deductCredits). Note: Always ensure you have a unique paymentId or transaction reference when adding credits to prevent duplicates. 5. Checking Balance (Backend/Common) Use canDeductCredits before performing an action. 6. Reference For deep dives into database schema and architecture, see reference.md.
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills aiskillstore/credits-handler