Credits
The kit provides you a way to allocate credits to a user according to the User Plan they have subscribed to. You can then use functions to check, consume, and reset the credits.
Life cycle
Following is the life cycle of the credits that are allocated to a user.
- User subscribes to a plan
- Credits are allocated to the user as per the plan
- Consume credits as per business logic
- If the planโs resetType is periodic, the credits are reset periodically.
Set Credits
You can set the credits for a plan in the User Plans. Decide the number of credits based on the business logic.
Check Credits
The User model has a plan
field that contains the credits
field. This field tells the number of credits that the user has.
Consume Credits
You can consume the credits using the consumeCredits
function. This function takes the amount of credits to be consumed and deducts it from the userโs credits.
Reset Credits
If the planโs resetType is periodic, the credits are reset periodically. You can reset the credits using the resetCredits
function on demand if required.