Home » Android » Why do I get an error when starting a purchase flow on IAP library?

Why do I get an error when starting a purchase flow on IAP library?

Posted by: admin November 1, 2017 Leave a comment

Questions:

Background

Google has recently published a new IAP library (links here and here, sample here named “TrivialDrive_v2”), that replaces the old one (here, sample here, named “TrivialDrive”).

The API is very different, but of course presents about the same functionality.

I have an app with just 2 SKUs (available in-app purchases in my case). One stays forever, and another gets consumed right after a purchase.

The problem

I’m trying to migrate to the new API. Everything seem ok. The purchases can get received from previous API, and I can get the details of all SKUs (available purchases ) :

List<String> skuList = new ArrayList<>();
skuList.add(...);
skuList.add(...);        
mBillingClient.querySkuDetailsAsync(SkuDetailsParams.newBuilder().setSkusList(skuList).setType(SkuType.INAPP).build(), new SkuDetailsResponseListener() {
                    @Override
                    public void onSkuDetailsResponse(final int responseCode, final List<SkuDetails> skuDetailsList) {
                        // I get here the 2 items in the list, with all their details
                    }
                });

However, when I use an SKU (that works fine when I query detail about it) for starting a purchase:

BillingFlowParams flowParams = BillingFlowParams.newBuilder()
        .setSku(...)
        .setType(SkuType.INAPP)
        .build();
int responseCode = mBillingClient.launchBillingFlow(activity, flowParams);

I get this dialog, saying “The item you requested is not available for purchase”.

enter image description here

What I tried

I thought it was an issue with the code I made, because I tried various tests on the same device, so I tried only to purchase flow on another device, but I got the same issue.

Of course, I tried to find a function or parameters that I might have missed, but both the docs and the sample show it should be just fine to use the above code.

I also tried to contact Google inside the Github repo of their sample (here), but so far I didn’t get a reply. No idea where’s the best place to ask them about it.

The question

Why do I get this issue? Am I supposed to use something else in case the SKUs were set a long time ago?

Will I have an issue with consuming (didn’t test yet, because first I need to perform a purchase) ?

Answers:

I forgot I had this issue in the past.

It’s because of multiple reasons:

  1. I’ve updated the version of the app to be higher than the one on the Play Store. I did it in order to test upgrades.

  2. Used non-signed version of the app.