Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

IAP Sandbox Testing for iOS
Started by kcdev Sep 24 2018 11:52 PM

3 replies to this topic
iap sandbox apple
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

kcdev

[GLOBAL: userInfoPane.html]
kcdev
  • Contributor

  • 107 posts
  • Corona SDK

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


[TOPIC: post.html]
#2

agramonte

[GLOBAL: userInfoPane.html]
agramonte
  • Contributor

  • 811 posts
  • Corona SDK

I would say failure. Last time I tested in sandbox, I get a receipt back.



[TOPIC: post.html]
#3

kcdev

[GLOBAL: userInfoPane.html]
kcdev
  • Contributor

  • 107 posts
  • Corona SDK

@agramonte
What kind of receipt? Did you get an email at your sandbox email address? 



[TOPIC: post.html]
#4

agramonte

[GLOBAL: userInfoPane.html]
agramonte
  • Contributor

  • 811 posts
  • Corona SDK

No. I mean you get an event that fires back when you make the purchase and in that event, you have a receipt.

 

 

receipt — A JSON-formatted string representation of the transaction receipt.



[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: iap, sandbox, apple