j3k0 / cordova-plugin-purchase

In-App Purchase for Cordova on iOS, Android and Windows
https://purchase.cordova.fovea.cc
1.29k stars 529 forks source link

IAP weird behavior and disability to restore old purchases. #334

Closed anonrig closed 5 years ago

anonrig commented 8 years ago

Hello,

I have 3 different non-renewable subscriptions in my itunes connect account. I've added my gist to https://gist.github.com/anonrig/cfdf88ad3a1d2f7d3b46

I have 3 questions and problems to ask the developers of this plugin.

1) Everytime the application is loaded, it prompts for my iTunes Store account email&password. (It shouldn't have done it unless I buy the product)

2) Calling inAppPurchase.restore() only calls onRestoreCompleted method and doesn't call any other method.

3) Even though it says that it takes 5 minutes for a monthly subscription in sandbox to expire, it doesn't expire at all. Therefore I tried validator method and nothing have changed. Any suggestions?

4) If a subscription is still active and you try to buy it again it says It will be restored free but there isn't any recognition in plugin side regarding which function will be called upon that

saniyusuf commented 8 years ago

I have point one as a problem 1 @anonrig . I keep getting the popup eveytime app starts or when it goes into background and back. Why is this happening and It happens on sabox mode.

d3orn commented 8 years ago

I am currently looking into it. Hope I will find a solution soon. It looks as if the observer is not removed correctly. I will post a possibly fix and PR if I figure it out

saniyusuf commented 8 years ago

@d3orn thanks man If there is anyway I can be of service please let me know. +1

d3orn commented 8 years ago

@saniyusuf well as soon as I have a solution it would be cool to have somebody else approve it as well xD

Update: Figured out that it is caused by the Observer added in the setup method. This observer is needed but it could be possible to add it only if a user is buying something instead of on start up. I will post updates

anonrig commented 8 years ago

@d3orn any other information about other problems that I faced?

d3orn commented 8 years ago

well 2) is the same for me but I guess it was changed by Apple and now it works this way. (I was using another plugin for IAP until yesterday and it stopped working maybe because of this. 4) I did look into it but did not find anything from the Apple Docs. I guess you should just provide a button to restore the purchases. I will try to figure 1) out today cause I need to submit my app ASAP xD P.S If anybody has time to help just write and we can see what we can do about this issue P.S.S The main issue is, that unfinished transaction still are save in the app and everytime a new observer is created all the unfinished transaction get sent to Apple, therefore calling for a user login. I have a clue how to solve it but not 100% sure and I will need some testers afterwards

d3orn commented 8 years ago

@anonrig @saniyusuf guys can you try if my fork works for you as well. Important: completely delete your app and sign out the iTunes account form your device before installing. (also stop the app in xcode xD).

My fork: https://github.com/d3orn/cordova-plugin-purchase/tree/transactionFix

Also @anonrig 4) is working for me I will get a call to 'onPurchase' and also I get triggers onRestore now...

Please tell me if it is working for you as well.

anonrig commented 8 years ago

@d3orn I've installed your fork and tried it. Unfortunately, it failed to solve problem 1. On the other hand, I found out that whenever storekit.load([]) function is called, automatically it adds a prompt for user&pass. So, maybe we should change our perspective on this matter on focus on load section?

d3orn commented 8 years ago

interesting. It is working perfectly fine for me. Could you first remove the plugin at all and see if you still get the pop ups. Only if no pop ups show up try my plugin again. Like I wrote the transactions are sometimes stuck in a weird state. Yes the storekit.load function adds an observer and if transactions are stuck this observer prompts the user & pass. My fix just removes the transaction if it is finished/restored or failed.

anonrig commented 8 years ago

@d3orn I logged out of AppStore and than installed it. After this operation, it didn't ask for any user&pass, but there are some other minor issues. I'm using the exact same code on GIST

1) onRestore function isn't called (again)

2) I have an error on purchasing. "[Log] InAppPurchase[js]: exception in options.purchase: "ReferenceError: Can't find variable: productId" (store-ios.js, line 794)"

3) onPurchase function isn't called at all.

UPDATE ON #2: There is a bug in example code, such that the function in onPurchase should have productId and transactionId

d3orn commented 8 years ago

can you try onRestore: function(transactionId, productId, transactionReceipt){} (same for onPurchase)

anonrig commented 8 years ago

I tried it @d3orn but the function isn't called at all upon restore.

d3orn commented 8 years ago

what about purchase?

anonrig commented 8 years ago

Purchase is working fine after your update. You're the best. @d3orn

d3orn commented 8 years ago

well I spent like 6h on this issue xD. So onPurchase is called and you do not have the prompt afterwards? So the only thing not working for you is the onRestore?

P.S I will pullrequest my branch as soon as I got some feedback

saniyusuf commented 8 years ago

@d3orn my problem still exisit unfortunately. This is what we do just like the docs we attach listners and call restore fucntion when app starts. However whenever app starts it asks for login to itunes. And once app goes to background and back, it asks for the same again and again.

Any Clues?

