API¶
After Balancy is initialized, a wide range of functions and methods are available to interact with the Balancy SDK.
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);