What is Credits Deduction
If you have a credits management system i.e. a system where your users can earn/spend credits, then CometChat can be integrated with it. You can configure CometChat to deduct credits whenever a CometChat feature is used.
Pre-requisites
- You must have a credits management system (where users are allocated credits)
- You must have Role Based Access control configured
How to activate Credits Deduction in CometChat
From CometChat Admin Panel
, click on the Editor
section and modify the Integration
file:
$enabled_credit = 0;
This value needs to be set to 1
to begin.
$enabled_credit = 1;
Once done, two functions need to be modified: getCredits
and deductCredits
.
Changes required in getCredits
and deductCredits
functions
getCredits function
This function should return the number of credits present for a user
function getCredits(){
global $userid;
$sql = ("SELECT `credits` FROM `users` WHERE `id` = '".sql_real_escape_string($userid)."'");
}
You can update the above query depending on where you store the credits information for a given user.
deductCredits function
This function will be called when credits need to be deducted for a given user
function deductCredits($params){
global $userid;
// For `$creditsToDeduct` refer deductCredits() function
$sql = ("UPDATE `users` SET `credits` = `credits` - ".sql_real_escape_string($creditsToDeduct)." WHERE `id`='".sql_real_escape_string($userid)."'");
}
You can modify the above query as per your requirements if the credits information is stored in a different table/field.
Accessing Credits Deduction via CometChat Admin Panel
1) Login to Admin panel using Access Credentials.
2) Click on Settings
-> Role Base Access
from left side navigation.
3) Now you can see all your User Roles. Select a role and have a look at the “Charge Credits when using certain features for this role”.
5) Modify the number of credits you would like to charge and hit Save!