How to use the react-native-iap.purchaseUpdatedListener 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 guardian / editions / projects / Mallard / src / hooks / use-subscribe.ts View on Github external
useEffect(() => {
        purchaseUpdateSubscription.current = purchaseUpdatedListener(
            async (purchase: ProductPurchase) => {
                const info = await findCurrentSubInfoFromPurchases([purchase])

                // This is not a requirement on iOS
                const wasAcknowledged = await maybeAcknowledgePurchaseAndroid(
                    purchase,
                )

                if (!wasAcknowledged) {
                    // TODO: what do we do in this case? the purchase has still gone through but will
                    // be cancelled in a few days
                    onWarning('Purchase was not acknowledged')
                }

                setCurrentSubscriptionInfo(info)
                onPurchase(info)
github esteemapp / esteem-mobile / src / containers / inAppPurchaseContainer.js View on Github external
_purchaseUpdatedListener = () => {
    const {
      currentAccount: { name },
      intl,
      fetchData,
    } = this.props;

    this.purchaseUpdateSubscription = purchaseUpdatedListener(purchase => {
      const receipt = get(purchase, 'transactionReceipt');
      const token = get(purchase, 'purchaseToken');

      if (receipt) {
        const data = {
          platform: Platform.OS === 'android' ? 'play_store' : 'app_store',
          product: get(purchase, 'productId'),
          receipt: Platform.OS === 'android' ? token : receipt,
          user: name,
        };

        purchaseOrder(data)
          .then(() => {
            if (Platform.OS === 'ios') {
              RNIap.finishTransactionIOS(get(purchase, 'transactionId'));
            } else if (Platform.OS === 'android') {