purchaseUpdatedListener called multiple times even after purchase
See original GitHub issueVersion 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:
- Created 3 years ago
- Reactions:10
- Comments:51 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Still same problem. Looks like it´s purchaseUpdatedListener is broken. Please fix this asap. No solution found.
I have the following behaviour.
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.