Procházet zdrojové kódy

Show error if user tries to link existing subscription to another account

Neeraj Gupta před 2 roky
rodič
revize
1612b4f8f6

+ 2 - 0
lib/core/errors.dart

@@ -6,6 +6,8 @@ class InvalidFileUploadState extends AssertionError {
   InvalidFileUploadState(String message) : super(message);
   InvalidFileUploadState(String message) : super(message);
 }
 }
 
 
+class SubscriptionAlreadyClaimedError extends Error {}
+
 class WiFiUnavailableError extends Error {}
 class WiFiUnavailableError extends Error {}
 
 
 class SyncStopRequestedError extends Error {}
 class SyncStopRequestedError extends Error {}

+ 7 - 0
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:in_app_purchase/in_app_purchase.dart';
 import 'package:logging/logging.dart';
 import 'package:logging/logging.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/core/configuration.dart';
+import 'package:photos/core/errors.dart';
 import 'package:photos/core/network.dart';
 import 'package:photos/core/network.dart';
 import 'package:photos/models/billing_plan.dart';
 import 'package:photos/models/billing_plan.dart';
 import 'package:photos/models/subscription.dart';
 import 'package:photos/models/subscription.dart';
@@ -111,6 +112,12 @@ class BillingService {
         ),
         ),
       );
       );
       return Subscription.fromMap(response.data["subscription"]);
       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) {
     } catch (e, s) {
       _logger.severe(e, s);
       _logger.severe(e, s);
       rethrow;
       rethrow;

+ 13 - 0
lib/ui/payment/subscription_page.dart

@@ -4,6 +4,7 @@ import 'dart:io';
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
 import 'package:in_app_purchase/in_app_purchase.dart';
 import 'package:in_app_purchase/in_app_purchase.dart';
 import 'package:logging/logging.dart';
 import 'package:logging/logging.dart';
+import 'package:photos/core/errors.dart';
 import 'package:photos/core/event_bus.dart';
 import 'package:photos/core/event_bus.dart';
 import 'package:photos/events/subscription_purchased_event.dart';
 import 'package:photos/events/subscription_purchased_event.dart';
 import 'package:photos/models/billing_plan.dart';
 import 'package:photos/models/billing_plan.dart';
@@ -93,6 +94,18 @@ class _SubscriptionPageState extends State<SubscriptionPage> {
             if (widget.isOnboarding) {
             if (widget.isOnboarding) {
               Navigator.of(context).popUntil((route) => route.isFirst);
               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) {
           } catch (e) {
             _logger.warning("Could not complete payment ", e);
             _logger.warning("Could not complete payment ", e);
             await _dialog.hide();
             await _dialog.hide();