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

Android is all of a sudden DEAD - getCustomerInfo doesn't work and getOfferings

Open peazz opened this issue 1 year ago • 23 comments

Environment

  • [x] Output of flutter doctor
[√] Flutter (Channel stable, 3.19.1, on Microsoft Windows [Version 10.0.22621.3155], locale en-GB)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.6.1)
[√] Android Studio (version 2022.3)
[√] VS Code (version 1.86.2)
[√] Connected device (4 available)
[√] Network resources
  • [x] Version of purchases-flutter

6.21.1

  • [x] Testing device version e.g.: iOS 15.5, Android API 30, etc.
Pixelel 4 / 7
API 33 / 34
  • [x] How often the issue occurs- every one of your customers is impacted? Only in dev?

Live and dev

D/[Purchases] - DEBUG(19380): ℹ️ Debug logging enabled
D/[Purchases] - DEBUG(19380): ℹ️ SDK Version - 7.5.2
D/[Purchases] - DEBUG(19380): ℹ️ Package name - com.thrudayapp.thruday_app
D/[Purchases] - DEBUG(19380): 👤 Initial App User ID - 44650fcf-fc04-4274-9025-86da81be8e8f
D/[Purchases] - DEBUG(19380): ℹ️ Purchases configured with response verification: DISABLED
D/[Purchases] - DEBUG(19380): 👤 Identifying App User ID: 44650fcf-fc04-4274-9025-86da81be8e8f
D/[Purchases] - DEBUG(19380): ℹ️ Deleting old synced subscriber attributes that don't belong to 44650fcf-fc04-4274-9025-86da81be88e8f
D/[Purchases] - DEBUG(19380): ℹ️ App foregrounded
D/[Purchases] - DEBUG(19380): ℹ️ CustomerInfo cache is stale, updating from network in foreground.
D/[Purchases] - DEBUG(19380): Retrieving customer info with policy: FETCH_CURRENT
D/[Purchases] - DEBUG(19380): ℹ️ Updating pending purchase queue
D/[Purchases] - DEBUG(19380): ℹ️ Offerings cache is stale, updating from network in foreground
D/[Purchases] - DEBUG(19380): 😻 Start Offerings update from network.
D/[Purchases] - DEBUG(19380): ℹ️ Querying purchases
D/[Purchases] - DEBUG(19380): Request already scheduled with jitter delay, adding existing callbacks to unjittered request with key: BackgroundAwareCallbackCacheKey(cacheKey=[/subscribers/44650fcf-fc04-4274-9025-86da81be8e8f/offerings], appInBackground=false)
D/[Purchases] - DEBUG(19380): ℹ️ Updating pending purchase queue
D/[Purchases] - DEBUG(19380): ℹ️ Querying purchases
D/[Purchases] - DEBUG(19380): ℹ️ Found 3 unsynced attributes for App User ID: 44650fcf-fc04-4274-9025-86da81be8e8fSubscriberAttriibute(key=SubscriberAttributeKey('$email'), [email protected], setTime=Mon Feb 26 22:30:30 GMT 2024, isSynced=false)        
D/[Purchases] - DEBUG(19380): SubscriberAttribute(key=SubscriberAttributeKey('$displayName'), value=Andy Cresswell, setTime=Mon Feb 26 22:30:30 GMT 2024, isSynced=false)
D/[Purchases] - DEBUG(19380): SubscriberAttribute(key=SubscriberAttributeKey('$firebaseAppInstanceId'), value=2ad6b90895a966152a22675dcad73154, setTime=Mon Feb 26 22:30:30 GMT 2024, isSynced=false)
D/[Purchases] - DEBUG(19380): Product entitlement mappings are stale. Updating.
D/[Purchases] - DEBUG(19380): ℹ️ Listener set
D/[Purchases] - DEBUG(19380): ℹ️ Starting connection for com.android.billingclient.api.BillingClientImpl@dfbe16a
D/[Purchases] - DEBUG(19380): ℹ️ setEmail called
D/[Purchases] - DEBUG(19380): ℹ️ setDisplayName called
D/[Purchases] - DEBUG(19380): ℹ️ Billing Service Setup finished for com.android.billingclient.api.BillingClientImpl@dfbe16a
D/[Purchases] - DEBUG(19380): ℹ️ Updating pending purchase queue
D/[Purchases] - DEBUG(19380): ℹ️ Querying purchases
D/[Purchases] - DEBUG(19380): ℹ️ Cleaning previously sent tokens
D/[Purchases] - DEBUG(19380): ℹ️ Tokens already posted: []
D/[Purchases] - DEBUG(19380): ℹ️ Saving tokens []
D/[Purchases] - DEBUG(19380): ℹ️ Tokens already posted: []
D/[Purchases] - DEBUG(19380): ℹ️ No pending purchases to sync
D/[Purchases] - DEBUG(19380): ℹ️ Cleaning previously sent tokens
D/[Purchases] - DEBUG(19380): ℹ️ Tokens already posted: []
D/[Purchases] - DEBUG(19380): ℹ️ Saving tokens []
D/[Purchases] - DEBUG(19380): ℹ️ Tokens already posted: []
D/[Purchases] - DEBUG(19380): ℹ️ No pending purchases to sync
D/[Purchases] - DEBUG(19380): ℹ️ Cleaning previously sent tokens
D/[Purchases] - DEBUG(19380): ℹ️ Tokens already posted: []
D/[Purchases] - DEBUG(19380): ℹ️ Saving tokens []
D/[Purchases] - DEBUG(19380): ℹ️ Tokens already posted: []
D/[Purchases] - DEBUG(19380): ℹ️ No pending purchases to sync
D/[Purchases] - DEBUG(19380): Request already scheduled with jitter delay, adding existing callbacks to unjittered request with key: BackgroundAwareCallbackCacheKey(cacheKey=[/subscribers/44650fcf-fc04-4274-9025-86da81be8e8f], appInBackground=false)
D/[Purchases] - DEBUG(19380): ℹ️ setFirebaseAppInstanceID called
D/EGL_emulation(19380): app_time_stats: avg=90.27ms min=12.04ms max=555.66ms count=17
D/[Purchases] - DEBUG(19380): Billing connected with country code: GB
  • [x] Steps to reproduce, with a description of expected vs. actual behavior Other information (e.g. stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, etc.)

