Skip to content

Credit System

o5faruk edited this page May 2, 2021 · 12 revisions

⚠️⚠️⚠️

This sdk documentation is deprecated and will not be updated. Check out our new docs at https://sdk.buildfire.com/docs/credit-system/

⚠️⚠️⚠️

Overview

API accessible via the Buildfire plugin SDK that allows plugin developers to add and manage user credits. Credits can be managed and consumed via the API’s for in-app purchases.

The credit-system is scoped to each individual instance of a Buildfire app in which the user is currently logged into.

Important Notes:

  • The user must be logged in and authenticated for credit-system API calls to succeed.

  • Bundles are configured through the Control Panel side of a Buildfire app and are not accessible through the SDK API.

  • The following link is an example of how to create a plugin with the Buildfire credit-system API.

    Examples included in demo plugin:

    • Integration with the credit-system on the control panel side to add bundles.
    • A complete example of UI integrated with the credit-system API.

Prerequisites

On the widget page or control page you need to include scripts/buildfire/services/creditSystem/credits.js:

<script src="../../../scripts/buildfire/services/credits/credits.js"></script>

Methods

buildfire.services.credits.getBundles(callback);

This method will return all bundles available.

arguments

  • callback(err, data): required
    • function will be invoked after all bundles have been retrieved.

Example:


var callback = function(err, result){
console.log("callback" + JSON.stringify(result));
}

buildfire.services.credits.getBundles(null, callback);

buildfire.services.credits.purchaseBundle(options, callback);

This method will facilitate the purchase of a bundle. When you call it your chosen payment provider will be called and credits will be deducted from the users balance within the credit system.

arguments

  • options : object
    • bundleId: string, required
      • This property is the id of the bundle the user is purchasing.
    • memo
    • xRef1
    • xRef2
    • xRef3
  • callback(err, data): required
    • function will be invoked after purchasing for bundle has been completed.

Example:

var options = {
  'bundleId': ''
};

var callback = function(err, result){
console.log("callback" + JSON.stringify(result));
}

buildfire.services.credits.purchaseBundle(options, callback);

buildfire.services.credits.consumeCredits({},function (err, data) { });

Calling this method will subtract credits from the balance of a user.

arguments

  • options : object
    • creditAmount: decimal, required
      • This property is the amount of credit you would like to add to a users account.
    • memo
    • xRef1
    • xRef2
    • xRef3
  • callback(err, data): required
    • function will be invoked after subtraction has been completed.

Example:

var options = {
  ‘amount’: 3.12
};

var callback = function(err, result){
console.log("callback" + JSON.stringify(result));
}

buildfire.services.credits.consumeCredits(options, callback);

buildfire.services.credits.getUser(function (err, data) { });

This method will retrieve the details of a users account.

arguments

  • callback(err, data): required
    • function will be invoked after user info is available.

Example:

var callback = function(err, result){
console.log("callback" + JSON.stringify(result));
}

buildfire.services.credits.getUser(callback);

buildfire.services.credits.getUserTransactions({},function (err, data) { });

This method returns the history of transactions for the currently logged in user.

arguments

  • options: object
    • pageSize: int, required
      • Indicates the amount of results to return per call.
    • pageIndex: int, required
      • Indicates the partition of the pagination to return.
  • callback(err, data): required
    • function will be returned all transactions for current user.

Example:

var callback = function(err, result){
console.log("callback" + JSON.stringify(result));
}

var options = {
  'pageSize': 2,
  'pageIndex': 3
}

buildfire.services.credits.getUserTransactions(options, callback);

buildfire.services.credits.transferCredits(options, function (err, data) { });

This method transfer credits from current loggedIn user to another user.

arguments

  • options: object
    • receiverUserToken: string, required if (receiverUserEmail) not specified
      • The user Id for the receiver user.
    • receiverUserEmail: string, required if (receiverUserToken) not specified
      • The user Email for the receiver user.
    • creditAmount: int, required
      • The amount that the current loggedIn user wants to transfer.
  • callback(err, data): required
    • function will be invoked after transfer credits has been updated.

Example:

var callback = function(err, result){
console.log("callback" + JSON.stringify(result));
}

var options = {
  'receiverUserToken': 'userToken',
  'creditAmount': 32
}

buildfire.services.credits.transferCredits(options, callback);

buildfire.services.credits.showTransactions(options, function (err, data) { });

This method works only on Control Panel, this method will show the transactions popup for all users

Example:


buildfire.services.credits.showTransactions();

Clone this wiki locally