## Pricing & Credits Configuration

Credit-Based System: LogoAIpro uses a credit-based pricing model with three credit packages. Each logo generation costs credits, which are deducted from user accounts when they create logos.

##
Credit Packages Overview

LogoAIpro offers three credit packages with different quantities of credits. Each package provides credits for logo generation operations.

### Package Structure

Package | Credits | Price | Price/Credit | Value
--- | --- | --- | --- | ---
Basic Pack | 50 | $9.99 | $0.20 | Entry Level
Pro Pack ⭐ | 150 | $24.99 | $0.17 | Best Value
Enterprise Pack | 500 | $79.99 | $0.16 | Professional

Best Value: The Pro Pack offers the best value with the lowest cost per credit ($0.17), making it perfect for regular users.
Free Tier: All new users receive 10 free credits to test the platform. No credit card required!

##
Credit Costs per Operation

Each logo generation typically costs 1 credit per logo. This applies to all logo generation operations regardless of style, size, or quality settings.

### Credit Costs

Operation | Credits per Operation | Description
--- | --- | ---
Logo Generation | 1 credit | Generate a single logo with any style, size, or quality
Logo Regeneration | 1 credit | Regenerate a logo with different parameters

##
Configuration Files

### 1. Frontend Pricing Display

Credit packages are configured in your pricing configuration file for display on the frontend:

    export const creditPackages = [
      {
        name: "Basic Pack",
        credits: 50,
        price: "$9.99",
        pricePerCredit: "$0.20 per credit",
        description: "Perfect for testing and small projects.",
        ctaLabel: "Buy Basic Pack",
        ctaHref: "/api/checkout/credits?plan=basic",
      },
      {
        name: "Pro Pack",
        credits: 150,
        price: "$24.99",
        pricePerCredit: "$0.17 per credit",
        description: "Best value for regular users and creators.",
        highlight: true, // This makes it the "Best Value" package
        ctaLabel: "Buy Pro Pack",
        ctaHref: "/api/checkout/credits?plan=pro",
      },
      {
        name: "Enterprise Pack",
        credits: 500,
        price: "$79.99",
        pricePerCredit: "$0.16 per credit",
        description: "For businesses and heavy users.",
        ctaLabel: "Buy Enterprise Pack",
        ctaHref: "/api/checkout/credits?plan=enterprise",
      },
    ];

### 2. Backend Credit Configuration

Credit pricing and checkout is handled in `app/api/checkout/credits/route.ts`:

    // Credit pricing plans (prices in cents for Stripe)
    const CREDIT_PLANS = {
      basic: { price: 999, credits: 50 }, // $9.99
      pro: { price: 2499, credits: 150 }, // $24.99
      enterprise: { price: 7999, credits: 500 }, // $79.99
    } as const;

Important: Prices in the backend are in cents (e.g., 999 = $9.99) for Stripe integration. Always convert dollar amounts to cents when updating prices.

##
Customizing Credit Packages

### Step 1: Modify Credit Amounts

To change credit amounts, update both files:

1. Frontend: Update your pricing configuration file with new credit amounts
2. Backend: Update `app/api/checkout/credits/route.ts` with matching credit amounts and prices (in cents)
3. Stripe: No changes needed in Stripe Dashboard since we use dynamic pricing

### Step 2: Modify Package Prices

1. Update prices in your frontend configuration (display price as string, e.g., "$9.99")
2. Update prices in `app/api/checkout/credits/route.ts` (in cents, e.g., 999 for $9.99)
3. Recalculate `pricePerCredit` in frontend configuration

### Step 3: Add a New Package

1. Add new package to your pricing configuration array
2. Add corresponding entry to `CREDIT_PLANS` object in `app/api/checkout/credits/route.ts`
3. Update the `ctaHref` to match the new plan key (e.g., `plan=premium`)
4. Test the checkout flow to ensure it works correctly

##
Stripe Integration

### Checkout Process Flow

The checkout API route creates Stripe checkout sessions with dynamic pricing. Here's how it works:

