You do what you did when they originally purchased the item. Lets say for instance, Your IAP lets them turn off ads or somehow sets a flag that they’ve paid for the app. You might have a variable like:
local isPaid = false
Then you have a button somewhere that lets them purchase something to unlock/pay for the app. In your transactionListener you probably have something like:
if transaction.state == "purchased" then if transaction.productIdentifier == "com.yourreversedomain.yourapp.unlockApp" then -- or whatever you named the purchase item isPaid = true -- code to save the setting native.showAlert("Your App Name", "Thank you for your support!", { "Ok" } ) end -- you can have multiple items... but will only do a basic unlock here. end
Then else where you might have:
if not isPaid then someAdProvider.show() end
This basic setup lets you buy something. When the sale is confirmed the flag showing the app is paid for is set and then anything you do for free apps is wrapped in an if statement like above. When the flag is true, the code in the if executes.
Now someone deletes their app. You’ve lost track of that saved setting and no longer know if isPaid is true or false so you have to assume it’s false. This is where store.restore() comes into play. Now the user knows they have previous unlocked the app. They press the restore button which calls store.restore() and you get your transaction listener called:
if transaction.state == "restored" then if transaction.productIdentifier == "com.yourreversedomain.yourapp.unlockApp" then -- or whatever you named the purchase item isPaid = true -- code to save the setting native.showAlert("Your App Name", "You're purchases have been restored!", { "Ok" } ) end -- you can have multiple items... but will only do a basic unlock here. end
If you don’t want to have an alert show for each of them and just wanted to silently make them work you could combine it into a single if test:
if transaction.state == "purchased" or transaction.state == "restored" then ...
But most people may want to do something a little different with purchases than they do with restores.
Rob