Purchase failed: Product not registered: monthly_subscription
I get this error
my code is
import { Injectable } from '@angular/core';
import { AngularFirestore } from '@angular/fire/firestore';
import { IAPProduct, InAppPurchase2 } from '@ionic-native/in-app-purchase-2/ngx';
import { AlertController, Platform } from '@ionic/angular';
@Injectable({
providedIn: 'root',
})
export class PremiumService{
isPremium = Boolean(false);
MONTHLY_SUBSCRIPTION = 'monthly_subscription';
constructor(
private fireStore: AngularFirestore,
private store: InAppPurchase2,
private platform: Platform,
private alertCtrl: AlertController
){
this.platform.ready().then(()=>{
console.log(this.store);
this.store.verbosity = this.store.DEBUG;
this.registerProducts();
this.store.ready(()=>{
this.setupListeners();
})
});
}
registerProducts(){
this.store.register({
id: this.MONTHLY_SUBSCRIPTION,
type: this.store.PAID_SUBSCRIPTION
});
this.store.refresh();
}
setupListeners(){
this.store.when('product').approved((p: IAPProduct) =>{
if(p.id === this.MONTHLY_SUBSCRIPTION){
this.isPremium = true;
}
return p.verify();
}).verified((p: IAPProduct)=> p.finish());
this.store.when(this.MONTHLY_SUBSCRIPTION).owned((p: IAPProduct) =>{
this.isPremium = true;
});
}
getProduct(product:string){
return this.store.get(product);
}
purchase(product:IAPProduct) {
if(this.isPremium){
this.log(true);
return
}
this.store.order(product).then((p: IAPProduct) => {
this.log(p);
}, e => {
this.log(e);
})
this.store.error((e)=>{
this.log(e);
});
}
async log(log){
const alert = await this.alertCtrl.create({
message:JSON.stringify(log)
});
alert.present();
}
restore() {
this.store.refresh();
}
}