Google Play's IAP Auto-Refunds Big Problem

Above, I wrote that on Android, when I receive a ‘finished’ or ‘purchased’ state in the callback, I then call store.finishTransaction. For consumables, it is vital to call store.consumePurchase, or the store will not allow any additional purchases of the same product. However, there must be a delay before calling store.consumePurchse after calling store.finishTransaction or you may end up receiving an error from the server. I use a delay of half a second (timer.performWithDelay(500,…)

I have also inserted some code to consume products in the event of an error within the transaction callback as follows:

--used primarily for android
if (event.transaction.isError) then
    local errorType=tostring(e.transaction.errorType)
    --errorType==6, errorString="Server error, please try again."
    --errorType==7, errorString="Unable to buy item (response: 7: Item Already Owned)"
    if G.platform=="android" and (errorType=="6" or errorType=="7") then
        timer.performWirthDelay(500,function () store.consumePurchase(transaction.productIdentifier) end)

I use G for my global variables and G.platform to "ios" or "android" - you can change to however you check for a specific platform OS.

Also, if may not be necessary to convert the errorType to a string; I just get in the habit of doing this occasionally to avoid runtime errors that occur from data mismatches.
1 Like