Describe the bug

25/02/2024 - Android stops completing futures...

  1. getCustomersInfo never completes
  2. getOfferings never compeletes
  3. Live and Sandbox
  4. No changes to cause this

When loading the subscriptions page and I try to load offerings;

/flutter (19380): ---------------------------------------------
I/flutter (19380): [is configured, true]
I/flutter (19380): ---------------------------------------------
I/flutter (19380): Settings up offerings
D/[Purchases] - DEBUG(19380): ℹ️ No cached Offerings, fetching from network
D/[Purchases] - DEBUG(19380): 😻 Start Offerings update from network.
D/[Purchases] - DEBUG(19380): Same call already in progress, adding to callbacks map with key: BackgroundAwareCallbackCacheKey(cacheKey=[/subscribers/44650fcf-fc04-4274-9025-86da81be8e8f/offerings], appInBackground=false)
D/[Purchases] - DEBUG(19380): Request already scheduled with jitter delay, adding existing callbacks to unjittered request with key: BackgroundAwareCallbackCacheKey(cacheKey=[/subscribers/44650fcf-fc04-4274-9025-86da81be8e8f/offerings], appInBackground=false)

And the code that produces the above debug log

@override
  void initState(){
    super.initState();

    Purchases.isConfigured.then((isConfigured) async {

      print('---------------------------------------------');
      print(['is configured', isConfigured]);
      
      // this never returns or completes!!
      print(['customerInfo', await Purchases.getCustomerInfo()]);
      
      if(await Purchases.appUserID != AuthedUser.get!.id){
        // login the user
        await Purchases.logIn(AuthedUser.get!.id);
        // ensure we have the latest customer info
        Provider.of<AppPurchaser>(context, listen: false)
          .updateCustomerInfo();
      }

      // ensure we can make payments
      if(await Purchases.canMakePayments()){
        // get our offerings for selected
        setupOfferings();
      } else {
        print('cant make purchases');
      }
    });

  }

  void setupOfferings() async {
    try {

      print('---------------------------------------------');
      print('Settings up offerings');
      
      // this does not return or complete!!
      offerings = await Purchases.getOfferings();
      

      if (offerings!.current != null) {
        
        if(null != offerings!.current!.monthly && null != offerings!.current!.annual){
          setState(() {
            subscriptions = [
              offerings!.current!.monthly!,
              offerings!.current!.annual!
            ];
          });
        }

      } else {
        FirebaseCrashlytics.instance.log('No offerings loaded, offerings: $offerings');
        
        setState(() {
          _error = 'There seem to be no offerings available at the moment. Please try again later.' as PlatformException;
        });
      }

    } on PlatformException catch (e) {
        FirebaseCrashlytics.instance.log(e.toString());
        setState(() {
          _error = e;
        });
    }
  }

