RevenueCat / purchases-flutter

Flutter plugin for in-app purchases and subscriptions. Supports iOS, macOS and Android.
https://www.revenuecat.com/
MIT License
608 stars 170 forks source link

Android Billing Confirmation Issue - Couldn't find purchase lists, trying to find single data. #249

Closed arodriguezgb closed 3 years ago

arodriguezgb commented 3 years ago

Describe the bug SDK is 3.4.5 Everything works on IOS, but android is not. Same code.

When the subscription is successful I get this message on the log.

W/BillingHelper( 5733): Couldn't find purchase lists, trying to find single data.

The subscription is working, but i cant get the confirmation working and it was working before. Im not really sure when it started malfunctioning, I noticed now because I am working on an event trigger based on the purchase confirmation.

  1. Environment In Pubspec file: purchases_flutter: ^3.4.5
    
    `Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel stable, 2.5.0, on macOS 11.5.2 20G95 darwin-x64, locale en-US)
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    [✓] Xcode - develop for iOS and macOS
    [✓] Chrome - develop for the web
    [✓] Android Studio
    [✓] Android Studio (version 4.1)
    [✓] VS Code (version 1.58.2)
    [✓] Connected device (2 available)

• No issues found! `

2. Debug logs that reproduce the issue
3. The only thing on the log is this 

W/BillingHelper( 5733): Couldn't find purchase lists, trying to find single data. W/[Purchases] - WARN( 5733): 🤖‼️ There's more than one sku in the PurchaseHistoryRecord, but only one will be used.

