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.
Configure Credits Management System
- Create Data Table
Please ensure you have configured the database. Copy the following SQL statement to create the credits table.
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
);
- Grant Credits to New Users
You can modify the following logic as needed to grant credits to new users:
- Credit Top-up
Modify the pricing table configuration by adding fields to implement credit purchases with expiration dates.
- 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.