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

Fix for prompt appearing on app start #338

Closed d3orn closed 7 years ago

d3orn commented 8 years ago

This fix solves the problem of the reappearing sign in prompt on app start which was cause by transactions being stuck in a unfinished state and therefore the observer always tried to finish does transactions. This is probably not the nicest fix but it works and has been tested with 3 different apps. If you have a better way of fixing this go ahead but at least with this pull request the plugin can be used without the annoying prompts

j3k0 commented 8 years ago

Hello,

This will break apps that provide downloadable content. For those apps, finish should only be called when the content has been provided (if download fails, app should retry at every restart).

Actually this is also true for any kind purchase, if the user closes the app (or get called) between the purchase and the moment your app is done unlocking the feature... He may have paid but didn't get what he paid for.

If you have unfinished transaction stuck in the queue, it's most probably because you didn't finish them properly (after the feature has been delivered): see https://github.com/j3k0/cordova-plugin-purchase/blob/master/doc/api.md#finish-a-purchase

d3orn commented 8 years ago

Ok, I see but could you have a look at https://github.com/j3k0/cordova-plugin-purchase/issues/334. The gist from him is what I am doing in my app currently (more or less) and we (3 people) all had the same problem. Maybe another example with the structure @anonrig is using would be nice because this is how a lot of people actually us your plugin! Keep up your work, awesome plugin I hope I can us it soon

anonrig commented 8 years ago

@j3k0 you can see an example from my gist https://gist.github.com/anonrig/cfdf88ad3a1d2f7d3b46

in such case, even though the transaction is completed, it prompts for username&password

LukePulverenti commented 8 years ago

@j3k0 since you do not consider this best practice, is there an alternative that you can suggest to resolve this? My users are also reporting repeated password prompts on app starts, and I believe I've followed your samples almost exactly. Thanks.

saniyusuf commented 8 years ago

are you saying we stay away from this fix @anonrig @j3k0

LukePulverenti commented 8 years ago

Has anyone tested this with a subscription? Could this result in receipt validation being bypassed?

bwalsh commented 8 years ago

Any progress on this? Does it only affect testflight users? Will it affect production users?

Cordova CLI: 5.4.0 Gulp version: CLI version 3.9.0 Gulp local: Local version 3.9.0 Ionic Version: 1.1.1 Ionic CLI Version: 1.7.10 Ionic App Lib Version: 0.6.5

anonrig commented 8 years ago

I've tested it with subscription. And this solution works well. But don't quite tested the case that @j3k0 told. @LukePulverenti

LukePulverenti commented 8 years ago

Thanks for reporting your results. I too have implemented it in my app until the developer provides an alternative solution.

I do still see repeated password prompts, but only in the situation of attempting to restoring a purchase after disabling the app store on the device (e.g., parental controls). Aside from this scenario it seems to be working well.

See here about that:

https://github.com/j3k0/cordova-plugin-purchase/issues/356

NGumby commented 8 years ago

@j3k0 I think I might have found the reason why the purchase is never finished. After my purchase, when I get to this code :

    if(downloads){
        [[SKPaymentQueue defaultQueue] startDownloads:transaction.downloads];
    }
    else if (g_autoFinishEnabled && canFinish) {
        [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
        [self transactionFinished:transaction];
    }
    else {
        [unfinishedTransactions setObject:transaction forKey:transactionIdentifier];
    }

downloads is not nil, but it's an array of 0 objects. So unfinishedTransactions is never set. When you call product.finish(), you get this log :

InAppPurchase[objc]: Cannot finish transaction 

So the correct fix seems to be this :

    if(downloads && [downloads count] > 0){
        [[SKPaymentQueue defaultQueue] startDownloads:transaction.downloads];
    } else ...

Let me know if this works for anybody else!

j3k0 commented 8 years ago

@NGumby this fix was already in master. I published a new version of the plugin that includes it (4.1.0)

LukePulverenti commented 8 years ago

Fyi - I do have a report from a user who shows that their subscription completed in iTunes but that they did not actually get what they paid for. Since I am currently unsure of the issue I suspect that the guidance from @j3k0 came true in this case.

Still @j3k0, you've been very quiet on this issue and there are a number of us reporting it. It would be great if you could help us hunt down a solution. Thanks.

j3k0 commented 8 years ago

Hi, I haven't been working on a Cordova app with in-app purchase since iOS 9, so I didn't really have the opportunity to look deeper into that yet... and do not know much about why this happens.

The attempted fix in this PR seems to indicate that there are some unfinished purchase in the StoreKit queue that causes the prompt to appear. If someone can track down "why?" then we may have some cleaner solution to the issue.

Volunteers?

LukePulverenti commented 8 years ago

Has anyone reproduced on iOS8? Are we sure it's iOS9-specific?

j3k0 commented 8 years ago

I didn't heard of anyone having this issue before iOS 9, so it most probably is specific.

bwalsh commented 8 years ago

This started with os9, didn't happen before, does not happen on Android On Dec 19, 2015 10:46 AM, "Jean-Christophe Hoelt" notifications@github.com wrote:

I didn't heard of anyone having this issue before iOS 9, so it most probably is specific.

— Reply to this email directly or view it on GitHub https://github.com/j3k0/cordova-plugin-purchase/pull/338#issuecomment-166013449 .

mralj commented 7 years ago

Hey, are there any updates on this issue :) ?

VanVan commented 7 years ago

Same issue with finished subscription on iOS 9. App prompt User for password at app startup

saniyusuf commented 7 years ago

Why was this issue closed? @j3k0 Has there been a definitive fix?