I've checked the profiler, I see no network requests being made at all... Network requests to my own custom API backend works If I manually query the subscriber endpoint using POSTMAN, offerings return Problem is only on Android, offerings / system works fine on Apple No changes with in Play Developer to cause this

Literally, started for no reason

Additional context

I got to a point where I started going through commits and got it down to where I updated the versions of;

flutter_keyboard_visability: 6.0.0 wolt_modal_sheet: 0.4.1 flutter_quill: 9.2.12

I have epilepsy, I am struggling after this - I will further figure out tomorrow which of this plugins caused this.

I have analysed the rest of the commit and there is nothing that could stop network requests getting through.

Day 3: I have now added back in the above plugins, cleaned the installation and tried again - still working so, there is two possibilities here;

  1. The problem was with RevenueCat and they silently fixed it
  2. Something corrupted the installation when trying to apply the above plugins

I have obsessively checked all commits, nothing there could have caused this - I am lost for words and can't even offer any help to someone facing the same problem.

peazz avatar Feb 26 '24 23:02 peazz

👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!

RCGitBot avatar Feb 26 '24 23:02 RCGitBot

I updated the details above with my findings

peazz avatar Feb 27 '24 13:02 peazz

Hey @peazz sorry for the delay on this, I read through your issue and it doesn't seem like it's something that would be affected by our backend. We checked our server logs to double check and didn't find any errors in our GET /offerings endpoint for your app. We also didn't have any incidents and haven't rolled anything out on our end that would address this issue.

Seems like redoing the plugin setup worked? Truly strange but it does indicate that the build on your machine got into a weird state. It's uncommon but it does happen enough to the point that we sometimes recommend redoing the install process if unexplained issues arise with seemingly no changes.

I'll get this on our @RevenueCat/sdk team's radar just in case. Sorry for the experience here, sounds like you've had a frustrating time. Let us know if there's anything else we can do to help.

mshmoustafa avatar Feb 27 '24 20:02 mshmoustafa

I did....everything. Flutter clean, pub cache reload, the entire lot but problem persisted.

I've tried to replicate and for some reason I have been unable too, I have to catch up on stuff but its on my radar to try and find this. I found it so unique.

peazz avatar Feb 27 '24 20:02 peazz

Hey @peazz, the SDK team agrees that this was probably a corrupted installation somehow. It's really unfortunate it happened to you but it does happen in rare circumstances. I've also confirmed that we haven't shipped anything that would have silently fixed it. If you're not having any other issues, would it be ok if we closed this issue as resolved? You can always reach back out if something does happen in the future.

mshmoustafa avatar Feb 29 '24 19:02 mshmoustafa

@mshmoustafa I would normally agree, I have been developing since v1 of flutter however, if I switch back to the branch, the issue reappears again.

Lets put it down to a config issue but if anyone else raises this, it would be wise to investigate. I got it down to the the platform calls that happen and never being returned from platform level functions.

peazz avatar Mar 07 '24 03:03 peazz

I am coming back to this after having to change a product... somehow a yearly subscription was configured to be monthly period.

Now, this has brought me full circle;

  1. API call is reporting the new product
  2. purchases_flutter: await Purchases.getOfferings() only returns a single product

I am getting the impression that there is a caching mechnism that is potentially buggy and disregarding changes (I assume because they don't happen often)

peazz avatar Mar 09 '24 16:03 peazz