In App Billing Plugin
In order for your app to be able to access Google's billing version 3 (which this plugin uses) you must use Googles new Developer Console web page. If you are still using the old version there will be a link at the top of the page allowing you to switch to the updated console. All products must be setup as Managed with the new billing system. Managed products can only be purchased once. For them to act like consumables you can now call the consumeProduct method which will then allow you to purchased the same product again.
You cannot test billing at all if you are logged into your device with your Google developer account. All testing must be done with a test account setup in the Developer Console. If the billingNotSupportedEvent fires with the error: "Error checking for billing v3 support. (response: 3:Billing Unavailable)" it could mean that your app was not setup in the new Developer Console, that you are not signed in with a test user on your device or many other undocumented things. There are some open bugs with regard to billing in the normal Google bug reporting system. One important one to take note of while testing here. If you experience any issues you should consult the bug reporter to see if they have already been reported.
The first thing you should do is call the init method passing it your public key (available in the Google Developer Console and now different for each app. This call will check to see if billing is supported and fire the billingSupportedEvent if it is. If billing is not supported the billingNotSupportedEvent will fire and you should not call any other methods. It is invalid and will cause a crash if you call any method other than init or enableLogging before the billingSupportedEvent fires!
After you know that billing is supported, you will want to call queryInventory with all your available skus. When the queryInventorySucceededEvent fires it will contain a list of all the current purchases and a list of all your project details. You can use this information to setup your store. The list is also handy when you want to consume an purchase. Any GooglePurchases returned are available for consumption. If you do not call queryInventory many of the checks that the plugin does to ensure proper operation cannot be done. It is highly recommended to always call queryInventory and only attempt to purchase items that Google returns as valid. Important note: subscriptions require that you call queryInventory and that the subscription that you want to purchase is properly returned by Google's servers!
Key points required for in-app billing to work (and associated documentation):
- you must use a test account setup in the Play dashboard (in the Settings -> Account Details section)
- your test device is running on Android SDK Version 2.2 (API level 8) or higher, and is installed with Google Play client Version 3.9.16 or higher
- the android:versionCode and android:versionName attributes values in the AndroidManifest.xml of the application that you are installing matches the values of your apk in the Developer Console
- you must upload your apk to Google Play (but do not publish it until you are ready to release!) Only the current version of the apk will work!
- your application is signed with the same certificate that you used for the apk that you uploaded to the Developer Console
GoogleIAB exposes the following methods:
// Toggles high detail logging on/off public static void enableLogging( bool shouldEnable ) // Toggles automatic signature verification on/off public static void setAutoVerifySignatures( bool shouldVerify ) // Initializes the billing system public static void init( string publicKey ) // Unbinds and shuts down the billing service public static void unbindService() // Returns whether subscriptions are supported on the current device public static bool areSubscriptionsSupported() // Sends a request to get all completed purchases and product information as setup in the Play dashboard about the provided skus public static void queryInventory( string skus ) // Sends our a request to purchase the product public static void purchaseProduct( string sku ) public static void purchaseProduct( string sku, string developerPayload ) // Sends out a request to consume the product public static void consumeProduct( string sku ) // Sends out a request to consume all of the provided products public static void consumeProducts( string skus )
GoogleIABManager fires the following events:
// Fired after init is called when billing is supported on the device public static event Action billingSupportedEvent; // Fired after init is called when billing is not supported on the device public static event Action<string> billingNotSupportedEvent; // Fired when the inventory and purchase history query has returned public static event Action<List<GooglePurchase>,List<GoogleSkuInfo>> queryInventorySucceededEvent; // Fired when the inventory and purchase history query fails public static event Action<string> queryInventoryFailedEvent; // Fired when a purchase completes allowing you to verify the signature on an external server if you would like public static event Action<string,string> purchaseCompleteAwaitingVerificationEvent; // Fired when a purchase succeeds public static event Action<GooglePurchase> purchaseSucceededEvent; // Fired when a purchase fails public static event Action<string> purchaseFailedEvent; // Fired when a call to consume a product succeeds public static event Action<GooglePurchase> consumePurchaseSucceededEvent; // Fired when a call to consume a product fails public static event Action<string> consumePurchaseFailedEvent;