Answer the question
In order to leave comments, you need to log in
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));
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question