Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component } from '@angular/core';
- import { App, NavController, LoadingController, Platform, ModalController } from 'ionic-angular';
- import { InAppPurchase2, IAPProduct } from '@ionic-native/in-app-purchase-2/ngx';
- // Providers
- import { AuthProvider } from '../../providers/auth/auth';
- // Pages
- import { SigninPage } from '../signin/signin';
- import { NumberaddPage } from '../numberadd/numberadd';
- import { EditAccountPage } from '../editaccount/editaccount';
- import {PrivacyPage } from '../privacy/privacy';
- import {PhonenumberPage } from '../phonenumber/phonenumber';
- // Providers
- import { ParseProvider } from '../../providers/parse/parse';
- // Parse
- import { Parse } from 'parse';
- @Component({
- selector: 'page-options',
- templateUrl: 'options.html'
- })
- export class OptionsPage {
- constructor(public platform: Platform, public store: InAppPurchase2, private parseProvider: ParseProvider, public navCtrl: NavController,private auth: AuthProvider, private app: App,
- public loadingCtrl: LoadingController, public modalController: ModalController ) {
- platform.ready().then(() => {
- //this.configurePurchasing();
- //'use strict';
- if(!this.store) {
- console.log('Store not available.');
- alert('Store not available.');
- }
- //alert(JSON.stringify(this.store));
- try {
- this.store.verbosity = this.store.DEBUG;1
- }
- catch(err3)
- {
- //alert("Store Debug error! " + JSON.stringify(err3));
- }
- });
- }
- ionViewDidEnter(){
- this.ngOnInit();
- }
- ngOnInit() {
- //this.configurePurchasing();
- }
- configurePurchasing() {
- if (!this.platform.is('cordova')) { return; }
- console.log('Starting Configurations');
- let productId;
- //try {
- if (this.platform.is('ios')) {
- //productId = this.program.appleProductId;
- } else if (this.platform.is('android')) {
- //productId = this.program.googleProductId;
- productId = 'credits10';
- }
- if(!this.store) {
- console.log('Store not available.');
- alert('Store not available.');
- }
- alert(JSON.stringify(this.store));
- try {
- this.store.verbosity = this.store.DEBUG;
- }
- catch(err3)
- {
- alert("Store Debug error! " + JSON.stringify(err3));
- }
- // Register Product
- console.log('Registering Product ' + JSON.stringify(productId));
- alert('Registering Product ' + JSON.stringify(productId));
- try {
- //this.store.verbosity = this.store.DEBUG;
- this.store.register({
- id: productId,
- //alias: productId,
- type: this.store.CONSUMABLE,
- });
- }
- catch(err2)
- {
- alert("Product register error! " + JSON.stringify(err2));
- }
- try {
- console.log("1");
- alert("1");
- // Handlers
- this.store.when(productId).approved( (product: IAPProduct) => {
- // Purchase was approved
- //this.logger.logEvent('purchase_approved', {programId: this.program._id});
- product.finish();
- //this.loader.dismiss();
- //this.subscribe();
- });
- console.log("2");
- alert("2");
- this.store.when(productId).registered( (product: IAPProduct) => {
- console.log('Registered: ' + JSON.stringify(product));
- });
- console.log("3");
- alert("3");
- this.store.when(productId).updated( (product: IAPProduct) => {
- console.log('Loaded' + JSON.stringify(product));
- });
- console.log("4");
- alert("4");
- this.store.when(productId).cancelled( (product) => {
- /*this.logger.logEvent('purchase_cancelled' , {});
- if (this.loader.isOverlay) {
- this.loader.dismiss();
- alert('Purchase was Cancelled');
- }*/
- console.error('Purchase was Cancelled');
- });
- console.log("5");
- alert("5");
- this.store.error( (err) => {
- /*this.logger.logEvent('store_error', {});
- this.loader.dismiss();
- alert('Store Error ' + JSON.stringify(err));*/
- console.error('Store Error ' + JSON.stringify(err));
- });
- console.log("6");
- alert("6");
- this.store.ready(() => {
- alert('Store is ready');
- console.log('Store is ready');
- alert('Products: ' + JSON.stringify(this.store.products));
- console.log('Products: ' + JSON.stringify(this.store.products));
- console.log(JSON.stringify(this.store.get(productId)));
- });
- console.log("7");
- alert("7");
- // Errors
- this.store.when(productId).error( (error) => {
- //this.logger.logEvent('store_error', {});
- //this.loader.dismiss();
- alert('An Error Occured' + JSON.stringify(error));
- });
- // Refresh Always
- console.log('Refresh Store');
- alert('Refreshing Store.');
- //this.store.refresh();
- } catch (err) {
- console.log('Error On Store Issues' + JSON.stringify(err));
- alert('Error On Store Issues' + JSON.stringify(err));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement