2
votes

My question is, on Android, does the p.purchase() method fire the implemented method (for non-consumable IAPs), in the main class, below, or is this just IOS?

    @Override
public void itemPurchased(String sku) {

Background info: My app uses non-consumable in-app purchases, and is released to IOS and Android. I store the IAP 'receipt' in my cloud database so i know if they have purchased the full version or not. If they have not purchased it then after x days use then it will prompt them on entry, before issuing the IAP purchase logic.

    public void askAndProcessMainIap() {
    if (Dialog.show("", "Your trial period has finished. Please upgrade to the Full Version", "Ok", null)) {
        Purchase p = Purchase.getInAppPurchase();
        p.purchase("main_app_iap_paid");
    }

On IOS all works, but on Android all my customers are reporting it not working - they are able to purchase the IAP from Google and the Google receipt does find the correct non-consumable IAP (as i have seen the name of it in screenshots). But my app is not storing the 'receipt' in my database. So when they go back into the app it asks them again, and then issues an error that they have already purchased it.

I need the itemPurchased() method to fire as this stores the database receipt entry. I ask this as the CN1 javadoc for the purchase() method says 'On Android you must use subscribe(java.lang.String) for play store subscription products'.

For ref, my build hints for android.nonconsumable should be correct as it is finding the Google Play IAP display name ok. Users aren't reporting any errors when they first make the purchase. Thanks

1
I had difficulty with IAP on Android myself and had to Ask Steve for help on this. I asked him to answer here. Just so we are clear, this isn't a subscription, it's a one time payment so you shouldn't need subscribe, just the itemPurchased callback? Are any callbacks invoked? Does it work correctly on the simulator? - Shai Almog
@ShaiAlmog This is a one time payment (non-consumable IAP). The simulator works (ignoring that it moans about no receipt store) in that it does invoke the callbacks. Yes its the itemPurchased(String sku) callback that i want to check if it should fire on Android, as was that javadoc made me think twice. I will debug further and let you know what i come up with. Perhaps it is firing and it is suppressing an error somewhere in the downstream code. - Think.Smart

1 Answers

2
votes

does the p.purchase() method fire the implemented method (for non-consumable IAPs), in the main class, below,

Yes. Android will fire the itemPurchased() method in your main class.

In app purchase can be really hard to get right. There are numerous steps on the Google Play side that need to be completed, and missing even one step, can cause things to just not work. The best strategy is to test it step by step. Test in the simulator, to ensure that your workflow works and that receipts are correctly submitted to your cloud database.

Then you need to test on an actual Android device. Create an internal release in the Play store, and set yourself up as a tester so that you can make purchases with a "test/dummy" credit card and ensure that the flow works properly. This page includes some instructions on this testing process. The important steps are:

  1. Create an internal alpha release.
  2. Add yourself to the the alpha testers list for the release.
  3. Add yourself to the "license testers" list in your google dev account (this is distinct from the alpha testers list).
  4. Install your internal/test version on your device.
  5. Try to make a purchase, and ensure that all the steps/callbacks happen.

I usually put in System.out.println statements into all of my purchase callback methods to help track the progress when testing. Then I can check my device log to see if/when/which callback is called.

Don't leave it to your users to test the IAP, as Murphy's law runs strong in IAP.