Ionic 3 in-app purchase2 do not show products

To begin, I have set up my app in google play console. I have added it in alpha closed testing also. And my install my billing license with the plugin. I currently testing it in android only. I used the ‘android.test.purchased’ as for google instructions

I have followed and tried every example I can see.

But the problem is when I click the button upgrade (non-consumable purchase). Nothing happens, no popup from my native device showing price or something. Maybe I missed something in implementation.

Please help me check my code.

import { Component } from '@angular/core';
import { Platform, NavController, NavParams } from 'ionic-angular';
import { InAppPurchase2, IAPProduct  } from '@ionic-native/in-app-purchase-2';

@Component({
  selector: 'page-offer',
  templateUrl: 'offer.html',
})
export class OfferPage {

  public product: any = {
    name: 'Upgrade to Pro',
    appleProductId: 'android.test.purchased',
    googleProductId: 'android.test.purchased'
  };
  
  constructor(
    public navCtrl: NavController, 
    public navParams: NavParams,
    public platform: Platform,
    public store: InAppPurchase2
    ) {
      platform.ready().then(() => {
        this.configurePurchasing();
      });
      
  }

  configurePurchasing() {
    if (!this.platform.is('cordova')) { return; }
    let productId;
    try {
      if (this.platform.is('ios')) {
        productId = this.product.appleProductId;
      } else if (this.platform.is('android')) {
        productId = this.product.googleProductId;
      }

      // Register Product
      // Set Debug High
      this.store.verbosity = this.store.DEBUG;
      
      // Register the product with the store
      this.store.register({
        id: productId,
        alias: productId,
        type: this.store.NON_CONSUMABLE
      });

      this.registerHandlers(productId);

      InAppPurchase2.getPlugin().ready().then((status) => {
        console.log(JSON.stringify(this.store.get(productId)));
        console.log('Store is Ready: ' + JSON.stringify(status));
        console.log('Products: ' + JSON.stringify(this.store.products));
        
      });

      // Errors On The Specific Product
      this.store.when(productId).error( (error) => {
        alert('An Error Occured' + JSON.stringify(error));
      });
      // Refresh Always
      console.log('Refresh Store');
      this.store.refresh();
    } catch (err) {
      console.log('Error On Store Issues' + JSON.stringify(err));
    }
  }

  registerHandlers(productId) {
    // Handlers
    this.store.when(productId).approved( (product: IAPProduct) => {
      // Purchase was approved
      product.finish();
    });

    this.store.when(productId).registered( (product: IAPProduct) => {
      console.log('Registered: ' + JSON.stringify(product));
    });

    this.store.when(productId).updated( (product: IAPProduct) => {
      console.log('Loaded' + JSON.stringify(product));
    });

    this.store.when(productId).cancelled( (product) => {
      alert('Purchase was Cancelled');
    });

    // Overall Store Error
    this.store.error( (err) => {
      alert('Store Error ' + JSON.stringify(err));
    });
  }

  async purchase() {
    /* Only configuring purchase when you want to buy, because when you configure a purchase
    It prompts the user to input their apple id info on config which is annoying */
    if (!this.platform.is('cordova')) { return };

    let productId;

    if (this.platform.is('ios')) {
      productId = this.product.appleProductId;
    } else if (this.platform.is('android')) {
      productId = this.product.googleProductId;
    }

    console.log('Products: ' + JSON.stringify(this.store.products));
    console.log('Ordering From Store: ' + productId);
    try {
      let product = this.store.get(productId);
      console.log('Product Info: ' + JSON.stringify(product));
      let order = await this.store.order(productId);
      alert('Finished Purchase');
    } catch (err) {
      console.log('Error Ordering ' + JSON.stringify(err));
    }
  }

}

my bad… i didnt notice this… now evrything is working

I need serious help with this. I’ve been trying for days, but I haven’t done it.

my app was released as beta. the products are attached and all are active.

but I’m trying the codes here, identifying the product IDs. I’m testing it from a real mobile device.

this error returns "Error On Store Issues{} "
is empty

which little point I’m missing ?

Hi Soulsmasher!

I’m having the same problem as you. I’m receiving the same “Error On Store Issues { }” empty. Did you solve it??? Please

Hello,

Require help with this. I’ve been trying for week, but I haven’t cracked it for both the platform(Android/iOS).
My app was released as beta. the products are attached and all are active.
I’m testing it from a real mobile device.

This error returns "Error On Store Issues{} "
is empty

What is that I’m missing ?
Ionic:

