💰Unity In App Purchases Wrapper

Package

Unity IAP requires UnityServices in order to work, so enable it.

Services tab

Select organization and Create project ID if you see the same window as above. Then toggle ads to "ON".

For Android:

  • Add billing permission in AndroidManifest:

<uses-permission android:name="android.permission.BILLING" />
  • Then upload aab with added permission to store. When it's done you can setup products in google console (if you have already setupped finance info in google console)

  • Add products in google console

Add all product ids from google console to IAP_Products.cs with product types, you will refer them then. By default added NO_ADS with id "no_ads" from google console as example.

Now you can call methods from IAP.cs by instance (IAP.instance.IsInitialized and etc). Below will be some snippets.

check if product bought:
if (IAP.instance.IsNonConsumableOwned(IAP_Products.PRODUCT_ID)) {
    // player has it - handle
}
else {
    // player doesn't own this product
}
use product bought event:
private void OnIAP_ProductBought(string id) {
    if (String.Equals(id, IAP_Products.NO_ADS, StringComparison.Ordinal)) {
        // player has bought no ads!
    }
}
get currency code and cost:
var product = IAP.instance.GetProduct(IAP_Products.PRODUCT_ID);
Debug.Log(product.metadata.localizedPriceString); // $4,99 or $4.99 (culture depends)
Debug.Log(product.metadata.localizedPrice);       // 4,99 or 4.99 (culture depends)
Debug.Log(product.metadata.isoCurrencyCode);      // USD

How to test guide links:

  • https://developer.android.com/google/play/billing/test#one-time

  • https://developer.android.com/google/play/billing/test#subs

Last updated