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

To help you get started, we’ve selected a few react-native-purchases 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 RevenueCat / react-native-purchases / example / app / screens / CatsScreen.js View on Github external
async componentDidMount() {
    try {
      const info = await Purchases.getPurchaserInfo();
      this.handleInfo(info);
    } catch (e) {
      // eslint-disable-next-line no-console
      console.log("Error handling");
    }
  }
github RevenueCat / react-native-purchases / example / App.js View on Github external
async componentDidMount() {
    Purchases.setDebugLogsEnabled(true);
    Purchases.setup("api_key");
    try {
      const purchaserInfo = await Purchases.getPurchaserInfo();
      if (typeof purchaserInfo.entitlements.active.pro_cat !== "undefined") {
        this.setState({
          load: "Cats",
          loading: false
        });
      } else {
        this.setState({
          load: "Upsell",
          loading: false
        });
      }
    } catch (e) {
      // eslint-disable-next-line no-console
      console.log(`Error ${JSON.stringify(e)}`);
    }
  }
github RevenueCat / react-native-purchases / example / app / screens / CatsScreen.js View on Github external
onPress={async () => {
                      try {
                        const info = await Purchases.restoreTransactions();
                        this.handleInfo(info);
                      } catch (e) {
                        // eslint-disable-next-line no-console
                        console.log(JSON.stringify(e));
                      }
                    }}
                  >
github RevenueCat / react-native-purchases / example / App.js View on Github external
async componentDidMount() {
    Purchases.setDebugLogsEnabled(true);
    Purchases.setup("api_key");
    try {
      const purchaserInfo = await Purchases.getPurchaserInfo();
      if (typeof purchaserInfo.entitlements.active.pro_cat !== "undefined") {
        this.setState({
          load: "Cats",
          loading: false
        });
      } else {
        this.setState({
          load: "Upsell",
          loading: false
        });
      }
    } catch (e) {
      // eslint-disable-next-line no-console
      console.log(`Error ${JSON.stringify(e)}`);
github RevenueCat / react-native-purchases / example / app / screens / UpsellScreen.js View on Github external
onPress={async () => {
                  const aPackage = this.state.offerings.current.lifetime;
                  try {
                    const purchaseMade = await Purchases.purchasePackage(aPackage, {oldSKU: "old", prorationMode: Purchases.PRORATION_MODE.DEFERRED}, Purchases.PURCHASE_TYPE.SUBS);
                    checkIfPro(purchaseMade.purchaserInfo, this.props.navigation);
                  } catch (e) {
                    if (!e.userCancelled) {
                      // eslint-disable-next-line no-console
                      console.log(`Error handling ${JSON.stringify(e)}`);
                    } else {
                      // eslint-disable-next-line no-console
                      console.log(`User cancelled ${JSON.stringify(e)}`);
                    }
                  }
                }}
                title={this.state.proMonthlyPrice}
github RevenueCat / react-native-purchases / example / app / screens / UpsellScreen.js View on Github external
async componentDidMount() {
    try {
      this.purchaserInfoUpdateListener = (info) => {
        checkIfPro(info, this.props.navigation);
      };
      this.shouldPurchasePromoProduct = async deferredPurchase => {
        this.deferredPurchase = deferredPurchase;
      };
      Purchases.addPurchaserInfoUpdateListener(this.purchaserInfoUpdateListener);
      Purchases.addShouldPurchasePromoProductListener(this.shouldPurchasePromoProduct);
      const offerings = await Purchases.getOfferings();
      // eslint-disable-next-line no-console
      console.log(JSON.stringify(offerings));
      this.setState({
        offerings,
        proAnnualPrice: `Buy Annual w/ Trial ${
          offerings.current.annual.product.price_string
        }`,
        proMonthlyPrice: `Buy Monthly w/ Trial ${
          offerings.current.lifetime.product.price_string
        }`
      });
    } catch (e) {
      // eslint-disable-next-line no-console
      console.log("Error handling");
github RevenueCat / react-native-purchases / example / app / screens / UpsellScreen.js View on Github external
async componentDidMount() {
    try {
      this.purchaserInfoUpdateListener = (info) => {
        checkIfPro(info, this.props.navigation);
      };
      this.shouldPurchasePromoProduct = async deferredPurchase => {
        this.deferredPurchase = deferredPurchase;
      };
      Purchases.addPurchaserInfoUpdateListener(this.purchaserInfoUpdateListener);
      Purchases.addShouldPurchasePromoProductListener(this.shouldPurchasePromoProduct);
      const offerings = await Purchases.getOfferings();
      // eslint-disable-next-line no-console
      console.log(JSON.stringify(offerings));
      this.setState({
        offerings,
        proAnnualPrice: `Buy Annual w/ Trial ${
          offerings.current.annual.product.price_string
        }`,
        proMonthlyPrice: `Buy Monthly w/ Trial ${
          offerings.current.lifetime.product.price_string
        }`
      });
    } catch (e) {
      // eslint-disable-next-line no-console
      console.log("Error handling");
    }
github RevenueCat / react-native-purchases / example / app / screens / UpsellScreen.js View on Github external
async componentDidMount() {
    try {
      this.purchaserInfoUpdateListener = (info) => {
        checkIfPro(info, this.props.navigation);
      };
      this.shouldPurchasePromoProduct = async deferredPurchase => {
        this.deferredPurchase = deferredPurchase;
      };
      Purchases.addPurchaserInfoUpdateListener(this.purchaserInfoUpdateListener);
      Purchases.addShouldPurchasePromoProductListener(this.shouldPurchasePromoProduct);
      const offerings = await Purchases.getOfferings();
      // eslint-disable-next-line no-console
      console.log(JSON.stringify(offerings));
      this.setState({
        offerings,
        proAnnualPrice: `Buy Annual w/ Trial ${
          offerings.current.annual.product.price_string
        }`,
        proMonthlyPrice: `Buy Monthly w/ Trial ${
          offerings.current.lifetime.product.price_string
        }`
      });
    } catch (e) {
      // eslint-disable-next-line no-console
      console.log("Error handling");
    }
  }
github RevenueCat / react-native-purchases / example / app / screens / UpsellScreen.js View on Github external
onPress={async () => {
                  const product = this.state.offerings.current.annual.product.identifier;
                  try {
                    const purchaseMade = await Purchases.purchaseProduct(product);
                    checkIfPro(purchaseMade.purchaserInfo, this.props.navigation);
                  } catch (e) {
                    if (!e.userCancelled) {
                      // eslint-disable-next-line no-console
                      console.log(`Error handling ${JSON.stringify(e)}`);
                    } else {
                      // eslint-disable-next-line no-console
                      console.log(`User cancelled ${JSON.stringify(e)}`);
                    }
                  }
                }}
                title={this.state.proAnnualPrice}
github RevenueCat / react-native-purchases / example / App.js View on Github external
async componentDidMount() {
    Purchases.setDebugLogsEnabled(true);
    Purchases.setup("api_key");
    try {
      const purchaserInfo = await Purchases.getPurchaserInfo();
      if (typeof purchaserInfo.entitlements.active.pro_cat !== "undefined") {
        this.setState({
          load: "Cats",
          loading: false
        });
      } else {
        this.setState({
          load: "Upsell",
          loading: false
        });
      }
    } catch (e) {
      // eslint-disable-next-line no-console