Przeglądaj źródła

address review comments

Neeraj Gupta 3 lat temu
rodzic
commit
14fa763d80

+ 2 - 4
lib/models/subscription.dart

@@ -60,7 +60,7 @@ class Subscription {
   }
 
   Map<String, dynamic> toMap() {
-    var map = <String, dynamic>{
+    final map = <String, dynamic>{
       'id': id,
       'productID': productID,
       'storage': storage,
@@ -69,10 +69,8 @@ class Subscription {
       'expiryTime': expiryTime,
       'price': price,
       'period': period,
+      'attributes': attributes?.toJson()
     };
-    if (attributes != null) {
-      map["attributes"] = attributes.toJson();
-    }
     return map;
   }
 

+ 27 - 27
lib/ui/payment/payment_web_page.dart

@@ -26,18 +26,18 @@ class PaymentWebPage extends StatefulWidget {
       : super(key: key);
 
   @override
-  State<StatefulWidget> createState() => _PaymentWebPage();
+  State<StatefulWidget> createState() => _PaymentWebPageState();
 }
 
-class _PaymentWebPage extends State<PaymentWebPage> {
-  final _logger = Logger("PaymentWebPage");
-  UserService userService = UserService.instance;
-  BillingService billingService = BillingService.instance;
+class _PaymentWebPageState extends State<PaymentWebPage> {
+  final _logger = Logger("PaymentWebPageState");
+  final UserService userService = UserService.instance;
+  final BillingService billingService = BillingService.instance;
+  final String basePaymentUrl = kWebPaymentBaseEndpoint;
   ProgressDialog _dialog;
   InAppWebViewController webView;
   double progress = 0;
   Uri initPaymentUrl;
-  String basePaymentUrl = kWebPaymentBaseEndpoint;
 
   @override
   void initState() {
@@ -53,21 +53,6 @@ class _PaymentWebPage extends State<PaymentWebPage> {
     super.initState();
   }
 
-  Uri _getPaymentUrl(String paymentToken) {
-    final queryParameters = {
-      'productID': widget.planId,
-      'paymentToken': paymentToken,
-      'action': widget.actionType,
-      'redirectURL': kWebPaymentRedirectUrl,
-    };
-    var tryParse = Uri.tryParse(kWebPaymentBaseEndpoint);
-    if (kDebugMode && kWebPaymentBaseEndpoint.startsWith("http://")) {
-      return Uri.http(tryParse.authority, tryParse.path, queryParameters);
-    } else {
-      return Uri.https(tryParse.authority, tryParse.path, queryParameters);
-    }
-  }
-
   @override
   Widget build(BuildContext context) {
     if (initPaymentUrl == null) {
@@ -104,7 +89,7 @@ class _PaymentWebPage extends State<PaymentWebPage> {
                     _logger.info("Loading url $loadingUri");
                     // handle the payment response
                     if (_isPaymentActionComplete(loadingUri)) {
-                      await handlePaymentResponse(loadingUri);
+                      await _handlePaymentResponse(loadingUri);
                       return NavigationActionPolicy.CANCEL;
                     }
                     return NavigationActionPolicy.ALLOW;
@@ -144,12 +129,27 @@ class _PaymentWebPage extends State<PaymentWebPage> {
     super.dispose();
   }
 
+  Uri _getPaymentUrl(String paymentToken) {
+    final queryParameters = {
+      'productID': widget.planId,
+      'paymentToken': paymentToken,
+      'action': widget.actionType,
+      'redirectURL': kWebPaymentRedirectUrl,
+    };
+    var tryParse = Uri.tryParse(kWebPaymentBaseEndpoint);
+    if (kDebugMode && kWebPaymentBaseEndpoint.startsWith("http://")) {
+      return Uri.http(tryParse.authority, tryParse.path, queryParameters);
+    } else {
+      return Uri.https(tryParse.authority, tryParse.path, queryParameters);
+    }
+  }
+
   // show dialog to handle accidental back press.
   Future<bool> _buildPageExitWidget(BuildContext context) {
     return showDialog(
         context: context,
         builder: (context) => AlertDialog(
-                title: Text('Are you sure you want to exit?'),
+                title: Text('are you sure you want to exit?'),
                 actions: <Widget>[
                   TextButton(
                       child: Text('yes'),
@@ -164,13 +164,13 @@ class _PaymentWebPage extends State<PaymentWebPage> {
     return loadingUri.toString().startsWith(kWebPaymentRedirectUrl);
   }
 
-  Future<void> handlePaymentResponse(Uri uri) async {
+  Future<void> _handlePaymentResponse(Uri uri) async {
     var queryParams = uri.queryParameters;
     var paymentStatus = uri.queryParameters['status'] ?? '';
     _logger.fine('handle payment response with status $paymentStatus');
     if (paymentStatus == 'success') {
       await _handlePaymentSuccess(queryParams);
-    } else if ('fail' == paymentStatus) {
+    } else if (paymentStatus == 'fail') {
       var reason = queryParams['reason'] ?? '';
       await _handlePaymentFailure(reason);
     } else {
@@ -209,8 +209,8 @@ class _PaymentWebPage extends State<PaymentWebPage> {
       await _dialog.hide();
       if (response != null) {
         var content = widget.actionType == 'buy'
-            ? 'you subscription purchase was successful'
-            : 'your subscription update was successful';
+            ? 'your purchase was successful'
+            : 'your subscription was updated successfully';
         await _showExitPageDialog(title: 'thank you', content: content);
       } else {
         throw Exception("verifySubscription api failed");

+ 1 - 1
lib/ui/payment/stripe_subscription_page.dart

@@ -84,7 +84,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
       if (plan.stripeID == null || plan.stripeID.isEmpty) {
         return false;
       }
-      var isYearlyPlan = plan.period == 'year';
+      final isYearlyPlan = plan.period == 'year';
       return isYearlyPlan == _showYearlyPlan;
     }).toList();
     setState(() {});