Page 1 of 1
Issues with Restoring IAPs
Posted: Wed May 17, 2017 5:05 pm
by MrCrussell
Hi all,
I've been messing about trying to get IAPs to work for what felt like forever and now I'm at the final stage, which is trying to get previous purchases to restore properly.
According to the docs, tutorials etc, if I set up a button which triggers the following:
Code: Select all
mobileStoreEnablePurchaseUpdates
mobileStoreRestorePurchases
If I read the docs correctly, this should return a list of ALL prior purchases linked to a user's account and cycle through them one at a time. My problem is that doesn't seem to be happening.
Having tested on a live device, if I tap the button I see the first purchase come through but thereafter nothing, even when I know there are more purchases to deal with.
Do I need to loop through the purchased list to get them all processed, and if so, how do I do it?
TIA
MrC
Re: Issues with Restoring IAPs
Posted: Wed May 17, 2017 7:29 pm
by LiveCode_Panos
Hi MrC,
The command "mobileStoreRestorePurchases" will trigger a callback to the "purchaseStateUpdate" message. The "purchaseStateUpdate" message will be called as many times as the number of **non-consumable** items you have already purchased, each time with a different productID and purchaseID, but always with the same state, "restored".
If you see the first purchase come through but thereafter nothing, I guess that:
- Either you have only one **non-consumable** item to restore (consumable ones are not restored)
- Or in the "purchaseStateUpdate" message, where you handle the pState=restored, you have a call to "mobileStoreDisablePurchaseUpdates". If this is the case, after the first purchase is successfully restored, you no longer get updates from the AppStore, because "mobileStoreDisablePurchaseUpdates" terminates the communication with the AppStore. So you have to call this command (i.e. "mobileStoreDisablePurchaseUpdates") once *all* the purchases are restored.
Hope this helps,
Panos
--
PS: I guess you are on iOS, is that correct? If yes, can someone move this thread to "iOS Deployment"?
Re: Issues with Restoring IAPs
Posted: Thu May 18, 2017 10:07 am
by MrCrussell
Thank Panos, I'll try it out.
This should be in iOS Deployment, apologies.
Re: Issues with Restoring IAPs
Posted: Thu May 18, 2017 10:49 am
by Klaus
Your wish is my command!
Re: Issues with Restoring IAPs
Posted: Thu May 18, 2017 10:52 am
by LiveCode_Panos
Thank you Klaus
Re: Issues with Restoring IAPs
Posted: Wed May 24, 2017 7:35 pm
by MrCrussell
So, I've picked through the code and I even removed any mention of mobileStoreDisablePurchaseUpdates and I'm still seen the same behaviour - every time I call mobileStoreRestorePurchases I get one item only. The items I'm trying to restore are all non-consumable and every time I test I use a new user (to make sure I don't get contaminated results). I've also checked to make sure there are no rogue disablePurchases anywhere .
I'm pretty much about ready to give up and rewrite the project in Swift. Can anyone shed any light on what's going on?
The code for the button triggering the restore is:
Code: Select all
on mouseUp
answer( "Execute Restoring Purchases" )
mobileStoreEnablePurchaseUpdates
mobileStoreRestorePurchases
end mouseUp
and the purchaseState code is stored in the stack script :
Code: Select all
on purchaseStateUpdate pPurchaseID, pProductID, pState
switch pState
case "paymentReceived"
offerPurchasedProduct pProductID
mobileStoreConfirmPurchase pProductID
mobileStoreDisablePurchaseUpdates
// other code removed
break
case "error"
answer "Error occured during purchase handling:" & return & return & mobileStorePurchaseError(pPurchaseID)
mobileStoreDisablePurchaseUpdates
break
case "invalidSKU"
answer "The SKU was invalid"
mobileStoreDisablePurchaseUpdates
break
case "alreadyEntitled"
answer "You already own this module"
mobileStoreDisablePurchaseUpdates
break
case "restored"
offerPurchasedProduct pProductID
mobileStoreConfirmPurchase pProductID
// answer ("restored: " & pProductID)
// mobileStoreDisablePurchaseUpdates
break
case "cancelled"
answer "Purchase cancelled for " && pProductID
mobileStoreDisablePurchaseUpdates
break
end switch
end purchaseStateUpdate
Re: Issues with Restoring IAPs
Posted: Mon May 29, 2017 12:07 pm
by LiveCode_Panos
Hi MrCrussell,
Could it be the case that there is an error in your `offerPurchasedProduct` handler, which causes the execution to stop just after the first IAP is restored?
What happens if you comment out the call to `offerPurchasedProduct`? Do you now get as many callbacks of `purchaseStateUpdate` as the number of IAPs you expect to be restored?
Best,
Panos
--