瀏覽代碼

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

Neeraj Gupta 2 年之前
父節點
當前提交
1612b4f8f6
共有 3 個文件被更改,包括 22 次插入0 次删除
  1. 2 0
      lib/core/errors.dart
  2. 7 0
      lib/services/billing_service.dart
  3. 13 0
      lib/ui/payment/subscription_page.dart

+ 2 - 0
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 {}

+ 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: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;

+ 13 - 0
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<SubscriptionPage> {
             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();