-
Notifications
You must be signed in to change notification settings - Fork 58
How to use OpenIAB Unity Plugin with Google Play
- 1. Introduction
We'll use the OpenIAB demo and modify code for a real product use.
- 2. Prerequisites
For instance, the following set up works with these instructions : Unity 4.5.2, Java 1.7.0_65 64 bits on Windows 7, with a Google Nexus 7 on Android 4.4.4.
You'll also need a Google Developer account, with a bank account verified (Google Wallet > Payment settings). Besides that, to have a second Gmail account is more convenient for testing purposes. For instance, on the Nexus 7, you can create an additional user account with a different Gmail address for that.
You're supposed to be familiar with the Google Play Developer Console (GPDC) uploads, and the terms of in-app billing, by reading [Official](http://developer.android.com/google/play/billing/index.html). You don't need to run all the Java code (OpenIAB-Unity-Plugin is a convenient C# wrapper of these Java functions) but at least to be aware of definition of SKU, License Key, in-app product prices, etc. .
- 3. GPDC - License Key
2. In "Store Listing", fill all needed fields (descriptions, icons, etc.)
3. Grab the License Key, to put it in your code later (> Services & APIs). It's a string like "MIIBIjANBg...(lots of characters)...E1rQIDAQAB" without a space.
- 4. Unity - Download & install
2. Set it for Android Platform, if needed. Set correctly the Bundle Identifier
- 5. Unity - AndroidManifest.xml, Publishing Settings and 1st test
...
</application>
<!--all-->
<uses-permission android:name="android.permission.INTERNET"/>
<!--Google Play-->
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="org.onepf.openiab.permission.BILLING" />
<!-- for tablets, important ! -->
<uses-feature android:name="android.hardware.telephony" android:required="false" />
<permission android:name="com.tmoney.vending.INBILLING"/>
</manifest>
3. Build & Run on your device. All the tests functions must work (check the internet !), the "Test Purchase" works only once because the consumable product bought is not consumed. The "Purchase Real Product" should tell "The item you were attempting to purchase could not be found".
- 6. Unity - Modify the code for the real product
2. Set a name of a real product (remember : "An ID should be composed of lower-case letters(a-z), numbers(0-9), underline(_) and dot(.). It should also start with lower-case letters or numbers"). You will reuse it later to declare it in GPDC.
private void Start() {
// Map skus for different stores
OpenIAB.mapSku(SKU, OpenIAB_Android.STORE_GOOGLE, "real_test_openiab_50_cents");
3. Replace the license key with yours (step 3)
var public_key = "MIIBIjANBg...pUkwIDAQAB";
4. (Optional) If you wish to re-test the billing several times, add code to consume product :
private void queryInventorySucceededEvent(Inventory inventory) {
Debug.Log("queryInventorySucceededEvent: " + inventory);
if (inventory != null)
{
_label = inventory.ToString();
List<Purchase> prods = inventory.GetAllPurchases();
foreach(Purchase p in prods) OpenIAB.consumeProduct(p);
}
}
private void purchaseSucceededEvent(Purchase purchase) {
Debug.Log("purchaseSucceededEvent: " + purchase);
_label = "PURCHASED:" + purchase.ToString();
OpenIAB.consumeProduct(purchase);
}
- 7. GPDC - Declare the In-app Product, Upload & Publish

2. Choose "Continue", set the prices and don't forget to Activate & Save the Product !
3. Finally, upload the APK.
4. in "Pricing & Distribution" don't forget to check "Content guidelines" & "US export laws"
5. Publish your game !
- 8. Android Device test