question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

purchaseUpdatedListener called multiple times even after purchase

See original GitHub issue

Version of react-native-iap

5.0.1

Version of react-native

0.63.3

Platforms you faced the error (IOS or Android or both?)

IOS

Expected behavior

purchaseUpdatedListener not getting called multiple times

Actual behavior

purchaseUpdatedListener getting called on startup multiple times, sometimes even in between

Tested environment (Emulator? Real Device?)

Real device (iOS 14, 13 in Test Flight and in AppStore)

Steps to reproduce the behavior

(Navigator Component)

const itemSkus = ['01', '02'];

const processNewPurchase = async (purchase) => {
  const { productId, transactionReceipt } = purchase;
  if (transactionReceipt !== undefined && transactionReceipt) {
       //backend call with fetch - validating receipt 
        if (data.ack === 'success') {
          console.log('finished');
          await finishTransaction(purchase);
      } else if (data.ack === 'failure') {
          props.setProcessing(false);
          console.log('error');
      }
    }
};


const getProductsIAP = useCallback(async () => {
  await clearProductsIOS();
  await clearTransactionIOS();

 try {
   const result = await initConnection();
   const products = await getProducts(itemSkus);
   props.setProducts(products);
   console.log('result', result);
 } catch (err) {
   console.warn(err.code, err.message);
 }

  purchaseUpdateSubscription = purchaseUpdatedListener(
    async (purchase) => {
      const receipt = purchase.transactionReceipt;
      console.log('purchaseUpdatedListener');
      if (receipt) {
        try {
          await processNewPurchase(purchase);
        } catch (ackErr) {
           console.log('ackErr', ackErr);
        }
      } else {
        console.log('purchaseUpdatedListener error: receipt');
      }
    },
  );

  purchaseErrorSubscription = purchaseErrorListener(
    (error: PurchaseError) => {
      console.log('purchaseErrorListener', error);
      console.log(JSON.stringify(error));
    },
  );

  setLoading(false);
}, []);


useEffect(() => {
  getProductsIAP();

  return () => {
    if (purchaseUpdateSubscription) {
      purchaseUpdateSubscription.remove();
      purchaseUpdateSubscription = null;
    }
    if (purchaseErrorSubscription) {
      purchaseErrorSubscription.remove();
      purchaseErrorSubscription = null;
    }
  };
}, []);

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:10
  • Comments:51 (8 by maintainers)

github_iconTop GitHub Comments

30reactions
marcibkcommented, Nov 25, 2020

Still same problem. Looks like it´s purchaseUpdatedListener is broken. Please fix this asap. No solution found.

13reactions
edo1493commented, Nov 4, 2020

I have the following behaviour.

  1. User buys IAP.
  2. purchaseUpdatedListener gets called.
  3. User uninstalls the app.
  4. User comes back to the app.
  5. purchaseUpdatedListener gets triggered and goes in a loop.

I am using classes, but I don’t see any re-render.

I am on “react-native-iap”: “4.4.1” and “react-native”: “0.63.3”.

I have tried to upgrade to 5.0.0, but I am getting the same behaviour.

Read more comments on GitHub >

github_iconTop Results From Across the Web

purchaseUpdatedListener called multiple times even after ...
purchaseUpdatedListener called multiple times even after purchase.
Read more >
In App Purchase seems to be called multiple times
Both times, the in-app purchase data is attached but I noticed that the intent Action was different for each broadcast.
Read more >
modules - React Native IAP - dooboolab
Add IAP purchase event Register a callback that gets called when the store has any updates to purchases that have not yet been...
Read more >
react-native-iap - npm
Purchases are inter-session asynchronuous meaning requests that are made may take several hours to complete and continue to exist even after the ...
Read more >
In-App Purchases in React Native
in-app purchases reference name and product id ... Title of publication or service; Length of subscription (time period and/or ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found