我正在使用离子框架用于Android应用程序,现在我想集成in-App-Purchase。所以,我按照编写了代码。但是当我尝试加载产品时,它会给app.js中的代码提供错误。
angular.module('starter.controllers', []).controller('purchaseCtrl', function($scope,$rootScope,$http,$state,$ionicPlatform, $ionicLoading, $ionicPopup) {
var productIds = ['productId']; // <- Add your product Ids here
var spinner = '<ion-spinner icon="dots" class="spinner-stable"></ion-spinner><br/>';
$ionicLoading.show({ template: spinner + 'Loading Products...' });
$scope.loadProducts = function () {
$ionicLoading.show({ template: spinner + 'Loading Products...' });
inAppPurchase
.getProducts(productIds)
.then(function (products) {
$ionicLoading.hide();
$scope.products = products;
})
.catch(function (err) {
$ionicLoading.hide();
console.log(err);
});
};
$scope.buy = function (productId) {
$ionicLoading.show({ template: spinner + 'Purchasing...' });
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 () {
var alertPopup = $ionicPopup.alert({
title: 'Purchase was successful!',
template: 'Check your console log for the transaction data'
});
console.log('consume done!');
$ionicLoading.hide();
})
.catch(function (err) {
$ionicLoading.hide();
console.log(err);
$ionicPopup.alert({
title: 'Something went wrong',
template: 'Check your console log for the error details'
});
});
};
});
错误是“inAppPurchase not define”。有谁可以帮助我。
答案 0 :(得分:1)
实际上cordova插件没有正确添加。所以,我只是删除并再次添加它。最后它的工作:-)