Testing IAP in sandbox environment

Hi All,

          I am in the process of testing out the IAP of my first word game for IOS. The transaction seem to go through fine after identifying the IAP product correctly, but the number of coins do not add up. If I try again, I get the message "You’ve already purchased this IAP but it hasn’t been downloaded:. Am I missing something here? My code is below:

==============================================================

local store = require( “store” )

store.init( “apple”, storeTransaction )

local function storeTransaction( event )

    local transaction = event.transaction

    if ( transaction.state == “purchased” ) then

        --handle a successful transaction here

        print( “productIdentifier”, transaction.productIdentifier )

        print( “receipt”, transaction.receipt )

        print( “signature:”, transaction.signature )

        print( “transactionIdentifier”, transaction.identifier )

        print( “date”, transaction.date )

        coinscnt = (coinscnt + 400)

        coinsText.text = (coinscnt + 400)

    end

    store.finishTransaction( event.transaction )

end

local function buyscrL400(event)   

store.purchase( { “com.tsrglobal.fourwords1groupInapp.C400” } )

   rembuyScr()  

  return true 

end  

==================================================

Also is it possible to display some debug messages on devices like iphone or ipad, like we do in the terminal?

thanks!

I think the issue is that you call store.init( “apple”, storeTransaction ) before the storeTransaction function is actually defined.  That means storeTransaction is nil at the time you pass it to store.init, which means it never gets called, which explains the behavior you’re seeing.

Try moving store.init( “apple”, storeTransaction ) to somewhere after you define storeTransaction, and it should work.

Here’s a blog post about debugging, and how to see debug messages when you’re running on a device: http://www.coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/.

  • Andrew

Thanks Andrew. That fixed it. working good now. 

Regards,

Ram

I think the issue is that you call store.init( “apple”, storeTransaction ) before the storeTransaction function is actually defined.  That means storeTransaction is nil at the time you pass it to store.init, which means it never gets called, which explains the behavior you’re seeing.

Try moving store.init( “apple”, storeTransaction ) to somewhere after you define storeTransaction, and it should work.

Here’s a blog post about debugging, and how to see debug messages when you’re running on a device: http://www.coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/.

  • Andrew

Thanks Andrew. That fixed it. working good now. 

Regards,

Ram