question about store.restore()

There is not much in the sense of examples in the API documents for how to use the store.restore()

as explained on this page: https://docs.coronalabs.com/api/library/store/restore.html

I was wondering, Do I simply just make a button that triggers this function and thats it?

or is there something else I need to put inside my store transaction listener function?

This is going to sound like  a way more complex answer than it is.

For iOS, Apple requires that you have a button in your app’s user interface that says “Restore purchases” or something similar. They will reject you if you don’t have a button. On the other hand Google seems to prefer that you call store.restore() after the .init() call finishes. Since Google generally doesn’t review apps unless they plan to show case them having a button should be fine. I’ve not heard about Amazon in this regard.  The button simply needs to call store.restore() with no parameters.

Now in Apple and Google’s cases, if there is nothing to restore, you won’t get any events telling you there was nothing to restore. This frustrates a lot of developers and most resort to also setting a timer.performWithDelay() of say 10-15 seconds and if nothing has happened in that time they go on. That timer could simply popup a native.showAlert() saying “No purchases to restore”, or you could just not do anything and let the user move along. I’m unsure of how Amazon handles this. I know there was some talk a while back about getting store.restore() to generate an event if nothing was found, but I don’t believe it ever got implemented.

Now in all three store’s cases, your transaction listener will get called once for each restored item. Consumable items are never restored only permanent things are like unlock levels 11-20 or turn off ads. For each of these types, you get one event. In Apple’s case, the transaction type will be “restored”. Easy. For Google and Amazon, the transaction type will be “purchased”.  The issue here is if your UI pops up a “Thank you for buying levels 11-20” type message and you get several of these restores in a row, your UI will be flooded with these popups. You can check the time stamp on the transaction and if its older than say 5 minutes, you know the user probably could not buy something, delete the app, reinstall it and hit the restore button that quickly so any transaction older than a few minutes is probably a restoration and  you could ignore showing any thing to the user.

Rob

From the docs:

If a user wipes clean the information on a device or buys a new device, he/she needs a way to restore items previously purchased from your app (without paying for them again). The store.restore() API initiates this process. You can check for previously-purchased items in the samestoreTransaction listener that you use for your successful, failed, and cancelled purchases.

https://docs.coronalabs.com/daily/guide/monetization/IAP/index.html#restoring-purchased-items

This being said, if you’re not doing anything fancy with your IAP config, I strongly suggest using IAP Badger. It’s a dead-simple plugin that takes care of the IAP heavy lifting for you.

https://marketplace.coronalabs.com/plugin/iap-badger

Thanks Rob,

I’m focusing on the iOS build right now, google will soon follow, but I’m pretty sure I got the point of what you’re saying

Alex@Panc, do you know of a video or tutorial that explains how to integrate IAP Badger into your own project?

I have found some info on: http://happymongoosegames.co.uk/iapbadger.php

it’s very useful info, but one thing I find it lacks is any notation on what needs to be changed in order for it to fit in with your own project.

I have both non-consumable products and consumable product in my app and I guess I will have to combine both the examples that are shown on that page, but other than the “productNames” I’m not sure what else would need to be changed.

There are a good amount of examples and discussion taking place in the original forum thread:

https://forums.coronalabs.com/topic/59137-iap-badger-a-unified-approach-to-in-app-purchases/

You should be able to find answers to your questions there.

This is going to sound like  a way more complex answer than it is.

For iOS, Apple requires that you have a button in your app’s user interface that says “Restore purchases” or something similar. They will reject you if you don’t have a button. On the other hand Google seems to prefer that you call store.restore() after the .init() call finishes. Since Google generally doesn’t review apps unless they plan to show case them having a button should be fine. I’ve not heard about Amazon in this regard.  The button simply needs to call store.restore() with no parameters.

Now in Apple and Google’s cases, if there is nothing to restore, you won’t get any events telling you there was nothing to restore. This frustrates a lot of developers and most resort to also setting a timer.performWithDelay() of say 10-15 seconds and if nothing has happened in that time they go on. That timer could simply popup a native.showAlert() saying “No purchases to restore”, or you could just not do anything and let the user move along. I’m unsure of how Amazon handles this. I know there was some talk a while back about getting store.restore() to generate an event if nothing was found, but I don’t believe it ever got implemented.

Now in all three store’s cases, your transaction listener will get called once for each restored item. Consumable items are never restored only permanent things are like unlock levels 11-20 or turn off ads. For each of these types, you get one event. In Apple’s case, the transaction type will be “restored”. Easy. For Google and Amazon, the transaction type will be “purchased”.  The issue here is if your UI pops up a “Thank you for buying levels 11-20” type message and you get several of these restores in a row, your UI will be flooded with these popups. You can check the time stamp on the transaction and if its older than say 5 minutes, you know the user probably could not buy something, delete the app, reinstall it and hit the restore button that quickly so any transaction older than a few minutes is probably a restoration and  you could ignore showing any thing to the user.

Rob

From the docs:

If a user wipes clean the information on a device or buys a new device, he/she needs a way to restore items previously purchased from your app (without paying for them again). The store.restore() API initiates this process. You can check for previously-purchased items in the samestoreTransaction listener that you use for your successful, failed, and cancelled purchases.

https://docs.coronalabs.com/daily/guide/monetization/IAP/index.html#restoring-purchased-items

This being said, if you’re not doing anything fancy with your IAP config, I strongly suggest using IAP Badger. It’s a dead-simple plugin that takes care of the IAP heavy lifting for you.

https://marketplace.coronalabs.com/plugin/iap-badger

Thanks Rob,

I’m focusing on the iOS build right now, google will soon follow, but I’m pretty sure I got the point of what you’re saying

Alex@Panc, do you know of a video or tutorial that explains how to integrate IAP Badger into your own project?

I have found some info on: http://happymongoosegames.co.uk/iapbadger.php

it’s very useful info, but one thing I find it lacks is any notation on what needs to be changed in order for it to fit in with your own project.

I have both non-consumable products and consumable product in my app and I guess I will have to combine both the examples that are shown on that page, but other than the “productNames” I’m not sure what else would need to be changed.

There are a good amount of examples and discussion taking place in the original forum thread:

https://forums.coronalabs.com/topic/59137-iap-badger-a-unified-approach-to-in-app-purchases/

You should be able to find answers to your questions there.