This is the code I use to handle purchasing of the coin packs in my new game.
//********************************************************************************
// void = BuyCoinPack(ui ref as tUI, player ref as tPlayer, coinPackID as integer)
//********************************************************************************
// This function will handle all the buying coins with IAP stuff. I will need to
// sort out the IAP on the Google Play page before I can do too much more with
// this aspect of the game.
//********************************************************************************
Function BuyCoinPack(player ref as tPlayer, coinPackAmounts ref as integer[], iapCoinPackID as integer)
// Local
Local iapStatus as integer
Local finished as integer
Local token as string
// Do the IAP stuff to buy coin pack
` If IAP fails then just exit the function
// 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
EndFunction
Sadly, whenever I try and buy the same coin pack a second time, it tells me I already own the product. It takes a third try to buy it again.
Can anyone offer any advice as to why this isn't working as intended?
Thanks in advance