Please Help with IOS Inapp Purchase

I have been trying for almost 2 months to implement Inapp Purchase in my game. I still can’t get it to work. I try the corona labs sample code I couldn’t get it to work. It just seem very complex to me.  I tried the code below, I prompted me to input my account and password. I created a test Sandbox account in itunesconnect and when I tried to signed in nothing happen. If anyone can help me I would really appreciate it.  Better yet, does any one has a very simple Inapp purchase code that works that they can share with me. All I want to do is remove ads after purchase. Thanks you so much!!

function transactionCallback( event ) --- this is call after the purchase is made -- Log transaction info. print("transactionCallback: Received event " .. tostring(event.name)) print("state: " .. tostring(event.transaction.state)) print("errorType: " .. tostring(event.transaction.errorType)) print("errorString: " .. tostring(event.transaction.errorString)) local productID= event.transaction.productIdentifier; if event.transaction.state == "purchased" then print("Product Purchased: ", productID) mainscore=1 -- THIS CONTROL WHEN THE ADS SHOW saveFile("mainscore1.txt", mainscore) print ("mainscore from moregame", mainscore) btnPurchase.alpha=0 --make purchase button disappear elseif event.transaction.state == "restored" then print("Product Restored", productID) elseif event.transaction.state == "refunded" then print("Product Refunded") elseif event.transaction.state == "cancelled" then print("Transaction cancelled") elseif event.transaction.state == "failed" then print("Transaction Failed") else print("Some unknown event occured. This should never happen.") 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 --initialize your tranaction callback with appropriate store(google or apple) 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 end local function purchaseItem(event) --make sure you add { } around your product id as you need to send a table value... not a string! store.purchase( {"com.mmp.xxxx"}) end local function restorePurchases(event) --no need to sepcify a product store.restore() end --create a button that purchases an item local btnPurchase= widget.newButton { onRelease = purchaseItem, label = "Purchase" } ---Enos Code -- Make button disappear after purchase: if mainscore==1 then btnPurchase.alpha=0 --make purchase button disappear end

Are you seeing this message show up?  “Using Apple’s in-app purchase system.” in your console log?

You are testing this on a device and not the Corona SDK simulator?

Are you testing using a developer provisioning profile (not an AdHoc or for the Store one?)

Are you getting any errors in your device’s console log?  See:

http://docs.coronalabs.com/guide/basics/debugging/index.html

Rob

Hi Rob,

Thanks for the quick response on this. I’ve really been trying. All I want to do is remove ads when a purchase is made.  Can’t seem to find a sample code that does that. Thanks again Rob for your help.

Here is the error message in my console:

Apr  5 17:16:20.418: the store API is not supported on this platform/Users/mycode/WordPuzzle/src/GameScene.lua:221:

This is the line 221:  store.purchase( {“com.mmp.xxxx”})

Here’s what I am seeing in my device log in Xcode:

Apr  5 17:06:18 Enos-Ipad wifid[64] <Notice>: WiFi:[449960778.170066]: Already connected to 2WIRE827.

Apr  5 17:06:18 Enos-Ipad itunesstored[79] <Warning>: Could not load library [21]

Apr  5 17:06:18 Enos-Ipad itunescloudd[92] <Notice>: (Note ) MC: User has completed cloud configuration. Not showing UI again.

Apr  5 17:06:18 Enos-Ipad itunescloudd[92] <Warning>: Updating media purchase history for initial load…

Apr  5 17:06:19 Enos-Ipad locationd[59] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0

Apr  5 17:06:19 Enos-Ipad itunescloudd[92] <Warning>: ============================== releasing power assertion: <CloudServerPowerAssertion: 0x15d82a40>

:34 Enos-Ipad accountsd[75] <Warning>: PKPassLibrary isn’t supported on iPads

Apr  5 17:06:34 Enos-Ipad accountsd[75] <Warning>: AIDA Notification plugin running

Apr  5 17:06:34 Enos-Ipad Word Drill[204] <Warning>: transactionCallback: Received event storeTransaction

Apr  5 17:06:34 Enos-Ipad Word Drill[204] <Warning>: state: cancelled

Apr  5 17:06:34 Enos-Ipad Word Drill[204] <Warning>: errorType: cancelled

