Essential Kit
Loading...
Searching...
No Matches
BillingServices

Provides cross-platform interface to request payment from a user for additional functionality or content that your application delivers.
More...

Static Public Member Functions

static void InitializeStore ()
 Sends a request to retrieve localized information about the billing products from the Store.

 
static void InitializeStore (BillingProductDefinition[] productDefinitions)
 Sends a request to retrieve localized information about the billing products from the Store.

 
static IBillingProduct GetProductWithId (string id, bool includeInactive=false)
 Gets the billing product with localized information, which was previously fetched from the Store.
 
static bool CanMakePayments ()
 Determines whether the user is authorised to make payments.
 
static bool IsProductPurchased (string productId)
 Determines whether specified billing product is already purchased.
 
static bool IsProductPurchased (IBillingProduct product)
 Determines whether specified billing product is already purchased.
 
static void BuyProduct (string productId, BuyProductOptions options=null)
 Initiates purchase process for the specified billing product.
 
static void BuyProduct (IBillingProduct product, BuyProductOptions options=null)
 Initiates purchase process for the specified billing product.
 
static IBillingTransaction[] GetTransactions ()
 Returns the pending transactions available in transaction queue.
 
static void FinishTransactions (IBillingTransaction[] transactions)
 Completes the pending transactions and removes it from transaction queue.
 
static void RestorePurchases (bool forceRefresh=false, string tag=null)
 
Advanced Usage
static void Initialize (BillingServicesUnitySettings settings)
 Initializes the billing services module with the given settings. This call is optional and only need to be called if you have custom settings to initialize this feature.
 
Obsolete methods
static bool BuyProduct (string productId, int quantity=1, string applicationUsername=null)
 Initiates purchase process for the specified billing product.
 
static bool BuyProduct (IBillingProduct product, int quantity=1, string applicationUsername=null)
 Initiates purchase process for the specified billing product.
 
static void RestorePurchases (string tag=null)
 Initiates purchase process for the specified billing product.
 

Properties

static IBillingProduct[] Products [get]
 Returns the cached products array retrieved from store.
 

Events

static EventCallback< BillingServicesInitializeStoreResultOnInitializeStoreComplete
 Event that will be called when registered billing products are retreived from the Store.
 
static Callback< BillingServicesTransactionStateChangeResultOnTransactionStateChange
 Event that will be called when payment state changes.
 
static EventCallback< BillingServicesRestorePurchasesResultOnRestorePurchasesComplete
 Event that will be called when restored transaction details are received from the Store.
 

Detailed Description

This feature connects to the Store on your app’s behalf to securely process payments from users, prompting them to authorize payment. The feature then notifies your app, which provides the purchased items to users. For processing requests, feature contacts App Store, Google Play Store on iOS, Android platform respectively. You need to configure iOS billing product details at iTunes Connect. Similarly for Android, you can set these details at Google Play Developer Console.

The interaction between the user, your app, and the Store during the purchase process take place in three stages. First, the your app displays purchasable products received from the Store. Second, the user selects a product to buy and the app requests payment from the Store. Third, the Store processes the payment and your app delivers the purchased product.

Optionally, you can choose to verify receipts of completed transactions. The receipt is a record of purchase made from within the application and enabling receipt validation, adds one more level security to avoid unauthorised purchases.

Users can also restore products that were previously purchased. As per iOS guidelines, if your application supports product types that are restorable, you must include an interface that allows users to restore these purchases.

Member Function Documentation

◆ Initialize()

static void Initialize ( BillingServicesUnitySettings settings)
static
Parameters
settingsThe settings to be used for initialization.

The settings configure the default image to be used for products.

References BillingServices.OnInitializeStoreComplete, BillingServices.OnRestorePurchasesComplete, BillingServices.OnTransactionStateChange, and BillingServices.Products.

◆ InitializeStore() [1/2]

static void InitializeStore ( )
static

Call to this method retrieves information of the products that are configured in Billing Settings. Your application uses this request to present localized prices and other information to the user without having to maintain that list itself.

Note
When the request completes, OnInitializeStoreComplete is fired.

References BillingServices.InitializeStore(), and BillingServicesUnitySettings.Products.

Referenced by BillingServices.InitializeStore().

◆ InitializeStore() [2/2]

static void InitializeStore ( BillingProductDefinition[] productDefinitions)
static

Call to this method retrieves information of the products that are configured in Billing Settings. Your application uses this request to present localized prices and other information to the user without having to maintain that list itself.

Note
When the request completes, OnInitializeStoreComplete is fired.

References BillingServices.OnInitializeStoreComplete.

◆ GetProductWithId()

