Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Google Play

akarimova edited this page Nov 6, 2014 · 12 revisions
  1. Add the corresponding billing permission

    <uses-permission android:name="com.android.vending.BILLING" />
  2. Provide your public key

    OpenIabHelper.Options.Builder builder = new OpenIabHelper.Options.Builder();
    builder.addStoreKey(OpenIabHelper.NAME_GOOGLE, googlePlayPublicKey);
    mHelper = new OpenIabHelper(this, builder.build());

    otherwise verify purchases on your server side.

  3. Map the SKUs if they are different for the supported stores

    OpenIabHelper.mapSku(SKU_PREMIUM, OpenIabHelper.NAME_GOOGLE, "org.onepf.trivialdrive.gp.premium");
    OpenIabHelper.mapSku(SKU_GAS, OpenIabHelper.NAME_GOOGLE, "org.onepf.trivialdrive.gp.gas");
    OpenIabHelper.mapSku(SKU_INFINITE_GAS, OpenIabHelper.NAME_GOOGLE, "org.onepf.trivialdrive.gp.infinite_gas");
  4. In the proguard configuration file add

     -keep class com.android.vending.billing.**
    
  5. To test .apk, please ensure

    • your .apk is submitted to Google Play Developer Console
    • your .apk is signed by the production key
    • versionCode in AndroidManifest.xml of your .apk is equal to versionCode of .apk submitted to Developer Console

Receipt Verification on Server

  1. Create OpenIabHelper with "Skip signature verification" option and no public keys. If you specify no public keys and forget VERIFY_SKIP option, an IllegalArgumentException will be thrown

    OpenIabHelper.Options.Builder builder = new OpenIabHelper.Options.Builder();
    builder.setVerifyMode(OpenIabHelper.Options.VERIFY_SKIP);
    mHelper = new OpenIabHelper(context, builder.build());
  2. Get receipt data and signature from Purchase object and send it to your server

    new IabHelper.OnIabPurchaseFinishedListener() {
        public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
            // … different result checks ...
            String receiptData = purchase.getOriginalJson();
            String receiptSignature = purchase.getSignature();
            String storeName = purchase.getAppstoreName();
            String urlToContent  = yourRequestReceiptVerificationOnServer(receiptData, receiptSignature, storeName);
            // … further code ...
        }
    }

or use the following methods