Hey… After a whole day working with IAP, I’m going to have to throw in the towel.
There’s 3 resources I’ve been working from; The official Corona tutorial, some old stuff from Github and a stripped down approach that someone posted on here a while back.
This is what I’ve done so far
Created products in iTunes connect (to the point where it’s asking for an image - as advised by Apple), I have not submitted them for review, in fact, I don’t think it works like that anymore, Apple state that you only add images after “you’re done testing”.
Created all certs and profiles (associated with the correct ID)
Created a test user account (in fact, a couple now)
I’ve absolutely scoured at the various code snippets, trying to make head or tail of it, and the existing resources are too complex. The sample code in Corona is way OTT, the official tutorial is great, but makes calls to external modules using JSON, and basically just clouds over the basic requirement (for me anyway)… The other one I found uses an external UI module which populates dynamic buttons with a product list.
In order for me to learn about what’s actually going, it’s difficult to strip out all of the ‘flowery stuff’. I appreciate that the guys who wrote it are smart. I think sometimes they forget that some of us aren’t quite at their standard.
Anyway, I found a snippet on a forum post, that I liked the look of, as it seemed to just deal with initialising the store and purchasing a product.
All I’ve done to it, is strip it back a little more, and include in a storyboard scene.
Currently there are two widgets and that’s it, one for purchase and one for restore… I’ve tested it on my device and the restore button prompts a log in. So I log in (with my test account), then it continuously keeps asking me to log in even though if I check iPhone settings, it already has me as ‘logged in’.
The purchase button does nothing at all.
I’ve literally spent 18 hours trying to get something to work before coming here, I’m a big believer in trying to figure it out yourself, but I’m totally stumped.
I’ve included the code below, to see if one of you (smarter) guys can tell me where I’m going wrong.
Thanks
local storyboard = require( "storyboard" ) local store = require("store") local widget = require("widget") local scene = storyboard.newScene() local btnPurchase local btnRestore local transactionCallback = function (event) --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 productID = event.transaction.productIdentifier; if event.transaction.state == "purchased" then print("Product Purchased: ", productID) local alert = native.showAlert( "Purchased",{ "OK" }) elseif event.transaction.state == "restored" then print("Product Restored", productID) local alert = native.showAlert( "Restored",{ "OK" }) elseif event.transaction.state == "refunded" then print("Product Refunded") local alert = native.showAlert( "Refunded",{ "OK" }) elseif event.transaction.state == "cancelled" then print("Transaction cancelled") local alert = native.showAlert( "Cancelled",{ "OK" }) elseif event.transaction.state == "failed" then print("Transaction Failed") local alert = native.showAlert( "Failed",{ "OK" }) else print("Some unknown event occured.") local alert = native.showAlert( "Gone tits up",{ "OK" }) end store.finishTransaction( event.transaction ) end store.init("apple", transactionCallback) local purchaseItem = function (event) store.purchase( {"com.appey.geekgamesounds.100coins"}) end local restorePurchases = function (event) store.restore() end function scene:createScene( event ) local group = self.view btnPurchase = widget.newButton{ defaultFile = "bbar.png", overFile = "bbar.png", label = "Purchase", width=346, height=107, onRelease = purchaseItem } btnPurchase.x = 320 btnPurchase.y = 650 btnRestore = widget.newButton{ defaultFile = "bbar.png", overFile = "bbar.png", label = "Restore", width=346, height=107, onRelease = restorePurchases } btnRestore.x = 320 btnRestore.y = 950 group:insert( btnPurchase ) group:insert( btnRestore ) end function scene:enterScene( event ) local group = self.view end function scene:exitScene( event ) local group = self.view end function scene:destroyScene( event ) local group = self.view end ----------------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION ----------------------------------------------------------------------------------------- scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) ----------------------------------------------------------------------------------------- return scene