In-App Purchase Consumable Product Error ( You Have Already Purchased… )

I’m trying to make an update to my application. Before iOS6 everything was fine. But now, I face with this problem:

1 . I buy a product. ( Sandbox mode, consumable product )
2 . Everything works correctly
3 . Then I try to buy the same product again. It gives me this massage :

“You’ve already purchased this but it hasn’t been downloaded. Tap OK to download it now. [Environment : Sandbox]”

After that, if I click to ok and tap to buy it, store returns some other transactions as purchased.

Note that, I use store.finishtransaction() function after all pruchases. I hope someone knows how to deal with this.

I also have this error : When I open the app, store.init() function is called and I recieve some reciepts from app store. They all are purchased products

 

Dogancan

Hi there,

I noticed you mentioned that you’re calling store.finishTransaction(), which was my first thought of what would probably causing this issue.  Just to check, are you calling it from within your transaction callback listener (the right place), or perhaps are you calling it immediately after you call store.purchase()?

It would be helpful if you posted the code from your transaction listener so we can see if there are any issues there.

  • Andrew

function transactionCallback( event )

    print("transactionCallback: Received event ", event.transaction.state)

    gotAnswered = 0

    verified = 0

    verify( event )

    local waiter

    function waiter()

        if gotAnswered == 1 then

            if event.transaction.state == “purchased” and verified == 1 then

                print(“transactionID”, event.transaction.productIdentifier )

                 …do stuff here…

            elseif  event.transaction.state == “restored” and verified == 1 then

                print( “restored” )

                 …do stuff here…

           elseif event.transaction.state == “cancelled” then

            print( “cancelled” )

                 …do stuff here…

           elseif event.transaction.state == “failed” then        

                 …do stuff here…

           elseif ( event.transaction.state == “purchased” or event.transaction.state == “restored” ) and verified == 0 and false then

                 print( “Unauthorized transaction” )

                 …do stuff here…

           else

                print(“unknown state”)

                 …do stuff here…

           end

            print( “Finishing transaction.” )

            store.finishTransaction( event.transaction )

            print( “Finished transaction.” )

            gotAnswered = 0

            verified = 0

            Runtime:removeEventListener( “enterFrame”, waiter )

        end

    end

    Runtime:addEventListener( “enterFrame”, waiter )

end

Here is my code segment… waiter() function is a function which checks transaction reciept through my own server from appstore. I’m absolutely sure that it works %100. To communucate with server in an asynchronous way, I have a waiter function in enterframe. So basicaly, when I recieve a transaction, I send reciept to my server, check it, get my response as verified (1/0). Then I do what needed to be done. I dont know what is wrong. And thats makes me crazy. Since I used this transactioncallback function in other applications. I suspect that there is something wrong with sandbox mode.

Hmm, nothing about that looks wrong to me.  (Although as a separate note, you might want to be careful with the scope of your variables.  Both gotAnswered and verified are global, which means if you use those names elsewhere in your code, you may run into surprising problems.)

You might be right that something is off with the sandbox environment at the moment – I just tested a purchase myself (which was working fine last week), and now I’m getting a strange, circular authentication cycle that keeps informing me I’m in sandbox mode but doesn’t move forward with the transaction.

I’m going to try again in a day or two and see if anything changes.

  • Andrew

Nevermind, the reason for my authentication issue was because I had inadvertently done something that deactivated my test account, which I’ve fixed.  So as far as I can tell, the sandbox environment is working fine.  (I’m able to do multiple purchases in a row of the same product without any issue.)

The only thing I can think of, which seems unlikely, is that in your verify function, you’re somehow accidentally changing the event table such that, when finishTransaction is called, it no longer works.

This forum post also has some ideas for potentially fixing it: http://stackoverflow.com/questions/2474663/how-to-skip-the-alert-youve-already-purchased-this-but-it-hasnt-been-download

  • Andrew

Hi there,

I noticed you mentioned that you’re calling store.finishTransaction(), which was my first thought of what would probably causing this issue.  Just to check, are you calling it from within your transaction callback listener (the right place), or perhaps are you calling it immediately after you call store.purchase()?

It would be helpful if you posted the code from your transaction listener so we can see if there are any issues there.

  • Andrew

function transactionCallback( event )

    print("transactionCallback: Received event ", event.transaction.state)

    gotAnswered = 0

    verified = 0

    verify( event )

    local waiter

    function waiter()

        if gotAnswered == 1 then

            if event.transaction.state == “purchased” and verified == 1 then

                print(“transactionID”, event.transaction.productIdentifier )

                 …do stuff here…

            elseif  event.transaction.state == “restored” and verified == 1 then

                print( “restored” )

                 …do stuff here…

           elseif event.transaction.state == “cancelled” then

            print( “cancelled” )

                 …do stuff here…

           elseif event.transaction.state == “failed” then        

                 …do stuff here…

           elseif ( event.transaction.state == “purchased” or event.transaction.state == “restored” ) and verified == 0 and false then

                 print( “Unauthorized transaction” )

                 …do stuff here…

           else

                print(“unknown state”)

                 …do stuff here…

           end

            print( “Finishing transaction.” )

            store.finishTransaction( event.transaction )

            print( “Finished transaction.” )

            gotAnswered = 0

            verified = 0

            Runtime:removeEventListener( “enterFrame”, waiter )

        end

    end

    Runtime:addEventListener( “enterFrame”, waiter )

end

Here is my code segment… waiter() function is a function which checks transaction reciept through my own server from appstore. I’m absolutely sure that it works %100. To communucate with server in an asynchronous way, I have a waiter function in enterframe. So basicaly, when I recieve a transaction, I send reciept to my server, check it, get my response as verified (1/0). Then I do what needed to be done. I dont know what is wrong. And thats makes me crazy. Since I used this transactioncallback function in other applications. I suspect that there is something wrong with sandbox mode.

Hmm, nothing about that looks wrong to me.  (Although as a separate note, you might want to be careful with the scope of your variables.  Both gotAnswered and verified are global, which means if you use those names elsewhere in your code, you may run into surprising problems.)

You might be right that something is off with the sandbox environment at the moment – I just tested a purchase myself (which was working fine last week), and now I’m getting a strange, circular authentication cycle that keeps informing me I’m in sandbox mode but doesn’t move forward with the transaction.

I’m going to try again in a day or two and see if anything changes.

  • Andrew

Nevermind, the reason for my authentication issue was because I had inadvertently done something that deactivated my test account, which I’ve fixed.  So as far as I can tell, the sandbox environment is working fine.  (I’m able to do multiple purchases in a row of the same product without any issue.)

The only thing I can think of, which seems unlikely, is that in your verify function, you’re somehow accidentally changing the event table such that, when finishTransaction is called, it no longer works.

This forum post also has some ideas for potentially fixing it: http://stackoverflow.com/questions/2474663/how-to-skip-the-alert-youve-already-purchased-this-but-it-hasnt-been-download

  • Andrew