IAP transaction states, why aren't they working?

Hi everyone,

I’m trying to get my IAP to work properly but so far the only thing that seems to work is the purchase. I noticed that when purchasing the add-ons in my game, the screen sits there for a while before the purchase is processed. This would seem to the user like the app is frozen when it isn’t. I then thought I would put a “loading” message on the screen which works well, however if I were to start the purchase process then cancel it, the loading message gets stuck on the screen. I have tried removing the loading message in the “cancelled” transaction state but none of the states seem to do anything except the “purchased” state. I am using the transactionCallback function in the IAP sample code. Any ideas? Has anyone else successfully put a loading indicator in their app that will disappear when cancelled? Please help!

[code]
function transactionCallback( event )
local infoString

if event.transaction.state == “purchased” then

elseif event.transaction.state == “restored” then

elseif event.transaction.state == “refunded” then

elseif event.transaction.state == “cancelled” then

elseif event.transaction.state == “failed” then

else

end

– Tell the store we are done with the transaction.
– If you are providing downloadable content, do not call this until
– the download has completed.
store.finishTransaction( event.transaction )
end

[/code] [import]uid: 31262 topic_id: 30831 reply_id: 330831[/import]

@aaron,

I have functions that get called with the “cancelled” callback listener, so it does work. My buttons change color and I have an alert that pops up confirming to the user that the transaction has in fact been canceled.

I’m thinking your function to remove the “purchase loading screen” must be out of scope somehow or there is a typo in it. It seems strange to me that the function fires with the “purchased” callback and not the “cancelled” callback, since the event.transaction.state is located just under the “purchased” listener.

I’d put a print statement just under the "cancelled"callback listener and see if it prints which confirms you are actually getting the “cancelled” callback.

Another possibility is that you somehow have the “cancelled” callback listener located inside of one of the other transaction callback listeners, possibly the “purchased” listener. Make sure your elseif’s line up properly like you code example above and you “end” any other “if” statements located inside of all the callback listeners. I know this sounds far fetched, but ya never know without seeing the actual code.

Hope this helps,

Nail

[import]uid: 106779 topic_id: 30831 reply_id: 123355[/import]

Thanks so much for responding Nail.

This is the exact code I am using in my app. Just to be clear, I am hiding the loading message in the “cancelled” state. All I am doing is setting the alpha of the “loading” image to zero when the user cancels the purchase. Hopefully I am understanding this correctly but does the cancel state fire off when a user initiates the purchase but cancels before they enter their password?

[code]
function transactionCallback( event )
if event.transaction.state == “purchased” then
–loading.alpha = 1
if packpurchased == 1 then
savePurchase(“PaintPack1”)
SQL:setValue( “pack1”, 1 )
elseif packpurchased == 2 then
savePurchase(“PaintPack2”)
SQL:setValue( “pack2”, 1 )
end
director:changeScene(“menu”,“fade”)
elseif event.transcation.state == “restored” then

elseif event.transaction.state == “cancelled” then
loading2.alpha = 0
elseif event.transaction.state == “failed” then
loading2.alpha = 0
infoString = "Transaction failed, type: ", event.transaction.errorType, event.transaction.errorString
local alert = native.showAlert("Failed ", infoString,{ “OK” })
else
loading2.alpha = 0
infoString = “Unknown event”
local alert = native.showAlert("Unknown ", infoString,{ “OK” })
end
store.finishTransaction( event.transaction )
end
[/code] [import]uid: 31262 topic_id: 30831 reply_id: 123632[/import]

@30Below wrote:

Hopefully I am understanding this correctly but does the cancel state fire off when a user initiates the purchase but cancels before they enter their password?

Yes, the cancel state fires at any point during the transaction process when the user clicks “Cancel”. This can be the during the immediate purchase prompt or at anytime when the user is entering their username and password to confirm the purchase if they click “Cancel”.

Have you tried adding a print statement under the cancelled transaction state? This will tell you if the cancelled state is returning in the callback? It only makes sense to add this print statement to proceed, if you haven’t already.

I don’t see anywhere in your “purchased” callback that “loading2.alpha = 0”, but I do see “loading.alpha = 1” is commented out. It seems you have 2 different loading screens? “loading and loading2” ? I don’t get it.

How is the loading2.alpha = 0 getting set if it isn’t called in your purchase callback?

There may be another problem, not really sure though, are you declaring the “loading2” screen “local” inside the function that creates it or is it declared “local” at the top of your .lua? It could be the reference in the cancelled callback can’t reference/locate “loading2”? I’m reaching here, but you never know.

Hope this helps,
Nail
[import]uid: 106779 topic_id: 30831 reply_id: 123695[/import]

Will the print work in the simulator? I thought you could only test on device. I have tried putting a popup box to indicate it has reached the cancelled state however I have not been able to get it to pop up.

I was doing some testing however the one I am working with is loading2. I declare it at the top of the .lua file and in the button listener for the buy button I set the loading2.alpha=1. It displays no problem I just can’t get it to disappear. I didn’t set the alpha to 1 in the purchase state because it actually makes the loading message appear after the loading time completes which is pointless.

I may have to start this part from scratch using the code from the sample. Thanks again for your response. [import]uid: 31262 topic_id: 30831 reply_id: 123711[/import]

30Below wrote:

Will the print work in the simulator? I thought you could only test on device. I have tried putting a popup box to indicate it has reached the cancelled state however I have not been able to get it to pop up.

You can view the print statement in the Xcode console. I load my app onto the device and leave the USB cable attached, then in Xcode, click on “console” and you can see your print statements just like on the simulator.

