Credits Deduction

Product:

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

  1. You must have a credits management system (where users are allocated credits)
  2. 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.

Role Base Access Panel

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”.

Assign Credit to CometChat Feature

5) Modify the number of credits you would like to charge and hit Save!

Please contact us if you would like to use credits deduction in CometChat Cloud.
  • Was this helpful?
  • Yes   No