Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recover lost purchase token for a subscription

I am having a major problem right now, we are having instances where our server is unsubscribing users to our application (not in Google Play) and deleting our purchase tokens we receive from Google Play after a successful purchase. We have taken care of them not getting deleted any more but I need to handle the ones we have already lost.

So my question is, Is there any way to recover the purchase token? (Mainly in the V2 APIs)

like image 679
theMTGDeckGenius Avatar asked Mar 22 '16 17:03

theMTGDeckGenius


1 Answers

You can get token and order id parsing the response from 'getPurchases'

https://developer.android.com/google/play/billing/billing_reference.html#getPurchases

But it is easer if you use IabHelper from TrialDrive Sample . https://github.com/googlesamples/android-play-billing/tree/master/TrivialDrive

There you app you can retrieve the token from the purchase object which you obtain starting a queryInventory:

IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
        public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
           Log.d(TAG, "Query inventory finished.");

            // Have we been disposed of in the meantime? If so, quit.
            if (mHelper == null) return;

            // Is it a failure?
            if (result.isFailure()) {
                Log.d(TAG, "Failed to query inventory: " + result);
                return;
            }

            Purchase premiumMonthly = inventory.getPurchase(SKU_SUSCRIPTION);
            if (premiumMonthly != null && premiumMonthly.isAutoRenewing()) {
                    String token = premiumMonthly.getToken();
                    String orderid = premiumMonthly.getOrderId();

                    Log.d(TAG, token);
                    Log.d(TAG, orderid);
                } 
            }
   ....

    mHelper.queryInventoryAsync(mGotInventoryListener);
like image 84
dmastra Avatar answered Nov 10 '22 00:11

dmastra