glenatron
glenatron

Reputation: 11362

What is the standard approach to checking an Android Play Store in app purchase has been cancelled?

My app uses an in-app purchase to enable a 'pro' version, through the Android BillingClient library. This makes it painless to get pricing details, accept payment and mark the upgrade as purchased.

However, if I go into the console as the app owner and refund a purchase, I can't figure out how I am supposed to disable the pro features in my app. There doesn't seem to be anything in the getPurchasesList() result that indicates the status of the purchase, but also as far as I can tell this is cached on the local device so it isn't updated automatically.

Currently my check looks like this:

Purchase.PurchasesResult purchases = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
        if (purchases != null)
        {
            List<Purchase> bought = purchases.getPurchasesList();
            if ( bought != null && 0 < bought.size() )
            {
                for (int i=0;i<bought.size(); i++)
                {
                    if ( bought.get(i).getSku().equals(PRO_VERSION) )
                    {
                        purchased = true;
                    }
                }
            }
        }

Is there something I can do here to check whether the purchase has been refunded or a way to make a secondary background check later? I don't want to routinely remove the purchase notification from the cache because the app is likely to be used in areas of limited or patchy signal and I don't want anyone who has legitimately purchased it to suddenly lose their 'pro' version at a time they need it. At the same time if someone has purchased it and then been refunded, I would like to be able to reflect that in the app.

I am not currently running any back-end infrastructure of my own and I would prefer to keep it that way.

Upvotes: 4

Views: 232

Answers (2)

Benjamin
Benjamin

Reputation: 7368

If an item has been refunded, it should not appear in the list returned by getPurchasesList(). Therefore, you could save the status of the purchase in the shared preferences:

Purchase.PurchasesResult purchases = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
    if (purchases != null)
    {
        preferences.setPro(false);
        List<Purchase> bought = purchases.getPurchasesList();
        if ( bought != null && 0 < bought.size() )
        {
            for (int i=0;i<bought.size(); i++)
            {
                if ( bought.get(i).getSku().equals(PRO_VERSION) )
                {
                    preferences.setPro(true);
                    purchased = true;
                }
            }
        }
    }

Upvotes: 1

Jujinko
Jujinko

Reputation: 319

It seems there actually is no real solution to your problem. But after going through some Google articles it actually seems that in-app purchases are not intended to be refunded, except in some very rare edge-cases. This would mean refund-behavior is not intended as far as I can tell.

Source: https://github.com/googlesamples/android-play-billing/issues/113

Upvotes: 2

Related Questions