8

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)

theMTGDeckGenius
  • 167
  • 1
  • 12
  • I have been resurrecting this issue all month and still have not gotten any results, any feed back would help – theMTGDeckGenius May 03 '16 at 19:31
  • Hi, did you find a solution? I have been looking for this for a long time. – abdfahim Aug 19 '16 at 05:20
  • @abdfahim: No i never found a solution, we just had to come up with a work around that involved giving free usage periods for our app and then ask the users to unsubscribe in Google Play and resubscribe when the free time is over. – theMTGDeckGenius Oct 07 '16 at 03:42
  • Thank you. This is very strange that Google don't allow to recover purchase token, specially when it is required to make any server side query. – abdfahim Oct 07 '16 at 04:56

1 Answers1

5

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);
dmastra
  • 439
  • 3
  • 9
  • Like I had mentioned before thank you for the answer. I have now been able to verify that the answer was indeed correct. However this functionality was introduced in V3 of the in-app billing APIs and my question was for V2 when this solution was not available. – theMTGDeckGenius Aug 17 '18 at 17:50