Cross Platform Native Plugins
A true cross platform tool for Unity which provides unique and unified way to access native functionality on mobile platforms.
Public Member Functions | Events | List of all members
Billing Class Reference

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

Public Member Functions

virtual bool IsAvailable ()
 Determines whether the billing feature is supported. More...
 
virtual bool CanMakePayments ()
 Determines whether the user is authorised to make payments. More...
 
BillingProduct GetStoreProduct (string _productID)
 Gets the billing product with localized information, which was previously fetched from the Store. More...
 
void RequestForBillingProducts ()
 Sends a request to retrieve localized information about the billing products from the Store. More...
 
virtual void RequestForBillingProducts (BillingProduct[] _billingProducts)
 Sends a request to retrieve localized information about the billing products from the Store. More...
 
bool IsProductPurchased (BillingProduct _product)
 Determines whether specified billing product is already purchased. More...
 
void BuyProduct (BillingProduct _product)
 Initiates purchase process for the specified billing product. More...
 
virtual void RestorePurchases ()
 Sends a request to restore completed purchases. More...
 
delegate void RequestForBillingProductsCompletion (BillingProduct[] _products, string _error)
 Delegate that will be called when localized information of products are retreived from the Store. More...
 
delegate void BuyProductCompletion (BillingTransaction _transaction)
 Delegate that will be called when Store completes processing product purchase request. More...
 
delegate void RestorePurchasesCompletion (BillingTransaction[] _transactions, string _error)
 Delegate that will be called when payment details of the products (non-consumable only) previously purchased by the user are retreived from the Store. More...
 

Events

static RequestForBillingProductsCompletion DidFinishRequestForBillingProductsEvent
 Event that will be called when localized information of billing products are retreived from the Store. More...
 
static BuyProductCompletion DidFinishProductPurchaseEvent
 Event that will be called when product payment response is received from the Store. More...
 
static RestorePurchasesCompletion DidFinishRestoringPurchasesEvent
 Event that will be called when restored transaction details are received from the Store. More...
 

Detailed Description

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

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

virtual bool IsAvailable ( )
virtual

Determines whether the billing feature is supported.

Returns
true if billing feature is supported; otherwise, false.
virtual bool CanMakePayments ( )
virtual

Determines whether the user is authorised to make payments.

Returns
true if the user is allowed to make product purchase payment; otherwise, false.
BillingProduct GetStoreProduct ( string  _productID)

Gets the billing product with localized information, which was previously fetched from the Store.

Returns
The billing product fetched with localized information.
Parameters
_productIDA string used to identify a billing product.
void RequestForBillingProducts ( )

Sends a request to retrieve localized information about the billing products from the Store.

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, DidFinishProductsRequestEvent is fired.
virtual void RequestForBillingProducts ( BillingProduct[]  _billingProducts)
virtual

Sends a request to retrieve localized information about the billing products from the Store.

Your application uses this request to present localized prices and other information to the user without having to maintain that list itself.

Parameters
_billingProductsList of billing products whose details has to be fetched.
Note
When the request completes, DidFinishProductsRequestEvent is fired.
bool IsProductPurchased ( BillingProduct  _product)

Determines whether specified billing product is already purchased.

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.
void BuyProduct ( BillingProduct  _product)

Initiates purchase process for the specified billing product.

Parameters
_productThe object identifies the billing product registered in the Store.
Note
The payment request must have a product identifier registered with the Store.
virtual void RestorePurchases ( )
virtual

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 consumable product information. So ensure that RequestForBillingProducts is called prior to this.
delegate void RequestForBillingProductsCompletion ( BillingProduct[]  _products,
string  _error 
)

Delegate that will be called when localized information of products are retreived from the Store.

Parameters
_productsAn array of BillingProduct objects, that holds localized information of products.
_errorIf the operation was successful, this value is nil; otherwise, this parameter holds the description of the problem that occurred.
delegate void BuyProductCompletion ( BillingTransaction  _transaction)

Delegate that will be called when Store completes processing product purchase request.

Parameters
_transactionThe BillingTransaction object holds payment details of the requested product.
delegate void RestorePurchasesCompletion ( BillingTransaction[]  _transactions,
string  _error 
)

