Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

listener "purchaseUpdatedListener" is saved many times in my database LOOP? #1194

Closed
chiporgar7 opened this issue Nov 24, 2020 · 12 comments
Closed
Labels
🙏 help wanted Extra attention is needed 📱 iOS Related to iOS Stale

Comments

@chiporgar7
Copy link

Version of react-native-iap ^5.1.1

Version of react-native 0.63.2

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

Expected behavior

After viewing the list of products to the options that a person can subscribe.

When I click on subscribe. Show the apple-Store buy window.
after accepting, it is saved in my backend only once. Later I will do other things like validate received etc.

thereafter. Redirect to another screen as the case may be.

Actual behavior

After subscribing to a product, the first time it is saved to my back-end, once it is successful

if I exit the application and enter again but now I subscribe to another product

is saved many times
up to 10-20-30 times is too many times, that's the first time.

If I wait like 30 minutes and do it again. (Save once) but if I do it it repeats and saves many times

When I do that after 10 minutes, I really don't know the time, because it does strange things.

When I go to the products view, I still do not subscribe and it is automatically saved in my backend 10-20-30 times

"The funny thing is that the receipt I don't know how it still exists"

The purchaseUpdatedListener listener seems to repeat many times

I don't know if something is being saved in the phone's memory, or something is not making NULL that listener

Tested environment (Emulator? Real Device?) Real Device Iphone 8

Steps to reproduce the behavior

Ignore the titles of the purchases, I fix it later

these are two products that are to subscribe.

image

when is the first time. Do this.

image

My code
`
useEffect(() => {
IAP.initConnection().then(()=>{

        IAP.getProducts(productIds).then(res => {
            setProducts(res)
        });
        

        purchaseUpdateSubscription =  purchaseUpdatedListener(async(purchase :InAppPurchase | SubscriptionPurchase) => {
    
                const  receipt = purchase.transactionReceipt
    
                if(receipt) {
    
                    try {
                        
                        console.log('entra')
    
                        
                        if(Platform.OS === 'ios') {
                           await  finishTransactionIOS(purchase.transactionId)
                        }
    
    
                        await finishTransaction(purchase)
    
    
    
    
                    }catch(error){
                        //console.log(error)
                    }
    
                    }
                },
            );
    
        })
    
    return () => {
        purchaseUpdateSubscription.remove()
        purchaseUpdateSubscription = null
    };
    


}, []);
`
  • When you make your first purchase. It is not saved many times (just once) sometimes up to 2 times.

  • When you close the app and do another test. Saved many times 20-30 times

  • When you just access the products view, it is saved in automatic (I do not understand this behavior, because I have not yet clicked buy)

  • How does it continue to enter the condition of the receipt, how does it continue to exist?

this is my log

image

ignore the time with my log, I still don't configure my Backend

this happens many times. How do I fix this?

image

@Yann-prak
Copy link

Hey,

Don't forget that it can be an expected behavior if your using it in Sandbox environment. You should take a look at the apple doc and this issue.

I think that if you're using multiple Sandbox account to make different purchases, when you reload the app, each transaction will be fired up to 5 times.

Don't forget to clearTransactionIOS.

@hyochan hyochan added 📱 iOS Related to iOS 🙏 help wanted Extra attention is needed labels Feb 7, 2021
@hyochan
Copy link
Owner

hyochan commented Feb 7, 2021

Try to check if your component which renders purchaseUpdatedListener from re-rendering. Try to prevent that with useCallback in that case.

@hiennguyen92
Copy link

Hi all, any update for this?

@cocoa-rum
Copy link

Faced with same issue, but with self implemented module (not using react-native-iap)
This happens randomly after restart the app, updatedTransactions triggers it self as many times as the purchases were made before. All purchases were finished with SKPaymentQueue.default().finishTransaction before this

Looks like this is a bug within sandbox. Also random errors when trying to purchase product

@egulhan
Copy link

egulhan commented Jun 2, 2021

Faced with same issue, but with self implemented module (not using react-native-iap)
This happens randomly after restart the app, updatedTransactions triggers it self as many times as the purchases were made before. All purchases were finished with SKPaymentQueue.default().finishTransaction before this

Looks like this is a bug within sandbox. Also random errors when trying to purchase product

@cocoa-rum does the same thing happen on prod?

@pct
Copy link

pct commented Jun 5, 2021

I'm also facing this issue and I'm using React hook version of react-native-iap, currently it happened at sandbox but not happened at production. but I'm afraid that iOS App Reviewers will reject the app if they found this issue.

@hyochan Thanks for your great work, but how could I use clearTransactionIOS() correctly?

Thanks.

@Yann-prak
Copy link

This is likely a bug with sandbox. Nothing happens in prod. You can safely release your app @pct. The iOS App Reviewers never rejected mine even if the bug existed in sandbox mode.

@YaoHuiJi
Copy link

This is likely a bug with sandbox. Nothing happens in prod. You can safely release your app @pct. The iOS App Reviewers never rejected mine even if the bug existed in sandbox mode.

Thank you for your reply, which comforted me. I hope what you said is true, for many days this question drives me crazy.

@egulhan
Copy link

egulhan commented Dec 29, 2021

This is likely a bug with sandbox. Nothing happens in prod. You can safely release your app @pct. The iOS App Reviewers never rejected mine even if the bug existed in sandbox mode.

This issue also happens on prod. This is a bloody bug. Hope it gets fixed ASAP.

@stale
Copy link

stale bot commented Apr 18, 2022

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.

@stale stale bot added the Stale label Apr 18, 2022
@andresesfm
Copy link
Contributor

Can you please help us check if this is still an issue on 8.x.x for iOS?

I have found the following as something that is expected from the native SDK: https://stackoverflow.com/a/3633571/570612
If it still happens on 8.x.x and the above doesn't fix. We'll reopen. Thank you

Note: I'm not trying to minimize the issue. I see there are multiple posts about it in various forms and I'm trying to make sense of it but with no help and it being reported on such an old version of the library is close to impossible. Thank you for understanding

@Abdulmateenchitrali
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙏 help wanted Extra attention is needed 📱 iOS Related to iOS Stale
Projects
None yet
Development

No branches or pull requests

10 participants