store.consumePurchase() problem

I got in app purchases to mostly work both on iOS and android. I sell coins in my app. I can buy the coins successfully one time but can’t for a second time. 

event.transaction.state

 returns 

failed

 when I try to buy it the second time. For iOS first time is successful but second time i get the message you already purchased this but it hasn’t been downloaded.

I want to user to be able to buy more coins right away after buying their first set. So here is what I did. 

local function transactionCallback( event ) print("In transactionCallback", event.transaction.state) local transaction = event.transaction local tstate = event.transaction.state if tstate == "purchased" then if transaction.productIdentifier == "com.mygame.item1" then --increment quality of bought item store.consumePurchase({"com.mygame.item1"}, transactionCallback)

This doesn’t work. I still can’t buy for the second time. Im trying to consumePurchase immediately after it is bought. That is why i put it inside of tstate == purchased

Secondly, i think store.consumePurchase() is only for google IAP v3. How can I do this with apple?

Make sure your IAP for coins is “consumable” (for Apple) or “Unmanaged Product” (for Google).

AFAIR if you’re using you must consume purchase to buy it again, but this only applies to Google v3.

This blog posts http://coronalabs.com/blog/2013/09/03/tutorial-understanding-in-app-purchases/ wraps IAP topic pretty well.

Hi, yes they are consumable and unmanaged. I still can’t buy it for the second time. 

I got it working for google by calling it after finishTransaction. But what about apple. I am still getting the same error.

Try:

store.consumePurchase( “com.mygame.item1”, transactionCallback)

If that doesn’t work, try putting it inside a timer:

timer.performWithDelay(10, function() store.consumePurchase( “com.mygame.item1”, transactionCallback); end )

Rob

Hi Rob, i got it working for google but not for ios. I am getting the error you already purchased this but it hasn’t been downloaded the second time i try to buy it. 

Apple does not support consumePurchase.  For Apple you should be able to purchase and unmanaged/consumable product immediately without any extra steps.

Rob

Make sure your IAP for coins is “consumable” (for Apple) or “Unmanaged Product” (for Google).

AFAIR if you’re using you must consume purchase to buy it again, but this only applies to Google v3.

This blog posts http://coronalabs.com/blog/2013/09/03/tutorial-understanding-in-app-purchases/ wraps IAP topic pretty well.

Hi, yes they are consumable and unmanaged. I still can’t buy it for the second time. 

I got it working for google by calling it after finishTransaction. But what about apple. I am still getting the same error.

Try:

store.consumePurchase( “com.mygame.item1”, transactionCallback)

If that doesn’t work, try putting it inside a timer:

timer.performWithDelay(10, function() store.consumePurchase( “com.mygame.item1”, transactionCallback); end )

Rob

Hi Rob, i got it working for google but not for ios. I am getting the error you already purchased this but it hasn’t been downloaded the second time i try to buy it. 

Apple does not support consumePurchase.  For Apple you should be able to purchase and unmanaged/consumable product immediately without any extra steps.

Rob