Hello,
I am trying to get my IAPs working, but can’t figure it out for the life of me.
I press my button to buy, I get the product name, description and price. When I hit buy it doesn’t add the coins purchased.
When I go to buy again it says I’ve bought the item but haven’t downloaded it.
Here is the code:
local function transactionCallback( event ) print("transactionCallback: Received event " .. tostring(event.name)) print("state: " .. tostring(event.transaction.state)) print("errorType: " .. tostring(event.transaction.errorType)) print("errorString: " .. tostring(event.transaction.errorString)) local transaction = event.transaction myDebugLabel.text="Transaction State: "..transaction.state print("This is the transaction State:"..transaction.state) if (transaction.state == "purchased") or (transaction.state == "restored") then if (transaction.productIdentifier == "android.test.purchased") then -- Transaction was successful; unlock/download content now print("I purchased!") storyboard.gameVars.totalCoins = storyboard.gameVars.totalCoins + 15000 myCoinsLabel.text= storyboard.gameVars.totalCoins print("Total Coins: "..storyboard.gameVars.totalCoins) loadsave.saveTable(storyboard.gameVars, "gameVars.json") myDebugLabel.text=transaction.state store.finishTransaction( transaction ) storyboard.hideOverlay() end if (transaction.productIdentifier == "30kcoins") then -- Transaction was successful; unlock/download content now print("I purchased!") storyboard.gameVars.totalCoins = storyboard.gameVars.totalCoins + 30000 myCoinsLabel.text= storyboard.gameVars.totalCoins print("Total Coins: "..storyboard.gameVars.totalCoins) loadsave.saveTable(storyboard.gameVars, "gameVars.json") myDebugLabel.text=transaction.state store.finishTransaction( transaction ) storyboard.hideOverlay() end elseif transaction.state == "restored" then -- Youll never reach this transaction state on Android. myDebugLabel.text=transaction.state elseif transaction.state == "refunded" then -- Android-only; user refunded their purchase local productId = transaction.productIdentifier myDebugLabel.text=transaction.state -- Restrict/remove content associated with above productId now elseif transaction.state == "cancelled" then -- Transaction was cancelled; tell you app to react accordingly here myDebugLabel.text=transaction.state elseif transaction.state == "failed" then -- Transaction failed; tell you app to react accordingly here myDebugLabel.text=transaction.state end -- The following must be called after transaction is complete. -- If your In-app product needs to download, do not call the following -- function until AFTER the download is complete: store.finishTransaction( transaction ) end