0

I have implemented In-App purchase with API 3 and for testing I published apk as alpha test version. I am able to make purchase using my test account ,it work fine . But I need to check restore functionality but purchase state is not changing as apk is in alpha test.

How can I check restore functionality before I publish?please help me.

mHelper = new IabHelper(this, base64EncodedPublicKey);

    // enable debug logging (for a production application, you should set this to false).
    mHelper.enableDebugLogging(true);

    // Start setup. This is asynchronous and the specified listener
    // will be called once setup completes.
    Log.d(TAG, "Starting setup.");
    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {


        public void onIabSetupFinished(IabResult result) {
            Log.d(TAG, "Setup finished.");

            if (!result.isSuccess()) {
                // Oh noes, there was a problem.
                complain("Problem setting up in-app billing: " + result);
                return;
            }

            // Have we been disposed of in the meantime? If so, quit.
            if (mHelper == null) return;

            // IAB is fully set up. Now, let's get an inventory of stuff we own.
            Log.d(TAG, "Setup successful. Querying inventory.");
            ArrayList<String> skuList = new ArrayList<String> ();
            skuList.add("purchase.test");
            skuList.add("purchase.test2");

            skuArray = new JSONArray(skuList);

            mHelper.queryInventoryAsync(true, skuList, mQueryFinishedListener);
        }
    });
}
IabHelper.QueryInventoryFinishedListener mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
    public void onQueryInventoryFinished(IabResult result, Inventory inventory)   
    {
       if (result.isFailure()) {
           Log.v("Menu", "RESULT FALIURE");
          return;
        }

   Log.v("Menu", "this +" + skuArray);
   Log.v("Menu", "Inventory +" + inventory);
   for(int i = 0; i < skuArray.length(); i++){
       try {
          String SKU = skuArray.getString(i);

          if(inventory.getSkuDetails(SKU) != null){
              Toast.makeText(getApplicationContext(), "SKU = " + SKU+"  ....  "+inventory.hasPurchase(SKU), Toast.LENGTH_LONG).show();
              Log.v("Menu", "SKU = " + SKU+"  ....  "+inventory.hasPurchase(SKU));
              Log.v("Menu", "SKU" + SKU + "= " + inventory.getSkuDetails(SKU).getTitle());



          }else{
              Log.v("Menu", "SKU RETURNED NULL" + SKU); 
          }



     } catch (Exception e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
     }


   }

}

};

AbiAndroid
  • 89
  • 2
  • 4
  • 14

1 Answers1

1

You can call getPurchases() method every time when app opens up, this method will return you transaction details if user has already purchased the item. This way you can check restoring functionality. Please refer the following link.

Bundle ownedItems = mservice.getPurchases(3, getPackageName(), "inapp",null);
int response = ownedItems.getInt("RESPONSE_CODE");
if (response == 0) {
    //user has purchased the item
   //do something here
} else {
  //user not purchased
}
Ramesh
  • 1,252
  • 3
  • 12
  • 29
  • After purchase still I am getting user not purchase.I this because I check alpha test apk. – AbiAndroid Oct 24 '14 at 12:52
  • are you using test product id ? did you created in app product in google play? if possible please share your code. i've recently worked on in app purchase and successfully integrated in my existing app. – Ramesh Oct 25 '14 at 10:51
  • I used same code of in-app sample project in sdk. Sample project don't have Service object. – AbiAndroid Oct 27 '14 at 04:34
  • Hey, Please use this example, it is working fine for me. https://www.dropbox.com/s/y1en5phqz45hd7x/TestInAppPurchase.zip?dl=0 – Ramesh Oct 27 '14 at 06:30
  • Also you can refer this youtube video. It explains clearly how to implement it from scratch. https://www.youtube.com/watch?v=-h2ESH71hAI – Ramesh Oct 27 '14 at 06:30
  • Please go through the above video once you'll get complete idea and don't use the example given sdk. It has lot of bugs in it. – Ramesh Oct 27 '14 at 06:51
  • Thanks,For security how to add License Key for This Application. – AbiAndroid Oct 27 '14 at 07:05
  • you can get license key in google play developer console under "Services and Api's" tab. If you want to provide more security then split the public key like the way it was mentioned in this ticket. http://stackoverflow.com/questions/14352758/android-in-app-billing-securing-application-public-key – Ramesh Oct 27 '14 at 07:31
  • mHelper = new IabHelper(this, base64EncodedPublicKey);is used for add security but based on this example dropbox.com/s/y1en5phqz45hd7x/TestInAppPurchase.zip?dl=0 we get IInAppBillingService object, then how can I give security License Key? – AbiAndroid Oct 27 '14 at 10:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/63696/discussion-between-abiandroid-and-ramesh6233). – AbiAndroid Oct 27 '14 at 10:41
  • you can give license key in MainActivity.java line no: 113 in the example i have given(there is already on example key is there just replace it), i would suggest you to not look into the example which found in sdk, i got lot of confusion when i looked in to it. Please try to implement it from scratch. It's very simple and just you have follow three steps as mentioned in the youtube video. – Ramesh Oct 27 '14 at 10:44
  • @AbiAndroid: Hey if you think my answer is helpful please upvote and make it as correct so that it'll be useful to other people who read this question. – Ramesh Oct 28 '14 at 10:54