Hi, im using Ionic 3.9.3 e in-app-purchase2 4.2…
I have two issues with PAID_SUBSCRIPTION:
- It does not return complete product data such as price.
- Events are unstable they execute when.update and when approved in infinite loop.
But the code follows everything in the documentation.
setup() {
let productId;
(this.plt.is('ios')) ? productId = this.product.appleId : productId = this.product.googleId;
this.iap2.validator = "https://validator.fovea.cc/v1/validate?appName=br.com.medsos.sosplantao&apiKey=dda8e8cc-150f-46fa-90d1-53e0a5bb6e49";
this.iap2.register({
id: productId,
alias: productId,
type: this.iap2.PAID_SUBSCRIPTION
});
console.log('productId', productId);
this.productInfo = this.iap2.get(productId);
this.hasInternet = true;
console.log('setup product get', JSON.stringify(this.productInfo));
this.iap2.refresh();
// this.registerHandlersForPurchase(productId);
}
getProduct() {
return this.productInfo;
}
subscribe() {
let productId;
(this.plt.is('ios')) ? productId = this.product.appleId : productId = this.product.googleId;
console.log('productId', productId);
this.registerHandlersForPurchase(productId);
this.iap2.order(productId);
this.iap2.refresh();
}
registerHandlersForPurchase(productId) {
this.iap2.when(productId).approved((product: IAPProduct) => {
console.log('approved state', product.state);
console.log('approved price', product.price);
console.log('approved transaction' , JSON.stringify(product.transaction));
console.log('approved valid', product.valid);
if (product.valid && product.transaction) {
// compra aprovada
this.setCustomer(product.transaction);
}
this.productInfo = product;
product.verify();
product.finish();
});
/* this.iap2.when(productId).updated((product: IAPProduct) => {
console.log('updated state', product.state);
if (product.loaded && product.valid && product.state === 'approved' && product.transaction != null) {
product.finish();
}
product.finish();
}); */
/*
this.iap2.when(productId).owned((product: IAPProduct) => {
console.log('owned', product.state);
product.finish();
}); */
this.iap2.when(productId).verified((product: IAPProduct) => {
console.log('verified', product.state);
product.finish();
});
this.iap2.when(productId).refunded((product: IAPProduct) => {
alert('refunded');
});
this.iap2.when(productId).expired((product: IAPProduct) => {
alert('expired');
});
this.iap2.when(productId).error((error: any) => {
alert('expired');
console.log('Error', error);
// this.registrarLog(error);
});
} ```