Hello everyone, i have a problem with in app purchase, when i purchase the premium access i get approved and transcation works but later when i try to enter to the premium section application gets stuck and sometimes it goes automatically to the premium section but i want that to happen when i click on button. This is my code really need some hlep over here… thanks.
setuppremium() {
this.iap2.verbosity = this.iap2.DEBUG;
this.iap2.register({
id: 'id1234',
type: this.iap2.PAID_SUBSCRIPTION
});
this.product = this.iap2.get('id1234');
this.registerHandlersForPurchase('id1234');
// restore purchase
this.iap2.refresh();
}
checkout() {
this.registerHandlersForPurchase('id1234');
try {
let product = this.iap2.get('id1234');
console.log('Product Info: ' + JSON.stringify(product));
this.iap2.order('id1234').then((p) => {
console.log('Purchase Succesful' + JSON.stringify(p));
}).catch((e) => {
console.log('Error Ordering From Store' + e);
});
} catch (err) {
console.log('Error Ordering ' + JSON.stringify(err));
}
}
registerHandlersForPurchase(productId) {
let self = this.iap2;
this.iap2.when(productId).updated(function (product) {
if (product.loaded && product.valid && product.state === self.APPROVED && product.transaction != null) {
product.finish();
}
});
this.iap2.when(productId).registered((product: IAPProduct) => {
});
this.iap2.when(productId).owned((product: IAPProduct) => {
this.router.navigate(['/premium']);
});
this.iap2.when(productId).approved((product: IAPProduct) => {
product.finish();
});
this.iap2.when(productId).refunded((product: IAPProduct) => {
});
this.iap2.when(productId).expired((product: IAPProduct) => {
// alert('expired');
});
this.iap2.when(productId).cancelled((product: IAPProduct) => {
this.showpremiumCancel();
});
}
In HTML Code when i press on button i call the checkout() function and in constructor (platform.ready) i call the setuppremium().
I don’t get what’s wrong with my code need some help thanks!