Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Sandbox mode, Optionally add callbacks
- store.inappbilling.setTestMode(function () {
- //successfully loaded test data
- console.log("Success");
- },
- function () {
- //failed to load test data
- console.log("Failed");
- });
- store.register({
- id: productId,
- type: store.PAID_SUBSCRIPTION
- });
- // Listen to the 'updated' event for individual product
- store.when(productId).updated(function (p) {
- $ionicLoading.hide();
- });
- // Initiate a purchase
- store.order(productId);
- // When the purchase is approved, show an alert
- store.when(productId).approved(function (order) {
- Store.subscribeWindows(month, order);
- order.finish();
- });
- // When the purchase is approved, show an alert
- store.when(productId).cancelled(function (order) {
- $ionicPopup.alert({
- title: 'Subscribe was cancelled!',
- template: 'Try again!'
- });
- order.finish();
- });
- // When the store is ready all products are loaded and in their "final" state.
- store.ready(function () {
- console.log("The store is ready");
- });
- // Deal with errors:
- store.error(function (err) {
- $ionicLoading.hide();
- $ionicPopup.alert({
- title: 'Something went wrong',
- template: err.message
- });
- })
- // This will contact the server to check all registered products validity and ownership status.
- // It's mostly fine to do this only at application startup but you can refresh it more often.
- store.refresh();
Add Comment
Please, Sign In to add comment