In App Purchase You've already purchased this but it hasn't been downloaded error.

hi

I trying to add In app purchasing to my game the iap is a consumable. I keep getting  You’ve already purchased this but it hasn’t been downloaded error when I try and buy for a second time.I’ve put my product code in the demo app put it on device ,tested it and it worked so I’m ruling out problems with iap on itunes connect , my test apple profile and provisioning profile . Something must be wrong with my code but I cannot see what , I am calling  store.finishTransaction( transaction );

here’s the code

local inApp = {};
local store = require “store”

– Connect to store at startup, if available.
if store.availableStores.apple then
    print(“Using Apple’s in-app purchase system.”)

elseif store.availableStores.google then
    print(“Using Google’s Android In-App Billing system.”)

else
    print(“In-app purchases is not supported on this system/device.”)
end
local listOfProducts =
{
    --my product id

}

local function productCallback( event )
    print(“showing valid products”, #event.products)
    for i=1, #event.products do
        print(event.products[i].title)    – This is a string.
        print(event.products[i].description)    – This is a string.
        print(event.products[i].price)    – This is a number.
        print(event.products[i].localizedPrice)    – This is a string.
        print(event.products[i].productIdentifier)    – This is a string.
    end

    print(“showing invalidProducts”, #event.invalidProducts)
    for i=1, #event.invalidProducts do
        print(event.invalidProducts[i])
    end
end

if store.canLoadProducts then
    store.loadProducts( listOfProducts, productCallback )
end

–transaction
function appStoretransactionCallback( event )
    local transaction = event.transaction

    if transaction.state == “purchased” then
        print(“Transaction succuessful!”)
        print(“productIdentifier”, transaction.productIdentifier)
        print(“receipt”, transaction.receipt)
       print(“transactionIdentifier”, transaction.identifier)
        print(“date”, transaction.date)
           native.showAlert(“Notice”, “Purchasing .”, { “OK” })

    elseif  transaction.state == “restored” then
        print(“Transaction restored (from previous session)”)
        print(“productIdentifier”, transaction.productIdentifier)
        print(“receipt”, transaction.receipt)
        print(“transactionIdentifier”, transaction.identifier)
        print(“date”, transaction.date)
        print(“originalReceipt”, transaction.originalReceipt)
        print(“originalTransactionIdentifier”, transaction.originalIdentifier)
        print(“originalDate”, transaction.originalDate)

    elseif transaction.state == “cancelled” then
        print(“User cancelled transaction”)

    elseif transaction.state == “failed” then
        print(“Transaction failed, type:”, transaction.errorType, transaction.errorString)

    else
        print(“unknown event”)
    end

    – Once we are done with a transaction, call this to tell the store
    – we are done with the transaction.
    – If you are providing downloadable content, wait to call this until
    – after the download completes.
    store.finishTransaction( transaction )
end

store.init( “apple”, appStoretransactionCallback )

function inApp.buyFromAppStore()
    if store.canMakePurchases then
        store.purchase( listOfProducts )
    else
           print(“Store purchases are not available”)
    end
end

return inApp

would be very grateful if anyone had any ideas whats wrong.

Hi Kerry,

I had the same problem. I had some coins that were a consumable item I purchased them fine initially then I received the same error on a second attempt. When you get this error it could mean the store.finishTransaction() function was never called in the transaction callback…although you look like you do it above, which I did as well.

To fix my problem I call store.init in my main.lua code (essentially early on in app start up). What this does is contact the store immediately and try to download any pending downloads which is the error I was essentially getting. After this change it worked fine.

I hope this helps,

Rick

Hi Kerry,

I had the same problem. I had some coins that were a consumable item I purchased them fine initially then I received the same error on a second attempt. When you get this error it could mean the store.finishTransaction() function was never called in the transaction callback…although you look like you do it above, which I did as well.

To fix my problem I call store.init in my main.lua code (essentially early on in app start up). What this does is contact the store immediately and try to download any pending downloads which is the error I was essentially getting. After this change it worked fine.

I hope this helps,

Rick