purchases-flutter icon indicating copy to clipboard operation
purchases-flutter copied to clipboard

addPurchaserInfoUpdateListener does not immediately call the listener

Open doppio opened this issue 3 years ago • 6 comments

Describe the bug The documentation for the addPurchaserInfoUpdateListener method says:

  /// Sets a function to be called on updated purchaser info.
  ///
  /// **The function is called right away with the latest purchaser info as soon
  /// as it's set.**

However, this doesn't seem to be the case. It does get called when updates are made to the subscription, but the method is not called as soon as this listener is added, as described. I figured I could rely on this listener to always get the latest purchaser info, but it seems that I need to manually request the purchaser info on startup. Subsequent changes to the subscription do trigger the callback.

Output of flutter doctor

              Doctor summary (to see all details, run flutter doctor -v):
              [✓] Flutter (Channel dev, 2.6.0-0.0.pre, on macOS 11.6 20G165 darwin-x64, locale en-US)
              [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
              [✓] Xcode - develop for iOS and macOS (Xcode 13.0)
              [✓] Chrome - develop for the web
              [✓] Android Studio (version 4.1)
              [✓] VS Code (version 1.61.2)
              [✓] Connected device (2 available)
              
              • No issues found!

Steps to reproduce After initializing RevenueCat, call Purchases.addPurchaserInfoUpdateListener(), passing in a callback method. Run on an Android device and notice that the callback method is not executed immediately as described by its documentation.

Additional context I'm testing exclusively on Android at the moment.

doppio avatar Nov 10 '21 23:11 doppio

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.

ghost avatar Nov 10 '21 23:11 ghost

I have the same problem, and It happens both on iOS and Android. This code is called only at app startup or if subscription changes, not as soon as it's set as the function comment says.

  static final _channel = MethodChannel('purchases_flutter')
    ..setMethodCallHandler((MethodCall call) async {
      switch (call.method) {
        case "Purchases-PurchaserInfoUpdated":
          _purchaserInfoUpdateListeners.forEach(
              (listener) => listener(PurchaserInfo.fromJson(call.arguments)));
          break;
      }
    });

GZaccaroni avatar Nov 17 '21 09:11 GZaccaroni

This issue has been automatically marked as stale due to inactivity. It will be closed if no further activity occurs. Please reach out if you have additional information to help us investigate further!

stale[bot] avatar Dec 03 '21 22:12 stale[bot]

This shouldn't be closed, bot. It's a bug.

doppio avatar Dec 04 '21 09:12 doppio

Same here, it's obviously a bug.

jezsung avatar Feb 19 '22 20:02 jezsung

Hey all, I'm not sure how we missed this ticket, but I sincerely apologize.

The listener should be getting called after getting set, with some considerations:

  • If the SDK hasn't fetched purchaserInfo at all, the listener will wait until the SDK gets purchaserInfo before it sends it.
  • If the listener had already been set before, and PurchaserInfo hasn't changed since the last time it was sent, it won't be sent.

Here's a link to the relevant code on Android.

If you have a situation where the listener doesn't get called at all, even if you wait a bit so the SDK has time to refresh purchaserInfo, that's a bug. Do you have a minimal project or code that we can use to reproduce? Which version of the SDK are you using?

aboedo avatar Feb 21 '22 17:02 aboedo