Apr  5 17:06:34 Enos-Ipad Word Drill[204] <Warning>: errorString: Cannot connect to iTunes Store

Apr  5 17:06:34 Enos-Ipad Word Drill[204] <Warning>: Transaction cancelled

Apr  5 17:06:34 Enos-Ipad wifid[64] <Notice>: WiFi:[449960794.807565]: Client itunesstored set type to

Apr  5 17:06:42 Enos-Ipad itunesstored[79] <Warning>: Could not load library [21]

Apr  5 17:06:42 Enos-Ipad itunescloudd[92] <Warning>: Updating media purchase history for initial load…

Apr  5 17:06:43 Enos-Ipad locationd[59] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0

Apr  5 17:06:44 Enos-Ipad itunescloudd[92] <Warning>: ============================== releasing power assertion: <CloudServerPowerAssertion: 0x15e7bff0>

Apr  5 17:06:48 Enos-Ipad wifid[64] <Notice>: WiFi:[449960808.267858]: Client itunesstored set type to normal application

Apr  5 17:07:46 Enos-Ipad itunescloudd[92] <Warning>: Updating media purchase history for initial load…

Apr  5 17:07:46 Enos-Ipad Word Drill[204] <Warning>: transactionCallback: Received event storeTransaction

Apr  5 17:07:46 Enos-Ipad Word Drill[204] <Warning>: state: failed

Apr  5 17:07:46 Enos-Ipad Word Drill[204] <Warning>: errorType: unknown

Apr  5 17:07:46 Enos-Ipad Word Drill[204] <Warning>: errorString: Cannot connect to iTunes Store

Apr  5 17:07:46 Enos-Ipad Word Drill[204] <Warning>: Transaction Failed

Apr  5 17:07:47 Enos-Ipad accountsd[75] <Warning>: [Warning] Unhandled server key: alert

Apr  5 17:07:47 Enos-Ipad accountsd[75] <Warning>: PKPassLibrary isn’t supported on iPads

Apr  5 17:07:47 Enos-Ipad accountsd[75] <Warning>: AIDA Notification plugin running

Apr  5 17:07:47 Enos-Ipad accountsd[75] <Warning>: PKPassLibrary isn’t supported on iPads

As-Ipad itunescloudd[92] <Warning>: ============================== releasing power assertion:

<CloudServerPowerAssertion: 0x15debda0>

Apr  5 17:07:50 Enos-Ipad wifid[64] <Notice>: WiFi:[449960870.829944]: Client itunesstored set type to normal application

Apr  5 17:07:50 Enos-Ipad wifid[64] <Notice>: WiFi:[449960870.831131]: __WiFiManagerSetEnableState: state TRUE, manager->enable.setting TRUE, manager->unlockedSinceBoot TRUE

Apr  5 17:07:50 Enos-Ipad wifid[64] <Notice>: WiFi:[449960870.833490]: BG Application: Not Present, BG Daemon: Present. Daemons: dataaccessd apsd networkd 

Are you running this in the Corona Simulator or on Device?  For IAP you have to test on device or in XCode’s Simulator.

Rob

Are you seeing this message show up?  “Using Apple’s in-app purchase system.” in your console log?

You are testing this on a device and not the Corona SDK simulator?

Are you testing using a developer provisioning profile (not an AdHoc or for the Store one?)

Are you getting any errors in your device’s console log?  See:

http://docs.coronalabs.com/guide/basics/debugging/index.html

Rob

Hi Rob,

Thanks for the quick response on this. I’ve really been trying. All I want to do is remove ads when a purchase is made.  Can’t seem to find a sample code that does that. Thanks again Rob for your help.

Here is the error message in my console:

Apr  5 17:16:20.418: the store API is not supported on this platform/Users/mycode/WordPuzzle/src/GameScene.lua:221:

This is the line 221:  store.purchase( {“com.mmp.xxxx”})

Here’s what I am seeing in my device log in Xcode:

Apr  5 17:06:18 Enos-Ipad wifid[64] <Notice>: WiFi:[449960778.170066]: Already connected to 2WIRE827.

Apr  5 17:06:18 Enos-Ipad itunesstored[79] <Warning>: Could not load library [21]

