skills/development-skills/promo-code-system/SKILL.md
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.
npx skillsauth add abcnuts/manus-skills promo-code-systemInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
4 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Add promotional and discount code functionality to web applications with tracking, analytics, and flexible discount types.
This skill helps implement promo code systems in web apps. Supports:
Follow these steps in order:
Run the discovery script to find existing promo code implementation:
python3 scripts/discover_promo_system.py /path/to/project
If you don't have the project path, locate it by:
gh repo list)The script identifies:
Based on discovery results, determine implementation type:
No System Found
Hardcoded System Found
DISCOUNT_CODES object or similarDatabase System Found
promo_codes tablePath A: Quick (Hardcoded) - 5 minutes
templates/hardcoded_codes_template.jsPath B: Proper (Database) - 45 minutes
templates/promo_schema.sql + API templatestemplates/hardcoded_codes_template.js contentserver.js, index.js)DISCOUNT_CODES object with their codescalculateDiscountedPrice()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 },
};
Create database tables:
templates/promo_schema.sql in Supabase SQL EditorImplement validation functions:
references/implementation_guide.md)Update API endpoints:
/api/validate-promo-code - Validate code/api/create-checkout - Apply discount/api/verify-payment - Track usage(Optional) Deploy admin panel:
templates/admin_panel.html for visual managementTest end-to-end
Always create a quick reference guide for the user:
templates/quick_reference_template.mdMY_PROMO_CODES.md in their projectThis answers the common question: "How do I remember my codes?"
Run through testing checklist:
Basic Tests:
Integration Tests (if using Stripe):
Test cards for Stripe:
4242 4242 4242 42424000 0000 0000 9995Use 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);
});
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);
}
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);
}
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]}
Read references/stripe_integration.md for detailed Stripe patterns.
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
}
Use the code generator script to create secure codes:
python3 scripts/generate_codes.py --count 10 --prefix FRIEND
Options:
--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:
'FREE': { type: 'free', value: 0 }
'FRIEND': { type: 'free', value: 0 }
'BETA': { type: 'free', value: 0 }
'SAVE10': { type: 'amount', value: 10 } // $10 off
'SAVE20': { type: 'amount', value: 20 } // $20 off
'HALF': { type: 'percentage', value: 50 } // 50% off
'QUARTER': { type: 'percentage', value: 25 } // 25% off
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 sessionSELECT code, current_uses
FROM promo_codes
ORDER BY current_uses DESC
LIMIT 10;
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;
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;
PROMO-2024-XJ9K)is_active = true)expires_at > NOW())current_uses < max_uses)recordPromoCodeUsage() is called after paymentreferences/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 templateAlways provide user with:
MY_PROMO_CODES.md with their codesUser says: "I need to add promo codes to my poker quiz app"
DISCOUNT_CODES object with 2 codesDISCOUNT_CODES objectMY_PROMO_CODES.md with all codesUser 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."
✅ 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
tools
Generate comprehensive demonstrations showing how to access projects and work across different environments (Manus terminals, personal computers, team collaboration). Use when users ask "how do I access this from another terminal/computer", "how do I share this with my team", "how do I get this on my Mac", or need clarification on Manus persistence vs GitHub usage.
development
Use when you have a spec or requirements for a multi-step task, before touching code
data-ai
Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always
development
Use when implementing any feature or bugfix, before writing implementation code