Hii Guys I am very new to In App purchase and don't have much knowledge
This is My Code in App: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String base64EncodedPublicKey ="@string/base64EncodedPublicKey"; iabHelper = new IabHelper(this,base64EncodedPublicKey); iabHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { @Override public void onIabSetupFinished(IabResult result) { if(!result.isSuccess()){ Log.d(TAG,"In-app Billing setup failed" + result); } else { Log.d(TAG,"In-app Billing setup OK" + result); } iabHelper.enableDebugLogging(true); iabHelper.queryInventoryAsync(mReceivedInventoryListener); } }); public void buyItem1Click(){ iabHelper.launchPurchaseFlow(this,ITEM_SKU,10001,mPurchaseFinishedListener,"mypurchasetoken"); } public void buyItem2Click(){ iabHelper.launchPurchaseFlow(this,ITEM2_SKU,10001,mPurchaseFinishedListener,"mypurchasetoken2"); } public void buyItem3Click(){ iabHelper.launchPurchaseFlow(this,ITEM3_SKU,10001,mPurchaseFinishedListener,"mypurchasetoken3"); } public void buyItem4Click(){ iabHelper.launchPurchaseFlow(this,ITEM4_SKU,10001,mPurchaseFinishedListener,"mypurchasetoken4"); } public void buyItem5Click(){ iabHelper.launchPurchaseFlow(this,ITEM5_SKU,10001,mPurchaseFinishedListener,"mypurchasetoken5"); } public void buyItem6Click(){ iabHelper.launchPurchaseFlow(this,ITEM6_SKU,10001,mPurchaseFinishedListener,"mypurchasetoken6"); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(!iabHelper.handleActivityResult(requestCode,resultCode,data)){ super.onActivityResult(requestCode,resultCode,data); } } IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() { @Override public void onIabPurchaseFinished(IabResult result, Purchase purchase) { if(result.isFailure()){ return; } else if(purchase.getSku().equals(ITEM_SKU)){ consumeItem(); } else if(purchase.getSku().equals(ITEM2_SKU)){ consumeItem(); } else if(purchase.getSku().equals(ITEM3_SKU)){ consumeItem(); } else if(purchase.getSku().equals(ITEM4_SKU)){ consumeItem(); } else if(purchase.getSku().equals(ITEM5_SKU)){ consumeItem(); } else if(purchase.getSku().equals(ITEM6_SKU)){ consumeItem(); } } }; public void consumeItem(){ iabHelper.queryInventoryAsync(mReceivedInventoryListener); } IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener = new IabHelper.QueryInventoryFinishedListener() { @Override public void onQueryInventoryFinished(IabResult result, Inventory inventory) { Purchase ITEM1 = inventory.getPurchase(ITEM_SKU); Purchase ITEM2 = inventory.getPurchase(ITEM2_SKU); Purchase ITEM3= inventory.getPurchase(ITEM3_SKU); Purchase ITEM4= inventory.getPurchase(ITEM4_SKU); Purchase ITEM5= inventory.getPurchase(ITEM5_SKU); Purchase ITEM6= inventory.getPurchase(ITEM6_SKU); if(result.isFailure()){ } else if (ITEM1!= null) { Log.d(TAG, "We have Life2. Consuming it"); iabHelper.consumeAsync(inventory.getPurchase(ITEM_SKU), mConsumeFinishedListener); return; } else if (ITEM2!= null ) { Log.d(TAG, "We have Life4. Consuming it."); iabHelper.consumeAsync(inventory.getPurchase(ITEM2_SKU), mConsumeFinishedListener); return; } else if (ITEM3!= null ) { Log.d(TAG, "We have Ester2. Consuming it."); iabHelper.consumeAsync(inventory.getPurchase(ITEM3_SKU), mConsumeFinishedListener); return; } else if (ITEM4!= null ) { Log.d(TAG, "We have Ester4. Consuming it."); iabHelper.consumeAsync(inventory.getPurchase(ITEM4_SKU), mConsumeFinishedListener); return; } else if (ITEM5!= null ) { Log.d(TAG, "We have Ester6. Consuming it."); iabHelper.consumeAsync(inventory.getPurchase(ITEM5_SKU), mConsumeFinishedListener); return; } else if (ITEM6!= null ) { Log.d(TAG, "We have Coins10K. Consuming it."); iabHelper.consumeAsync(inventory.getPurchase(ITEM6_SKU), mConsumeFinishedListener); return; } } }; IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() { @Override public void onConsumeFinished(Purchase purchase, IabResult result) { if(result.isSuccess()){ if(purchase.getSku().equals(ITEM_SKU) && result.isSuccess()){ setCoins(500); } else if(purchase.getSku().equals(ITEM2_SKU) && result.isSuccess()){ setCoins(1000); } else if(purchase.getSku().equals(ITEM3_SKU) && result.isSuccess()){ setCoins(2000); } else if(purchase.getSku().equals(ITEM4_SKU) && result.isSuccess()){ setCoins(5000); } else if(purchase.getSku().equals(ITEM5_SKU) && result.isSuccess()){ setCoins(10000); } else if(purchase.getSku().equals(ITEM6_SKU) && result.isSuccess()){ setCoins(20000); } } } }; @Override protected void onDestroy() { super.onDestroy(); if(iabHelper != null) iabHelper.dispose(); iabHelper= null; } I have basically 6 cosumable SKU that can be consumed multiple times. Its a coin Game and so every in app purchase is based on coins. I kindly request you please check this code and let me know have i implemented correctly. I don't know much about in app purchase but i guess it will be viewed by much experience developer. So please help me out with your sugesstions or refactoring etc.I checked developer site as well but couldn't understand any thing. I also wanted to ask that i used static response for testing and my app got started and when i click on buy button. Google play test intent poped up and showed payment sucessful but it didn't add any data in game. So i closed the app, next time when i tried to start the app it gave error "java.lang.NullPointerException: Attempt to invoke virtual method com.xyzApps.Purchase.utility.Inventory. getPurchase(java.lang.String)' on a null object reference" and showed "Unfortunately game stopped" I don't know what's the reason i checked IabHelper.QueryInventoryFinishedListener but everything looks good please let me know -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. To post to this group, send email to android-developers@googlegroups.com. Visit this group at https://groups.google.com/group/android-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/android-developers/c96e27e3-f5d2-471b-818a-3d6e3174fd51%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.