diff --git a/lib/core/errors.dart b/lib/core/errors.dart index 0ca27e687..8b0cf4c8a 100644 --- a/lib/core/errors.dart +++ b/lib/core/errors.dart @@ -6,6 +6,8 @@ class InvalidFileUploadState extends AssertionError { InvalidFileUploadState(String message) : super(message); } +class SubscriptionAlreadyClaimedError extends Error {} + class WiFiUnavailableError extends Error {} class SyncStopRequestedError extends Error {} diff --git a/lib/services/billing_service.dart b/lib/services/billing_service.dart index d746df099..6165bdfa0 100644 --- a/lib/services/billing_service.dart +++ b/lib/services/billing_service.dart @@ -6,6 +6,7 @@ import 'package:dio/dio.dart'; import 'package:in_app_purchase/in_app_purchase.dart'; import 'package:logging/logging.dart'; import 'package:photos/core/configuration.dart'; +import 'package:photos/core/errors.dart'; import 'package:photos/core/network.dart'; import 'package:photos/models/billing_plan.dart'; import 'package:photos/models/subscription.dart'; @@ -111,6 +112,12 @@ class BillingService { ), ); return Subscription.fromMap(response.data["subscription"]); + } on DioError catch (e) { + if (e.response != null && e.response.statusCode == 409) { + throw SubscriptionAlreadyClaimedError(); + } else { + rethrow; + } } catch (e, s) { _logger.severe(e, s); rethrow; diff --git a/lib/ui/payment/subscription_page.dart b/lib/ui/payment/subscription_page.dart index 72de2d53f..b5d444026 100644 --- a/lib/ui/payment/subscription_page.dart +++ b/lib/ui/payment/subscription_page.dart @@ -4,6 +4,7 @@ import 'dart:io'; 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/event_bus.dart'; import 'package:photos/events/subscription_purchased_event.dart'; import 'package:photos/models/billing_plan.dart'; @@ -93,6 +94,18 @@ class _SubscriptionPageState extends State { if (widget.isOnboarding) { Navigator.of(context).popUntil((route) => route.isFirst); } + } on SubscriptionAlreadyClaimedError catch (e) { + _logger.warning("subscription is already claimed ", e); + await _dialog.hide(); + final String title = "${Platform.isAndroid ? "Play" : "App"}" + "Store subscription"; + final String id = + Platform.isAndroid ? "Google Play ID" : "Apple ID"; + final String message = '''Your $id is already linked to another + ente account.\nIf you would like to use your $id with this + account, please contact our support'''; + showErrorDialog(context, title, message); + return; } catch (e) { _logger.warning("Could not complete payment ", e); await _dialog.hide();