Here’s the code for the catalogue:
[lua]
local catalogue = {
products = {
removeAds = {
--A list of product names or identifiers specific to apple’s App Store or Google Play.
productNames = { apple="", google=“XXXXXXX”, amazon="" },
productType = “non-consumable”,
onPurchase = function() iap.setInventoryValue(“unlock”, true) end,
onRefund = function() iap.removeFromInventory(“unlock”, true) end,
},
500coins = {
--A list of product names or identifiers specific to apple’s App Store or Google Play.
productNames = { apple="", google=“XXXXXXX”, amazon="" },
productType = “consumable”,
onPurchase = function() iap.addToInventory(“coins”, 500) end,
onRefund = function() iap.removeFromInventory(“coins”, 500) end,
},
200coins = {
--A list of product names or identifiers specific to apple’s App Store or Google Play.
productNames = { apple="", google=“XXXXXXX”, amazon="" },
productType = “consumable”,
onPurchase = function() iap.addToInventory(“coins”, 200) end,
onRefund = function() iap.removeFromInventory(“coins”, 200) end,
},
50coins = {
--A list of product names or identifiers specific to apple’s App Store or Google Play.
productNames = { apple="", google=“XXXXXXX”, amazon="" },
productType = “consumable”,
onPurchase = function() iap.addToInventory(“coins”, 50) end,
onRefund = function() iap.removeFromInventory(“coins”, 50) end,
},
},
--Information about how to handle the inventory item
inventoryItems = {
unlock = { productType=“non-consumable” },
coins = { productType=“consumable” },
}
}
[/lua]
I got it to work somewhat. I uncommented the line(s) [lua]onPurchase = function() iap.addToInventory(“coins”, 50) end,[/lua] and placed the [lua]iap.addToInventory(“coins”, 50)[/lua] directly within the purchaseListener. I assign the item name to a variable called purchaseChoice.
[lua]
local function purchaseListener()
--Remove the ads
if(purchaseChoice == “removeAds”) then
removeAds()
elseif(purchaseChoice == “50coins”) then
iap.addToInventory(“coins”, 50)
elseif(purchaseChoice == “200coins”) then
iap.addToInventory(“coins”, 200)
elseif(purchaseChoice == “500coins”) then
iap.addToInventory(“coins”, 500)
end
iap.saveInventory()
native.showAlert(“Info”, “Congrats! Your purchase was successful.”, {“Okay”})
end
[/lua]
However, while this does add the correct value to inventory, I find that I can’t make consecutive purchases without the coin value getting all messed up. For instance, the first purchase is successful and everything goes accordingly. However, if I try again immediately after, the second purchase does not increment the value.
I have to exit the store scene and return to it for it to function normally.
Is this by design?