Apr  5 17:06:18 Enos-Ipad itunescloudd[92] <Notice>: (Note ) MC: User has completed cloud configuration. Not showing UI again.

Apr  5 17:06:18 Enos-Ipad itunescloudd[92] <Warning>: Updating media purchase history for initial load…

Apr  5 17:06:19 Enos-Ipad locationd[59] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0

Apr  5 17:06:19 Enos-Ipad itunescloudd[92] <Warning>: ============================== releasing power assertion: <CloudServerPowerAssertion: 0x15d82a40>

:34 Enos-Ipad accountsd[75] <Warning>: PKPassLibrary isn’t supported on iPads

Apr  5 17:06:34 Enos-Ipad accountsd[75] <Warning>: AIDA Notification plugin running

Apr  5 17:06:34 Enos-Ipad Word Drill[204] <Warning>: transactionCallback: Received event storeTransaction

Apr  5 17:06:34 Enos-Ipad Word Drill[204] <Warning>: state: cancelled

Apr  5 17:06:34 Enos-Ipad Word Drill[204] <Warning>: errorType: cancelled

Apr  5 17:06:34 Enos-Ipad Word Drill[204] <Warning>: errorString: Cannot connect to iTunes Store

Apr  5 17:06:34 Enos-Ipad Word Drill[204] <Warning>: Transaction cancelled

Apr  5 17:06:34 Enos-Ipad wifid[64] <Notice>: WiFi:[449960794.807565]: Client itunesstored set type to

Apr  5 17:06:42 Enos-Ipad itunesstored[79] <Warning>: Could not load library [21]

Apr  5 17:06:42 Enos-Ipad itunescloudd[92] <Warning>: Updating media purchase history for initial load…

Apr  5 17:06:43 Enos-Ipad locationd[59] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0

Apr  5 17:06:44 Enos-Ipad itunescloudd[92] <Warning>: ============================== releasing power assertion: <CloudServerPowerAssertion: 0x15e7bff0>

Apr  5 17:06:48 Enos-Ipad wifid[64] <Notice>: WiFi:[449960808.267858]: Client itunesstored set type to normal application

Apr  5 17:07:46 Enos-Ipad itunescloudd[92] <Warning>: Updating media purchase history for initial load…

Apr  5 17:07:46 Enos-Ipad Word Drill[204] <Warning>: transactionCallback: Received event storeTransaction

Apr  5 17:07:46 Enos-Ipad Word Drill[204] <Warning>: state: failed

Apr  5 17:07:46 Enos-Ipad Word Drill[204] <Warning>: errorType: unknown

Apr  5 17:07:46 Enos-Ipad Word Drill[204] <Warning>: errorString: Cannot connect to iTunes Store

Apr  5 17:07:46 Enos-Ipad Word Drill[204] <Warning>: Transaction Failed

Apr  5 17:07:47 Enos-Ipad accountsd[75] <Warning>: [Warning] Unhandled server key: alert

Apr  5 17:07:47 Enos-Ipad accountsd[75] <Warning>: PKPassLibrary isn’t supported on iPads

Apr  5 17:07:47 Enos-Ipad accountsd[75] <Warning>: AIDA Notification plugin running

Apr  5 17:07:47 Enos-Ipad accountsd[75] <Warning>: PKPassLibrary isn’t supported on iPads

As-Ipad itunescloudd[92] <Warning>: ============================== releasing power assertion:

<CloudServerPowerAssertion: 0x15debda0>

Apr  5 17:07:50 Enos-Ipad wifid[64] <Notice>: WiFi:[449960870.829944]: Client itunesstored set type to normal application

Apr  5 17:07:50 Enos-Ipad wifid[64] <Notice>: WiFi:[449960870.831131]: __WiFiManagerSetEnableState: state TRUE, manager->enable.setting TRUE, manager->unlockedSinceBoot TRUE

Apr  5 17:07:50 Enos-Ipad wifid[64] <Notice>: WiFi:[449960870.833490]: BG Application: Not Present, BG Daemon: Present. Daemons: dataaccessd apsd networkd 

Are you running this in the Corona Simulator or on Device?  For IAP you have to test on device or in XCode’s Simulator.

Rob