From 7ee0f274778d75fc19e5e292ab2c82687a903403 Mon Sep 17 00:00:00 2001 From: Philipp Bauer Date: Sun, 22 Jan 2023 16:08:40 +0100 Subject: [PATCH 1/4] Product: Add missing currencyCode --- example/lib/product_listview.dart | 2 +- lib/src/utils/product.dart | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/example/lib/product_listview.dart b/example/lib/product_listview.dart index 62fd1ae..c54a294 100644 --- a/example/lib/product_listview.dart +++ b/example/lib/product_listview.dart @@ -47,7 +47,7 @@ class ProductListViewState extends State { color: Colors.black54, fontWeight: FontWeight.bold, fontSize: 18)), - subtitle: Text(listProducts[pos].price, + subtitle: Text(listProducts[pos].price + " (currencyCode: "+ listProducts[pos].currencyCode + ")", style: const TextStyle( fontWeight: FontWeight.normal, fontSize: 15)), diff --git a/lib/src/utils/product.dart b/lib/src/utils/product.dart index f5f4fc9..addc6fe 100644 --- a/lib/src/utils/product.dart +++ b/lib/src/utils/product.dart @@ -3,13 +3,15 @@ class Product { String id; String price; String title; - Product(this.id, this.price, this.title); + String currencyCode; + + Product(this.id, this.price, this.title, this.currencyCode); factory Product.fromJson(dynamic json) { print(json); return Product(json['productId'] as String, json['productPrice'] as String, - json['productTitle'] as String); + json['productTitle'] as String, json['currencyCode'] as String); } } From d4923a2cdf2ac601046717c3133d4ce2f843aebc Mon Sep 17 00:00:00 2001 From: Philipp Bauer Date: Sun, 22 Jan 2023 16:18:29 +0100 Subject: [PATCH 2/4] Hide constructor. #38 --- lib/src/chargebee.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/src/chargebee.dart b/lib/src/chargebee.dart index 3c430b2..438f2a0 100644 --- a/lib/src/chargebee.dart +++ b/lib/src/chargebee.dart @@ -7,6 +7,8 @@ import 'package:flutter/services.dart'; import 'dart:convert'; class Chargebee { + Chargebee._(); + static const platform = MethodChannel(Constants.methodChannelName); static bool get _isIOS => defaultTargetPlatform == TargetPlatform.iOS; From 99a3931bedc08675a04e7461aa68797e2b1ecf5e Mon Sep 17 00:00:00 2001 From: Philipp Bauer Date: Sun, 22 Jan 2023 16:27:07 +0100 Subject: [PATCH 3/4] configure(): Switched to named args --- README.md | 7 ++++++- example/lib/main.dart | 7 ++++++- lib/src/chargebee.dart | 8 ++++++-- test/chargebee_test.dart | 19 ++++++++++++++++--- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9a37606..3424d71 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,12 @@ Initialize the Chargebee Flutter SDK with your Chargebee site, Publishable API K ```dart import 'package:chargebee_flutter/chargebee_flutter.dart'; try { - await Chargebee.configure("SITE_NAME", "API-KEY", "iOS SDK Key", "Android SDK Key"); + await Chargebee.configure( + site: "SITE_NAME", + publishableApiKey: "API_KEY", + iosSdkKey: "iOS_SDK_Key", + androidSdkKey: "Android_SDK_Key", + ); } on PlatformException catch (e) { print('${e.message}, ${e.details}'); } diff --git a/example/lib/main.dart b/example/lib/main.dart index 62035ed..bc9564e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -129,7 +129,12 @@ class _MyHomePageState extends State { Future authentication(String siteName, String apiKey, [String? iosSdkKey="", String? androidSdkKey = ""]) async { try { - await Chargebee.configure(siteName, apiKey, iosSdkKey, androidSdkKey); + await Chargebee.configure( + site: siteName, + publishableApiKey: apiKey, + androidSdkKey: androidSdkKey, + iosSdkKey: iosSdkKey, + ); } on PlatformException catch (e) { print('${e.message}, ${e.details}'); } diff --git a/lib/src/chargebee.dart b/lib/src/chargebee.dart index 438f2a0..97f4e2a 100644 --- a/lib/src/chargebee.dart +++ b/lib/src/chargebee.dart @@ -13,8 +13,12 @@ class Chargebee { static bool get _isIOS => defaultTargetPlatform == TargetPlatform.iOS; /* Configure the app details with chargebee system */ - static Future configure(String site, String publishableApiKey, - [String? iosSdkKey = "", androidSdkKey = ""]) async { + static Future configure({ + required String site, + required String publishableApiKey, + String? iosSdkKey = "", + String? androidSdkKey = "", + }) async { if (_isIOS) { final args = { Constants.siteName: site, diff --git a/test/chargebee_test.dart b/test/chargebee_test.dart index 97d53bf..c322f19 100644 --- a/test/chargebee_test.dart +++ b/test/chargebee_test.dart @@ -34,7 +34,11 @@ void main() { test('works for iOS', () async { channelResponse = true; debugDefaultTargetPlatformOverride = TargetPlatform.iOS; - await Chargebee.configure(siteName, apiKey, iosSDKKey); + await Chargebee.configure( + site: siteName, + publishableApiKey: apiKey, + iosSdkKey: iosSDKKey, + ); expect(callStack, [ isMethodCall( Constants.mAuthentication, @@ -50,7 +54,11 @@ void main() { test('works for android', () async { channelResponse = true; debugDefaultTargetPlatformOverride = TargetPlatform.android; - await Chargebee.configure(siteName, apiKey, "", androidSDKKey); + await Chargebee.configure( + site: siteName, + publishableApiKey: apiKey, + androidSdkKey: androidSDKKey, + ); expect(callStack, [ isMethodCall( Constants.mAuthentication, @@ -68,7 +76,12 @@ void main() { throw PlatformException(code: "Dummy"); }); debugDefaultTargetPlatformOverride = TargetPlatform.iOS; - await expectLater(() => Chargebee.configure(siteName, apiKey, iosSDKKey), + await expectLater( + () => Chargebee.configure( + site: siteName, + publishableApiKey: apiKey, + iosSdkKey: iosSDKKey, + ), throwsA(isA())); channel.setMockMethodCallHandler(null); }); From d610807068eb2a2b2246b032c4c1cecade5af3e1 Mon Sep 17 00:00:00 2001 From: Philipp Bauer Date: Sun, 22 Jan 2023 16:33:57 +0100 Subject: [PATCH 4/4] Override toString(): Product, PurchaseResult --- lib/src/utils/product.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/src/utils/product.dart b/lib/src/utils/product.dart index addc6fe..a227ba5 100644 --- a/lib/src/utils/product.dart +++ b/lib/src/utils/product.dart @@ -13,6 +13,11 @@ class Product { return Product(json['productId'] as String, json['productPrice'] as String, json['productTitle'] as String, json['currencyCode'] as String); } + + @override + String toString() { + return 'Product(id: $id, price: $price, title: $title, currencyCode: $currencyCode)'; + } } class PurchaseResult { @@ -24,6 +29,11 @@ class PurchaseResult { factory PurchaseResult.fromJson(dynamic json) { return PurchaseResult(json['subscriptionId'] as String, json['planId'] as String, json['status'] as String); } + + @override + String toString() { + return 'PurchaseResult(subscriptionId: $subscriptionId, planId: $planId, $status)'; + } } class Subscripton {