Inapp购买消失在Android离子应用程序上

时间:2016-10-18 05:33:17

标签: javascript android angularjs cordova ionic-framework

我正在尝试使用插件cordova-plugin-inapppurchase实施inapp购买产品加载,但产品加载后产品没有显示。

我的错误是什么?

这是我的代码:

<h3 class="inapp_textw" ng-click="loadProducts()" ng-if="!products">Or Inappp purchases</h3>
<h3 class="inapp_textw" ng-repeat="product in products" ng-click="buy(product.productId)">Or Inappp purchases</h3>

JS

var productIds = ["com.domain.example"]; //I have the correct ID

  var spinner = '<ion-spinner icon="dots" class="spinner-stable"></ion-spinner><br/>';

  $scope.loadProducts = function() {

      console.log("loaded inapp products"); // This logs 

    $ionicLoading.show({
      template: spinner + 'Loading...'
    });
    inAppPurchase
      .getProducts(productIds)
      .then(function(products) {
        $ionicLoading.hide();
        $scope.products = products;
      })
      .catch(function(err) {
        $ionicLoading.hide();
        console.log(err);
      });
  };


  $scope.buy = function(productId) {
      console.log("buy clicked");

    $ionicLoading.show({
      template: spinner + 'Acquisto in corso...'
    });
    inAppPurchase
      .buy(productId)
      .then(function(data) {
        console.log(JSON.stringify(data));
        console.log('consuming transactionId: ' + data.transactionId);
        return inAppPurchase.consume(data.type, data.receipt, data.signature);
      })
      .then(function() {
        localStorage.setItem('sold', 'true');
        $ionicLoading.hide();
        if (state == "l2") {
          $state.go("12")
        }
      })
      .catch(function(err) {
        $ionicLoading.hide();
        console.log(err);
      });

  };

  $scope.restore = function() {


    console.log("IT WORKS");


    $ionicLoading.show({
      template: spinner + 'Ripristino degli acquisti in corso...'
    });
    inAppPurchase
      .restorePurchases()
      .then(function(purchases) {
        $ionicLoading.hide();
        console.log(JSON.stringify(purchases));
        localStorage.setItem('sold', 'true');
        $state.go("12")
      })
      .catch(function(err) {
        $ionicLoading.hide();
        console.log(err);
        $ionicPopup.alert({
          title: 'Something went wrong',
          template: 'Check your console log for the error details'
        });
      });
  };

1 个答案:

答案 0 :(得分:0)

您只是在加载产品,这就是它没有出现的原因。

你必须打印它以显示如下。

standalone blastn