store api questions

To give you some context, I’m trying to set up non-consumable in app purchases. I’ve read the tutorial and the store.api and I have a few questions.

First, is it safe to initialize the store every time the customer opens the in-app store or is it important to only initialize it once? If I can only initialize it once, should I do it when the app launches or on enter screen in case the device has been locked and the port closed? Obviously, it would be preferable to just do it every time they open the store to be sure nothing funky has happened to the connection.

Second, when I use store.restore is that going to send me a series of transaction callbacks to process or a single transaction callback with a bunch of products in it? The documentation says that when I restore I don’t have to specify the product to restore so I’m assuming the store will send information on all purchases associated with the app. Reading between the lines in the documentation, I’m guessing it sends a series of callbacks which are handled separately, but I felt like it was prudent to ask.

Thanks in advance for your expertise.

You should only initialize it once.  I’m not sure what the ramifications are of doing it multiple times.  I usually initialize it in my main.lua as part of start up.  The only gotcha is that Apple wants the store.restore() call to be made when the user pushes the “Restore” button.  For Google, you can do a restore a few seconds after initializing it.

I believe the restore will result in multiple transaction call backs.

I’m trying to implement store.restore() right now on the Apple App Store. I do the call but never get anything back, not even an error. 

I have a log event happening right at the beginning of the transaction listener and things work fine for purchases, but ZERO is coming back after making a call to store.restore() – anybody have any hints? This is the last thing I need to do before submitting the game!

 Jay

PS - I’m using Corona 2014.2511

Do you have it on a restore button or are you trying to call it immediately?

I have it on a button.

I log that the button was pressed (via requestb.in) and then call store.restore(). I have requestb.in calls inside the transaction listener which is how I know purchases work (plus, the items show up) and how I know restore doesn’t.

 Jay

Do you actually have purchases to restore?

Rob

Well, that’s a good question. But shouldn’t *something* happen even if there aren’t? The Restore button has to be there according to Apple, right?

So how would I alert the user there’s nothing to restore if nothing happens when they hit the button?

Jay

The common workflow is to set a timer.  If you get restored items then cancel the timer. 

Rob

Seriously, a timer? How do I know how slow the internet is at that point?

What kind of limit would you suggest, 5 seconds? 10?

 Jay

Set it for something like 20-30 seconds, if the response comes back faster than that (which it almost always will) then have it cancel the timer. Normally, restores take a couple of seconds. I also like to check for an internet connection and for the store before I send the request. If they can’t actually reach the store then fail immediately. So, now you are only really covering yourself in case the person hits the restore button and they have nothing to restore.

Thanks for the advice, Mark. I’m already checking for connection and store availability, so I guess a longer wait is no big deal.

 Jay

I would think 5-10 seconds should be sufficient.

In my case I don’t care about alerting people.  If they don’t have the purchases that they payed for, I’ll get the restore event and I can do any unlocks and then show an alert thanking them.  If there is nothing to restore no need to alert them.  The app will stay unlocked.

Rob

Rob, if someone *thinks* they have stuff to restore and they hit the button and nothing happens, they’d likely think there was a bug in the app. At least with a message they know I looked. :slight_smile:

I’m having trouble testing this – if I use the same sandbox test account on two devices should I be able to “buy” on one device and restore on the other?

 Jay

Just to kind of bump this…in case anyone else has trouble testing the store.restore() functionality.

I was able to test it by putting the app on two devices, “buying” on one device with a sandbox test account, and then hitting the game’s Restore button on the other device (using the same test account).

I ran into a problem at first because I was trying to restore consumable items, which is a no-no. You can only restore a non-consumable item. Once I switched that, my test worked.

 Jay

You should only initialize it once.  I’m not sure what the ramifications are of doing it multiple times.  I usually initialize it in my main.lua as part of start up.  The only gotcha is that Apple wants the store.restore() call to be made when the user pushes the “Restore” button.  For Google, you can do a restore a few seconds after initializing it.

I believe the restore will result in multiple transaction call backs.

I’m trying to implement store.restore() right now on the Apple App Store. I do the call but never get anything back, not even an error. 

I have a log event happening right at the beginning of the transaction listener and things work fine for purchases, but ZERO is coming back after making a call to store.restore() – anybody have any hints? This is the last thing I need to do before submitting the game!

 Jay

PS - I’m using Corona 2014.2511

Do you have it on a restore button or are you trying to call it immediately?

I have it on a button.

I log that the button was pressed (via requestb.in) and then call store.restore(). I have requestb.in calls inside the transaction listener which is how I know purchases work (plus, the items show up) and how I know restore doesn’t.

 Jay

Do you actually have purchases to restore?

Rob

Well, that’s a good question. But shouldn’t *something* happen even if there aren’t? The Restore button has to be there according to Apple, right?

So how would I alert the user there’s nothing to restore if nothing happens when they hit the button?

Jay