How to use the react-native-iap.addAdditionalSuccessPurchaseListenerIOS function in react-native-iap

To help you get started, we’ve selected a few react-native-iap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Musicoin / app / components / product / ProductModal.js View on Github external
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');
    }
  }
github HenryQuan / WoWs-Info-Re / WoWsInfo / src / component / common / Donation.js View on Github external
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();
      });
    }
  }
}