In app purchases, help needed

Hi everyone.

I want to implement In App Purchases on my app. I have a first screen with four levels, and I want to lock 3 of them and the users can buy them or buy a pack with all.

I make a new screen wich contains all the purchase information I mean, the image of the second, third, four and the 3 package levels, and I want if the user click buy in each one, the respective level is unlocked.

Any help with how to this? I ready the corona documentation and see the In App Purchases demo but i dont get it.

Thank You [import]uid: 81363 topic_id: 16336 reply_id: 316336[/import]

You should have something like this (following the documentation:

  1. Create all IAP functions:
 local store = require("store")   
 local listOfProducts = {   
 "com.yourcompany.app.productID",   
 }   
 ----------------------------------  
 -- In-App area  
 ----------------------------------  
 local validProducts, invalidProducts = {}, {}  
  
 function unpackValidProducts()  
 print ("Loading product list")  
 if not validProducts then  
 native.showAlert( "In-App features not available", "initStore() failed", { "OK" } )   
 else  
 for i=1, #invalidProducts do  
 native.showAlert( "Item " .. invalidProducts[i] .. " is invalid.",{ "OK" } )  
 end  
  
 end  
 end  
  
 function loadProductsCallback( event )  
 validProducts = event.products  
 invalidProducts = event.invalidProducts   
 unpackValidProducts ()  
  
 end  
  
 function savePurchase(product)  
 --function on what should be save when user buy a product  
 end  
  
 function transactionCallback( event )  
 if event.transaction.state == "purchased" then   
 savePurchase("product") --you should enter here the product being purchased  
 elseif event.transcation.state == "restored" then   
 savePurchase("product") --you should enter here the product being purchased  
 elseif event.transaction.state == "cancelled" then  
 elseif event.transaction.state == "failed" then   
 infoString = "Transaction failed, type: ", event.transaction.errorType, event.transaction.errorString  
 local alert = native.showAlert("Failed ", infoString,{ "OK" })  
 else  
 infoString = "Unknown event"  
 local alert = native.showAlert("Unknown ", infoString,{ "OK" })  
 end  
 store.finishTransaction( event.transaction )  
 end  
  
 function setupMyStore (event)  
 store.loadProducts( listOfProducts, loadProductsCallback )  
 end  

then, for each button:

 local onbuyButTouch = function(event)   
 if event.phase=="ended" then   
 local buyThis = function ( product )   
 if store.canMakePurchases then   
 store.purchase( {product} )   
 else   
 native.showAlert("Store purchases are not available, please try again later", { "OK" } )   
 end   
 end   
 -- Enter your product id here  
 buyThis ("com.youcompany.app.productID")   
 end   
 end   
 buyBut = ui.newButton{   
 defaultSrc="p1\_buyBut.png",   
 defaultX = 272,   
 defaultY = 68,   
 overSrc="p1\_buyBut.png",   
 overX = 272,   
 overY = 68,   
 onRelease=onbuyButTouch,   
 id="buyButButton"   
 }   

Then, you will need the to start the store call:

[code]
store.init(transactionCallback)
timer.performWithDelay (1000, setupMyStore)
[import]uid: 4883 topic_id: 16336 reply_id: 60894[/import]

d3mac123 tank you very much. Thats what Im looking for. I really appreciate your help. I have another question. What I have to do to unlock the levels?

Regards [import]uid: 81363 topic_id: 16336 reply_id: 60926[/import]

It depends of a few factors (read more at www.kwiksher.com/blog - my last posting talks about IAP).

First thing to understand is that IAP can be implemented in two different ways when users buy a product from your app:

  • an internal asset (a page, or an addition of points, for example), previously locked, becomes available after the purchase;
  • an external asset (more levels or a new magazine issue, for example) is downloaded and integrated into the current application;

answering your question, for example you can simply create an external file that is checked when the user tries to access the locked area. if the external file exists, the level is unlocked.

[import]uid: 4883 topic_id: 16336 reply_id: 60929[/import]

d3mac123, again, thank you. [import]uid: 81363 topic_id: 16336 reply_id: 60933[/import]

Hi, you know whats wrong in the button part its print me this error:

unexpected symbol near ‘/’
thanks [import]uid: 81363 topic_id: 16336 reply_id: 60945[/import]

Have you added the local ui = require(“ui”) into your project? what is the error line number? [import]uid: 4883 topic_id: 16336 reply_id: 60948[/import]

yes d3mac, this is what appear in the terminal
/Users/desarrollo3/Desktop/Stomp inap 2/ui.lua:124: attempt to index local ‘button’ (a nil value)

[import]uid: 81363 topic_id: 16336 reply_id: 60950[/import]

You have to declare first:

local buyBut  

or use:

local buyBut = ui.newButton{   

[import]uid: 4883 topic_id: 16336 reply_id: 60959[/import]

It doesnt works. A question: there is no problem if I use images instead on buttons? [import]uid: 81363 topic_id: 16336 reply_id: 60963[/import]

Hard to tell what is not working without seen the full code.

Yes, you can use an image as a button (without the ui library). Example:

Layer1 = display.newImageRect( "p1\_Layer1.png", 960, 640 ); Layer1.x = 480; Layer1.y = 320; Layer1.alpha = 1 Layer1:addEventListener("touch", onbuyButTouch) [import]uid: 4883 topic_id: 16336 reply_id: 60973[/import]

@d3mac123, after dissecting the In-App Purchase demo/sample that comes with Corona SDK, and after I eliminated everything I can see as contributing to my problem, I still cannot go beyond the function setupMyStore (event).

Finding your post (how timely!) here, I replaced what I had with what you posted above (comment #1). But… my build still cannot go beyond the setupMyStore function. Here’s what I have, and my Xcode console shows the print statement I entered inside the setupMyStore function, and there, it stops:

[lua]function setupMyStore (event)
store.loadProducts( listOfProducts, loadProductsCallback )
print (">>>>>>>>>>>>After store.loadProducts, waiting for callback")
end[/lua]

My loadProductsCallback looks like this:

[lua]function loadProductsCallback(event)
– Debug info for testing
print(">>>>>>>>>>>>>>>>>>>>>>>>>In loadProductsCallback()")
print(“event, event.name”, event, event.name)
print(event.products)
print("#event.products", #event.products)

– save for later use
validProducts = event.products
invalidProducts = event.invalidProducts
unpackValidProducts()
end[/lua]

Shouldn’t I at least see the print statement included in loadProductsCallback(event) function? Why on earth I don’t see any print statement other than “>>>>>>>>>>>>After store.loadProducts, waiting for callback” from inside setupMyStore function? I must be missing something, but I don’t know what it is that I’m not doing right.

I’m completely stumped. I’d so love to hear any and all suggestions, clues and/or advices that anyone could offer.
[import]uid: 67217 topic_id: 16336 reply_id: 61164[/import]

Naomi, I am not an expert in this subject by far but, it is my understanding the store calls do not execute in the simulators (only in the device).

The worse part building this feature into Kwik was exactly to test it. I had lots of “build to device” trial and errors until I get the “ah ha!” moment.

Alex [import]uid: 4883 topic_id: 16336 reply_id: 61172[/import]

Naomi,
I am currently getting my butt kicked by In-App Purchases too, so take my advice with a grain of salt. But from what I understand:
function setupMyStore (event)
store.loadProducts( listOfProducts, loadProductsCallback )
print (">>>>>>>>>>>>After store.loadProducts, waiting for callback")
end
Wont actually call loadProductsCallback, which is why your not seeing that print statement. Once you do some sort of transaction(buy, restore, etc) Thats when it call loadProductsCallback, and that is when you will see your print statement. of course as far as I can tell you can only do that on device… so yeah like the other guy said, painstaking trial and error on device.
Keep posting here on your progress, and I will do the same, maybe we can help each other get this working!
**** UPDATE- ok ignore what I said before, it should be printing… sorry I am just as confused as anyone. [import]uid: 46742 topic_id: 16336 reply_id: 61175[/import]

Make sure you are setting up your listOfProducts table with the correct product IDs. They need to be populated with the exact product IDs you set up in itunesConnect for your app.

You could try using the Corona IAP test app and substitute your real product IDs, build for the device, and see what happens. If that doesn’t work then there’s probably something wrong with the products you set up.

This guide isn’t Corona specific but it has a lot of good information that helped me get IAP working:
http://troybrant.net/blog/2010/01/in-app-purchases-a-full-walkthrough/

[import]uid: 9422 topic_id: 16336 reply_id: 61191[/import]

NERD SMASH!
Is how I feel right now. I think I have everything coded right, but now I am having an issue with the test user account. I set it up correctly, through iTunes Connect >> Manage Users >> Test User >> BS info.
I built my app for universal. Deleted the old version off of my phone. Installed the new one. I made sure I was signed out of any accounts, then started my app.
Here are my two problems

  1. When I press the buy button, it does nothing at all.(I know its calling the function as I used the print method to test on simulator, also the restore and buy functions are the same just one uses store.purchase, and the other store.restore)
  2. When I press the restore button, it prompts me to sign in. When I enter my test user info, it asks me to review the information- “This Apple ID has not yet been used in the iTunes Store. Tap Review to sign in”

As I understand this is NOT suppose to be happening if the test account is set up right. I cant figure it out, I even went so far as to delete the provisioning profile off my phone, make a whole new one, and try it with that. No luck!

** I am using the exact code posted at the top of this thread

Sooo I’m gonna smash my phone soon. Especially if I waste 24 hours trying to get this stupid in-app purchase set up. Please help! For the sake of my 3g

Thanks! [import]uid: 46742 topic_id: 16336 reply_id: 61197[/import]

@XenonBL , thank you for sharing your thoughts. I have gone through the website you’ve posted. And still, I am having a problem. As for the iTunes Connect setup, I wish that is the problem, but I’m totally stuck even before I get there.

@chris.r.martone , don’t smash your 3G. Honestly, I wish my problem was yours.

I’ve been able to generate device build using Ad Hoc (and Distribution Certificate), and I’ve never used Dev Certificate to generate device build before (yeah, I guess I was stupid, but when things work and serves the purpose I’m after, I don’t tend to try breaking the system.) I’ve been testing my game on device with Ad Hoc certificate. Now that I need to use Dev Certificate to build my game, I’ve come to a complete standstill. I simply cannot build it to test any part of In-App Purchase – because Corona tells me warning: Application failed codesign verification. The signature was invalid, or it was not signed with an iPhone Distribution Certificate. (-19011)

I searched online for this error, and I’ve clean slated my keychain, wiped clean the dev certificate, distribution certificate, ad hoc certificate, and all my provisional profiles. And I completely uninstalled Xcode (yes, upteenth times already). And yet again, I get this “failed codesign verification”. I am ready to smash my MacBook!

I used the single line code offered here to remove XCode. But I have a feeling something isn’t fully removed – because after I uninstall, reboot, reinstall and launch Xcode, I can still see the list of devices that I registered some happy months ago.

Okay, I’m off ins search of solution to my problem – but if anyone have any additional suggestions or thoughts, I would so very much like to hear it. (And @chris.r.martone would sure like to hear any help you can offer him too.)
[import]uid: 67217 topic_id: 16336 reply_id: 61215[/import]

Hey, thought I would list my steps for creating a dev certificate.
It should go:

  1. Log in to dev center
  2. Go to provisioning profiles
  3. Create new dev certificate (Make sure you put in the correct APP ID and enable the devices you want to build on)
  4. Download your certificate one it is active
    5)Add it your your certificate library(I do this simply by opening it)
    6)Make sure you close, then re-open Corona
    7)Build it using the correct code signing identity

Some notes:
I never use Xcode for anything, so I cant comment on that.
Are you building with the Corona simulator? [import]uid: 46742 topic_id: 16336 reply_id: 61217[/import]

Hey, Chris, I build my game using Corona simulator. I only use XCode to install/delete device build to registered devices. I drag and drop the provisional profiles to XCode so that Corona simulator can know that I have the provisional profiles to build the game.

Where can I find the certificate library on the Mac system? I might be accessing the same place through XCode, but maybe deleting whatever is in it and replacing with the latest might just solve the most pressing problem of mine (which has been plaguing me over a week!) [import]uid: 67217 topic_id: 16336 reply_id: 61219[/import]

I use the iPhone Configuration Utility. I think you can download it from the Dev center. Or it might already be installed, cant remember [import]uid: 46742 topic_id: 16336 reply_id: 61221[/import]