Delegate that will be called when payment details of the products (non-consumable only) previously purchased by the user are retreived from the Store.

Parameters
_transactionsAn array of BillingTransaction objects, that holds payment details of products to be restored.
_errorIf the operation was successful, this value is nil; otherwise, this parameter holds the description of the problem that occurred.

Event Documentation

RequestForBillingProductsCompletion DidFinishRequestForBillingProductsEvent
static

Event that will be called when localized information of billing products are retreived from the Store.

The following example illustrates how to handle response to a request for information about a list of products.

using System.Collections;
public class ExampleClass : MonoBehaviour
{
private void OnEnable ()
{
// Registering for event
Billing.DidFinishRequestForBillingProductsEvent += OnDidFinishRequestForBillingProducts;
}
private void OnDisable ()
{
// Unregistering event
Billing.DidFinishRequestForBillingProductsEvent -= OnDidFinishRequestForBillingProducts;
}
private void OnDidFinishRequestForBillingProducts (BillingProduct[] _products, string _error)
{
if (_error == null)
{
foreach (BillingProduct _currentProduct in _products)
{
// Insert your code, eg: populating app's store screen
}
}
else
{
// Something went wrong
// Show an alert message informing user that store initialisation failed
}
}
}
BuyProductCompletion DidFinishProductPurchaseEvent
static

Event that will be called when product payment response is received from the Store.

The following example illustrates how to handle product payment response.

using System.Collections;
public class ExampleClass : MonoBehaviour
{
private void OnEnable ()
{
// Registering for event
Billing.DidFinishProductPurchaseEvent += OnDidFinishProductPurchase;
}
private void OnDisable ()
{
// Unregistering event
Billing.DidFinishProductPurchaseEvent -= OnDidFinishProductPurchase;
}
private void OnDidFinishProductPurchase (BillingTransaction _transaction)
{
if (_transaction.VerificationState == eBillingTransactionVerificationState.SUCCESS)
{
if (_transaction.TransactionState == eBillingTransactionState.PURCHASED)
{
// Product successfully purchased; Insert code to credit the item associated with this product
}
else if (_transaction.TransactionState == eBillingTransactionState.FAILED)
{
// Product was not purchased; Insert code to handle failed purchase scenario
}
}
else if (_transaction.VerificationState == eBillingTransactionVerificationState.FAILED)
{
// Something went wrong!
// At this point, we recommend you not to credit the associated item
}
else
{
// Received transaction object is not validated yet!
// This can happen only when developer opts out of inbuilt receipt validation
// Now its your responsiblity to provide appropriate receipt validation status for this transaction
// Skipping this step will cause unusual behaviour
_transaction.OnCustomVerificationFinished(_newVerificationState);
}
}
}
RestorePurchasesCompletion DidFinishRestoringPurchasesEvent
static

Event that will be called when restored transaction details are received from the Store.

The following example illustrates how to handle a response to restore purchases request.

using System.Collections;
public class ExampleClass : MonoBehaviour
{
private void OnEnable ()
{
// Registering for event
Billing.DidFinishRestoringPurchasesEvent += OnDidFinishRestoringPurchases;
}
private void OnDisable ()
{
// Unregistering event
Billing.DidFinishRestoringPurchasesEvent -= OnDidFinishRestoringPurchases;
}
private void OnDidFinishRestoringPurchases (BillingTransaction[] _transactions, string _error)
{
if (_error == null)
{
foreach (BillingTransaction _eachTransaction in _transactions)
{
if (_eachTransaction.VerificationState == eBillingTransactionVerificationState.SUCCESS)
{
// Insert code to restore product associated with this transaction
}
else if (_transaction.VerificationState == eBillingTransactionVerificationState.FAILED)
{
// Something went wrong!
// At this point, we recommend you not to credit the associated item
}
else
{
// Received transaction object is not validated yet!
// This can happen only when developer opts out of inbuilt receipt validation
// Now its your responsiblity to provide appropriate receipt validation status for this transaction
// Skipping this step will cause unusual behaviour
_transaction.OnCustomVerificationFinished(_newVerificationState);
}
}
}
else
{
// Something went wrong
// Display an alert informing user that restore request failed
}
}
}