From 173fae7472529a4141dab422996a9bfdb2b5d2ef Mon Sep 17 00:00:00 2001 From: Jonas Bark Date: Fri, 26 Dec 2025 22:57:43 +0100 Subject: [PATCH] handle old migrated purchases --- lib/utils/iap/revenuecat_service.dart | 23 ++++++++++++----------- pubspec.yaml | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/utils/iap/revenuecat_service.dart b/lib/utils/iap/revenuecat_service.dart index 2446ef9..f1a668e 100644 --- a/lib/utils/iap/revenuecat_service.dart +++ b/lib/utils/iap/revenuecat_service.dart @@ -138,7 +138,7 @@ class RevenueCatService { try { // Check current entitlement status from RevenueCat final customerInfo = await Purchases.getCustomerInfo(); - _handleCustomerInfoUpdate(customerInfo); + await _handleCustomerInfoUpdate(customerInfo); } catch (e, s) { debugPrint('Error checking existing purchase: $e'); recordError(e, s, context: 'Checking existing purchase'); @@ -146,18 +146,20 @@ class RevenueCatService { } /// Handle customer info updates from RevenueCat - void _handleCustomerInfoUpdate(CustomerInfo customerInfo) { + Future _handleCustomerInfoUpdate(CustomerInfo customerInfo) async { final hasEntitlement = customerInfo.entitlements.active.containsKey(fullVersionEntitlement); - debugPrint('RevenueCat entitlement check: $hasEntitlement'); - core.connection.signalNotification( - LogNotification('Full Version entitlement: $hasEntitlement'), - ); + core.connection.signalNotification(LogNotification('Full Version entitlement: $hasEntitlement')); - isPurchasedNotifier.value = hasEntitlement; - - if (hasEntitlement) { - _prefs.write(key: _purchaseStatusKey, value: "true"); + if (!hasEntitlement) { + final storedStatus = await _prefs.read(key: _purchaseStatusKey); + if (storedStatus == "true") { + core.connection.signalNotification(LogNotification('Setting full version based on stored status')); + await Purchases.setAttributes({_purchaseStatusKey: "true"}); + isPurchasedNotifier.value = true; + } + } else { + isPurchasedNotifier.value = hasEntitlement; } } @@ -356,6 +358,5 @@ class RevenueCatService { await Purchases.setAttributes({"purchase_id": purchaseId}); await Purchases.syncPurchases(); isPurchasedNotifier.value = true; - await _prefs.write(key: _purchaseStatusKey, value: isPurchasedNotifier.value.toString()); } } diff --git a/pubspec.yaml b/pubspec.yaml index 397b3a8..78a98fb 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: bike_control description: "BikeControl - Control your virtual riding" publish_to: 'none' # Remove this line if you wish to publish to pub.dev -version: 4.2.4+67 +version: 4.2.4+68 environment: sdk: ^3.9.0