promo-code-system
Skill0 starsChanged 3 months agoMITView on GitHub
Add, manage, and track promotional/discount codes in web applications. Use when adding promo codes to existing apps, creating discount code systems, tracking code usage, implementing coupon functionality, managing promotional campaigns, or when users ask about discount codes, free access codes, or promotional features. Apply automatically when the request matches; the user does not need to mention this skill.
In this repository76 other files it gives its agents.
- app-store-submission-packagerSkill
- digital-product-inventorSkill
- ios-testflight-github-actionsSkill
- meta-ads-analyzerSkill
- get-to-know-a-clientSkill
- investigate-before-recommendSkill
- production-system-auditSkill
- similarweb-analyticsSkill
- stock-analysisSkill
- system-architectSkill
- autonomous-github-syncSkill
- autonomous-sync-scriptSkill
- github-gem-seekerSkill
- organize-github-reposSkill
- using-git-worktreesSkill
- brainstorm-logosSkill
- brand-driven-ux-overhaulSkill
- canvas-designSkill
- excel-generatorSkill
- frontend-designSkill
- inspirational-music-video-productionSkill
- theme-factorySkill
- video-generatorSkill
- multiplayer-game-builderSkill
- realistic-ai-persona-builderSkill
- role-based-access-controlSkill
- serverless-debuggingSkill
- vertical-expansion-blueprintSkill
- manus-mcp-configuratorSkill
- mcp-auto-recoverySkill
- mcp-builderSkill
- mcp-connector-testerSkill
- mcp-ecosystem-optimizerSkill
- voice-ai-integrationSkill
- api-endpoint-builderSkill
- database-schema-generatorSkill
- testing-frameworkSkill
- deployment-automationSkill
- error-monitoring-setupSkill
- github-workflow-automationSkill
- analytics-dashboardSkill
- email-system-builderSkill
- feature-flag-systemSkill
- user-authentication-systemSkill
- cron-job-schedulerSkill
- file-upload-systemSkill
- notification-systemSkill
- payment-integrationSkill
- search-implementationSkill
- debug-mining-engineSkill
- doc-coauthoringSkill
- docxSkill
- internet-skill-finderSkill
- pdfSkill
- pptxSkill
- project-handoff-ingestionSkill
- serverless-debuggingSkill
- skill-arsenal-builderSkill
- skill-creatorSkill
- skill-demo-builderSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
29 rules. About 0 are common, 15 are distinctive, and 14 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈15
Distinctive · estimate
This author's own choices. Worth a look.
14
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
Add promotional and discount code functionality to web applications with tracking, analytics, and flexible discount types.
- Distinctive: line 33
Follow these steps in order:
- Distinctive: line 37
Run the discovery script to find existing promo code implementation:
- Distinctive: line 43
If you don't have the project path, locate it by:
- Distinctive: line 60
No promo code patterns detected
- Very specific: line 83
Use: templates/promo_schema.sql + API templates
- Very specific: line 92
Add to user's server file (e.g., server.js, index.js)
- Very specific: line 94
Update checkout endpoint to use calculateDiscountedPrice()
- Very specific: line 110
Run templates/promo_schema.sql in Supabase SQL Editor
- Very specific: line 113
Add server-side validation (see references/implementation_guide.md)
- Very specific: line 121
Use templates/admin_panel.html for visual management
- Distinctive: line 127
Always create a quick reference guide for the user:
- Distinctive: line 142
Run through testing checklist:
- Distinctive: line 156
Test cards for Stripe:
- Very specific: line 179
Create API routes in app/api/:
- Very specific: line 222
Read references/stripe_integration.md for detailed Stripe patterns.
- Distinctive: line 249
Use the code generator script to create secure codes:
- Distinctive: line 341
Always validate server-side: - Never trust client input
- Very specific: line 350
Check code is active (is_active = true)
- Very specific: line 351
Check not expired (expires_at > NOW())
- Very specific: line 352
Check usage limit not reached (current_uses < max_uses)
- Very specific: line 361
Verify recordPromoCodeUsage() is called after payment
- Distinctive: line 363
Verify promo_code_id is passed correctly
- Distinctive: line 368
Verify calculation logic is correct
- Distinctive: line 380
Always provide user with:
- Distinctive: line 391
Discover: Run discovery script, find existing hardcoded system
- Very specific: line 394
Implement: Add 10 new codes to their DISCOUNT_CODES object
- Very specific: line 395
Document: Create MY_PROMO_CODES.md with all codes
- Distinctive: line 396
Test: Verify codes work on live site
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Promo Code System
Add promotional and discount code functionality to web applications with tracking, analytics, and flexible discount types.
Overview
This skill helps implement promo code systems in web apps. Supports:
- Quick implementation (hardcoded codes, 5 minutes)
- Proper implementation (database-driven, 45 minutes)
- Multiple discount types (free access, percentage off, fixed amount)
- Usage tracking and analytics
- Expiration dates and limits
- Stripe integration
When to Use This Skill
- User wants to add promo codes to their app
- User asks "how do I remember my codes?"
- User needs to track which codes are being used
- User wants to offer free access via codes
- User has existing discount system that needs extension
Quick Start Workflow
Follow these steps in order:
Step 1: Discover Existing System
Run the discovery script to find existing promo code implementation:
python3 scripts/discover_promo_system.py /path/to/projectIf you don't have the project path, locate it by:
- Checking Supabase projects (MCP)
- Checking Vercel deployments (MCP)
- Checking GitHub repositories (
gh repo list) - Asking user for local path
The script identifies:
- Hardcoded discount codes
- Database tables
- API endpoints
- Payment processor integration
Step 2: Analyze Current State
Based on discovery results, determine implementation type:
No System Found
- No promo code patterns detected
- → Recommend Path A (Quick Start)
Hardcoded System Found
- Found
DISCOUNT_CODESobject or similar - Codes defined in source code
- → Extend existing system or upgrade to database
Database System Found
- Found
promo_codestable - Has API endpoints
- → Enhance existing system
Step 3: Choose Implementation Path
Path A: Quick (Hardcoded) - 5 minutes
- Best for: MVPs, <20 codes, simple needs
- Use:
templates/hardcoded_codes_template.js - Pros: Fast, simple, no database changes
- Cons: No tracking, must redeploy to add codes
Path B: Proper (Database) - 45 minutes
- Best for: Production, >20 codes, need tracking
- Use:
templates/promo_schema.sql+ API templates - Pros: Full tracking, expiration, limits, analytics
- Cons: More complex, requires database
Step 4: Implement Solution
For Path A (Quick/Hardcoded):
- Copy
templates/hardcoded_codes_template.jscontent - Add to user's server file (e.g.,
server.js,index.js) - Customize
DISCOUNT_CODESobject with their codes - Update checkout endpoint to use
calculateDiscountedPrice() - Deploy
Example codes to add:
const DISCOUNT_CODES = {
'FREE': { type: 'free', value: 0 },
'FRIEND': { type: 'free', value: 0 },
'SAVE10': { type: 'amount', value: 10 },
'HALF': { type: 'percentage', value: 50 },
};For Path B (Database-Driven):
- Create database tables:
- Run
templates/promo_schema.sqlin Supabase SQL Editor
- Run
- Implement validation functions:
- Add server-side validation (see
references/implementation_guide.md)
- Add server-side validation (see
- Update API endpoints:
- POST
/api/validate-promo-code- Validate code - POST
/api/create-checkout- Apply discount - POST
/api/verify-payment- Track usage
- POST
- (Optional) Deploy admin panel:
- Use
templates/admin_panel.htmlfor visual management
- Use
- Test end-to-end
Step 5: Create Reference Documentation
Always create a quick reference guide for the user:
- Copy
templates/quick_reference_template.md - Fill in placeholders:
- Project name
- File path where codes are stored
- List of active codes
- Instructions for adding more codes
- Instructions for remembering codes
- Save as
MY_PROMO_CODES.mdin their project
This answers the common question: "How do I remember my codes?"
Step 6: Test Implementation
Run through testing checklist:
Basic Tests:
- Valid code applies discount correctly
- Invalid code returns error
- Free code sets price to $0
- Case insensitivity works (FRIEND = friend)
Integration Tests (if using Stripe):
- Checkout with discount code
- Free checkout (skip Stripe for $0)
- Payment verification
- Usage tracking (if database-driven)
Test cards for Stripe:
- Success:
4242 4242 4242 4242 - Decline:
4000 0000 0000 9995
Tech Stack Specific Instructions
Node.js + Express
Use templates/hardcoded_codes_template.js directly:
// Add to server.js
const { validateDiscountCode, calculateDiscountedPrice } = require('./promo-codes');
app.post('/api/validate-promo-code', (req, res) => {
const { code } = req.body;
const result = validateDiscountCode(code);
res.json(result);
});Next.js (App Router)
Create API routes in app/api/:
// app/api/validate-promo/route.ts
export async function POST(request: Request) {
const { code } = await request.json();
const result = validateDiscountCode(code);
return Response.json(result);
}Next.js (Pages Router)
Create API routes in pages/api/:
// pages/api/validate-promo.ts
export default function handler(req, res) {
const { code } = req.body;
const result = validateDiscountCode(code);
res.json(result);
}Python + Flask/FastAPI
For Python implementations, adapt the JavaScript logic to Python:
DISCOUNT_CODES = {
'FREE': {'type': 'free', 'value': 0},
'SAVE10': {'type': 'amount', 'value': 10},
}
def validate_discount_code(code):
code = code.upper().strip()
if code not in DISCOUNT_CODES:
return {'valid': False, 'error': 'Invalid code'}
return {'valid': True, **DISCOUNT_CODES[code]}Stripe Integration
Read references/stripe_integration.md for detailed Stripe patterns.
Key Points:
- Apply discount by adjusting line item price (recommended):
unit_amount: Math.round(finalAmount * 100) - Handle $0 checkouts separately (Stripe doesn't allow $0):
if (finalAmount === 0) { return { accessToken: generateToken() }; } - Store promo code in metadata:
metadata: { promo_code: discountCode, original_amount: originalAmount, final_amount: finalAmount }
Generating Promo Codes
Use the code generator script to create secure codes:
python3 scripts/generate_codes.py --count 10 --prefix FRIENDOptions:
--count N- Number of codes to generate--prefix PREFIX- Code prefix (e.g., SAVE, FRIEND)--length N- Random part length (default: 8)--format- alphanumeric, alpha, or numeric--separator- Separator character (default: -)
Output includes ready-to-paste formats:
- JavaScript object
- SQL INSERT statements
- Markdown list
- Plain text
Common Patterns
Free Access Codes
'FREE': { type: 'free', value: 0 }
'FRIEND': { type: 'free', value: 0 }
'BETA': { type: 'free', value: 0 }Fixed Amount Discounts
'SAVE10': { type: 'amount', value: 10 } // $10 off
'SAVE20': { type: 'amount', value: 20 } // $20 offPercentage Discounts
'HALF': { type: 'percentage', value: 50 } // 50% off
'QUARTER': { type: 'percentage', value: 25 } // 25% offDatabase Schema (Path B)
For database-driven systems, use templates/promo_schema.sql:
Main table: promo_codes
code- The promo code (unique)discount_type- 'free', 'amount', or 'percentage'discount_value- Discount amountis_active- Enable/disable codemax_uses- Usage limit (NULL = unlimited)current_uses- Usage counterexpires_at- Expiration date (NULL = never)
Tracking table: promo_code_usage
promo_code_id- Link to promo codeuser_email- Who used itused_at- When usedstripe_session_id- Payment session
Analytics Queries
Most Used Codes
SELECT code, current_uses
FROM promo_codes
ORDER BY current_uses DESC
LIMIT 10;Recent Usage
SELECT pc.code, pcu.user_email, pcu.used_at
FROM promo_code_usage pcu
JOIN promo_codes pc ON pcu.promo_code_id = pc.id
ORDER BY pcu.used_at DESC
LIMIT 50;Revenue Impact
SELECT
pc.code,
COUNT(*) as uses,
SUM(CASE WHEN pc.discount_type = 'amount'
THEN pc.discount_value ELSE 0 END) as total_discount
FROM promo_code_usage pcu
JOIN promo_codes pc ON pcu.promo_code_id = pc.id
GROUP BY pc.code;Security Best Practices
- Always validate server-side - Never trust client input
- Rate limit validation - Prevent brute force guessing
- Use secure code format - Hard-to-guess codes (e.g.,
PROMO-2024-XJ9K) - Normalize codes - Convert to uppercase, trim whitespace
- Track usage patterns - Monitor for abuse
Troubleshooting
Code not working
- Check code is active (
is_active = true) - Check not expired (
expires_at > NOW()) - Check usage limit not reached (
current_uses < max_uses) - Verify case-insensitive comparison
$0 checkout fails
- Stripe doesn't allow $0 checkouts
- Skip Stripe for free codes
- Generate access token directly
Usage not tracked
- Verify
recordPromoCodeUsage()is called after payment - Check database connection
- Verify promo_code_id is passed correctly
Discount not applied in Stripe
- Stripe shows final amount only
- Store original amount in metadata for tracking
- Verify calculation logic is correct
Reference Files
references/implementation_guide.md- Detailed implementation workflowsreferences/stripe_integration.md- Stripe-specific patternstemplates/promo_schema.sql- Database schematemplates/hardcoded_codes_template.js- Quick implementation templatetemplates/quick_reference_template.md- User reference doc template
Deliverables
Always provide user with:
- Implementation code - Ready to paste into their project
- Quick reference guide -
MY_PROMO_CODES.mdwith their codes - Testing instructions - How to verify it works
- Deployment steps - How to deploy changes
Example Complete Workflow
User says: "I need to add promo codes to my poker quiz app"
- Discover: Run discovery script, find existing hardcoded system
- Analyze: They have
DISCOUNT_CODESobject with 2 codes - Choose: Recommend extending existing system (Path A)
- Implement: Add 10 new codes to their
DISCOUNT_CODESobject - Document: Create
MY_PROMO_CODES.mdwith all codes - Test: Verify codes work on live site
- Deliver: Send updated code + reference doc
User asks: "How do I remember my codes?"
Answer: "Your codes are in MY_PROMO_CODES.md (attached). They're also in your server.js file at line 159."
Success Criteria
✅ User can add promo codes in < 5 minutes (Path A)
✅ User has reference doc to remember codes
✅ Codes work on live site
✅ User understands how to add more codes
✅ (Optional) User has path to upgrade to database system
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

