Google IAP v3, crash while calling store.consumePurchase()

Hello, I’m a Corona SDK starter.

We are working on Google IAP v3, but fail to consumePurchase() our product.

Our program works as follow,

local store = require("plugin.google.iap.v3") local ourTrans = nil store.init(function(event) ourTrans = event.transaction end) ------------------- while purchase -------------------------- if store.target == "google" then timer.performWithDelay(100, function() store.purchase("our\_product\_identifier") end) repeat coroutine.yield() until ourTrans ~= nil if ourTrans.state == "purchased" then local consumeTrans = nil store.consumePurchase({ourTrans.productIdentifier}, function(event) consumeTrans = event.transaction end) repeat coroutine.yield() until consumeTrans ~= nil end store.finishTransaction(ourTransaction) end

We can buy our product and receive the bill send from google play.

However, our app crash immediately when calling consumePurchase().

The product is “unmanaged type” which can be consumed, I think.

Is our work flow correct?

  1. store.init()   (only once)

  2. when purchase come,  store.purchase()

  3. if purchase succeed, store.consumePurchase({productIdentifier return by purchase event})

  4. store.finishTransaction() after all the calls finishe

Has anyone got the same problem before?

Thanks.

You need to be a “basic” or above user to have access to IAP.

http://coronalabs.com/products/corona-sdk/faqs/

Thanks, Alex. But I already use a pro version of Corona.

By the way, the crash problem is gone although I don’t know why…

And I got some other questions,

  1. consumePurchase() do not execute the function I pass in the second argument. Instead, it call the listener in store.init().

    What is the actually functionality of the second argument?

  1. If I call consumePurchase() as soon as the purchase finish(we get a transaction state like “purchased”), corona won’t invoke any callback just like we pass an invalid identifier to it. However, the consumePurchase() still work! We can buy the product again.

I’m confusing what really happen here?

Hi @demon7893612,

Did you write this unusual code using coroutines and repeat and so forth, or borrow it from somewhere? I cannot recommend that you try to implement IAP in this fashion, as it may cause other issues and listener callback problems. It’s better if you structure your code based on more common proven examples, including those found in our documentation.

Best regards,

Brent

I’m also having issues with this (with consumable IAPs). I call consumePurchase() immediately after the product has been successfully purchased (so the user can keep buying it over and over). I call consumePurchase() in my transaction listener when I get the “purchased” phase for an IAP. Lots of weirdness with crashes and people reporting that they got the IAP multiple times (so the “purchased” phase happened like 5 times for 1 purchase and they got 5 times the amount of in-game currency).

Try putting your call to consumePurchase() inside a timer.  You might also want to try calling the store.finishTransaction( transaction ) before you can consumePurchase() to make sure you’re clearing out the store’s state correctly.

Rob

You need to be a “basic” or above user to have access to IAP.

http://coronalabs.com/products/corona-sdk/faqs/

Thanks, Alex. But I already use a pro version of Corona.

By the way, the crash problem is gone although I don’t know why…

And I got some other questions,

  1. consumePurchase() do not execute the function I pass in the second argument. Instead, it call the listener in store.init().

    What is the actually functionality of the second argument?

  1. If I call consumePurchase() as soon as the purchase finish(we get a transaction state like “purchased”), corona won’t invoke any callback just like we pass an invalid identifier to it. However, the consumePurchase() still work! We can buy the product again.

I’m confusing what really happen here?

Hi @demon7893612,

Did you write this unusual code using coroutines and repeat and so forth, or borrow it from somewhere? I cannot recommend that you try to implement IAP in this fashion, as it may cause other issues and listener callback problems. It’s better if you structure your code based on more common proven examples, including those found in our documentation.

Best regards,

Brent

I’m also having issues with this (with consumable IAPs). I call consumePurchase() immediately after the product has been successfully purchased (so the user can keep buying it over and over). I call consumePurchase() in my transaction listener when I get the “purchased” phase for an IAP. Lots of weirdness with crashes and people reporting that they got the IAP multiple times (so the “purchased” phase happened like 5 times for 1 purchase and they got 5 times the amount of in-game currency).

Try putting your call to consumePurchase() inside a timer.  You might also want to try calling the store.finishTransaction( transaction ) before you can consumePurchase() to make sure you’re clearing out the store’s state correctly.

Rob