static IBillingProduct GetProductWithId ( string id,
bool includeInactive = false )
static
Returns
The billing product fetched with localized information.
Parameters
idA string used to identify a billing product.
includeInactiveWhether inactive products should be considered in search. Default is false.

References BillingServices.Products.

Referenced by BillingServices.BuyProduct(), and BillingServices.IsProductPurchased().

◆ CanMakePayments()

static bool CanMakePayments ( )
static
Returns
true if the user is allowed to make product purchase payment; otherwise, false.

◆ IsProductPurchased() [1/2]

static bool IsProductPurchased ( string productId)
static
Returns
true if specified billing product is already purchased; otherwise, false.
Parameters
productIdThe identifier of the billing product.
Note
This works only for Non-Consumable (Managed) billing product. For Consumable products, this will always returns false.

References BillingServices.GetProductWithId(), and BillingServices.IsProductPurchased().

Referenced by BillingServices.IsProductPurchased().

◆ IsProductPurchased() [2/2]

static bool IsProductPurchased ( IBillingProduct product)
static
Returns
true if specified billing product is already purchased; otherwise, false.
Parameters
productThe object identifies the billing product registered in the Store.
Note
This works only for Non-Consumable (Managed) billing product. For Consumable products, this will always returns false.

◆ BuyProduct() [1/4]

static void BuyProduct ( string productId,
BuyProductOptions options = null )
static
Parameters
productIdThe product you want to purchase.
optionsAdditional options for the purchase.

References BillingServices.BuyProduct(), and BillingServices.GetProductWithId().

Referenced by BillingServices.BuyProduct().

◆ BuyProduct() [2/4]

static void BuyProduct ( IBillingProduct product,
BuyProductOptions options = null )
static
Note
The payment request must have a product identifier registered with the Store.
Parameters
productThe product you want to purchase.
optionsCreate BuyProductOptions object to set custom quantity and purchase tag.

References BuyProductOptions.Default, IBillingProduct.Id, and IBillingProduct.PlatformId.

◆ GetTransactions()

static IBillingTransaction[] GetTransactions ( )
static

///

Note
User needs to manually call this method after receiving completed transactions, incase if autoFinishTransactions flag is turned off in billing settings.
Returns
An array of unfinished transactions.

◆ FinishTransactions()

static void FinishTransactions ( IBillingTransaction[] transactions)
static
Parameters
transactionsAn array of unfinished transactions.

◆ RestorePurchases() [1/2]

static void RestorePurchases ( bool forceRefresh = false,
string tag = null )
static

Sends a request to restore completed purchases.

Your application calls this method to restore transactions that were previously purchased so that you can process them again.

Note
Internally this feature requires non-consumable product information. So ensure that InitializeStore is called prior to this.
Parameters
forceRefreshIf set to true force refresh by contacting server. On iOS this will trigger a login prompt to let user signin. So set this to true only if user clicks manually "Restore" option in IAP screens.
tagThis can be a unique identifier which was passed in BuyProductOptions when purchasing a product. Usually, this can be the application username or any unique identifier for which you want to restore purchases for. (optional)

◆ BuyProduct() [3/4]

static bool BuyProduct ( string productId,
int quantity = 1,
string applicationUsername = null )
static
Returns
true, if request was initiated, false otherwise failed. This can happen if product is not found
Note
The payment request must have a product identifier registered with the Store.
Parameters
productIdThe product you want to purchase.
quantityThe number of units you want to purchase. Default quantity value is 1.
applicationUsernameApplication provided username that initiated this request. (optional)

◆ BuyProduct() [4/4]

static bool BuyProduct ( IBillingProduct product,
int quantity = 1,
string applicationUsername = null )
static
Returns
true, if request was initiated, false otherwise failed. This can happen if product is not found
Note
The payment request must have a product identifier registered with the Store.
Parameters
productThe product you want to purchase.
quantityThe number of units you want to purchase. Default quantity value is 1.
applicationUsernameSpecify user data associated with the purchase. Eg: Application provided username that initiated this request. (optional)

◆ RestorePurchases() [2/2]

static void RestorePurchases ( string tag = null)
static
Returns
true, if request was initiated, false otherwise failed. This can happen if product is not found
Note
The payment request must have a product identifier registered with the Store.
Parameters
productIdThe product you want to purchase.
quantityThe number of units you want to purchase. Default quantity value is 1.
applicationUsernameApplication provided username that initiated this request. (optional)

Property Documentation

◆ Products

IBillingProduct [] Products
staticget
Remarks
This property is invalid until a call to InitializeStore is completed.

Referenced by BillingServices.GetProductWithId(), and BillingServices.Initialize().