1. User clicks "Buy Credits" button on pricing page
2. Frontend redirects to `/api/checkout/credits?plan=basic`
3. Backend validates the plan and creates a Stripe checkout session
4. User completes payment on Stripe checkout page
5. Stripe webhook triggers and adds credits to user account
6. User is redirected back to credits page with success message

### Stripe Checkout Session Configuration

    const session = await stripe.checkout.sessions.create({
      allow_promotion_codes: true, // Allows coupon codes
      metadata: {
        userId, // User ID from Clerk
        credits: plan.credits.toString(),
        type: "user_credits", // Identifies this as a credit purchase
      },
      line_items: [
        {
          price_data: {
            currency: "usd",
            unit_amount: plan.price, // Price in cents
            product_data: {
              name: `${plan.credits.toLocaleString()} Credit Pack`,
              description: `${plan.credits.toLocaleString()} credits for logo generation`,
            },
          },
          quantity: 1,
        },
      ],
      mode: "payment", // One-time payment
      success_url: `${process.env.NEXT_PUBLIC_APP_URL}/dashboard/credits?session_id={CHECKOUT_SESSION_ID}&success=true`,
      cancel_url: `${process.env.NEXT_PUBLIC_APP_URL}/dashboard/credits?canceled=true`,
    });

Dynamic Pricing: LogoAIpro uses dynamic Stripe pricing (`price_data`) instead of predefined Stripe Price IDs. This allows easy price changes without updating Stripe Dashboard.

### Modify Credit Costs per Operation

To change credit costs for logo generation, update the credit check in your API route:

    // In API route (e.g., app/api/generate/route.ts)
    import { checkAndDeductCredits } from "@/lib/utils/credits";

    // Check and deduct credits (change 1 to your desired credit cost)
    const creditCheck = await checkAndDeductCredits(1);
    if (!creditCheck.success) {
      return NextResponse.json(
        { error: creditCheck.error || "Insufficient credits" },
        { status: 400 }
      );
    }

##
Credit Validation System

### Credit Check Function

Credits are checked and deducted using your credit utility function:

    export async function checkAndDeductCredits(
      amount: number,
      userId?: string
    ): Promise<{ success: boolean; error?: string }> {
      // Implementation:
      // 1. Checks user credit balance from database
      // 2. Deducts credits if sufficient balance exists
      // 3. Updates user credit balance in database
      // 4. Returns success or error message
    }

### Credit Balance Check

- Before Operation: System checks if user has enough credits
- During Operation: Credits are deducted immediately when operation starts
- After Operation: If operation fails, credits are not refunded (prevent abuse)

##
Webhook Integration

### Stripe Webhook Handler

Credits are automatically added to user accounts via Stripe webhook when payment is completed:

    // app/api/stripe-webhook/route.ts
    if (event.type === 'checkout.session.completed') {
      const session = event.data.object;
      const userId = session.metadata.userId;
      const credits = parseInt(session.metadata.credits);

      // Validate this is a credit purchase
      if (session.metadata.type === 'user_credits') {
        // Add credits to user account in database
        await addCreditsToUser(userId, credits);
      }
    }

Webhook Security: Always verify webhook signatures using `STRIPE_WEBHOOK_SECRET` to ensure requests are from Stripe.

##
Pricing Strategy Recommendations

### Current Pricing Tiers

- Basic Pack ($9.99): Perfect for testing the platform or occasional use
- Pro Pack ($24.99): Ideal for regular users and content creators
- Enterprise Pack ($79.99): Best for heavy users and businesses

### Pricing Tips

- Lower cost per credit with larger packs incentivizes bulk purchases
- The Pro pack being highlighted as "Best Value" drives conversions
- Clear pricing per credit helps users understand value
- Free tier (10 credits) allows users to test before purchasing

##
Testing Credit System

### Test Checklist

1. Test credit purchase flow with Stripe test mode
2. Verify credits are added correctly after payment
3. Test credit deduction when generating logos
4. Verify insufficient credits error message
5. Test webhook handling for successful payments
6. Verify credit balance displays correctly in dashboard

Next Steps:

- Configure Stripe Payment Setup
- Complete Environment Variables Setup
- Learn how users purchase credits
- Customize Pricing Display