Code Monkey home page Code Monkey logo

Comments (6)

aboedo avatar aboedo commented on May 29, 2024 1

I see. Yeah, behavior isn't ideal in this case.
We try not to wait for a server response because there's no guarantee that we'll actually get one - the user might have no connectivity, and waiting for a very slow network might lead to a bad user experience for people who actually paid.

There might be a middleground here, though. Maybe the SDK could provide, along with the purchaserInfo, some information that would indicate whether the purchaserInfo cache was outdated and it's trying to refresh it.

Or a separate method that only returns after refreshing (or a timeout).

Thoughts on how to handle this in the meantime:

  • get purchaser info earlier in the flow, before the paywall, and subscribe to purchaser info updates. This way you lower the chances of purchaser info being updated while the user is in the paywall.

  • alternatively, your app could wait until you get updated purchaserInfo or a timeout before you update the UI. This wouldn't be ideal, however, because you'd have to add the wait any time you query purchaser info, since as of right now the SDK doesn't provide a way of knowing if it's currently trying to update the cache.

from purchases-flutter.

aboedo avatar aboedo commented on May 29, 2024

Hi! 👋
This is a valid concern. We're trying to strike a balance here between getting the SDK to be as responsive as possible, while fetching new data if needed.
The SDK will cache purchaser info for 5 minutes (or until next app open, whichever happens first). Usually this isn't a problem, because purchaser info is updated at a slower rate than that (specially in production).

However, there are situations where the purchaser info could be out of date.

Our current approach to this is to:

  • provide the cached info if available
  • if it's stale (like in your case), return whatever we have so far (so that your app doesn't have to wait for us), then fetch from the backend, and inform the app as soon as results arrive.

In order to get that latest information as soon as it arrives, you can use the PurchaserInfoUpdateListener. See https://github.com/RevenueCat/purchases-flutter/blob/develop/lib/purchases_flutter.dart#L64.

The idea is that you set up a listener function, and the SDK will call it whenever there are updates to purchaserInfo, triggered by any number of events, including detecting an outdated cache.

from purchases-flutter.

aboedo avatar aboedo commented on May 29, 2024

I just realized that you also had another ticket where you mentioned you were already using the purchaserInfoUpdateListener.
Is it not getting called after refreshing the cache? Otherwise, is there a situation that isn't covered by the combination of checking for purchaserInfo directly + the listener?

from purchases-flutter.

liri2006 avatar liri2006 commented on May 29, 2024

Hi!

Thanx for the response. Listener works as expected. But...

The use case here is as follows - user navigates to paywall where he can buy subscription. If user is already subscribed an image/text is shown a-la "You are already subscribed, thank you, etc" if not - button "Subscribe" is shown. And with current behavior it basically works. The "but" here is that if subscription status was changed in the meanwhile, user would briefly see "previous" state (because getPurchaserInfo returned cached data) until listener gets updated data and updates the UI accordingly. So there is this ugly UI "blink" (it is also hard to say how long user will be seeing the old state as it also depends on network latency, server response time, etc) - not the end of the world, but in this particular scenario I would prefer to show loader until I have most recent data.

Maybe separate method can be introduced (or flag of some sort added to current getPurchaserInfo) which waits for new data to arrive to tackle with such use cases. Or always trigger PurchaserInfoUpdateListener after the staleness check - even if there is no data change (mb with flag hasChanges: false), so there will be a possibility to set loader before calling getPurchaserInfo and then switching it off on listener callback.

from purchases-flutter.

liri2006 avatar liri2006 commented on May 29, 2024

Thanx for the response!

For now I will go with suggestion nr.1. But it would be great if SDK provided more "reliable" way of achieving that at some point in the future.

from purchases-flutter.

aboedo avatar aboedo commented on May 29, 2024

Thanks for the feedback, and for the patience on this. I agree that there are better ways for the SDK to provide this information. Hopefully we'll improve this soon.

Closing this ticket in the meantime.

from purchases-flutter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.