Your method of adding an alert should work though, anything to fire when the “cancelled” callback is received.

I just can’t understand how you are getting a “Purchase” callback and not a “Canceled”.

30Below wrote:
I didn’t set the alpha to 1 in the purchase state because it actually makes the loading message appear after the loading time completes which is pointless.

You misunderstand my point. In the “Purchased” callback, I don’t see how loading2.alpha = 0 is being called or executed. I thought you mentioned it was working from the “Purchased” callback.

I’d be curious to hear what the problem was.

GL,

Nail [import]uid: 106779 topic_id: 30831 reply_id: 123749[/import]

@aaron,

I have functions that get called with the “cancelled” callback listener, so it does work. My buttons change color and I have an alert that pops up confirming to the user that the transaction has in fact been canceled.

I’m thinking your function to remove the “purchase loading screen” must be out of scope somehow or there is a typo in it. It seems strange to me that the function fires with the “purchased” callback and not the “cancelled” callback, since the event.transaction.state is located just under the “purchased” listener.

I’d put a print statement just under the "cancelled"callback listener and see if it prints which confirms you are actually getting the “cancelled” callback.

Another possibility is that you somehow have the “cancelled” callback listener located inside of one of the other transaction callback listeners, possibly the “purchased” listener. Make sure your elseif’s line up properly like you code example above and you “end” any other “if” statements located inside of all the callback listeners. I know this sounds far fetched, but ya never know without seeing the actual code.

Hope this helps,

Nail

[import]uid: 106779 topic_id: 30831 reply_id: 123355[/import]

Thanks so much for responding Nail.

This is the exact code I am using in my app. Just to be clear, I am hiding the loading message in the “cancelled” state. All I am doing is setting the alpha of the “loading” image to zero when the user cancels the purchase. Hopefully I am understanding this correctly but does the cancel state fire off when a user initiates the purchase but cancels before they enter their password?

[code]
function transactionCallback( event )
if event.transaction.state == “purchased” then
–loading.alpha = 1
if packpurchased == 1 then
savePurchase(“PaintPack1”)
SQL:setValue( “pack1”, 1 )
elseif packpurchased == 2 then
savePurchase(“PaintPack2”)
SQL:setValue( “pack2”, 1 )
end
director:changeScene(“menu”,“fade”)
elseif event.transcation.state == “restored” then

elseif event.transaction.state == “cancelled” then
loading2.alpha = 0
elseif event.transaction.state == “failed” then
loading2.alpha = 0
infoString = "Transaction failed, type: ", event.transaction.errorType, event.transaction.errorString
local alert = native.showAlert("Failed ", infoString,{ “OK” })
else
loading2.alpha = 0
infoString = “Unknown event”
local alert = native.showAlert("Unknown ", infoString,{ “OK” })
end
store.finishTransaction( event.transaction )
end
[/code] [import]uid: 31262 topic_id: 30831 reply_id: 123632[/import]

@30Below wrote:

Hopefully I am understanding this correctly but does the cancel state fire off when a user initiates the purchase but cancels before they enter their password?

Yes, the cancel state fires at any point during the transaction process when the user clicks “Cancel”. This can be the during the immediate purchase prompt or at anytime when the user is entering their username and password to confirm the purchase if they click “Cancel”.

Have you tried adding a print statement under the cancelled transaction state? This will tell you if the cancelled state is returning in the callback? It only makes sense to add this print statement to proceed, if you haven’t already.

I don’t see anywhere in your “purchased” callback that “loading2.alpha = 0”, but I do see “loading.alpha = 1” is commented out. It seems you have 2 different loading screens? “loading and loading2” ? I don’t get it.

How is the loading2.alpha = 0 getting set if it isn’t called in your purchase callback?

There may be another problem, not really sure though, are you declaring the “loading2” screen “local” inside the function that creates it or is it declared “local” at the top of your .lua? It could be the reference in the cancelled callback can’t reference/locate “loading2”? I’m reaching here, but you never know.

Hope this helps,
Nail
[import]uid: 106779 topic_id: 30831 reply_id: 123695[/import]

Will the print work in the simulator? I thought you could only test on device. I have tried putting a popup box to indicate it has reached the cancelled state however I have not been able to get it to pop up.

I was doing some testing however the one I am working with is loading2. I declare it at the top of the .lua file and in the button listener for the buy button I set the loading2.alpha=1. It displays no problem I just can’t get it to disappear. I didn’t set the alpha to 1 in the purchase state because it actually makes the loading message appear after the loading time completes which is pointless.

I may have to start this part from scratch using the code from the sample. Thanks again for your response. [import]uid: 31262 topic_id: 30831 reply_id: 123711[/import]

30Below wrote:

Will the print work in the simulator? I thought you could only test on device. I have tried putting a popup box to indicate it has reached the cancelled state however I have not been able to get it to pop up.

You can view the print statement in the Xcode console. I load my app onto the device and leave the USB cable attached, then in Xcode, click on “console” and you can see your print statements just like on the simulator.

Your method of adding an alert should work though, anything to fire when the “cancelled” callback is received.

I just can’t understand how you are getting a “Purchase” callback and not a “Canceled”.

30Below wrote:
I didn’t set the alpha to 1 in the purchase state because it actually makes the loading message appear after the loading time completes which is pointless.

You misunderstand my point. In the “Purchased” callback, I don’t see how loading2.alpha = 0 is being called or executed. I thought you mentioned it was working from the “Purchased” callback.

I’d be curious to hear what the problem was.

GL,

Nail [import]uid: 106779 topic_id: 30831 reply_id: 123749[/import]