react-native-iap
react-native-iap copied to clipboard
purchaseUpdateSubscription runs multiple times which cause multiple times DB query
Please use Discussion board if you want get some help out of it. Please report issue if there is a bug.
Version of react-native-iap : 6.0.6
Version of react-native : 0.62
Platforms you faced the error (IOS or Android or both?) : both
Expected behavior :
Actual behavior
Tested environment (Emulator? Real Device?) Real Device
Steps to reproduce the behavior
Code :
const getProducts = useCallback(async () => { await RNIap.clearProductsIOS(); await RNIap.clearTransactionIOS(); await RNIap.flushFailedPurchasesCachedAsPendingAndroid();
try {
const result = await RNIap.initConnection();
console.log('result', result);
} catch (err) {
console.warn(err.code, err.message);
}
purchaseUpdateSubscription = purchaseUpdatedListener(
async (purchase) => {
const receipt = purchase.transactionReceipt;
if (receipt) {
try {
if (purchase.purchaseStateAndroid === 1 && !purchase.isAcknowledgedAndroid) {
// RNIap.consumePurchaseAndroid(purchase.purchaseToken)
const ackResult = await RNIap.acknowledgePurchaseAndroid(purchase.purchaseToken);
console.log("ackResultpurchase", purchase);
}
// IOS
if (Platform.OS == "ios") {
// alert(purchase.transactionId)
await RNIap.finishTransactionIOS(purchase.transactionId);
}
const ackResult = await finishTransaction(purchase);
console.log('ackResult', ackResult);
} catch (ackErr) {
console.warn('ackErr', ackErr);
}
// Alert.alert('purchase error', JSON.stringify(receipt));
}
},
);
purchaseErrorSubscription = purchaseErrorListener(
(error) => {
console.log('purchaseErrorListener', error);
Alert.alert('purchase error', JSON.stringify(error));
},
);
const productss = await RNIap.getProducts(itemSkus);
setProducts(productss);
productss.forEach((product) => {
products.type = 'inapp';
});
// console.log('products', JSON.stringify(productss));
}, []);
useEffect(() => { getProducts();
return () => {
if (purchaseUpdateSubscription) {
purchaseUpdateSubscription.remove();
}
if (purchaseErrorSubscription) {
purchaseErrorSubscription.remove();
}
};
}, []);
One of the things I notice is that you didn't add getProducts
as a dependency to the useEffect
hook. I'm not quite sure how this would affect your code but make sure that your listeners are never registered more than once
I'm also facing this issue, if the previous purchase was not acknowledged then it appears every app opening
I'm also facing this issue, if the previous purchase was not acknowledged then it appears every app opening
if you didn't acknowledge the purchase - then this is not an issue. I's supposed to appear again so you can proceed acknowledge it. Once you complete validating your receipt you should consume or acknowledge the purchase depending on its type.
If the server is down and from the app we could not validate the receipt and the user tried multiple times then it will trigger multiple purchases using the purchaseUpdatedListener. Is there any way to avoid that?
If the server is down and from the app we could not validate the receipt and the user tried multiple times then it will trigger multiple purchases using the purchaseUpdatedListener. Is there any way to avoid that?
Hello sir, have you found any solution for the same, purchaseUpdatedListener is firing multiple time
purchaseUpdatedListener is being fired multiple times on opening the app and is not being fired when the actual purchase is being made.
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.
Same issue here. Although the transaction is finished correctly, the listener keeps firing in some cases..don't know how to reproduce unfrotuantly.
Please open a new issue if this is still happening on the latest version. Please include what kind of transactions are being sent. Are they cancelled for example? They should be easy to filter