Closed vahidvdn closed 4 years ago
Or even for checking the status of subscription (to see if it's not expired)
Hey @vahidvdn , the correct way to get the purchases is to call restorePurchases()
. getPurchases
is something specific to android so not a good idea to be exposed if there isn't an alternative for iOS.
As for subscription validation you have getStoreReceipt
for iOS and the receipt for android is included in every transaction (including the restored ones).
@PeterStaev I'm still a bit confused. As I know restorePurchases()
method is for refunding the purchase (giving back the money). Isn't it?
What is the relation between refunding and the thing I want to do? (The thing I want to know, the status of the purchase, if the user reinstalls the app which leads the locally saved data to get removed.)
@vahidvdn you are wrong, it has nothing to do refunding. This is used to get the transactions for all not-consumed purchases for the current user. This is usually used when the user changes devices, or reinstalling the app (assuming you store your purchase flags in Local Settings). This triggers the transactionCompleted event so you can restore the purchase flags in the Local Settings.
And actually if you have searched the repo for the function you would even see that the android implementation for restorePurchases
uses internally the getPurchases
method 😃
@PeterStaev Thank you for detailed descriptions. Now I understood the solution.
Let me sum up the scenario. When the app gets opened, first I call restorePurchases
to set up my local storage. (As I call this method, the transactionUpdatedEvent
get fired and I can determine the state of my local storage and set signed token in order to verify the purchase in the server later. As I remember it's called dataSignature
in Transaction
type )
Then based on my local storage value, I decide to show the product list to the user or send my request to get the data. (And in server, before returning data, I should request to Google Play servers in orderr to verify the purchase)
Is it true?
Seems correct 👍
Hi @PeterStaev
Sorry for the pinging. Why should we pass the product ids to the init
method? Maybe they are not static and we add more products from google play developer console.
@vahidvdn , both iOS and Android API require you to send the IDs of the in-app products you want to load. So even if init
doesn't have the array, getProducts
will have to have it. So you can't really add a product w/o changing your code and adding the product there.
And there are other method of communication, but to post an unrelated comment in GH 😄
As you know, there is a
getPurchases
method to check if a product has already purchased or not. For example if the app is removed by the user, we can use this method to ensure that whether the product has already purchased or not. Or is there any other method to do this?