TheGameCreators / AGKRepo

New Home of AGK Source Code for 2024 and Beyond
18 stars 15 forks source link

Resetting a consumable purchase does not work correctly #22

Open TheMadProf opened 1 month ago

TheMadProf commented 1 month ago

My current game has IAP coin packs which the player can buy.

When the player first buys a coin pack, it works fine.

The second time the player tries to buy the same coin pack, it throws up an error stating the player already owns the product.

The third time the player tries to buy the same coin pack, it works fine.

fv-iap-error-pu89

The above image shows the purchase error on every other attempt by the user.

//  Starts the buying process
InAppPurchaseActivate(iapCoinPackID)

Repeat

        iapStatus = GetInAppPurchaseAvailable2(iapCoinPackID)

        Select iapStatus

            //  Cancelled?  The IAP was cancelled by the user
            Case 0:
                //  Break out of loop
                finished = true
            Endcase

            //  IAP Queued
            Case 1:
                Print("IAP in progress..")
            Endcase

            //  IAP In progress
            Case 2:
                Print("IAP in progress..")
            Endcase

            //  IAP Pending
            Case 3:
                Print("IAP in progress..")
            Endcase

            //  IAP Completed
            Case 4:
                //  Award the IAP

                //  Add the relevant amount of coins to the player total
                Inc player.coinTotal, coinPackAmounts[iapCoinPackID - 1]

                //  Break out of loop
                finished = true

                //  Resets the purchase
                token = GetInAppPurchaseToken(iapCoinPackID)

                InAppPurchaseResetPurchase(token)

            Endcase

        EndSelect

        sync()

Until finished = true

The above code handles the purchase and resetting of the products. I have tried several different things to try and resolve the issue, moving the InAppPurchaseResetPurchase(token) around and putting it in a loop.

Edit< I forgot to say this is an issue on Android

SilverHawk731 commented 3 weeks ago

Do you attempt to place another purchase immediately after the previous one? If so, does this error also appear if you wait a while (a few seconds up to a minute) before starting a second purchase?

TheMadProf commented 3 weeks ago

The problem persists even if the purchases are days apart from each other.