Skip to main content
Samsung Developer Program

Terminate Commercial Item Processing

In order to release resources used by the OpenIAB billing service and event listeners, the following routines need to be added to your Unity project source code:

Unbind from the IAP billing service

After working with the in-app purchases, unbind from the IAP billing service by calling the unbindService() method, which unbinds and shuts down the billing service. This unbinding is implemented in the onDestroy() method in the Shop.cs file.

Shop.cs
// Remove listeners when the application exits

private void OnDestroy()
    {
    ...
    // Unbind from the IAP billing service
    OpenIAB.unbindService();
}


Unsubscribe to plugin events

To prevent memory leaks or to free memory, unsubscribe to OpenIAB plugin events via the OpenIABEventManager class, which unregisters any listeners that were previously set in Awake().

In City Flyer, unsubscribing is implemented in the onDestroy()class. 

In Unity, onDestroy() is invoked when the class is destroyed.

Shop.cs
// Remove listeners when the application exits

private void onDestroy()
    {
        // Remove listeners from the event manager to avoid nasty leaks
        OpenIABEventManager.billingSupportedEvent -= onBillingSupported;
        OpenIABEventManager.billingNotSupportedEvent -= OnBillingNotSupported;
        OpenIABEventManager.queryInventorySucceededEvent -= OnQueryInventorySucceeded;
        OpenIABEventManager.queryInventoryFailedEvent -= OnQueryInventoryFailed;
        OpenIABEventManager.purchaseSucceededEvent -= OnPurchaseSucceeded;
        OpenIABEventManager.purchaseFailedEvent -= OnPurchaseFailed;
        OpenIABEventManager.consumePurchaseSucceededEvent -= OnConsumePurchaseSucceeded;
        OpenIABEventManager.consumePurchaseFailedEvent -= OnConsumePurchaseFailed;
        OpenIABEventManager.transactionRestoredEvent -= OnTransactionRestored;
        OpenIABEventManager.restoreSucceededEvent -= OnRestoreSucceeded;
        OpenIABEventManager.restoreFailedEvent -= OnRestoreFailed;
    }