How to check what in-app purchases had a user made using the In-App Billing Module for Android with Appcelerator's Titanium SDK?

StackOverflow https://stackoverflow.com/questions/23351195

Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top