transaction.receipt returns nil

Hi,

The event.transaction.receipt for Apple Store returns nil for me in store.init at startup.

Similarly, event.transaction.state returns failed.

Can someone explain why this is happening? I am sure everything is set up correctly, as almost all of my code is based off of the InAppPurchase sample code provided by Corona itself.

All components related to IAPs in Xcode and AppStoreCorrect are already configured, so it has to be my code that is wrong.

Many thanks in advance! :slight_smile:

Here is my code.

Any help is much appreciated!

local store = require("store") local w, h = display.contentWidth, display.contentHeight local cx, cy = w/2, h/2 local appleProductList = { "com.kcthomas.talesofchessia.100\_Manite", "com.kcthomas.talesofchessia.250\_Manite", "com.kcthomas.talesofchessia.500\_Manite", } local status local buttons = {} local function initBackground() local background = display.newImageRect("images/scenes/storeA.png", w, h) background:translate(cx, cy) end local function initStatusBanner() local bannerGradientL = display.newRect(w/4, 40, w/2, 20) local bannerGradientR = display.newRect(3\*w/4, 40, w/2, 20) 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"} status = display.newText("Please select an item.", cx, 41, "blackchancery.ttf", 24) status:setFillColor(1) end local function productInfo(product) if (product == appleProductList[1]) then return "100 Manite", "$0.99", 1 elseif (product == appleProductList[2]) then return "250 Manite", "$1.99", 2 else return "500 Manite", "$2.99", 3 end end local function newButton(product) -- Called when user taps on button local function buyThis(productID) -- Update the status and selection if not alreadu selected if (not store.isActive) then status.text = "Unable to open Store; please check your internet connection." elseif (not store.canMakePurchases) then status.text = "Unable to make purchase. Please try again later." elseif (productID) then -- Purchase successful store.purchase({productID}) timer.performWithDelay(2000, function () status.text = "Waiting for transaction on "..tostring(productID) end) end end function buyThis\_closure (product) -- Closure wrapper for buyThis() to remember which button return function (event) buyThis(product) return true end end local button = display.newImageRect("images/"..product:sub(29)..".png", 180, 100) button:addEventListener("tap", buyThis\_closure(product)) return button end local function onLoadProducts(event) for i = 1, #appleProductList do buttons[i] = newButton(appleProductList[i]) buttons[i]:translate(cx, 120\*i) end end local function loadStoreProducts() if (store.isActive and store.canLoadProducts) then store.loadProducts(appleProductList, onLoadProducts) else timer.performWithDelay(1000, function () status.text = "Unable to load products: Check internet connection and try again." 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 == "consumed") then status.text = "Consuming transaction: Original ID: "..id.." Original date: "..date elseif event.transaction.state == "refunded" then status.text = "A previously purchased product was refunded by store for product ID: "..id 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 initBackground() initStatusBanner() if (store.availableStores.apple) then store.init("apple", transactionCallback) else status.text = "Apple Store Not Available: please check your internet connection and try again." end timer.performWithDelay(1000, function () loadStoreProducts() end) status.text = "Please select an item." for i = 1, #buttons do buttons[i]:setFillColor(1) end collectgarbage()

Here is my code.

Any help is much appreciated!

local store = require("store") local w, h = display.contentWidth, display.contentHeight local cx, cy = w/2, h/2 local appleProductList = { "com.kcthomas.talesofchessia.100\_Manite", "com.kcthomas.talesofchessia.250\_Manite", "com.kcthomas.talesofchessia.500\_Manite", } local status local buttons = {} local function initBackground() local background = display.newImageRect("images/scenes/storeA.png", w, h) background:translate(cx, cy) end local function initStatusBanner() local bannerGradientL = display.newRect(w/4, 40, w/2, 20) local bannerGradientR = display.newRect(3\*w/4, 40, w/2, 20) 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"} status = display.newText("Please select an item.", cx, 41, "blackchancery.ttf", 24) status:setFillColor(1) end local function productInfo(product) if (product == appleProductList[1]) then return "100 Manite", "$0.99", 1 elseif (product == appleProductList[2]) then return "250 Manite", "$1.99", 2 else return "500 Manite", "$2.99", 3 end end local function newButton(product) -- Called when user taps on button local function buyThis(productID) -- Update the status and selection if not alreadu selected if (not store.isActive) then status.text = "Unable to open Store; please check your internet connection." elseif (not store.canMakePurchases) then status.text = "Unable to make purchase. Please try again later." elseif (productID) then -- Purchase successful store.purchase({productID}) timer.performWithDelay(2000, function () status.text = "Waiting for transaction on "..tostring(productID) end) end end function buyThis\_closure (product) -- Closure wrapper for buyThis() to remember which button return function (event) buyThis(product) return true end end local button = display.newImageRect("images/"..product:sub(29)..".png", 180, 100) button:addEventListener("tap", buyThis\_closure(product)) return button end local function onLoadProducts(event) for i = 1, #appleProductList do buttons[i] = newButton(appleProductList[i]) buttons[i]:translate(cx, 120\*i) end end local function loadStoreProducts() if (store.isActive and store.canLoadProducts) then store.loadProducts(appleProductList, onLoadProducts) else timer.performWithDelay(1000, function () status.text = "Unable to load products: Check internet connection and try again." 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 == "consumed") then status.text = "Consuming transaction: Original ID: "..id.." Original date: "..date elseif event.transaction.state == "refunded" then status.text = "A previously purchased product was refunded by store for product ID: "..id 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 initBackground() initStatusBanner() if (store.availableStores.apple) then store.init("apple", transactionCallback) else status.text = "Apple Store Not Available: please check your internet connection and try again." end timer.performWithDelay(1000, function () loadStoreProducts() end) status.text = "Please select an item." for i = 1, #buttons do buttons[i]:setFillColor(1) end collectgarbage()