Skip to content

Credits

This plugin allows to sell "credits" - count of credits will be configured in product billing plan settings, and added to user account after purchase. This module does not have any consumer-visible part, it just provides API that developers may use to implement its own "credits" billing system base on aMember.

  • Sell limited count of downloads from big files catalog
  • Sell time-based access to website or software
  • Sell service tickets
  1. Code to deduct "credits" must be implemented by your system!
  2. Credits are not expiring with subscription (!). aMember does not take account of subscription dates at all when accounting credits
  3. Once accounted, credit records are not updated if product setting changed
require_once '/var/www/html/amember/bootstrap.php';
// following code checks that it is running from an authenticated user
// context - if user session is checked and user is logged-in to aMember
// if user is not logged-in, user will be redirected to login page first
Am_Di::getInstance()->auth->requireLogin();
// now when user is checked, play with credits
$creditsModule = Am_Di::getInstance()->plugins_misc->loadGet('credits');
// without comment
$creditsModule->debit(120);
// with comment
$creditsModule->debit(120, "Used 120 credits");
// debit 120 credits from user# 1234
$creditsModule->debit(120, "Used 120 credits", 1234);
// balance - get current number of credits
echo $creditsModule->balance();