Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async buyProduct(product) {
if (this.props.profile.profileAddress) {
try {
// Will return a purchase object with a receipt which can be used to validate on your server.
const purchase = await RNIap.buyProduct(product.productId);
console.log(purchase);
this.setState({
receipt: purchase, // save the receipt if you need it, whether locally, or to your server.
});
await this.consumePurchases();
} catch (err) {
// standardized err.code and err.message available
console.log(err.code, err.message);
this.props.addAlert('error', '', 'Failed to buy product');
const subscription = RNIap.addAdditionalSuccessPurchaseListenerIOS(async (purchase) => {
this.setState({receipt: purchase}, async () => await this.consumePurchases());
subscription.remove();
});
}
} else {
this.props.addAlert('error', '', 'No wallet address available');
}
}
async supportWoWsInfo(item) {
try {
// Will return a purchase object with a receipt which can be used to validate on your server.
const purchase = await RNIap.buyProduct(item.productId);
// Consume it right away to buy multiple times
await RNIap.consumePurchase(purchase.purchaseToken);
this.setState({
receipt: purchase.transactionReceipt, // save the receipt if you need it, whether locally, or to your server.
});
} catch(err) {
// standardized err.code and err.message available
console.error(err.code, err.message);
const subscription = RNIap.addAdditionalSuccessPurchaseListenerIOS(async (purchase) => {
this.setState({ receipt: purchase.transactionReceipt }, () => this.goToNext());
subscription.remove();
});
}
}
}