Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Commit

Permalink
refactor storeService
Browse files Browse the repository at this point in the history
  • Loading branch information
negue committed May 25, 2015
1 parent f700ef9 commit 76ea0e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
4 changes: 1 addition & 3 deletions scripts/controllers/purchaseCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
habitrpg.controller('PurchaseCtrl',
['$scope', 'StoreService', '$rootScope', 'ApiUrl',
function($scope, store, $rootScope, ApiUrl){
$scope.store = store.getStore();

$scope.buy = function(id){
if($rootScope.isIOS){
alert("In-App-Purchases are currently not available on IOS.");
Expand All @@ -17,7 +15,7 @@ habitrpg.controller('PurchaseCtrl',
}

try{
$scope.store.order(id)
store.getStore().order(id)
.then(function(ex){
// Callback Order started
})
Expand Down
22 changes: 20 additions & 2 deletions scripts/services/storeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,43 @@ function(ApiUrl, $rootScope, User, $ionicPlatform, $timeout){
});
}

$ionicPlatform.ready(function() {
var storeInitialized = false;

function initializeStore()
{
if(w.store){
registerProductAndCallback({
id: "buy.20.gems",
alias: "20 Gems",
type: w.store.CONSUMABLE
});

w.store.ready(function(){
// store is ready :)
});

$timeout(function(){
w.store.refresh();
}, 250);

storeInitialized = true;
}
else
{
console.log("No store available");
}
}

$ionicPlatform.ready(function() {
$timeout(initializeStore, 500);
});

this.getStore = function(){
if(!storeInitialized)
{
initializeStore();
}

return w.store || {};
};
}]);

0 comments on commit 76ea0e5

Please sign in to comment.