purchaseUpdatedListener is repeatedly called
See original GitHub issueVersion of react-native-iap
4.3.0
Version of react-native
0.60.5
Platforms you faced the error (IOS or Android or both?)
Both
Expected behavior
Following the example I want to call a custom method after my subscription has been purchased. It is my understanding that after acknowledging the purchase the listener should be removed? I have tried explicitly calling remove
but had no success.
Example
const purchaseListener = purchaseUpdatedListener(purchase => {
const receipt = purchase.transactionReceipt;
if (receipt) {
callCustomEndpoint().then(result => {
if(result){
// Subscription is valid
finishTransaction(purchase);
}
})
};
finishTransaction(purchase);
});
Actual behavior
The callCustomEndpoint() method is being called multiple times. How can I stop this from happening? As I only need to hit this endpoint once.
I’m using a functional component instead of class component if it’s important.
Tested environment (Emulator? Real Device?)
Real Device
Steps to reproduce the behavior
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
purchaseUpdatedListener called multiple times even after ...
Any solution I am facing the same issue of calling both purchaseUpdatedListener purchaseErrorListener multiple times (more than 15 times).
Read more >java - onPurchasesUpdated called multiple times
When I call launchBillingFlow on the BillingClient : BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder() .
Read more >purchaseUpdatedListener called multiple times even after ...
purchaseUpdatedListener called multiple times even after purchase.
Read more >react-native-iap - npm
On Android, it can be called at app launch, but on iOS, only at restoring purchase is ... purchaseUpdatedListener will receive the result....
Read more >React Native: Subscriptions with In-App Purchases - Ross Bulat
The way react-native-iap keeps track of incoming transactions is via ... processNewPurchase is called inside the purchaseUpdatedListener ...
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
I am going to put down my solution for hooks for those who will need it later on.
outside your state component (though probably works also inside):
inside your state component:
@wootwoot1234 @osmantuna Can you please provide the event handler codes if you managed to fix it?