Produkte werden direkt vom Store abgerufen

This commit is contained in:
Carsten Hilmer 2016-02-02 01:13:11 +01:00
parent 40f83058b2
commit 89e8dde72c
3 changed files with 185 additions and 68 deletions

View File

@ -60,15 +60,6 @@ angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter
function successHandler (result) { function successHandler (result) {
/*
var strResult = "";
if(typeof result === 'object') {
strResult = JSON.stringify(result);
} else {
strResult = result;
}
alert("SUCCESS: \r\n"+strResult );
*/
$rootScope.storeinit=1; $rootScope.storeinit=1;
} }

View File

@ -8,6 +8,28 @@ angular.module('starter.controllers', [])
$scope.items=[]; $scope.items=[];
$scope.item=[]; $scope.item=[];
$scope.producitems=[];
$scope.rosen1titel="";
$scope.rosen1preis="";
$scope.rosen1beschreibung="";
$scope.rosen3titel="";
$scope.rosen3preis="";
$scope.rosen3beschreibung="";
$scope.rosen9titel="";
$scope.rosen9preis="";
$scope.rosen9beschreibung="";
$scope.flateraterosentitel="";
$scope.flateraterosenpreis="";
$scope.flateraterosenbeschreibung="";
$scope.showrosen = false;
$scope.showflatrate = true;
$scope.show = function() { $scope.show = function() {
$ionicLoading.show({ $ionicLoading.show({
@ -33,10 +55,145 @@ $scope.show = function() {
}; };
/*
* Produkt-Details abrufen START
*/
function getProducts(){
inappbilling.getProductDetails(successProducts, errorProducts,["rosenflatrate","9xrose","3xrose","1xrose"]);
}
function successProducts (result) {
//alert(JSON.stringify(result));
$scope.producitems = [
angular.fromJson(result[0]),
angular.fromJson(result[1]),
angular.fromJson(result[2]),
angular.fromJson(result[3])
];
$scope.producitems[0].title=$scope.producitems[0].title.replace("(Wolle Rosen kaufen)", "");
$scope.producitems[1].title=$scope.producitems[1].title.replace("(Wolle Rosen kaufen)", "");
$scope.producitems[2].title=$scope.producitems[2].title.replace("(Wolle Rosen kaufen)", "");
$scope.producitems[3].title=$scope.producitems[3].title.replace("(Wolle Rosen kaufen)", "");
$scope.rosen1titel=$scope.producitems[2].title;
$scope.rosen1preis=$scope.producitems[2].price;
$scope.rosen1beschreibung=$scope.producitems[2].description;
$scope.rosen3titel=$scope.producitems[1].title;
$scope.rosen3preis=$scope.producitems[1].price;
$scope.rosen3beschreibung=$scope.producitems[1].description;
$scope.rosen9titel=$scope.producitems[0].title;
$scope.rosen9preis=$scope.producitems[0].price;
$scope.rosen9beschreibung=$scope.producitems[0].description;
$scope.flateraterosentitel=$scope.producitems[3].title;
$scope.flateraterosenpreis=$scope.producitems[3].price;
$scope.flateraterosenbeschreibung=$scope.producitems[3].description;
$scope.showrosen = true;
$timeout(function(){
$scope.showrosen = true;
}, 500);
}
function errorProducts (result) {
var strResult = "";
if(typeof result === 'object') {
strResult = JSON.stringify(result);
} else {
strResult = result;
}
alert(strResult);
}
$timeout(getProducts, 1000);
/*
* Produkt-Details abrufen ENDE
*/
/*
* Rosen kaufen START
*/
$scope.buyRose = function() {
if((window.device && device.platform == "Android") && typeof inappbilling !== "undefined") {
if ($rootScope.storeinit==1){
inappbilling.buy(successBuyHandler, errorBuyHandler, $scope.preis);
}
else{
var alertPopup = $ionicPopup.alert({
title: 'Achtung',
template: 'Der Google-Store konnte nicht initialisiert werden.'
});
alertPopup.then(function(res) {
console.log('Store steht nicht zur Verfuegung');
});
}
}
}
function errorBuyHandler (error) {
var strResult = "";
var returnBool=false;
if(typeof error === 'object') {
strResult = JSON.stringify(error);
} else {
strResult = error;
}
/*
* Prüfen ob Kuf schonmal durchgeführt wurde, aber noch nicht konsumiert
*/
returnBool=strResult.indexOf("Item Already Owned") != -1;
if (returnBool==true){
//Rose wurde schon gekauft, jetzt konsumieren
$timeout(consumesuccessHandler, 500);
}
else{
//Ein anderer Fehler ist auf getreten Kauf wird abgebrochen
var alertPopup = $ionicPopup.alert({
title: 'Oh Nein',
template: 'Der Kauf konnte nicht durchgeführt werden.'
});
alertPopup.then(function(res) {
console.log('Der Kauf konnte nicht durchgeführt werden');
});
}
}
function successBuyHandler (result) { function successBuyHandler (result) {
$timeout(consumesuccessHandler, 500); $timeout(consumesuccessHandler, 500);
} }
/*
* Rosen kaufen ENDE
*/
/*
* Rosen konsuieren START
*/
function successConsumeHandler (result) { function successConsumeHandler (result) {
$scope.show($ionicLoading); $scope.show($ionicLoading);
var link = 'http://api.raataar.de/rosen/kauf.php'; var link = 'http://api.raataar.de/rosen/kauf.php';
@ -94,37 +251,6 @@ $scope.show = function() {
return false; return false;
}); });
}
function errorBuyHandler (error) {
var strResult = "";
var returnBool=false;
if(typeof error === 'object') {
strResult = JSON.stringify(error);
} else {
strResult = error;
}
returnBool=strResult.indexOf("Item Already Owned") != -1;
if (returnBool==true){
//alert("Schon gekauft");
$timeout(consumesuccessHandler, 500);
}
else{
var alertPopup = $ionicPopup.alert({
title: 'Oh Nein',
template: 'Der Kauf konnte nicht durchgeführt werden.'
});
alertPopup.then(function(res) {
console.log('Der Kauf konnte nicht durchgeführt werden');
});
}
} }
function errorConsumeHandler (error) { function errorConsumeHandler (error) {
@ -142,31 +268,10 @@ $scope.show = function() {
function consumesuccessHandler (result) { function consumesuccessHandler (result) {
inappbilling.consumePurchase(successConsumeHandler, errorConsumeHandler, $scope.preis); inappbilling.consumePurchase(successConsumeHandler, errorConsumeHandler, $scope.preis);
} }
/*
* Rosen konsuieren ENDE
*/
$scope.buyRose = function() {
if((window.device && device.platform == "Android") && typeof inappbilling !== "undefined") {
if ($rootScope.storeinit==1){
//Wegenbug ausgehebelt
inappbilling.buy(successBuyHandler, errorBuyHandler, $scope.preis);
//successConsumeHandler();
}
else{
var alertPopup = $ionicPopup.alert({
title: 'Achtung',
template: 'Der Google-Store konnte nicht initialisiert werden.'
});
alertPopup.then(function(res) {
console.log('Store steht nicht zur Verfuegung');
});
}
}
}
}) })

View File

@ -18,10 +18,31 @@
</div> </div>
<div style="padding-bottom:15px;"> <div style="padding-bottom:15px;">
<div class="item item-divider oleo">Wählen Sie Ihre Rosen aus:</div> <div class="item item-divider oleo">Wählen Sie Ihre Rosen aus:</div>
<ion-list> <ion-list ng-show="showrosen">
<ion-radio ng-model="$parent.preis" ng-value="'1xrose'" class="item item-thumbnail-left item-text-wrap"><img src="img/rose1.png"><h2 class="oleo">1 Rose </h2> <span class="oleo-vsmall"<p>Preis: 0,50 € (inkl. MwSt.)</p></span> </ion-radio> <ion-radio ng-model="$parent.preis" ng-value="'1xrose'" class="item item-thumbnail-left item-text-wrap">
<ion-radio ng-model="$parent.preis" ng-value="'3xrose'" class="item item-thumbnail-left item-text-wrap"><img src="img/rose3.png"><h2 class="oleo">3 Rosen</h2> <span class="oleo-vsmall"<p>Preis: 1,00 € (inkl. MwSt.)</p></span> </ion-radio> <img src="img/rose1.png">
<ion-radio ng-model="$parent.preis" ng-value="'9xrose'" class="item item-thumbnail-left item-text-wrap"><img src="img/rose10.png"><h2 class="oleo">9 Rosen</h2> <span class="oleo-vsmall"<p>Preis: 2,00 € (inkl. MwSt.)</p></span> </ion-radio> <h2 class="oleo">{{ rosen1titel }}</h2>
<span class="oleo-vsmall">{{ rosen1beschreibung }}</span><br>
<span class="oleo-vsmall">Preis: {{ rosen1preis }} € (inkl. MwSt.)</span>
</ion-radio>
<ion-radio ng-model="$parent.preis" ng-value="'3xrose'" class="item item-thumbnail-left item-text-wrap">
<img src="img/rose3.png">
<h2 class="oleo">{{ rosen3titel }}</h2>
<span class="oleo-vsmall">{{ rosen3beschreibung }}</span><br>
<span class="oleo-vsmall">Preis: {{ rosen3preis }} € (inkl. MwSt.)</span>
</ion-radio>
<ion-radio ng-model="$parent.preis" ng-value="'9xrose'" class="item item-thumbnail-left item-text-wrap">
<img src="img/rose10.png">
<h2 class="oleo">{{ rosen9titel }}</h2>
<span class="oleo-vsmall">{{ rosen9beschreibung }}</span><br>
<span class="oleo-vsmall">Preis: {{ rosen9preis }} € (inkl. MwSt.)</span>
</ion-radio>
<ion-radio ng-model="$parent.preis" ng-value="'rosenflatrate'" class="item item-thumbnail-left item-text-wrap" ng-show="showflatrate">
<img src="img/rose10.png">
<h2 class="oleo">{{ flateraterosentitel }}</h2>
<span class="oleo-vsmall">{{ flateraterosenbeschreibung }}</span><br>
<span class="oleo-vsmall">Preis: {{ flateraterosenpreis }} € (inkl. MwSt.)</span>
</ion-radio>
</ion-list> </ion-list>
</div> </div>