Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

angularjs variable (product id) pass to javascript function #110

Closed
cyrusonline opened this issue Mar 8, 2016 · 7 comments
Closed

angularjs variable (product id) pass to javascript function #110

cyrusonline opened this issue Mar 8, 2016 · 7 comments

Comments

@cyrusonline
Copy link

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

@driannaude
Copy link

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.

@cyrusonline
Copy link
Author

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~~~

@driannaude
Copy link

So you would like to know whether the purchase was successful? Or whether an item is already owned?

@cyrusonline
Copy link
Author

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

@driannaude
Copy link

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. 😸

@driannaude
Copy link

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

@cyrusonline
Copy link
Author

close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants