0

I am using subscription based billing in my app where users can subscribe to premium membership on a monthly payment basis. I am writing the code where I check the payment status of the premium user every 30 days and accordingly cancel his premium membership in case the monthly payment has not been made. My question is that what will "inventory.getPurchase(my_prod_id) return in case of failed payment? Also will it be the same for a cancelled order as well.

My code for checking the payment status is below

/**
 * query for the product for premium membership from inventory, 
 */
public void queryInventory(){
    IabHelper.QueryInventoryFinishedListener  mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
           public void onQueryInventoryFinished(IabResult result, Inventory inventory)   
           {
              if (result.isFailure()) {
                     // handle error
                      Toast.makeText(getApplicationContext(), "Error : "+result.toString(), Toast.LENGTH_LONG).show();
               }
              else{
                  try{
                        //check if user has existing subscription purchase
                        Purchase membershipPurchase = inventory.getPurchase
                        if (membershipPurchase !=null){
                            if (Integer.parseInt(membershipPurchase.getOrderId())>Integer.parseInt(jsonPurchase.getString("OrderId"))){
                            //means membership has been renewed, hence update the backend database with new purchase data
                            updateUserTable();
                            }

                        }
                        else{
                        //subscription has not been renewed or has expired. Alert user and update user status back to free member.
                            Toast.makeText(ctx.getApplicationContext(), "Your Premium User membership has expired or not renewed. Please go to 'MyApps' in Google Play and verify", Toast.LENGTH_LONG).show();
                            //update backend database with status change to free member
                        updatetoFree();
                        }
                  }
                  catch(Exception e){
                      Toast.makeText(ctx.getApplicationContext(), "Error in membership verification: "+e.toString(), Toast.LENGTH_LONG).show();
                  }
                }
           }
        };
    List<String> additionalSkuList = new ArrayList<String>();
    additionalSkuList.add(sku_premium_membership);
    mHelper.queryInventoryAsync(true, additionalSkuList, mQueryFinishedListener);
}
opalenzuela
  • 3,139
  • 21
  • 41
user1938357
  • 1,466
  • 3
  • 20
  • 33
  • the best way to do this by using purchase states api to check purchase status of the subs product. check this link: https://developer.android.com/google/play/billing/gp-purchase-status-api.html you can either implement it in your server side or your coding side. – Maulik Nov 22 '13 at 06:52
  • they don't work for subscriptions based billing. I had tried that. its mentioned as well in the website. – user1938357 Nov 22 '13 at 14:01
  • Purchase status api is worked for me, hope you get it working check this link: 1) http://stackoverflow.com/questions/12427479/am-i-getting-the-steps-right-for-verifying-a-users-android-in-app-subscription 2) http://stackoverflow.com/questions/11115381/unable-to-get-the-subscription-information-from-google-play-android-developer-ap and I have no idea what queryInventory() method give result after cancel product but it should be give response like product is not to be purchased after billing cycle is completed according to my knowledge. – Maulik Nov 23 '13 at 13:03
  • you are right. One can use the Purchase Status API here. I got that confused with something else. However in my application I am storing the purchase data(JSON String) in backend database. And I update that purchase data on a frequent basis by the queryInventory() method in my app. Thus I can check validity of the subscription(whether use renewed the subscription or not) by reading the Purchase data string. For example by seeing ir orderId is getting increased or not etc. And hence the question I had raised initially about what will getPurchase return for expired/cancelled subsctiption. – user1938357 Nov 25 '13 at 19:32

0 Answers0