IAP issues on Android

Hi all,

I’m finishing up testing an Android version of my app but I’m having problems with store.restore() on. I’m wondering if anyone has any insight.

I’ve uploaded an apk (not published), set up the IAP unmanaged product on google play and set it to active. I also went to the license testing page and added one of my email addresses as a test account.

When I run the app and make the purchase, it works (I’m hoping its not actually charging my card).

I then delete the app from my device and reinstall it so I can test restore.

When I call store.restore() it seems that it is not even hitting my storeTransaction callback handler. For eg, I have this at the top of that function:

function storeTransaction(event)     local transaction=event.transaction     print ("\>\>\>\> transaction state: " .. transaction.state)    

but its not even hitting that print. I use the same storeTransaction handler for purchases and its called properly. It just seems that store.restore() is failing before getting to the handler. Has anyone else had this problem? Its frustrating!

I’m getting this in the log right after my app tries a restore. Not sure what it might mean. The “>>> trying restore” is printed by my app right before it tries the restore.

Any help would be appreciated.

08-27 11:32:09.309: I/Corona(27596): \>\>\>\> trying restore 08-27 11:32:09.459: W/InputMethodManagerService(432): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@430bebe0 attribute=null, token = android.os.BinderProxy@43247cc8 08-27 11:32:09.499: I/qtaguid(1197): Failed write\_ctrl(u 39) res=-1 errno=22 08-27 11:32:09.499: I/qtaguid(1197): Untagging socket 39 failed errno=-22 08-27 11:32:09.499: W/NetworkManagementSocketTagger(1197): untagSocket(39) failed with errno -22 08-27 11:32:09.499: I/ElegantRequestDirector(1197): I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond 08-27 11:32:09.499: I/ElegantRequestDirector(1197): Retrying request 08-27 11:32:13.959: I/EntropyMixer(432): Writing entropy...  

Can you post more code?

Sure, more code below.

As mentioned, the purchase seems to work. It actually auths my real credit card (hope that’s normal for testing) and the storeTransaction handler is called properly. It’s only for restore that the handler is never reached and I always get a “target server failed to respond” in the log.

initing the store:

function initStore()     if (not gDebug) then         if ( store.availableStores.apple ) then             currentProductList = appleProductList             store.init( "apple", storeTransaction )         elseif ( store.availableStores.google ) then             currentProductList = googleProductList             store.init( "google", storeTransaction )         else             print( "In-app purchases are not supported on this system/device." )         end     end end

When the restore button is touched onscreen, this gets called. It always prints “trying to restore” so it’s getting to the right place:

function restoreOKClicked(event)     if (event.action=="clicked") then         if (event.index== 2) then             -- for now just check if full game present             if (gGameOptions.freeVersion == false) then                 showAlert(lstrings.store.congrats,lstrings.store.purchased) -- already full game, no need to restore             else                             gWaitingGroup=showBrowser(gRWaitIcon,true)                 showActivityInd()                              -- now attempt restore                 print ("\>\>\>\> trying restore")                 store.restore()             end         end     end end

and then the storeTransaction function, which it’s not even getting to for restore, but getting to for purchases.

function storeTransaction(event)     local transaction=event.transaction     print ("\>\>\>\> transaction state: " .. transaction.state)          if (transaction.state=="purchased" or transaction.state=="restored") then         local pid=transaction.productIdentifier         print ("transation " .. transaction.state .. " pid: " .. pid)         -- eventually go through products and see which item purchased/restored, for now assume full game                  -- turn game into FULL version.         gGameOptions.freeVersion=false         saveGameOptions()         gActiveDemoNum=gDemoNums.full         productDescriptions[fullPDIndex].status="purchased" -- show that full item already purchased         showFooter(docdata:getGameTitle())         hideActivityInd()         showAlert(lstrings.store.congrats,lstrings.store.purchased)     elseif (transaction.state== "refunded") then         -- turn game back into FREE version.         gGameOptions.freeVersion=true         saveGameOptions()         gActiveDemoNum=gDemoNums.free         productDescriptions[fullPDIndex].status="available"         showFooter(docdata:getGameTitle())         hideActivityInd()         showAlert(lstrings.store.congrats,lstrings.store.refunded)     elseif (transaction.state=="cancelled") then         hideActivityInd()             elseif (transaction.state=="failed") then         local message=lstrings.store.failed.pre .. transaction.errorType             .. lstrings.store.failed.post .. transaction.errorString         hideActivityInd()         showAlert(lstrings.alert.alert,message)     end     store.finishTransaction( event.transaction ) end  

