Added 2nd Restore button causes all Restores to activate. 1st Restore Button worked

WHEN I ADDED COMMENTED PART BELOW THE FIRST RESTORE BUTTON TO BE TOUCHED WILL TRIGGER BOTH RESTORES.  IT DOESNT MATTER IN WHICH ORDER.  WHEN RESTORE WORKED CORRECTLY I DIDNT INCLUDE “(trans.productIdentifier == productID[1])”  BUT I ADDED IT LATER WHEN I ADDED THE 2ND RESTORE AND I FIGURED THAT WOULD DIFFERENTIATE BETWEEN RESTORES.  I JUST COPIED THE CODE FROM “(trans.state == “purchased”)” WHICH HAS (trans.productIdentifier == productID[1]) AND productID[2].  THOSE WORK  PERFECTLY.

<lua>

function transactionCallback(e)

    local trans = e.transaction;

    

    

    if (trans.state == “purchased”) then

        if (trans.productIdentifier == productID[1]) then --item1

            callTimer()

            myIAP1:store(‘iap20’,4)

            myIAP1:save()

            native.showAlert(“Thank You!” , “IAP Purchased.” , {“OK”}, none);

        

        elseif (trans.productIdentifier == productID[2]) then --item2

                myIAP2:store(‘iap21’,4)

                myIAP2:save()

                hintpage()

                native.showAlert(“Thank You!” , “IAP Purchased.” , {“OK”}, none);

            print (“success buying product 2! Give the user the item here or in the callback (see comments above)”);

        end   

         

    elseif (trans.state == “restored”) then    

        if (trans.productIdentifier == productID[1]) then

        callTimer()

        myIAP1:store(‘iap20’,4)

        myIAP1:save()

        native.showAlert(“Thank You!” , “IAP Restored.” , {“OK”}, none);

        

question repeated here:

        --WHEN I ADDED COMMENTED PART BELOW THE FIRST RESTORE BUTTON TO BE TOUCHED WILL TRIGGER BOTH RESTORES (above and below).

        --IT DOESNT MATTER IN WHICH ORDER.  WHEN 1 RESTORE WORKED CORRECTLY I DIDNT INCLUDE “(trans.productIdentifier == productID[1])” (above)

        --BUT I ADDED IT LATER WHEN I ADDED THE 2ND RESTORE(below commented part) AND I FIGURED THAT WOULD DIFFERENTIATE BETWEEN RESTORES.  I JUST COPIED

        --THE CODE FROM “(trans.state == “purchased”)” WHICH HAS (trans.productIdentifier == productID[1]) AND productID[2].  THOSE WORK  PERFECTLY

    --[[    

        elseif (trans.productIdentifier == productID[2]) then

        

                myIAP2:store(‘iap21’,4)

                myIAP2:save()

                hintpage()

                native.showAlert(“Thank You!” , “IAP Restored.” , {“OK”}, none);

            --]]    

        end

        

        

    elseif (trans.state == “cancelled”) then

        

        print (“player cancelled; you may want to show an alert here”);

        native.showAlert(“Oops!” , “Cancelled.” , {“Dismiss”}, none);

        

    elseif (trans.state == “failed”) then

        

        print (“transaction failed”);

        native.showAlert(“Oops!” , “Please check your internet connection and try again.” , {“Dismiss”}, none);

        

    end

end    

It’s a bit hard to follow the issue you’re describing.  It sounds like you’ve added two ‘restore’ buttons, one for each of your two products, and you’re expecting to be able to restore each product separately?  Unfortunately that’s not how restore works.  store.restore() doesn’t take any arguments, and it will restore all of the products that user has previously purchased.  Your callback function will get a callback for each of the restored products.

Also, please don’t use all caps in the future.  It makes it very hard to read.  See http://www.coronalabs.com/blog/2013/04/02/corona-forum-rules-and-guidelines/  #11)

  • Andrew

Thank you, yes I thought I could restore them separately.  So if it restores all the products the user has purchased, how do I set up the code inside of.

elseif (trans.state == “restored”) then    

end

Originally I had-

    elseif (trans.state == “restored”) then    

       callTimer()

        myIAP1:store(‘iap20’,4)

        myIAP1:save()

        native.showAlert(“Thank You!” , “IAP Restored.” , {“OK”}, none);

 

-which worked.  How should I set up the code now so it knows to restore products that user has previously purchased?

The way you set up the code in your first post actually looked fine to me.  When you use store.restore(), your transaction callback gets called multiple times, once for each product that is being restored, so you were correctly setting up your code to handle each possible product.  What wasn’t working for you?

  • Andrew

Haha your correct Im confusing myself.  I think it is working fine the way it is knowing that the Restore button Restores all purchases.  Thank you!

It’s a bit hard to follow the issue you’re describing.  It sounds like you’ve added two ‘restore’ buttons, one for each of your two products, and you’re expecting to be able to restore each product separately?  Unfortunately that’s not how restore works.  store.restore() doesn’t take any arguments, and it will restore all of the products that user has previously purchased.  Your callback function will get a callback for each of the restored products.

Also, please don’t use all caps in the future.  It makes it very hard to read.  See http://www.coronalabs.com/blog/2013/04/02/corona-forum-rules-and-guidelines/  #11)

  • Andrew

Thank you, yes I thought I could restore them separately.  So if it restores all the products the user has purchased, how do I set up the code inside of.

elseif (trans.state == “restored”) then    

end

Originally I had-

    elseif (trans.state == “restored”) then    

       callTimer()

        myIAP1:store(‘iap20’,4)

        myIAP1:save()

        native.showAlert(“Thank You!” , “IAP Restored.” , {“OK”}, none);

 

-which worked.  How should I set up the code now so it knows to restore products that user has previously purchased?

The way you set up the code in your first post actually looked fine to me.  When you use store.restore(), your transaction callback gets called multiple times, once for each product that is being restored, so you were correctly setting up your code to handle each possible product.  What wasn’t working for you?

  • Andrew

Haha your correct Im confusing myself.  I think it is working fine the way it is knowing that the Restore button Restores all purchases.  Thank you!