Skip to content

API

After Balancy is initialized, a wide range of functions and methods are available to interact with the Balancy SDK.

Balancy Status

The GetStatus method returns the current status of the Balancy SDK.

var status = Balancy.API.GetStatus();
const status = Balancy.API.getStatus();

Don't cache the status object because it can change after each call.

Parameter Description
BranchName The name of the branch the SDK is connected to.
Deploy The unique number of the Deploy. You can the version of configs, that's being used
LastCloudConfigsUpdate The unix time (seconds) of the last successful synchronization of the game configs during this session.
ServerTime The server time in seconds since 1970.
GameTime The game time in seconds since 1970. The Game time is used for all the conditions and can be changed in the Balancy Dashboard.
ServerTimeMs The server time in milliseconds.
GameTimeMs The game time in milliseconds.

Purchasing

Balancy provides robust purchasing methods that integrate seamlessly with the inventory system. After a successful purchase:

  • Items are automatically added to the inventory.
  • If the price is in soft currency, the amount is deducted from the inventory.
  • If there are insufficient items in the inventory, the purchase still proceeds because using Balancy’s inventory is optional. However, the inventory amount can go negative in such cases.

Soft Purchasing

Soft purchasing methods return a bool value indicating whether the purchase was successful.

Balancy.API.SoftPurchaseStoreItem(storeItem);
Balancy.API.SoftPurchaseGameOffer(offerInfo);
Balancy.API.SoftPurchaseGameOfferGroup(offerGroupInfo, storeItem);
Balancy.API.softPurchaseStoreItem(storeItem);
Balancy.API.softPurchaseGameOffer(offerInfo);
Balancy.API.softPurchaseGameOfferGroup(offerGroupInfo, storeItem);

Hard Purchasing

Hard purchasing methods require a PaymentInfo object containing payment details. This object is used for validation and segmentation purposes. The purchase result is returned via a callback.

var paymentInfo = new Balancy.Core.PaymentInfo
{
    Receipt = unityProduct.receipt,
    Price = (float)unityProduct.metadata.localizedPrice,
    Currency = unityProduct.metadata.isoCurrencyCode,
    ProductId = unityProduct.definition.id,
    OrderId = unityProduct.transactionID
};

void PurchaseCompleted(Balancy.Core.Responses.PurchaseProductResponseData responseData) {
    Debug.Log("Success = " + responseData.Success);
    Debug.Log("ErrorCode = " + responseData.ErrorCode);
    Debug.Log("ErrorMessage = " + responseData.ErrorMessage);
    Debug.Log("ProductId = " + responseData.ProductId);
}

Balancy.API.HardPurchaseStoreItem(storeItem, paymentInfo, PurchaseCompleted, requireValidation);
Balancy.API.HardPurchaseGameOffer(offerInfo, paymentInfo, PurchaseCompleted, requireValidation);
Balancy.API.HardPurchaseGameOfferGroup(offerGroupInfo, storeItem, paymentInfo, PurchaseCompleted, requireValidation);
import {Balancy, BalancyPaymentInfo} from '@balancy/core';    
import {BalancyPurchaseProductResponseData} from "@balancy/wasm";

function purchaseCompleted(response: BalancyPurchaseProductResponseData): void {
    console.log("Response received:");
    console.log("Success:", response.success);
    console.log("Error Code:", response.errorCode);
    console.log("Error Message:", response.errorMessage);
    console.log("ProductId: ", response.productId);
}

let paymentInfo = new BalancyPaymentInfo(...);

Balancy.API.hardPurchaseStoreItem(storeItem, paymentInfo, purchaseCompleted, requireValidation);
Balancy.API.hardPurchaseGameOffer(offerInfo, paymentInfo, purchaseCompleted, requireValidation);
Balancy.API.hardPurchaseGameOfferGroup(offerGroupInfo, storeItem, paymentInfo, purchaseCompleted, requireValidation);