Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob] Service locator for billingService

Neeraj Gupta0dc44b9337f5
diff --git a/mobile/lib/core/configuration.dart b/mobile/lib/core/configuration.dart
index 16a65d497f..f71256a61c 100644
--- a/mobile/lib/core/configuration.dart
+++ b/mobile/lib/core/configuration.dart
@@ -22,7 +22,6 @@ import 'package:photos/events/user_logged_out_event.dart';
import 'package:photos/models/key_attributes.dart';
import 'package:photos/models/key_gen_result.dart';
import 'package:photos/models/private_key_attributes.dart';
-import 'package:photos/services/billing_service.dart';
import 'package:photos/services/collections_service.dart';
import 'package:photos/services/favorites_service.dart';
import "package:photos/services/home_widget_service.dart";
@@ -216,7 +215,6 @@ class Configuration {
CollectionsService.instance.clearCache();
FavoritesService.instance.clearCache();
MemoriesService.instance.clearCache();
- BillingService.instance.clearCache();
SearchService.instance.clearCache();
unawaited(HomeWidgetService.instance.clearHomeWidget());
Bus.instance.fire(UserLoggedOutEvent());
diff --git a/mobile/lib/main.dart b/mobile/lib/main.dart
index ef99f57b5e..74ad7a99f4 100644
--- a/mobile/lib/main.dart
+++ b/mobile/lib/main.dart
@@ -28,7 +28,6 @@ import "package:photos/extensions/stop_watch.dart";
import "package:photos/l10n/l10n.dart";
import "package:photos/service_locator.dart";
import 'package:photos/services/app_lifecycle_service.dart';
-import 'package:photos/services/billing_service.dart';
import 'package:photos/services/collections_service.dart';
import 'package:photos/services/favorites_service.dart';
import "package:photos/services/filedata/filedata_service.dart";
@@ -242,10 +241,6 @@ Future<void> _init(bool isBackground, {String via = ''}) async {
await UserService.instance.init();
_logger.info("UserService init done $tlog");
- _logger.info("BillingService init $tlog");
- BillingService.instance.init();
- _logger.info("BillingService init done $tlog");
-
_logger.info("CollectionsService init $tlog");
await CollectionsService.instance.init(preferences);
_logger.info("CollectionsService init done $tlog");
diff --git a/mobile/lib/service_locator.dart b/mobile/lib/service_locator.dart
index e799cb2702..2f023e229b 100644
--- a/mobile/lib/service_locator.dart
+++ b/mobile/lib/service_locator.dart
@@ -4,6 +4,7 @@ import "package:ente_cast_normal/ente_cast_normal.dart";
import "package:ente_feature_flag/ente_feature_flag.dart";
import "package:package_info_plus/package_info_plus.dart";
import "package:photos/gateways/entity_gw.dart";
+import "package:photos/services/billing_service.dart";
import "package:photos/services/entity_service.dart";
import "package:photos/services/location_service.dart";
import "package:photos/services/magic_cache_service.dart";
@@ -114,3 +115,11 @@ MagicCacheService get magicCacheService {
);
return _magicCacheService!;
}
+
+BillingService? _billingService;
+BillingService get billingService {
+ _billingService ??= BillingService(
+ ServiceLocator.instance.enteDio,
+ );
+ return _billingService!;
+}
diff --git a/mobile/lib/services/billing_service.dart b/mobile/lib/services/billing_service.dart
index 1d67531cc9..2037cb8ad0 100644
--- a/mobile/lib/services/billing_service.dart
+++ b/mobile/lib/services/billing_service.dart
@@ -7,7 +7,6 @@ import 'package:flutter/material.dart';
import 'package:in_app_purchase/in_app_purchase.dart';
import 'package:logging/logging.dart';
import 'package:photos/core/errors.dart';
-import 'package:photos/core/network/network.dart';
import "package:photos/generated/l10n.dart";
import 'package:photos/models/billing_plan.dart';
import 'package:photos/models/subscription.dart';
@@ -32,16 +31,16 @@ const kFamilyPlanManagementUrl = String.fromEnvironment(
);
class BillingService {
- BillingService._privateConstructor();
-
- static final BillingService instance = BillingService._privateConstructor();
-
- final _logger = Logger("BillingService");
- final _enteDio = NetworkClient.instance.enteDio;
+ late final _logger = Logger("BillingService");
+ final Dio _enteDio;
bool _isOnSubscriptionPage = false;
Future<BillingPlans>? _future;
+ BillingService(this._enteDio) {
+ _logger.finest("BillingService constructor");
+ init();
+ }
void init() {
// if (Platform.isIOS && kDebugMode) {
diff --git a/mobile/lib/ui/payment/payment_web_page.dart b/mobile/lib/ui/payment/payment_web_page.dart
index e3bf5cccd0..162aa99f6f 100644
--- a/mobile/lib/ui/payment/payment_web_page.dart
+++ b/mobile/lib/ui/payment/payment_web_page.dart
@@ -9,6 +9,7 @@ import "package:photos/core/constants.dart";
import 'package:photos/ente_theme_data.dart';
import "package:photos/generated/l10n.dart";
import 'package:photos/models/subscription.dart';
+import "package:photos/service_locator.dart";
import 'package:photos/services/billing_service.dart';
import 'package:photos/services/user_service.dart';
import 'package:photos/ui/common/loading_widget.dart';
@@ -29,7 +30,7 @@ class PaymentWebPage extends StatefulWidget {
class _PaymentWebPageState extends State<PaymentWebPage> {
final _logger = Logger("PaymentWebPageState");
final UserService userService = UserService.instance;
- final BillingService billingService = BillingService.instance;
+ late final BillingService billService = billingService;
final String basePaymentUrl = kWebPaymentBaseEndpoint;
InAppWebViewController? webView;
double progress = 0;
@@ -229,7 +230,7 @@ class _PaymentWebPageState extends State<PaymentWebPage> {
final checkoutSessionID = queryParams['session_id'] ?? '';
try {
// ignore: unused_local_variable
- final response = await billingService.verifySubscription(
+ final response = await billService.verifySubscription(
widget.planId,
checkoutSessionID,
paymentProvider: stripe,
diff --git a/mobile/lib/ui/payment/store_subscription_page.dart b/mobile/lib/ui/payment/store_subscription_page.dart
index 86d29fd715..e937af6a4d 100644
--- a/mobile/lib/ui/payment/store_subscription_page.dart
+++ b/mobile/lib/ui/payment/store_subscription_page.dart
@@ -12,7 +12,7 @@ import "package:photos/generated/l10n.dart";
import 'package:photos/models/billing_plan.dart';
import 'package:photos/models/subscription.dart';
import 'package:photos/models/user_details.dart';
-import 'package:photos/services/billing_service.dart';
+import "package:photos/service_locator.dart";
import 'package:photos/services/user_service.dart';
import "package:photos/theme/colors.dart";
import "package:photos/theme/ente_theme.dart";
@@ -46,7 +46,7 @@ class StoreSubscriptionPage extends StatefulWidget {
class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {
final _logger = Logger("SubscriptionPage");
- final _billingService = BillingService.instance;
+ late final _billingService = billingService;
final _userService = UserService.instance;
Subscription? _currentSubscription;
late StreamSubscription _purchaseUpdateSubscription;
@@ -445,7 +445,7 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {
(route) => false,
);
unawaited(
- BillingService.instance.verifySubscription(
+ _billingService.verifySubscription(
freeProductID,
"",
paymentProvider: "ente",
@@ -501,7 +501,7 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {
(route) => false,
);
unawaited(
- BillingService.instance.verifySubscription(
+ _billingService.verifySubscription(
freeProductID,
"",
paymentProvider: "ente",
@@ -625,7 +625,7 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {
(route) => false,
);
unawaited(
- BillingService.instance.verifySubscription(
+ _billingService.verifySubscription(
freeProductID,
"",
paymentProvider: "ente",
diff --git a/mobile/lib/ui/payment/stripe_subscription_page.dart b/mobile/lib/ui/payment/stripe_subscription_page.dart
index 93479b8038..eceefa4f36 100644
--- a/mobile/lib/ui/payment/stripe_subscription_page.dart
+++ b/mobile/lib/ui/payment/stripe_subscription_page.dart
@@ -9,7 +9,7 @@ import "package:photos/generated/l10n.dart";
import 'package:photos/models/billing_plan.dart';
import 'package:photos/models/subscription.dart';
import 'package:photos/models/user_details.dart';
-import 'package:photos/services/billing_service.dart';
+import "package:photos/service_locator.dart";
import 'package:photos/services/user_service.dart';
import "package:photos/theme/colors.dart";
import 'package:photos/theme/ente_theme.dart';
@@ -46,7 +46,7 @@ class StripeSubscriptionPage extends StatefulWidget {
}
class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
- final _billingService = BillingService.instance;
+ late final _billingService = billingService;
final _userService = UserService.instance;
Subscription? _currentSubscription;
late ProgressDialog _dialog;
@@ -484,7 +484,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
(route) => false,
);
unawaited(
- BillingService.instance.verifySubscription(
+ _billingService.verifySubscription(
freeProductID,
"",
paymentProvider: "ente",
@@ -609,7 +609,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
(route) => false,
);
unawaited(
- BillingService.instance.verifySubscription(
+ _billingService.verifySubscription(
freeProductID,
"",
paymentProvider: "ente",
diff --git a/mobile/lib/ui/settings/general_section_widget.dart b/mobile/lib/ui/settings/general_section_widget.dart
index c01db225d3..ccc941b4ee 100644
--- a/mobile/lib/ui/settings/general_section_widget.dart
+++ b/mobile/lib/ui/settings/general_section_widget.dart
@@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
import "package:photos/app.dart";
import "package:photos/generated/l10n.dart";
import "package:photos/l10n/l10n.dart";
-import 'package:photos/services/billing_service.dart';
+import "package:photos/service_locator.dart";
import 'package:photos/services/user_service.dart';
import 'package:photos/theme/ente_theme.dart';
import "package:photos/ui/components/captioned_text_widget.dart";
@@ -118,7 +118,7 @@ class GeneralSectionWidget extends StatelessWidget {
final userDetails =
await UserService.instance.getUserDetailsV2(memoryCount: false);
// ignore: unawaited_futures
- BillingService.instance.launchFamilyPortal(context, userDetails);
+ billingService.launchFamilyPortal(context, userDetails);
}
void _onNotificationsTapped(BuildContext context) {