d3orn commented 8 years ago

@saniyusuf did you try my fork? Did you log out completely (settings) and deleted the app (see chat with @anonrig)

saniyusuf commented 8 years ago

@d3orn yes i did I delete the app. Not sure about the order of logging out I can try again if that is critical.

d3orn commented 8 years ago

@saniyusuf well if you are at it also delete the sandbox user and create a new one. Furthermore try to do what I suggested to @anonrig build the app without the plugin, see if the prompt pops up if not build with my fork

saniyusuf commented 8 years ago

@d3orn ahaaa i rmeoved the plugin and the popup behaviour persists. And this is when I am logged out of the device. What does this indicate please?

anonrig commented 8 years ago

@saniyusuf if you just replace the plugins/inappurchase folder with the one that @d3orn 's fork (you should install the transactionFix branch) it will solve your problem.

ps. The only problem I've been facing is restore function right now.

d3orn commented 8 years ago

@saniyusuf this means you have some stuck transactions. There are two possible ways to solve this. First log in a couple of times (10 or so) and see if it persists otherwise delete the app, logout and reboot your device.

anonrig commented 8 years ago

When your remove the plugin on plugins folder just remove the ios platform and readd it using 'cordova platform rm ios && cordova platform add ios'

d3orn commented 8 years ago

@anonrig can you test if you actually cal your restore function (console.log or what ever). Furthermore what IAP product are you trying to restore it has to be a non-consumable!

anonrig commented 8 years ago

Yes, I tested it multiple times, and it is non consumable. @d3orn

saniyusuf commented 8 years ago

@anonrig this is undoable for us as we have some in house customisation of our IOS project which is why we actually version control it due to this heavy customisation. Is there any reason why the platform needs removing and do you know what native files it affects so we can do try to do this manually?

anonrig commented 8 years ago

@saniyusuf Because @d3orn 's fork is not registered to any npm package, you should do this in order to check if it's working. When he sends a pull request to this branch, you can go back to having a version control system based solution. In that process, just don't ignore the plugins/inapppurchase folder in your gitignore

d3orn commented 8 years ago

@saniyusuf yes of course I know which files to change xD just replace your platforms/ios/Plugins/.purchase folder with my files and also platforms/ios/www/plugins/.purchase with my file

@anonrig can you provide a current gist of your problem

anonrig commented 8 years ago

I've updated my gist @d3orn https://gist.github.com/anonrig/cfdf88ad3a1d2f7d3b46

d3orn commented 8 years ago

@anonrig what does storekit.finish(transactionId); ? Well I am sorry I do not see why it is not working currently. Maybe I get back to it later this evening

saniyusuf commented 8 years ago

@d3orn @anonrig not sure what I am doing wrong but even after I have removed the app signed out used your forked files, as soon as the app starts i still get a popup asking for itunes details. As soon as I put it it doesnt come up again even when i have tapped the manual resotre button.

However asap I go background and back, the popup comes up again asking for itunes details.

d3orn commented 8 years ago

@saniyusuf see my previous post about stuck transaction try to build without the plugin at all you need to get rid of all stuck transactions first before anything helps

anonrig commented 8 years ago

@saniyusuf @d3orn maybe we should take a shot on google chat or slack for communication?

saniyusuf commented 8 years ago

yes I agree @anonrig the cordova slack channel? or which one?

anonrig commented 8 years ago

Cordova slack channel is perfect @d3orn @saniyusuf

saniyusuf commented 8 years ago

To get rid of the annoyin login popup, use this link to the branch provided in this comment where there is a fix. You might have to delte your app completely from the phone and sign out restart you phone and even remove and re add the IOS project then run again after putting the fix. https://github.com/d3orn/cordova-plugin-purchase/tree/transactionFix

d3orn commented 8 years ago

@saniyusuf so you figured it out and my fix is working? Do you get onRestore and onPurchase callbacks? I will pull request my branch as soon as I get your feedback

anonrig commented 8 years ago

Your fix is working perfectly @saniyusuf

saniyusuf commented 8 years ago

@d3orn i dont use the onRestore or onPurchase callbacks in my case so I cant know for sure. @anonrig might be able to help on this one

pvandrunen commented 8 years ago

Hi everyone, not sure if this is the same issue or not — I installed transactionFix because I was constantly being asked to put in passwords for old test accounts. Also, products that were purchased with old test accounts always validate using remote validation — I think that the API is returning receipts for products purchased with old test accounts.

I installed transactionFix but now when I start the app it insists that I login, it cycles through requiring me to put in the password for several user accounts that I used in the past, but no longer exist. When I cancel, it pops up a message saying I have to login, prompts me with a password field for a different non-existent test account and so on.

I've deleted the app. Logged out in settings. I've restarted the device. I've done all three at once. Same behavior: I launch the app, it insists I login with a test account that was deleted a long time ago and if I hit cancel the another pop-up says I have to login. Rinse, repeat.

pvandrunen commented 8 years ago

Update: after clicking cancel a million times, restarting the app, etc. I was able to get things to start behaving better.

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.