ShipNow LogoShipNow

Credits

Learn how to manage and use credits in your ShipNow application.

Overview

ShipNow's complete credit system enables you to:

  • 💳 Manage user credits
  • 🎁 Provide initial credits for new users
  • 📅 Handle monthly, yearly and one-time purchase credits
  • 🔄 Automatic renewal and expiration of credits

View Credits

Users can check their credit balance in the user dropdown menu:

Credits

Credits Sources

  1. Initial Credits: New users receive initial credits that are valid for one year from registration.
  2. Subscription Credits: Credits from monthly/yearly subscription that renew and expire monthly.
  3. One-time Purchase Credits: Credits from one-time purchases that expire after one month.
  4. Manual Credits: You can manually add credits and specify the expiration time.

Configure Initial Credits

Set the initial credit amount to .env.local, credits are added automatically when a new user registers.

.env.local
CREDIT_INITIAL_AMOUNT="10"

Configure Subscription/One-time Purchase Credits

Define Credit Amounts

Configure credits in your pricing plans:

messages/en.json
{
  "pricing": {
    "plans": [
      {
        "id": "basic",
        "monthlyPricing": {
          "credits": 100
        },
        "yearlyPricing": {
          "credits": 100
        },
        "features": [
            "100 credits monthly",
        ]
      },
      {
        "id": "one-time-purchase",
        "oneTimePricing": {
          "credits": 100
        },
        "features": [
          "100 credits one-time purchase",
        ]
      }
    ]
  }
}

Subscription/One-time Purchase Credits

  • Monthly Plans: Credits are renewed on next billing
  • Yearly Plans: User pays for a year in advance, but credits are reset monthly
  • One-time Purchase: Credits are added to the user's account immediately

🔥 Yearly Subscription Credit Reset Monthly

ShipNow features a monthly credit reset system for yearly subscriptions:

  1. User purchases yearly subscription plan
  2. User gets first month's credits immediately
  3. User can use credits
  4. Unused credits expire and new credits are added after 1 month
  5. Process repeats monthly until subscription ends

All credits are managed automatically by the system, you don't need to handle the credit expiration and renewal logic.

Credits API

Get Available Credits

import { getUserAvailableCredits } from "@/lib/credits";
 
const credits = await getUserAvailableCredits("user_id");

Add Credits

import { addCredits } from "@/lib/credits";
import { addMonths } from "date-fns";
 
await addCredits({
  userId: "user_id",
  amount: 100,
  description: "Monthly subscription credits",
  expiresAt: addMonths(new Date(), 1)
});

Deduct Credits

import { deductCredits } from "@/lib/credits";
 
// Check before deducting credits
const credits = await getUserAvailableCredits("user_id");
if (credits >= 10) {
  await deductCredits({ 
    userId: "user_id",
    amount: 10,
    description: "Generate image"
  });
}

Need Help?

  • Join our Discord community
  • Open an issue on GitHub

On this page

ShipNow LogoGet ShipNow