Hi, I tried to implement in-app purchases in my app. I have several buttons, each signed with a purchase id. When I press the button, the store should be initialized and the purchase made. But nothing is happening when I press.
I have the following code for when the button is touched(i’m using test purchases, the others don’t work as well):
store.init( "google", transactionCallback ) if store.isActive == false then print("not available") elseif store.canMakePurchases == false then native.showAlert("Store purchases are not available, please try again later", {"OK"}) elseif productId then if system.getInfo("targetAppStore") == "amazon" or system.getInfo("targetAppStore") == "google" then store.purchase("android.test.purchased") videolist[event.target.number].paid = false myData.save("Purchases",videolist) else store.purchase( {"android.test.purchased"}) end end
TransactionCallback is this:
function transactionCallback( event ) local transaction = event.transaction if ( transaction.state == "purchased" ) then --handle a successful transaction here print( "productIdentifier", transaction.productIdentifier ) print( "receipt", transaction.receipt ) print( "signature:", transaction.signature ) print( "transactionIdentifier", transaction.identifier ) print( "date", transaction.date ) elseif ( transaction.state == "cancelled" ) then --handle a cancelled transaction here elseif ( transaction.state == "failed" ) then --handle a failed transaction here end --tell the store that the transaction is complete! --if you're providing downloadable content, do not call this until the download has completed store.finishTransaction( event.transaction ) end
So, is this all I need for in-app purchases? Also, how do I know what purchase I made, so I can update the game settings and unlock the content?
Thanks.