Hi Corona Community,
I’ve been testing the IAPs on my app using a sandbox test account to see if the transaction will complete successfully.
In the IAP scene of my app, there are 3 buttons, each corresponding to the appropriate product. Each button implements an actionListener, when tapped upon attempts to buy the product by calling store.purchase( )
When the user taps it, it asks their login credentials (i.e. Apple ID and Password). But then, nothings happens for a while (no errors, yet no success message either) and after about 2 seconds, it asks the user to sign in again.
My question is as follows; would this equate to a success or a failure if this were a distribution build and the user was a real account (not a sandbox)?
Currently I am targeting Apple Store only, and will not expand into Google Play or Amazon until later.
I made a Youtube video to better illustrate when I am experiencing (video too large to post here).
https://www.youtube.com/watch?v=q_0ddwmsE5c&feature=youtu.be
Below is the code for the IAP section of my app (which is based on Corona SDK’s In App Purchase sample code).
Thanks in advance!
-- Only Apple Store for now local composer = require("composer") local store = require("store") local w, h = display.contentWidth, display.contentHeight --================================= Fields =================================-- local appleProductList = { "com.kcthomas.talesofchessia.100\_Manite", "com.kcthomas.talesofchessia.250\_Manite", "com.kcthomas.talesofchessia.500\_Manite", } local scene = composer.newScene() local viewGroup local status local buttons = {} local function initBackground() local background = display.newImageRect("background.png", display.content w, h) background:translate(w/2, h/2) viewGroup:insert(background) end local function initStatusBanner() local bannerGradientL = display.newRect(w/4, 50, w/2, 30) local bannerGradientR = display.newRect(3\*w/4, 50, w/2, 30) bannerGradientL.fill = {type = "gradient", color1 = {0, 0.7}, color2 = {0, 0.3}, direction = "left"} bannerGradientR.fill = {type = "gradient", color1 = {0, 0.7}, color2 = {0, 0.3}, direction = "right"} viewGroup:insert(bannerGradientL); viewGroup:insert(bannerGradientR) status = display.newText("Please select an item.", w/2, 50, "blackchancery.ttf", 20) status:setFillColor(1) viewGroup:insert(status) end local function newButton(product) -- Called when user taps on button local function buyProduct(productID) -- Attempt to buy item if (not store.isActive) then print("Unable to open Store: please check your internet connection and try again.") elseif (not store.canMakePurchases) then print("Unable to make purchase. Please try again later.") elseif (productID) then store.purchase({productID}) timer.performWithDelay(1000, function () status.text = "Waiting for transaction on "..tostring(productID) end) end end function buyProduct\_closure (product) -- Closure wrapper for buyThis() to remember which button return function (event) buyProduct(product) return true end end local button = display.newImageRect("button.png", 100, 50) button:addEventListener("tap", buyProduct\_closure(product)) return button end local function onLoadProducts(event) for i = 1, #appleProductList do buttons[i] = newButton(appleProductList[i]) buttons[i]:translate(w/2, 100 + 100\*1) viewGroup:insert(buttons[i]) end end local function loadStoreProducts() if (store.isActive and store.canLoadProducts) then store.loadProducts(appleProductList, onLoadProducts) else timer.performWithDelay(1000, function () alert("Unable to load products: please check your internet connection and try again.", {"OK"}, {function () composer.hideOverlay() end}) end) end end local function transactionCallback(event) local id, date = tostring(event.transaction.originalTransactionIdentifier), tostring(event.transaction.originalDate) if (event.transaction.state == "purchased") then status.text = "Transaction successful!" elseif (event.transaction.state == "restored") then status.text = "Restoring transaction: Original ID: "..id.." Original date: "..date elseif event.transaction.state == "cancelled" then status.text = "Transaction cancelled by user." elseif event.transaction.state == "failed" then status.text = "Transaction failed, type: "..tostring(event.transaction.errorType).." "..tostring(event.transaction.errorString) else status.text = "Unknown error" end store.finishTransaction(event.transaction) end function scene:create(event) viewGroup = self.view initBackground() initStatusBanner() if (store.availableStores.apple) then store.init("apple", transactionCallback) else print("Apple Store Not Available: please check your internet connection and try again.") end timer.performWithDelay(1000, function () loadStoreProducts() end) collectgarbage() end scene:addEventListener("create", scene) return scene