Example #1
0
 BuyerWalletPage.prototype.addMoney = function () {
     var _this = this;
     var payPalEnvironmentSandbox = 'AT305vLOagTklhmxCnE_6jYJsq0-5i4zY-47q2otpDJ0ynpLKYvMoMRT8LGlo8iD4WGvs5Y_3Xf1RIwo';
     var payPalEnvironmentProduction = '';
     var payment = new PayPalPayment(this.formCtrl.value.quantity, 'PHP', 'Ecrotion E-wallet', 'sale');
     var currencies = ['EUR', 'USD', 'PHP'];
     var payPalEnvironment = 'payPalEnvironmentSandbox';
     this.loading = this.loadingCtrl.create({
         spinner: 'hide',
         content: "<img src='assets/icon/loader.gif'>",
     });
     this.loading.present();
     this.loadingStatus = true;
     var update = {};
     var timeCreated = firebase.database.ServerValue.TIMESTAMP;
     var latestBlock = this.transactionHistory[this.transactionHistory.length - 1];
     var latestBlockHash = sha512.sha512(this.transactionHistory[this.transactionHistory.length - 1].toString());
     var description = "Added " + this.formCtrl.value.quantity + " to your account.";
     var key = sha512.sha512(this.formCtrl.value.quantity + description + latestBlockHash + timeCreated);
     this.payPal.init({
         PayPalEnvironmentProduction: "Config.payPalEnvironmentProduction",
         PayPalEnvironmentSandbox: "AT305vLOagTklhmxCnE_6jYJsq0-5i4zY-47q2otpDJ0ynpLKYvMoMRT8LGlo8iD4WGvs5Y_3Xf1RIwo"
     }).then(function () {
         _this.payPal.prepareToRender(payPalEnvironment, new PayPalConfiguration({})).then(function () {
             _this.payPal.renderSinglePaymentUI(payment).then(function (response) {
                 alert("Successfuly added " + _this.formCtrl.value.quantity + " php to your E-wallet");
                 _this.db.list('users/' + _this.fireAuth.auth.currentUser.uid + '/transactions/').push({
                     currentAmount: parseInt(_this.formCtrl.value.quantity) + parseInt(_this.transactionHistory[_this.transactionHistory.length - 1].currentAmount),
                     description: description,
                     key: key,
                     timeCreated: timeCreated,
                     previousKey: latestBlockHash
                 });
                 console.log(response);
             }, function () {
                 console.error('Error or render dialog closed without being successful');
                 _this.loading.dismiss();
                 _this.loadingStatus = false;
             });
         }, function () {
             console.error('Error in configuration');
             _this.loading.dismiss();
             _this.loadingStatus = false;
         });
     }, function () {
         console.error('Error in initialization, maybe PayPal isn\'t supported or something else');
         _this.loading.dismiss();
         _this.loadingStatus = false;
     });
 };
 BuyerCheckoutPage.prototype.payOut = function () {
     var _this = this;
     if (this.total <= this.currentMoney) {
         var checker_1 = false;
         var orderKey_1 = this.db.createPushId();
         var keys_1 = {};
         var productLists = {};
         console.log(this.shops);
         this.shopsChecker.forEach(function (data) {
             console.log(data);
             console.log(_this.drivers);
             if (_this.drivers[data] != null) {
                 checker_1 = true;
             }
             keys_1[data] = { key: _this.db.createPushId() };
         });
         if (this.address != null && checker_1) {
             var products = {};
             this.productsToBePayedArray.forEach(function (item) {
                 _this.productsToBePayed["users/" + _this.drivers[item.shopID].key + "/driverStatus"] = "Taken";
                 _this.productsToBePayed['/orderReceipts/' + orderKey_1] = {
                     orederedOn: firebase.database.ServerValue.TIMESTAMP,
                     orderedBy: _this.fireAuth.auth.currentUser.uid
                 };
                 _this.productsToBePayed['/orderBundles/' + keys_1[item.shopID].key] = {
                     driver: _this.drivers[item.shopID].key,
                     driverStatus: "Pending",
                     products: _this.getProducts(item.shopID),
                     orderedBy: _this.fireAuth.auth.currentUser.uid,
                     driverPrice: _this.drivers[item.shopID].price,
                     orderReceipt: orderKey_1,
                     shopID: item.shopID,
                     readyToPickUp: 0,
                     orderedOn: firebase.database.ServerValue.TIMESTAMP,
                     status: "Pending",
                     total: _this.getTotal(item.shopID),
                     address: _this.address
                 };
                 _this.productsToBePayed['/users/' + _this.fireAuth.auth.currentUser.uid + "/cart/" + item.key] = null;
             });
             this.db.object('/').update(this.productsToBePayed).then(function (data) {
                 _this.navCtrl.push(BuyerOrdersPage, { checkOutSuccess: "Success" }).then(function (data) {
                     _this.navCtrl.remove(_this.navCtrl.length() - 2);
                 });
                 ;
             });
             // deduct money from user
             this.loading = this.loadingCtrl.create({
                 spinner: 'hide',
                 content: "<img src='assets/icon/loader.gif'>",
             });
             this.loading.present();
             this.loadingStatus = true;
             var update = {};
             var timeCreated = firebase.database.ServerValue.TIMESTAMP;
             var latestBlock = this.transactionHistory[this.transactionHistory.length - 1];
             var latestBlockHash = sha512.sha512(this.transactionHistory[this.transactionHistory.length - 1].toString());
             var description = "Deducted " + this.total + " to your account to pay your order.";
             var key = sha512.sha512(this.total + description + latestBlockHash + timeCreated);
             this.db.list('users/' + this.fireAuth.auth.currentUser.uid + '/transactions/').push({
                 currentAmount: parseInt(this.transactionHistory[this.transactionHistory.length - 1].currentAmount) - this.total,
                 description: description,
                 key: key,
                 timeCreated: timeCreated,
                 previousKey: latestBlockHash
             });
         }
         else {
             alert("Please select a delivery method!");
         }
     }
     else {
         alert("You do not have enough money, make sure you have enough balance in your E-Wallet.");
     }
 };