Closed cyrusonline closed 8 years ago
Hey @cyrusonline, I think i understand your request, you want the product ID to be dynamic, rather than a hardcoded string? in that case you can probably pass it down the scope method that's attached to your view user action, i.e.:
<!-- ng-repeat example -->
<button ng-click="buyThisItem(item.productID)" ng-repeat="item in storeItems">Buy Now</button>
<!-- Just as a string example -->
<button ng-click="buyThisItem('product.id.here')">Buy Now</button>
// in your controller
$scope.buyThisItem = function(productId){
inappbilling.buy(successHandler, errorHandler,productId);
}
I would recommend you generate your list of available products from inappbilling.getAvailableProducts() [see here] and also cross compare with your owned products if they are non-consumable using inappbilling.refreshPurchases() [see here].
It will help avoid so many errors that pertain to state with the products/store.
Thank you @driannaude for your reply, do you also know
how to let the page check whether the item(e.g. "infinte_gas") get purchased and then show the purchased item(e.g. picture or mp3 download button) Thanks~~~
So you would like to know whether the purchase was successful? Or whether an item is already owned?
The later one. I want to create a list page, after clicking a specific item, then go to another page, in this page if the item is already purchased , hide the buy button and show the item(e.g. download link). otherwise, if not purchased, show the buy button only
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:
Also, as per request on some of your other threads, please close this topic if your initial question was answered, we can continue this discussion at #109, which relates to your second question in this thread
close
i am using angularjs to build an app, however, i cannot figure out how to pass {{product_id}} to the javascript function of this plugin.
So, i hope instead of purchasing gas function buy(){ // make the purchase inappbilling.buy(successHandler, errorHandler,"gas");
we can pass the variable {{product_id}} into the above function function buy(item){ // make the purchase inappbilling.buy(successHandler, errorHandler,item);
Thanks