store.restore crashes app

Hi,

I have a ‘restore purchase’ button in my app for users to restore their previous iap purchase if needed.

However, if a user presses ‘restore purchase’ without having previously purchased, the app crashes (activity indicator keeps circling, but the app stops responding to taps or back button press; you have to force exit/close the app). Obviously, the button shouldn’t be used for that scenario. But it seems some users press it anyway.

Here is my restore function and listener in my iap module:

storeTransaction = function( event )     local transaction = event.transaction          if transaction.state == "purchased" then                 -- on Google market the restored items will also come here         \_g.isFullVersion = true             local event = { name = "purchased", target = Runtime }         Runtime:dispatchEvent(event)                      elseif  transaction.state == "restored" then         \_g.isFullVersion = true                 local event = { name = "purchased", target = Runtime }         Runtime:dispatchEvent(event)              else         -- handles the following states:         -- cancelled, failed, revoked, refunded         \_g.isFullVersion = false     end          saveStateToFile()          --tell the store that the transaction is complete!     store.finishTransaction( event.transaction )          -- remove activity indicator after transaction is complete     native.setActivityIndicator( false ) end module.restore = function( isSilent )     -- shows activity indicator and prevents clicking or other      -- interaction from user, until the transaction is complete     if not isSilent then         native.setActivityIndicator( true )     end          if system.getInfo("targetAppStore") == "amazon" then         store.restore( \_g.purchaseList[1] )     else         store.restore( \_g.purchaseList )     end end  

Here is how i call restore:

restoreBtnHandler = function(event)     if event.phase == "ended" then         if \_g.isFullVersion == false then             iap.restore(false )         end     end     return true end  

Is it possible that event.transaction is nil and that’s the reason for the freeze? I understand from the documentation that the listener will always receive a callback and in the above scenario event.transaction should be ‘failed’. If that’s true then why the freeze?

Your help and insight regarding this issue is much needed and appreciated.

Thanks,

Luay