If no one else is having this issue (though I’ve seen similar forum topics on the restore call on Android), then it must be something on my end. I’m using the last release build of Corona 1137.

I noticed one of my in app products was set to unmanaged and that was the cause of all the headaches! I happened to be testing everything on that product instead of all the others which were set up properly. It all works now.

Can you post more code?

Sure, more code below.

As mentioned, the purchase seems to work. It actually auths my real credit card (hope that’s normal for testing) and the storeTransaction handler is called properly. It’s only for restore that the handler is never reached and I always get a “target server failed to respond” in the log.

initing the store:

function initStore()     if (not gDebug) then         if ( store.availableStores.apple ) then             currentProductList = appleProductList             store.init( "apple", storeTransaction )         elseif ( store.availableStores.google ) then             currentProductList = googleProductList             store.init( "google", storeTransaction )         else             print( "In-app purchases are not supported on this system/device." )         end     end end

When the restore button is touched onscreen, this gets called. It always prints “trying to restore” so it’s getting to the right place:

function restoreOKClicked(event)     if (event.action=="clicked") then         if (event.index== 2) then             -- for now just check if full game present             if (gGameOptions.freeVersion == false) then                 showAlert(lstrings.store.congrats,lstrings.store.purchased) -- already full game, no need to restore             else                             gWaitingGroup=showBrowser(gRWaitIcon,true)                 showActivityInd()                              -- now attempt restore                 print ("\>\>\>\> trying restore")                 store.restore()             end         end     end end

and then the storeTransaction function, which it’s not even getting to for restore, but getting to for purchases.

function storeTransaction(event)     local transaction=event.transaction     print ("\>\>\>\> transaction state: " .. transaction.state)          if (transaction.state=="purchased" or transaction.state=="restored") then         local pid=transaction.productIdentifier         print ("transation " .. transaction.state .. " pid: " .. pid)         -- eventually go through products and see which item purchased/restored, for now assume full game                  -- turn game into FULL version.         gGameOptions.freeVersion=false         saveGameOptions()         gActiveDemoNum=gDemoNums.full         productDescriptions[fullPDIndex].status="purchased" -- show that full item already purchased         showFooter(docdata:getGameTitle())         hideActivityInd()         showAlert(lstrings.store.congrats,lstrings.store.purchased)     elseif (transaction.state== "refunded") then         -- turn game back into FREE version.         gGameOptions.freeVersion=true         saveGameOptions()         gActiveDemoNum=gDemoNums.free         productDescriptions[fullPDIndex].status="available"         showFooter(docdata:getGameTitle())         hideActivityInd()         showAlert(lstrings.store.congrats,lstrings.store.refunded)     elseif (transaction.state=="cancelled") then         hideActivityInd()             elseif (transaction.state=="failed") then         local message=lstrings.store.failed.pre .. transaction.errorType             .. lstrings.store.failed.post .. transaction.errorString         hideActivityInd()         showAlert(lstrings.alert.alert,message)     end     store.finishTransaction( event.transaction ) end  

If no one else is having this issue (though I’ve seen similar forum topics on the restore call on Android), then it must be something on my end. I’m using the last release build of Corona 1137.

I noticed one of my in app products was set to unmanaged and that was the cause of all the headaches! I happened to be testing everything on that product instead of all the others which were set up properly. It all works now.