D
D
Denis Tkachenko2018-09-27 11:39:10
Google Play
Denis Tkachenko, 2018-09-27 11:39:10

In-app-purchase ionic 3 - where to get this com.yourapp.prod1 and productName?

Downloaded plugin and installed from ionic-native
My code:

public product: any = {
    name: 'My Product',
    googleProductId: 'com.yourapp.prod1'
  };

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

      this.store.verbosity = this.store.DEBUG;
      this.store.register({
        id: productId,
        alias: productId,
        type: this.store.NON_RENEWING_SUBSCRIPTION
      });
     this.registerHandlers(productId);
     this.store.when(productId).error( (error) => {
        alert('An Error Occured' + JSON.stringify(error));
      });
      console.log('Refresh Store');
      this.store.refresh();
    } catch (err) {
      console.log('Error On Store Issues' + JSON.stringify(err));
    }
}

registerHandlers(productId) {
    this.store.when(productId).approved( (product: IAPProduct) => {
      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');
    });

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

async purchase() {
    if (!this.platform.is('cordova')) { return };

    let productId;
    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));
    }
  }

Please tell me what is com.yourapp.prod1 and "My Product" and where to get it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2018-09-27
@GavriKos

In the Google Developer Console, register the inapps you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question