anjlab / android-inapp-billing-v3

A lightweight implementation of Android In-app Billing Version 3
Other
2.2k stars 536 forks source link

Question: how can I get already owned purchase ? #228

Open CyrilNb opened 7 years ago

CyrilNb commented 7 years ago

Hi,

It's not totally clear on how to check if a user owns a product. I mean, I implement the way to buy a product by calling "bp.purchase(productID)" in my app but then when I restarted the app, It should have check at the beginning if "productID" is already owned, and then do something (which is set up a new layout without any ads on it).

I used the method billingProcessor.isPurchased("productID") in my oncreate method and then set my layout without ads if boolean returned is true.

But it's not working. Is there something I missed ? How do you guys retrieve a owned product ?

Ashish-Bansal commented 7 years ago

Once billing processor gets initialized, you can check it like this :

TransactionDetails transactionDetails = billingProcessor.getPurchaseTransactionDetails(productId);
if (transactionDetails != null) {
    //Already purchased
    //You may save this as boolean in the SharedPreferences.
}
CyrilNb commented 7 years ago

Thanks, I'll try this out.

nguyencongbinh commented 7 years ago

@Ashish-Bansal

Your above code can use for case no internet?

CyrilNb commented 7 years ago

The above code worked for me with internet access. I guess .getPurchaseTransactionDetails retrieves information from internet.

Ashish-Bansal commented 7 years ago

@nguyencongbinh I'm not sure about that but it should work without internet too as this library is just acting as a wrapper and Google Play Services most probably would be caching/storing purchase transaction details.

kevalpatel2106 commented 7 years ago

@CyrilNb Did you tried this solution? #244

It worked for me.

ameenmaheen commented 7 years ago

@Ashish-Bansal is there any way to check the expiry date of the subscription ?

4nku5h commented 4 years ago

TransactionDetails transactionDetails = billingProcessor.getPurchaseTransactionDetails(productId); will this method return false for canceled Transactions?????