Credits Management

ShipAny has a built-in credits management system that helps developers implement features like user top-up to obtain credits and deduct credits for using services.

It also provides users with a credits management page where they can view their credit balance and consumption records.

credits

Configure Credits Management System

  1. Create Data Table

Please ensure you have configured the database. Copy the following SQL statement to create the credits table.

data/install.sql
CREATE TABLE credits (
    id SERIAL PRIMARY KEY,
    trans_no VARCHAR(255) UNIQUE NOT NULL,
    created_at timestamptz,
    user_uuid VARCHAR(255) NOT NULL,
    trans_type VARCHAR(50) NOT NULL,
    credits INT NOT NULL,
    order_no VARCHAR(255),
    expired_at timestamptz
);
  1. Grant Credits to New Users

You can modify the following logic as needed to grant credits to new users:

newuser-credits

  1. Credit Top-up

Modify the pricing table configuration by adding fields to implement credit purchases with expiration dates.

credits-pricing

  1. Deduct Credits for Consumption

You can implement your own credit deduction logic as needed. For example, deduct 2 credits when a user generates an image, or 3 credits when generating a video.

Before deducting credits, check the user’s credit balance. If the balance is insufficient, prompt the user to top up.

credits-cost