Advertisement
Guest User

options.ts

a guest
Jul 14th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component } from '@angular/core';
  2. import { App, NavController, LoadingController, Platform, ModalController } from 'ionic-angular';
  3. import { InAppPurchase2, IAPProduct  } from '@ionic-native/in-app-purchase-2/ngx';
  4.  
  5.  
  6.  
  7. // Providers
  8. import { AuthProvider } from '../../providers/auth/auth';
  9.  
  10. // Pages
  11. import { SigninPage } from '../signin/signin';
  12. import { NumberaddPage } from '../numberadd/numberadd';
  13. import { EditAccountPage } from '../editaccount/editaccount';
  14.  
  15. import {PrivacyPage } from '../privacy/privacy';
  16. import {PhonenumberPage } from '../phonenumber/phonenumber';
  17.  
  18. // Providers
  19. import { ParseProvider } from '../../providers/parse/parse';
  20. // Parse
  21. import { Parse } from 'parse';
  22.  
  23.  
  24.  
  25.  
  26. @Component({
  27.   selector: 'page-options',
  28.   templateUrl: 'options.html'
  29. })
  30. export class OptionsPage {
  31.  
  32.  
  33.  
  34.   constructor(public platform: Platform, public store: InAppPurchase2, private parseProvider: ParseProvider, public navCtrl: NavController,private auth: AuthProvider, private app: App,
  35.         public loadingCtrl: LoadingController, public modalController: ModalController ) {
  36.  
  37.           platform.ready().then(() => {
  38.             //this.configurePurchasing();
  39.             //'use strict';
  40.             if(!this.store) {
  41.               console.log('Store not available.');
  42.               alert('Store not available.');
  43.             }
  44.             //alert(JSON.stringify(this.store));
  45.      
  46.             try {
  47.               this.store.verbosity = this.store.DEBUG;1
  48.            
  49.             }
  50.             catch(err3)
  51.             {
  52.               //alert("Store Debug error! " + JSON.stringify(err3));
  53.      
  54.             }
  55.           });  
  56.   }
  57.   ionViewDidEnter(){
  58.  
  59.     this.ngOnInit();    
  60.   }
  61.   ngOnInit() {
  62.    
  63.     //this.configurePurchasing();
  64.   }
  65.  
  66.  
  67.  
  68.     configurePurchasing() {
  69.     if (!this.platform.is('cordova')) { return; }
  70.     console.log('Starting Configurations');
  71.     let productId;
  72.     //try {
  73.       if (this.platform.is('ios')) {
  74.         //productId = this.program.appleProductId;
  75.       } else if (this.platform.is('android')) {
  76.         //productId = this.program.googleProductId;
  77.         productId = 'credits10';
  78.       }
  79.  
  80.       if(!this.store) {
  81.         console.log('Store not available.');
  82.         alert('Store not available.');
  83.       }
  84.       alert(JSON.stringify(this.store));
  85.  
  86.       try {
  87.         this.store.verbosity = this.store.DEBUG;
  88.      
  89.       }
  90.       catch(err3)
  91.       {
  92.         alert("Store Debug error! " + JSON.stringify(err3));
  93.  
  94.       }
  95.  
  96.       // Register Product
  97.       console.log('Registering Product ' + JSON.stringify(productId));
  98.       alert('Registering Product ' + JSON.stringify(productId));
  99.       try {
  100.         //this.store.verbosity = this.store.DEBUG;
  101.      
  102.         this.store.register({
  103.           id: productId,
  104.           //alias: productId,
  105.           type: this.store.CONSUMABLE,
  106.         });
  107.       }
  108.       catch(err2)
  109.       {
  110.         alert("Product register error! " + JSON.stringify(err2));
  111.  
  112.       }
  113.       try {
  114.       console.log("1");
  115.       alert("1");
  116.       // Handlers
  117.       this.store.when(productId).approved( (product: IAPProduct) => {
  118.         // Purchase was approved
  119.         //this.logger.logEvent('purchase_approved', {programId: this.program._id});
  120.         product.finish();
  121.         //this.loader.dismiss();
  122.         //this.subscribe();
  123.       });
  124.       console.log("2");
  125.       alert("2");
  126.       this.store.when(productId).registered( (product: IAPProduct) => {
  127.         console.log('Registered: ' + JSON.stringify(product));
  128.       });
  129.       console.log("3");
  130.       alert("3");
  131.       this.store.when(productId).updated( (product: IAPProduct) => {
  132.         console.log('Loaded' + JSON.stringify(product));
  133.       });
  134.       console.log("4");
  135.       alert("4");
  136.       this.store.when(productId).cancelled( (product) => {
  137.         /*this.logger.logEvent('purchase_cancelled' , {});
  138.         if (this.loader.isOverlay) {
  139.           this.loader.dismiss();
  140.           alert('Purchase was Cancelled');
  141.         }*/
  142.         console.error('Purchase was Cancelled');
  143.       });
  144.       console.log("5");
  145.       alert("5");
  146.       this.store.error( (err) => {
  147.         /*this.logger.logEvent('store_error', {});
  148.         this.loader.dismiss();
  149.         alert('Store Error ' + JSON.stringify(err));*/
  150.         console.error('Store Error ' + JSON.stringify(err));
  151.       });
  152.       console.log("6");
  153.       alert("6");
  154.       this.store.ready(() =>  {
  155.         alert('Store is ready');
  156.         console.log('Store is ready');
  157.         alert('Products: ' + JSON.stringify(this.store.products));
  158.         console.log('Products: ' + JSON.stringify(this.store.products));
  159.         console.log(JSON.stringify(this.store.get(productId)));
  160.       });
  161.       console.log("7");
  162.       alert("7");
  163.       // Errors
  164.       this.store.when(productId).error( (error) => {
  165.         //this.logger.logEvent('store_error', {});
  166.         //this.loader.dismiss();
  167.         alert('An Error Occured' + JSON.stringify(error));
  168.       });
  169.       // Refresh Always
  170.       console.log('Refresh Store');
  171.       alert('Refreshing Store.');
  172.       //this.store.refresh();
  173.     } catch (err) {
  174.       console.log('Error On Store Issues' + JSON.stringify(err));
  175.       alert('Error On Store Issues' + JSON.stringify(err));
  176.     }
  177.  
  178.   }
  179.  
  180.  
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement