D.Hodges
D.Hodges

Reputation: 2107

cordova in app purchase returning invalid product

I'm following a tutorial to implement in app purchase in an Ionic app and I'm getting the following warning:

InAppPurchase[js]: load ok: { valid:[] invalid:["productname","productname"] } [store.js] DEBUG: ios -> products loaded [store.js] DEBUG: state: comionicheathenwws -> invalid invalid productname [store.js] WARNING: ios -> product productname is NOT valid (productname)

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

const PRODUCT = 'productname';
const PRODUCT1 = 'productname';

@Component({
  selector: 'app-upgrade',
  templateUrl: './upgrade.page.html',
  styleUrls: ['./upgrade.page.scss'],
})
export class UpgradePage implements OnInit {
  products: IAPProduct[] = [];

  constructor(public platform: Platform, private store: InAppPurchase2) { }

  ngOnInit() {
    this.store.verbosity = this.store.DEBUG;
    this.registerProducts();
    this.setupListeners();
    this.products = this.store.products;
    console.log('products', JSON.stringify(this.products));
  }

  registerProducts() {
    this.store.register({
      id: PRODUCT,
      type: this.store.NON_RENEWING_SUBSCRIPTION
    });

    this.store.register({
      id: PRODUCT1,
      type: this.store.NON_RENEWING_SUBSCRIPTION
    });

    this.store.refresh();
  }

  setupListeners() {

    // Register purchase
    this.store.when('product')
      .registered((product: IAPProduct) => {
        if (product.id === PRODUCT) {
          console.log('Register PRODUCT');
        } else if (product.id === PRODUCT1) {
          console.log('Register PRODUCT1');
        }
      });

  
    // Approved purchase
    this.store.when('product')
      .approved((product: IAPProduct) => {
        if (product.id === PRODUCT) {
          console.log('approved PRODUCT');
        } else if (product.id === PRODUCT1) {
          console.log('approved PRODUCT1');
        }
        return product.verify();
      }).verified((productVerified: IAPProduct) => {
        productVerified.finish();
      });

    // finished purchase
    this.store.when('product')
      .finished((product: IAPProduct) => {
        if (product.id === PRODUCT) {
          console.log('finished PRODUCT');
        } else if (product.id === PRODUCT1) {
          console.log('finished PRODUCT1');
        }
      });
  }
}

I'm using "cordova-plugin-purchase": "^9.0.0", 10.0 wouldn't work.

I'm running the app from an ios emulator to get that error.

Upvotes: 1

Views: 1052

Answers (1)

Elias
Elias

Reputation: 31

Your code looks fine. Check your boundle id to ensure it is the same with the id you use in your appleconnect. I ran into this problem because of that.

Upvotes: 0

Related Questions