poiuytrez / AndroidInAppBilling

Android App Billing plugin for Cordova
173 stars 144 forks source link

purchased and showitem #109

Open cyrusonline opened 8 years ago

cyrusonline commented 8 years ago

I am new in programming, could somebody show me how to edit the code such that

when somebody purchased , the corresponding item shown (e.g. button or picture)

Thanks

driannaude commented 8 years ago

You can use the refreshPurchases() method to force retrieving a list of owned products from the app store. From the documentation:

The plugin retrieve the list of owned products from Google Play during the initialisation and cache the it internally, the getPurchase method returns the local copy of this list. If for some reason you have to force refresh the list of the owned products, use the refreshPurchases method.

inappbilling.refreshPurchases(success, fail);

The parameters are exactly the same, the success callback provides also an array with the owned products.

On success you will be returned an array of owned products. Compare this against your products in your view and apply the appropriate logic to show/change state. :smile_cat:

cyrusonline commented 8 years ago

thanks, I understand your algorithm, but as I am an newbie, could you please teach me(sample code) how to check whether the product is bought by comparing with the return json object of "refreshPurchase". I found a lot in stackflow, but they usually talk about hasownproperty but not the value. For example I want to check whether product id="apple" purchased.