store.* API error handling

I’m beginning to implement In App Purchases and I’ve been researching the docs. Something I don’t really see is what happens in the case of an error (mainly if the internet gets disconnected or the connection is too poor).

I want to set some kind of timeout but I’m not sure how. I don’t see any functions in the store API to stop waiting for requests. For example, I want to make use of store.loadProducts() and timeout within 10 seconds if I haven’t received anything. How would I accomplish this?

I would also like to do the same thing for purchases. If the purchase hasn’t gone through in a certain amount of time I want to cancel the process and have them try again later.

If anybody has some working code that shows how you’ve implemented timeouts and other error handling I would be grateful!

You would use a timer.performWtihDelay() to call a function that would set some type of flag, maybe call it “iapTimeout” and you could set it to true in your timer function and do what ever you needed.

Then in the transaction call back function, test to see if iapTimeout is true and if so, handle the issue accordingly. 

Rob

Thanks Rob! One thing I’m not sure about, what happens if for example my time out for waiting for a pruchase is 30 seconds, but then I get a successful response after 31 seconds? Technically the purchase is successful but according to my app it would have failed. Are there any best practices to handle this scenario?

Also, could somebody clarify what is the advantage of calling store.init and passing in the store name? If it’s not required then why pass in that parameter at all?

Are you talking about:

store.init( “apple”, transactionCallback ) or

store.init( “google”, transactionCallback )

???

If so, back in the day, the store.* API was something built into Corona’s core  You had to pass in which provider you wanted to use, so we would make the right server calls under the hood.  Today Amazon, Google IAP V3, and a few other services are done using plugins.  Apple’s IAP is still built into the core, so store.init() still needs to know what library to use under the hood.  For the plugins, while you’re including them specifically, they still conform to the previous API.

Rob

You would use a timer.performWtihDelay() to call a function that would set some type of flag, maybe call it “iapTimeout” and you could set it to true in your timer function and do what ever you needed.

Then in the transaction call back function, test to see if iapTimeout is true and if so, handle the issue accordingly. 

Rob

Thanks Rob! One thing I’m not sure about, what happens if for example my time out for waiting for a pruchase is 30 seconds, but then I get a successful response after 31 seconds? Technically the purchase is successful but according to my app it would have failed. Are there any best practices to handle this scenario?

Also, could somebody clarify what is the advantage of calling store.init and passing in the store name? If it’s not required then why pass in that parameter at all?

Are you talking about:

store.init( “apple”, transactionCallback ) or

store.init( “google”, transactionCallback )

???

If so, back in the day, the store.* API was something built into Corona’s core  You had to pass in which provider you wanted to use, so we would make the right server calls under the hood.  Today Amazon, Google IAP V3, and a few other services are done using plugins.  Apple’s IAP is still built into the core, so store.init() still needs to know what library to use under the hood.  For the plugins, while you’re including them specifically, they still conform to the previous API.

Rob