How to use react-native-iap - 10 common examples

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
if (Platform.OS === 'ios') {
        validation = await validateAppleIAPJSON(this.props.auth.email, this.props.auth.accessToken, this.state.receipt.transactionReceipt);
      }

      if (Platform.OS === 'android') {
        //ToDo: check verify Play store purchases
        validation = await validateGoogleIAPJSON(this.props.auth.email, this.props.auth.accessToken, {receipt: this.state.receipt.dataAndroid, signature: this.state.receipt.signatureAndroid});
        // console.log(validation);
        // validation = {tx: "remove this"};
      }
      console.log('validation:');
      console.log(validation);

      // consume products
      const purchases = await RNIap.getAvailablePurchases();
      console.log(purchases);
      purchases.forEach(async purchase => {
        console.log(purchase);
        await RNIap.consumePurchase(purchase.purchaseToken);
      });

      if (validation.tx) {
        this.props.addAlert('success', 'Thank you for your purchase!', 'Your coins will appear in your wallet soon');
      } else {
        this.props.addAlert('error', '', validation.error ? validation.error : 'Something went wrong');
      }
    } catch (err) {
      console.log(err); // standardized err.code and err.message available
      this.props.addAlert('error', '', err.message);
    }
  };
github Musicoin / app / components / product / ProductModal.js View on Github external
async componentDidMount() {
    try {
      const products = await RNIap.getProducts(itemSkus);
      products.sort(this.compare);
      this.setState({products});
      console.log(products);
    } catch (err) {
      console.log(err); // standardized err.code and err.message available
    }
  }
github HenryQuan / WoWs-Info-Re / WoWsInfo / src / component / common / Donation.js View on Github external
async componentDidMount() {
    if (!GITHUB_VERSION) {
      try {
        const products = await RNIap.getProducts(itemSkus);
        // Do this just to ensure that all IAPs are available
        await RNIap.consumeAllItems();
        products.sort((a, b) => a.price.localeCompare(b.price));
        this.setState({products});
      } catch(err) {
        console.warn(err); // standardized err.code and err.message available
      }
    }
  }
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 {
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();
      });
    }
  }
}
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();
      });
    }
  }
}
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();
      });
    }
  }
}
github guardian / editions / projects / Mallard / src / hooks / use-subscribe.ts View on Github external
const maybeAcknowledgePurchaseAndroid = async (purchase: ProductPurchase) => {
    if (requiresAcknowledging(purchase)) {
        try {
            // TODO check the response!
            return !!(await acknowledgePurchaseAndroid(
                purchase.purchaseToken || '', // if it's not set then set to empty string which will fail
            ))
        } catch (ackErr) {
            console.warn('ackErr', ackErr)
            return false
        }
    }
    return true
}
github HenryQuan / WoWs-Info-Re / WoWsInfo / src / component / common / Donation.js View on Github external
async componentDidMount() {
    if (!GITHUB_VERSION) {
      try {
        const products = await RNIap.getProducts(itemSkus);
        // Do this just to ensure that all IAPs are available
        await RNIap.consumeAllItems();
        products.sort((a, b) => a.price.localeCompare(b.price));
        this.setState({products});
      } catch(err) {
        console.warn(err); // standardized err.code and err.message available
      }
    }
  }