Solved - mobileStoreRestorePurchases on Google Play

The place to discuss anything and everything about running your LiveCode on Android

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
KimD
Posts: 203
Joined: Wed Jul 08, 2015 5:51 am
Location: Wellington, New Zealand

Solved - mobileStoreRestorePurchases on Google Play

Post by KimD » Thu Apr 06, 2017 9:07 am

I'm trying to implement a non-consumable in-app purchase.

Purchase sequence:
mobileStoreEnablePurchaseUpdates
mobileStoreSetProductType "com.runrev.sampleapp.nonconsumable", "inapp"
mobileStoreMakePurchase "com.runrev.sampleapp.nonconsumable", "1", "This belongs to me"

The purchase sequence successfully triggers a "purchaseStateUpdate" event, with a pState of "paymentReceived".

Restore sequence:
mobileStoreEnablePurchaseUpdates
mobileStoreRestorePurchases

The restore sequence does NOT trigger a "purchaseStateUpdate" event.

Because of this, I'm running into problems with two use cases:
1) User installs app, user purchases non-consumable, user deletes app, user re-installs app. The user then cannot re-purchase the non-consumable, as they get an "alreadyEntitled" pState.
2) User installs app on one device, user purchases non-consumable, user installs app on 2nd device. I thought that in this situation the user should be automatically entitled to receive the non-consumable on the 2nd device.

I realise that a work around would be to treat a "alreadyEntitled" pState in the same way that I treat a "paymentReceived" pState, but it does leave the user having to re-push the purchase button - without knowing that they will NOT be charged - which if I was the user I'd probably be too annoyed to do.

Note - I have read the following in the dictionary entry for mobileStoreRestorePurchases -
Consumable products cannot be restored, except when interacting with the Google Play Store in-app purchasing API... Which left me with some existential questions about this command ;-)

Any advice on how to get mobileStoreRestorePurchases to work for non-consumables on Google Play?

Thanks in advance

Kim
Last edited by KimD on Sat Apr 08, 2017 4:51 am, edited 1 time in total.

LiveCode_Panos
Livecode Staff Member
Livecode Staff Member
Posts: 671
Joined: Fri Feb 06, 2015 4:03 pm

Re: mobileStoreRestorePurchases - on Google Play

Post by LiveCode_Panos » Thu Apr 06, 2017 9:53 am

Hi Kim,

Calling "mobileStoreRestorePurchases" triggers a "purchaseStateUpdate" msg with status="restored". So you have to handle this case in the "purchaseStateUpdate" handler. The user will not be asked to re-purchase the item in this case.

See this lesson for more details:

http://lessons.livecode.com/m/4069/l/18 ... play-store

Best regards,
Panos
--

KimD
Posts: 203
Joined: Wed Jul 08, 2015 5:51 am
Location: Wellington, New Zealand

Re: mobileStoreRestorePurchases - on Google Play

Post by KimD » Fri Apr 07, 2017 5:26 am

Thanks Panos

I've spent a few hours playing around with this. What I'm seeing is that:

mobileStoreRestorePurchases works if it is called in a script that is located on a button.

mobileStoreRestorePurchases does not work if it is called in a script that is located in the OpenCard handler of my first card. I had been trying to implement it this way so that my app would automatically restore purchases.

In both cases my code was -
if environment() is "mobile" then
mobileStoreEnablePurchaseUpdates
mobileStoreRestorePurchases
end if

Regards

Kim

LC 8.1.2 rc3 on Windows 7.

LiveCode_Panos
Livecode Staff Member
Livecode Staff Member
Posts: 671
Joined: Fri Feb 06, 2015 4:03 pm

Re: mobileStoreRestorePurchases - on Google Play

Post by LiveCode_Panos » Fri Apr 07, 2017 6:58 pm

Hi Kim,

hmm interesting. What happens if you try this:

Code: Select all

on preopenstack
  if environment() is "mobile" then 
    mobileStoreEnablePurchaseUpdates
    send "restorePurchases" to me in 100 milliseconds
  end if
end preopenstack

on restorePurchases
  mobileStoreRestorePurchases
end restorePurchases
Best,
Panos
--

KimD
Posts: 203
Joined: Wed Jul 08, 2015 5:51 am
Location: Wellington, New Zealand

Re: Solved - mobileStoreRestorePurchases on Google Play

Post by KimD » Sat Apr 08, 2017 4:54 am

Thanks Panos

Getting it to execute outside of the OpenCard handler makes all of the difference.

On OpenCard // the first card in my stack
if environment() is "mobile" then
mobileStoreEnablePurchaseUpdates
mobileStoreRestorePurchases // Does NOT work
send "mobileStoreRestorePurchases" to me in 100 milliseconds // Does work
end if
end OpenCard

Weird

Kim

Post Reply

Return to “Android Deployment”