iOS: nothing happens on store.purchase

I’m having an issue with getting IAP to work properly on iOS. When I use store.purchase(“com.someIAPIDHere”) nothing happens. None of my print statements in my transaction callback are fired. Even if I am not signed in with any Apple Id it does not prompt me for a login. If I use the loadProducts call I can see my IAP listed as valid(there is only 1 IAP item). I based the code off of the IAP demo. In some other apps I used the google play IAP with this code and it worked fine.

Here is what I did on iTunes Connect/Apple dev center. I did this 30+ hours ago so the changes should of propagated through all of apple’s systems by now.

  1. Created my unique app id
  2. Created a provisioning profile using the app id
  3. Created the app in iTunesConnect. The app is currently at Waiting for Review.
  4. Created the IAP item. The current status is cleared for sale and Waiting for Review
  5. Created a test user

Here is slimmed down version of my code based off of the IAP demo:

[lua]local store = require(“store”)

function transactionCallback(event)
print(“callback received”)
local transaction = event.transaction
local productId = transaction.productIdentifier
if transaction.state == “purchased” then
print(“purchased”)
–some code here to handle purchase

elseif transaction.state == “restored” then
print(“restored”)
– You’ll never reach this transaction state on Android.
–some code here to handle restore
elseif transaction.state == “refunded” then
print(“refunded”)
elseif transaction.state == “cancelled” then

– Transaction was cancelled; tell you app to react accordingly here
print(“cancelled”)

elseif transaction.state == “failed” then

– Transaction failed; tell you app to react accordingly here
print(“failed”)
end

– The following must be called after transaction is complete.
– If your In-app product needs to download, do not call the following
– function until AFTER the download is complete:

store.finishTransaction( transaction )

end
if store.availableStores.apple then

store.init(“apple”, transactionCallback)
print(“Using Apple’s in-app purchase system.”)

elseif store.availableStores.google then

store.init(“google”, transactionCallback)
print(“Using Google’s Android In-App Billing system.”)

else
print(“In-app purchases is not supported on this system/device.”)
end

function doPurchase()
print(“do purchase”)
store.purchase(“com.mycompany.myapp.myiapid”)

end[/lua]

With the store.init call, at first I just had it as store.init(transactionCallback) but later switched it to what’s in the code above. I can confirm the I do get the print statement stating it is using apples in app purchase system

I receive the “do purchase” print statement everytime I try to run the purchase however nothing inside the transactionCallback is ever printed. On the device itself nothing happens.
If anyone has seen something similar or has any suggested I’d appreciate it. Somewhat stumped on what to do now :X [import]uid: 147305 topic_id: 35344 reply_id: 335344[/import]

The issue was I was pasing a string to the store.purchase and not a table. To fix it I did this

[lua] store.purchase({“com.mycompany.myapp.myiapid”})[/lua] [import]uid: 147305 topic_id: 35344 reply_id: 140499[/import]

Glad you solved it. [import]uid: 199310 topic_id: 35344 reply_id: 140506[/import]

The issue was I was pasing a string to the store.purchase and not a table. To fix it I did this

[lua] store.purchase({“com.mycompany.myapp.myiapid”})[/lua] [import]uid: 147305 topic_id: 35344 reply_id: 140499[/import]

Glad you solved it. [import]uid: 199310 topic_id: 35344 reply_id: 140506[/import]

Thanks for posting this, the same problem was driving me mad

I should add that this is pretty poor error handling from the SDK - if the arguments of a method are invalid then some sort of error should be passed back to the client rather than a silent fail

Thanks for posting this, the same problem was driving me mad

I should add that this is pretty poor error handling from the SDK - if the arguments of a method are invalid then some sort of error should be passed back to the client rather than a silent fail

Thank you for sharing your solution.  I can’t believe I left the curly brackets out!

Thank you for sharing your solution.  I can’t believe I left the curly brackets out!