3. Steps to reproduce, with a description of expected vs. actual behavior
This works perfectly on IOS, but on Android buying the item never returns a confirmation so I cannot trigger an event or close the page.Here is some code.
                         PurchaserInfo purchaserInfo =
                            await Purchases.purchasePackage(_packages[0]);

                        if (purchaserInfo != null) {

                          var isPro = purchaserInfo
                              .entitlements.all["Premium"]!.isActive;

                          if (isPro) {
                            final Map eventValues = {"userId": _userId};

                            if (Platform.isIOS) {
                              appsflyerSdk.logEvent(
                                  'inapp_purchase_ios', eventValues);
                            } else {
                              appsflyerSdk.logEvent(
                                  'inapp_purchase_android', eventValues);
                            }                    

4. Other information (e.g. stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, etc.)

**Additional context**
Like I mentioned before this is not an issue on IOS as everything works fine. When the user purchases the subscription I get the confirmation, I trigger my event  and the close the current page. But on Android I get the issue I shared here.
ghost commented 3 years ago

Hello! It doesn't seem like we have quite enough information to send this to a human yet to help out. We would love if you could provide more details about your issue by following the template without modifying any of the pre-filled text. If you're looking for support, head over to our Help Center to get in touch with our team directly.

stwarwas commented 3 years ago

I'm also experiencing a problem with the billing confirmation under Android.

As test user who performs a purchase I receive an email confirming that I purchased the subscription.

Short after I get another email telling me that the subscription was not confirmed.

As I understood from the documentation revenuecat should confirm it automatically.

The observer mode is off.

Error code 2: "There was a problem with the Play Store"

aboedo commented 3 years ago

hi!! 👋 thanks for reporting, I'm going to try to reproduce and report back.

developer-farhan commented 3 years ago

@aboedo Purchases.addPurchaserInfoUpdateListener is not working for me

im using the latest sdk 3.4.5

im testing to get my grip on the package but im getting a little issues

basically I have one stful widget and in that widget I have an App bar and 1 button in centre

in my INIT state I have used the following code

**@override void initState() {

Purchases.addPurchaserInfoUpdateListener((purchaserInfo) {
  activeSubscriptions = purchaserInfo.entitlements.active.values.toList();

  print(activeSubscriptions.length);
  print(purchaserInfo.activeSubscriptions.length);
  setState(() {
    color = activeSubscriptions.isEmpty || activeSubscriptions == null
        ? Colors.red
        : Colors.green;
  });
});
super.initState();

}**

im trying to make appBar color change depending on subscription state

when I make a purchase and I get the successful prompt the app bar goes green so this works exactly how I want but when the expiration time ends it does not go back to red UNTIL the state is set again

aboedo commented 3 years ago

hi everyone!! There seem to be a few different things going on in this ticket, so I'll address them one at a time:

@arodriguezgb This message happens when you haven't added the email you're using in Google Play to the licensed testers list. Here's our guide on getting that set up, let me know if that doesn't do the trick!

@stwarwas that's correct, our SDK automatically acknowledges purchases. It sounds like there might be an issue with your Google Play Store configuration in the RevenueCat dashboard. Does the purchase show up there? (Remember to check "View Sandbox data" on the top right). If it' doesn't get registered at all, here's our guide to setting up credentials. If that doesn't help, would you mind opening up a separate ticket so we can track it there and figure out what's going on?

@officialFlutterDeveloper and I continued the conversation on a separate ticket for their concerns, if there are any more related questions let's continue on that ticket.

arodriguezgb commented 3 years ago

@aboedo The account is on the licensed testers.

I thought it could be the account at first but I tried different accounts on different phones and the same issue, the confirmation never happens.

The process was working fine and it stopped working, same code, nothing changed.

It doesn't work on debug, it doesn't work live. The confirmation just never happens.

The app has been on production for almost two years now, and it was working fine. It all started suddenly, i dont know what version caused this as I noticed because I had to do something else with the confirmation.

Whats supposed to happen:

The user buys the subscription, google play says all is okay, the check mark appears. I check for the status, it says premium, etc. I can confirm the entitlement is active I close the window, because i get that the entitlement is active.

Whats happening: The user buys the subscription, google play says all is okay, the check mark appears. I cannot confirm the entitlement because its never found. The page never closes because its not confirmed.

Edit:

The subscription is working fine, but the confirmation of subscription is not.

I guess I will have to downgrade the plugin and see when it was last working.

aboedo commented 3 years ago

@arodriguezgb Thanks for the quick response!

Does the MagicWeather sample app work correctly for you on the same account? If you haven't yet, all you need to do to test it is to edit constant.dart to set up your API key and entitlement id.

I just tested it and it works correctly on my account on purchases_flutter 3.4.5.

I'm asking to try to figure out whether the problem could be on the app or on the account.

arodriguezgb commented 3 years ago

Im getting thus ready, however, there may be something because this was working on earlier versions of the plugin.

Unless something changed in how things have to be done and I missed it.

aboedo commented 3 years ago

awesome, let me know how it goes!

arodriguezgb commented 3 years ago

@aboedo The subscription status on Weather app is Active. However I mentioned before the subscription is working fine.

Like , if the user restarts the app after doing the subscription, the user will be subscribed.

This app does not cover the issue im having , unless im doing something wrong.

The issue I am having is that after I successfully subscribe, revenuecat is not finding the premium entitlement right away so I can't confirm the order and close the window etc.

Im following the SDK guide and its not working forme, but it was.

edit:

try {
  PurchaserInfo purchaserInfo = await Purchases.purchasePackage(package);
  var isPro = purchaserInfo.entitlements.all["my_entitlement_identifier"].isActive;
  if (isPro) {
    // Unlock that great "pro" content
  }
} on PlatformException catch (e) {
  var errorCode = PurchasesErrorHelper.getErrorCode(e);
  if (errorCode != PurchasesErrorCode.purchaseCancelledError) {
    showError(e);             
  }
}

IsPro is never called, because the active entitlements are not being found or something. It doesn't find it. It has nothing to do with debug, since I confirmed it's happening on production with live payments aswell.

Sadly i cant confirm since when this started happening.

aboedo commented 3 years ago

thanks for reporting back! A couple of questions:

arodriguezgb commented 3 years ago

I am not sure if it shows there, but its definitely working.

this is what happens: When the subscription is successful on google's framework, I don't get the confirmation right away. But lets say if I close the app and open it again, I am subscribed. So it definitely works,

but that's not the way it should work, the subscription confirmation should work right away to confirm isPRO like in the code I pasted above which is the one on the documentation

And same thing on the second point, the identifier is is correct, its the same yes. Right away entitlements.isActive does not show anything I believe because isPro is not working. But like i said, the sub worked fine, its just in that moment, if I close the app and open it again, when I check again for active entitlements its there and it says its Active.

the issue is here at the time of purchase.

  PurchaserInfo purchaserInfo = await Purchases.purchasePackage(package);
  var isPro = purchaserInfo.entitlements.all["my_entitlement_identifier"].isActive;
  if (isPro) {
    **// THIS IS NEVER BEING CALLED BECAUSE ISACTIVE IS NOT WORKING RIGHT AWAY**
}
aboedo commented 3 years ago

@arodriguezgb thanks for your patience on this one. And yes, what you describe is the expected behavior - isActive should be true for the entitlement that's coming from the purchaserInfo instance returned by purchasePackage.

I haven't been able to reproduce the bug yet, though: I just tried this again on one of our sample apps, on 3.4.5, with the following code:

image

And I did go into isPro right away. I'm not sure what might be happening for your case. Have you tried with other test users?

Any chance that the code within isPro is being called, but it's not making the expected updates? I imagine you might have tested this already, but I'm trying to cover all bases.

arodriguezgb commented 3 years ago

@aboedo Yes , I have tried with other tests users.

No , i have tried removing everything and just doing comments like you have there, but it does not get inside isPro. It doesnt get to the else either.

Im not sure what can be causing this :(.

Edit:

This warning could cause that issue ? W/[Purchases] - WARN(12683): 🤖‼️ There's more than one sku in the PurchaseHistoryRecord, but only one will be used.

Not from RevCat, but https://github.com/flutter/flutter/issues/35741

Nothing that could get me to think that is why im having the issue tho.

Edit 2:

I just noticed this when im setting up the revcat when the app launcher.

await Purchases.setup("IDGOESHERE",
    appUserId: userid.uid);

E/[Purchases] - ERROR(15061): 😿‼️ Error performing request. E/Purchases(15061): Error fetching subscriber data: Error performing request.

What these two errors mean ? Could that be it.. I am testing on IOS now to see if that error also pops up.

YUP. I dont know what that issue means because I cant find anything to it on the documents but that doesnt happen on IOS wich is why maybe its working.

Edit 3:

Im using the sdk debugging tools i dont know why I didnt before. I think im close to finding a solution, if this works ill update back.

Edit 4:

I have fixed the issue , so for some reason it seems that the Purchases.setup was being called again after doing the Purchase and that seems to have cancelled the completion of the object from purchases so it seems thats why I wasn't getting it. Took a while to figure out what was wrong.

Im sorry for taking too much time on your part and it ended up being on me.

Im going to close this issue ,thanks for your help.

aboedo commented 3 years ago

@arodriguezgb Thanks for the update! I'm glad you figured this out! For what it's worth, we've been thinking about ways to make it more apparent when there's a problem like setup being called more than once, so that this kind of thing is less likely to happen.

Don't hesitate to reach out again if you run into more issues in the future.

Have a great day! Andy

daniel-hopkins commented 2 years ago

If anyone has a similar issue where ios is working, but not android. Perhaps you are sending your apple apiKey to google like I was :(. Now I'm checking platform and it works perfectly.

if (Platform.isAndroid) {
      apiKey = Config.revenueCatAPIKey_google;
    } else if (Platform.isIOS) {
      apiKey = Config.revenueCatAPIKey_apple;
    }