Ionic CLI : 5.2.1 (/usr/local/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 4.4.2
@angular-devkit/build-angular : 0.13.9
@angular-devkit/schematics : 7.3.9
@angular/cli : 7.3.9
@ionic/angular-toolkit : 1.5.1

Cordova:

Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : android 8.0.0, ios 5.0.1
Cordova Plugins : cordova-plugin-ionic-webview 4.1.0, (and 7 other plugins)

Utility:

cordova-res : 0.5.1 (update available: 0.5.2)
native-run : 0.2.2 (update available: 0.2.7)

System:

ios-deploy : 1.9.4
ios-sim : 8.0.1
NodeJS : v10.16.0 (/usr/local/bin/node)
npm : 6.9.0
OS : macOS Mojave
Xcode : Xcode 10.2.1 Build version 10E1001

import { Component, OnInit } from '@angular/core';
import { ApiService  } from '../../shared/api.service';
import { InAppPurchase2, IAPProduct } from '@ionic-native/in-app-purchase-2/ngx';
import { CommonProvider } from 'src/app/shared/common';
import { Platform, AlertController } from '@ionic/angular';

@Component({
  selector: 'app-subscriptions',
  templateUrl: './subscriptions.page.html',
  styleUrls: ['./subscriptions.page.scss'],
})
export class SubscriptionsPage implements OnInit {
  products = [];
  previousPurchases = [];
  crystalCount = 0;
  specialGame = false;
  monthlySub = false;
  public item;

  public product: any = {
    name: 'Upgrade to Pro',
    appleProductId: 'com.squarepanda.parentappdemo.coins100',
    googleProductId: 'android.test.purchased'
  };

  public productInfo: any = {
    name: 'parentapp',
    googleProductId: 'android.test.purchased'
  };
  
  constructor(
    public API: ApiService,
    private iap2: InAppPurchase2,
    private platform: Platform,
    private alertCtrl:AlertController,
    public store: InAppPurchase2,
    public productkeys: CommonProvider) {
      // this.setup();
      // this.item = this.iap2.get(this.productInfo.googleProductId);
      platform.ready().then(() => {
        alert('platform ready');
        this.configurePurchasing();
      });
    }

    configurePurchasing() {
      alert('configurePurchasing');
      if (!this.platform.is('cordova')) { return; }
      let productId;
      try {
        if (this.platform.is('ios')) {
          productId = this.product.appleProductId;
        } else if (this.platform.is('android')) {
          alert('platform android');
          productId = this.product.googleProductId;
          alert('product id '+ productId);
        }
  
        // Register Product
        // Set Debug High
        this.store.verbosity = this.store.DEBUG;
        
        // Register the product with the store
        this.store.register({
          id: productId,
          alias: productId,
          type: this.store.NON_CONSUMABLE
        });
  
        this.registerHandlers(productId);
  
        InAppPurchase2.getPlugin().ready().then((status) => {
          alert(JSON.stringify(this.store.get(productId)));
          alert('Store is Ready: ' + JSON.stringify(status));
          alert('Products: ' + JSON.stringify(this.store.products));
          
        });
  
        // Errors On The Specific Product
        this.store.when(productId).error( (error) => {
          alert('An Error Occured' + JSON.stringify(error));
        });
        // Refresh Always
        alert('Refresh Store');
        this.store.refresh();
      } catch (err) {
        alert('Error On Store Issues111' + JSON.stringify(err));
      }
    }


    setup() {
      alert('setup');
      if (!this.platform.is('cordova')) {
        return;
      }
      let productId;
      try {
        if (this.platform.is('android')) {
          productId = this.productInfo.googleProductId;
        }
  
        this.iap2.register({
          id: productId,
          alias: productId,
          type: this.iap2.PAID_SUBSCRIPTION
        });
  
        this.registerHandlers(productId);
  
        this.iap2.ready(function () {
          alert(JSON.stringify(this.store.get(productId)));
          alert('Store is Ready: ' + JSON.stringify(status));
          alert('Products: ' + JSON.stringify(this.store.products));
        });
  
        // Errors On The Specific Product
        this.iap2.when(productId).error((error) => {
          alert('An Error Occured' + JSON.stringify(error));
        });
        // Refresh Always
        alert('Refresh Store');
        this.iap2.refresh();
      } catch (err) {
        alert('Error On Store Issues' + JSON.stringify(err));
      }
    }
  
    registerHandlers(productId) {
          // Handlers
          this.iap2.when(productId).approved( (product: IAPProduct) => {
            // Purchase was approved
            product.finish();
          });
  
      this.iap2.when(productId).owned((product: IAPProduct) => {
        product.finish();
      });
  
      this.iap2.when(productId).verified((product: IAPProduct) => {
        product.verify();
      });
  
      this.iap2.when(productId).updated((product: IAPProduct) => {
        alert('Loaded' + JSON.stringify(product));
  
      });
  
      this.iap2.when(productId).cancelled((product) => {
        
         let alert = this.alertCtrl.create({
          message: 'Thanks for trying the adfree purchase but you where unlucky and it failed',
          buttons: [
            {
              text: 'Try Again',
              role: 'retry',
              handler: () => {
                this.purchase();
              }
            },
            {
              text: 'Ok',
            }
          ]
        });
      });
  
      // Overall Store Error
      this.iap2.error((err) => {
        alert('Store Error ' + JSON.stringify(err));
      });
    }
  
    async purchase() {
  
      if (!this.platform.is('cordova')) {
        return
      }
  
      let productId;
  
      if (this.platform.is('ios')) {
        productId = this.productInfo.appleProductId;
      } else if (this.platform.is('android')) {
        productId = this.productInfo.googleProductId;
      }
  
      alert('Products: ' + JSON.stringify(this.iap2.products));
      alert('Ordering From Store: ' + productId);
      try {
        let product = this.iap2.get(productId);
        alert('Product Info: ' + JSON.stringify(product));
        let order = await this.iap2.order(productId);
      } catch (err) {
        alert('Error Ordering ' + JSON.stringify(err));
      }
    }
  
    async restore() {
      if (!this.platform.is('cordova')) {
        return
      }
  
      let productId;
  
      if (this.platform.is('ios')) {
        productId = this.productInfo.appleProductId;
      } else if (this.platform.is('android')) {
        productId = this.productInfo.googleProductId;
      }
  
      alert('Products: ' + JSON.stringify(this.iap2.products));
      alert('Refreshing Store: ' + productId);
      try {
        let product = this.iap2.get(productId);
        alert('Product Info: ' + JSON.stringify(product));
        this.iap2.refresh();
      } catch (err) {
        alert('Error Ordering ' + JSON.stringify(err));
      }
    }
  

    getProducts(){
      alert('getProducts');
       this.setup();
    }
 

  ngOnInit() {
  }



}