2

Our app makes use of managed purchases in Google Play Store, we use the In-App Billing free module from the market and we were able to implement its functionality into our project with no problem. That was until a question arose: How do we check for these managed purchases?

Natively, the In-App Billing library access the Play Store app and checks the purchases made by the user, but we checked the documentation and example for this module and there's no exposed method to make this check, so how can we check what purchases a user has made?

This is important since if a user purchases, for example, a Basic skin, the user must be able to see this skin in every device he owns with the app installed in it and logged to the same account that has the product marked as purchased.

In short, how can I check for the managed purchases a user has made from the Play Store? Can it be done using the In-App Billing module? In case the module can't do it, can it be done at all?

We're using Titanium SDK 3.2.0.GA, Studio 3.2.0.201312191547 and testing on Moto G with Android 4.4 and Xperia Acro S with Android 4.1.2.

Uriel Arvizu
  • 1,876
  • 6
  • 37
  • 97

1 Answers1

1

You can indirectly do this with the restore purchases functionality, I believe the way you handle this is by listening for the state changes AFTER calling restoreTransactions, then as each one is returned (or none at all) you set those objects as purchases in the same way as if the user was buying them right there, so like this I think...

InAppBilling.restoreTransactions();

...

// Then wait for this to get called per item to be restored
InAppBilling.addEventListener(InAppBilling.PURCHASE_STATE_CHANGED_EVENT, function(e){
    // These events and the JSON object returned are detailed on the [Android Dev Site](http://developer.android.com/google/play/billing/billing_reference.html#billing-intents)
    // verify signature 
    var sign = e.signature;
    .....
    // Get the returned JSON object
    var response = JSON.parse(e.signedData);

    // Now do app logic with an identifier from the response object, I think like below
    var id = response.productId;
    ....
});

Or some variant of the above, I think the key observation here is that using restoreTransactions is the way to go.

Josiah Hester
  • 6,065
  • 1
  • 24
  • 37
  • I'm still lost on how *restoreTransactions* works, mainly because the In-App Billing library v3 can access to the information in the Play Store App so I didn't get to use the restore transactions from earlier version. As far as I understand, *restoreTransactions* gets all the managed products associated to the current main account logged into the device, right? It doesn't do something like resetting the user purchases? If the case is the first one(retrieving purchases) then how do users reset the purchases? I know this isn't the main point of my question but it'd be good to know. – Uriel Arvizu Apr 28 '14 at 23:20
  • 1
    Yeah, it is the first one, as far as resetting purchases, usually that is handled by dev code. restoreTransactions just gets all the stuff the current user has bought. – Josiah Hester Apr 29 '14 at 00:22
  • ok, so I have to run restoreTransactions every time the user opens the app? The documentation in the module says it must be performed on a fresh install or a reinstall, in which case, how can I tell those scenarios on Titanium? – Uriel Arvizu Apr 29 '14 at 00:24
  • 1
    Set a flag using [Ti.App.Properties](http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.App.Properties), these persist, if the flag is not set, then call `restoreTransactions`, if it is set then don't call it, also I would leave UI option for the user to do this manually. – Josiah Hester Apr 29 '14 at 00:50
  • And to reset the purchases made, that's done by the user or can I do it too? – Uriel Arvizu Apr 29 '14 at 00:57