Promo code system

From abcnuts/manus-skills · View interactive version

Promo code system is an AI agent skill from the GitHub repository abcnuts/manus-skills. 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 p

How to use this skill

Skill file

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:

When to Use This Skill

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/project

If you don't have the project path, locate it by:

  1. Checking Supabase projects (MCP)
  2. Checking Vercel deployments (MCP)
  3. Checking GitHub repositories (gh repo list)
  4. Asking user for local path

The script identifies:

Step 2: Analyze Current State

Based on discovery results, determine implementation type:

No System Found

Hardcoded System Found

Database System Found

Step 3: Choose Implementation Path

Path A: Quick (Hardcoded) - 5 minutes

Path B: Proper (Database) - 45 minutes

Step 4: Implement Solution

For Path A (Quick/Hardcoded):
  1. Copy templates/hardcoded_codes_template.js content
  2. Add to user's server file (e.g., server.js, index.js)
  3. Customize DISCOUNT_CODES object with their codes
  4. Update checkout endpoint to use calculateDiscountedPrice()
  5. 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):
  1. Create database tables:
  1. Implement validation functions:
  1. Update API endpoints:
  1. (Optional) Deploy admin panel:
  1. Test end-to-end

Step 5: Create Reference Documentation

Always create a quick reference guide for the user:

  1. Copy templates/quick_reference_template.md
  2. Fill in placeholders:
  1. Save as MY_PROMO_CODES.md in their project

This answers the common question: "How do I remember my codes?"

Step 6: Test Implementation

Run through testing checklist:

Basic Tests:

Integration Tests (if using Stripe):

Test cards for Stripe:

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:

  1. Apply discount by adjusting line item price (recommended):

```javascript

unit_amount: Math.round(finalAmount * 100)

```

  1. Handle $0 checkouts separately (Stripe doesn't allow $0):

```javascript

if (finalAmount === 0) {

return { accessToken: generateToken() };

}

```

  1. Store promo code in metadata:

```javascript

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 FRIEND

Options:

Output includes ready-to-paste formats:

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 off

Percentage Discounts

'HALF': { type: 'percentage', value: 50 }     // 50% off
'QUARTER': { type: 'percentage', value: 25 }  // 25% off

Database Schema (Path B)

For database-driven systems, use templates/promo_schema.sql:

Main table: promo_codes

Tracking table: promo_code_usage

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

  1. Always validate server-side - Never trust client input
  2. Rate limit validation - Prevent brute force guessing
  3. Use secure code format - Hard-to-guess codes (e.g., PROMO-2024-XJ9K)
  4. Normalize codes - Convert to uppercase, trim whitespace
  5. Track usage patterns - Monitor for abuse

Troubleshooting

Code not working

$0 checkout fails

Usage not tracked

Discount not applied in Stripe

Reference Files

Deliverables

Always provide user with:

  1. Implementation code - Ready to paste into their project
  2. Quick reference guide - MY_PROMO_CODES.md with their codes
  3. Testing instructions - How to verify it works
  4. Deployment steps - How to deploy changes

Example Complete Workflow

User says: "I need to add promo codes to my poker quiz app"

  1. Discover: Run discovery script, find existing hardcoded system
  2. Analyze: They have DISCOUNT_CODES object with 2 codes
  3. Choose: Recommend extending existing system (Path A)
  4. Implement: Add 10 new codes to their DISCOUNT_CODES object
  5. Document: Create MY_PROMO_CODES.md with all codes
  6. Test: Verify codes work on live site
  7. 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

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.