diff --git a/.flutter-plugins b/.flutter-plugins deleted file mode 100644 index dfc2742..0000000 --- a/.flutter-plugins +++ /dev/null @@ -1,11 +0,0 @@ -# This is a generated file; do not edit or check into version control. -url_launcher=/Users/segun/.pub-cache/hosted/pub.dev/url_launcher-6.2.5/ -url_launcher_android=/Users/segun/.pub-cache/hosted/pub.dev/url_launcher_android-6.3.0/ -url_launcher_ios=/Users/segun/.pub-cache/hosted/pub.dev/url_launcher_ios-6.2.5/ -url_launcher_linux=/Users/segun/.pub-cache/hosted/pub.dev/url_launcher_linux-3.1.1/ -url_launcher_macos=/Users/segun/.pub-cache/hosted/pub.dev/url_launcher_macos-3.1.0/ -url_launcher_web=/Users/segun/.pub-cache/hosted/pub.dev/url_launcher_web-2.3.0/ -url_launcher_windows=/Users/segun/.pub-cache/hosted/pub.dev/url_launcher_windows-3.1.1/ -webview_flutter=/Users/segun/.pub-cache/hosted/pub.dev/webview_flutter-4.7.0/ -webview_flutter_android=/Users/segun/.pub-cache/hosted/pub.dev/webview_flutter_android-3.16.0/ -webview_flutter_wkwebview=/Users/segun/.pub-cache/hosted/pub.dev/webview_flutter_wkwebview-3.13.0/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ba6661..2b32385 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.3.1 + +- Rebase web logic onto platform interface + ## 1.3.0 - Update License diff --git a/README.md b/README.md index 727edc7..a3cbf53 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ add to your index.html ## Usage ```dart - import 'package:kkiapay_flutter_sdk/kkiapay.dart'; + import 'package:kkiapay_flutter_sdk/kkiapay_flutter_sdk.dart'; ``` #### Initialise the Kkiapay Instance @@ -63,26 +63,21 @@ final kkiapay = KKiaPay( Mobile: ```dart - Navigator.push(context, MaterialPageRoute(builder: (context) => kkiapay), + Navigator.push( context, MaterialPageRoute(builder: (context) => kkiapay), ); ``` Web: ```dart - KKiaPayWeb.pay(kkiapay, (response){}); + KkiapayFlutterSdkPlatform.instance.pay( kkiapay, context, callback ); ``` ## Example ```dart import 'package:flutter/material.dart'; -import 'package:kkiapay_flutter_sdk/kkiapay.dart'; +import 'package:kkiapay_flutter_sdk/kkiapay_flutter_sdk.dart'; -/// NOTICE THAT YOU CAN'T IMPORT THIS LINE TO RUN MOBILE AND WEB AT SAME TIME -/// ADD IT ONLY FOR WEB -/// import 'package:kkiapay_flutter_sdk/kkiapay_web.dart'; -/// -import './successScreen.dart'; void main() => runApp(App()); @@ -201,7 +196,7 @@ class KkiapaySample extends StatelessWidget { style: TextStyle(color: Colors.white), ), onPressed: () { - /// KKiaPayWeb.pay(kkiapay, context, callback); + KkiapayFlutterSdkPlatform.instance.pay(kkiapay, context, callback); }, ), ) diff --git a/example/lib/main.dart b/example/lib/main.dart index 5f944ce..309eb31 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,10 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:kkiapay_flutter_sdk/kkiapay.dart'; - -/// NOTICE THAT YOU CAN'T IMPORT THIS LINE TO RUN MOBILE AND WEB AT SAME TIME -/// ADD IT ONLY FOR WEB -/// import 'package:kkiapay_flutter_sdk/kkiapay_web.dart'; -/// +import 'package:kkiapay_flutter_sdk/kkiapay_flutter_sdk.dart'; import 'success_screen.dart'; void main() => runApp(const App()); @@ -112,7 +107,7 @@ class KkiapaySample extends StatelessWidget { foregroundColor: MaterialStateProperty.all(Colors.white), ), child: const Text( - 'Pay Now', + 'Pay Now ( on Mobile )', style: TextStyle(color: Colors.white), ), onPressed: () { @@ -134,11 +129,11 @@ class KkiapaySample extends StatelessWidget { foregroundColor: MaterialStateProperty.all(Colors.white), ), child: const Text( - 'Pay Now ( WEB )', + 'Pay Now ( on WEB )', style: TextStyle(color: Colors.white), ), onPressed: () { - /// KKiaPayWeb.pay(kkiapay, context, callback); + KkiapayFlutterSdkPlatform.instance.pay(kkiapay, context, callback); }, ), ) diff --git a/example/pubspec.lock b/example/pubspec.lock index f68fdcc..f1283f4 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -149,7 +149,7 @@ packages: path: ".." relative: true source: path - version: "1.3.0" + version: "1.3.1" leak_tracker: dependency: transitive description: diff --git a/lib/kkiapay.dart b/lib/kkiapay.dart deleted file mode 100644 index a3ad220..0000000 --- a/lib/kkiapay.dart +++ /dev/null @@ -1,3 +0,0 @@ -export 'src/features/mobile/kkiapay.dart'; -export 'src/utils/utils.dart'; -export 'src/utils/config.dart'; diff --git a/lib/kkiapay_flutter_sdk.dart b/lib/kkiapay_flutter_sdk.dart index 63cf920..c57a848 100644 --- a/lib/kkiapay_flutter_sdk.dart +++ b/lib/kkiapay_flutter_sdk.dart @@ -1,6 +1,7 @@ -library kkiapay; +library kkiapay_flutter_sdk; + +export 'src/features/mobile/kkiapay.dart'; +export 'src/utils/utils.dart'; +export 'src/utils/config.dart'; +export 'package:kkiapay_flutter_sdk/kkiapay_flutter_sdk_platform_interface.dart'; -export 'src/platform_web.dart'; -export 'src/widget_builder_view.dart'; -export 'utils/utils.dart'; -export 'utils/config.dart'; diff --git a/lib/kkiapay_flutter_sdk_method_channel.dart b/lib/kkiapay_flutter_sdk_method_channel.dart index 7f66659..8463a49 100644 --- a/lib/kkiapay_flutter_sdk_method_channel.dart +++ b/lib/kkiapay_flutter_sdk_method_channel.dart @@ -9,9 +9,4 @@ class MethodChannelKkiapayFlutterSdk extends KkiapayFlutterSdkPlatform { @visibleForTesting final methodChannel = const MethodChannel('kkiapay_flutter_sdk'); - @override - Future getPlatformVersion() async { - final version = await methodChannel.invokeMethod('getPlatformVersion'); - return version; - } } diff --git a/lib/kkiapay_flutter_sdk_platform_interface.dart b/lib/kkiapay_flutter_sdk_platform_interface.dart index 78b3c02..623201a 100644 --- a/lib/kkiapay_flutter_sdk_platform_interface.dart +++ b/lib/kkiapay_flutter_sdk_platform_interface.dart @@ -1,5 +1,6 @@ +import 'package:flutter/cupertino.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; - +import 'kkiapay_flutter_sdk.dart'; import 'kkiapay_flutter_sdk_method_channel.dart'; abstract class KkiapayFlutterSdkPlatform extends PlatformInterface { @@ -23,7 +24,9 @@ abstract class KkiapayFlutterSdkPlatform extends PlatformInterface { _instance = instance; } - Future getPlatformVersion() { + /// Init kkiapay payment interface + Future pay (KKiaPay paymentRequest, BuildContext context, Function(dynamic, BuildContext) callback) async { throw UnimplementedError('platformVersion() has not been implemented.'); } + } diff --git a/lib/kkiapay_flutter_sdk_web.dart b/lib/kkiapay_flutter_sdk_web.dart index ef0a88f..8af93d0 100644 --- a/lib/kkiapay_flutter_sdk_web.dart +++ b/lib/kkiapay_flutter_sdk_web.dart @@ -2,10 +2,11 @@ // of your plugin as a separate package, instead of inlining it in the same // package as the core of your plugin. // ignore: avoid_web_libraries_in_flutter - +import 'dart:js' as js; +import 'package:flutter/cupertino.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; -import 'package:web/web.dart' as web; +import 'kkiapay_flutter_sdk.dart'; import 'kkiapay_flutter_sdk_platform_interface.dart'; /// A web implementation of the KkiapayFlutterSdkPlatform of the KkiapayFlutterSdk plugin. @@ -17,10 +18,48 @@ class KkiapayFlutterSdkWeb extends KkiapayFlutterSdkPlatform { KkiapayFlutterSdkPlatform.instance = KkiapayFlutterSdkWeb(); } - /// Returns a [String] containing the version of the platform. @override - Future getPlatformVersion() async { - final version = web.window.navigator.userAgent; - return version; + Future pay ( + KKiaPay paymentRequest, + BuildContext context, + Function(dynamic, BuildContext) callback) async { + final data = js.JsObject.jsify({ + 'amount': paymentRequest.amount.toString(), + 'key': paymentRequest.apikey.toString(), + 'sandbox': paymentRequest.sandbox.toString(), + 'name': paymentRequest.name.toString(), + 'phone': paymentRequest.phone.toString(), + 'email': paymentRequest.email.toString(), + 'data': paymentRequest.data.toString(), + 'theme': paymentRequest.theme.toString(), + 'reason': paymentRequest.reason.toString(), + 'partnerId': paymentRequest.partnerId.toString(), + 'countries': paymentRequest.countries, + }); + + void onSuccessListener(js.JsObject response) async { + callback( { + 'requestData': { + 'amount': paymentRequest.amount, + 'key': paymentRequest.apikey, + 'sandbox': paymentRequest.sandbox, + 'name': paymentRequest.name, + 'phone': paymentRequest.phone, + 'email': paymentRequest.email, + 'data': paymentRequest.data, + 'theme': paymentRequest.theme, + 'countries': paymentRequest.countries.toString(), + 'reason': paymentRequest.reason.toString(), + 'partnerId': paymentRequest.partnerId.toString(), + }, + 'transactionId': response["transactionId"], + 'status': PAYMENT_SUCCESS + },context ); + } + + js.context.callMethod('addSuccessListener', [onSuccessListener]); + + js.context.callMethod('openKkiapayWidget', [data]); } + } diff --git a/lib/kkiapay_web.dart b/lib/kkiapay_web.dart deleted file mode 100644 index f59b550..0000000 --- a/lib/kkiapay_web.dart +++ /dev/null @@ -1 +0,0 @@ -export 'src/features/web/kkiapay_web.dart'; \ No newline at end of file diff --git a/lib/src/features/web/kkiapay_web.dart b/lib/src/features/web/kkiapay_web.dart index b363332..ece80e2 100644 --- a/lib/src/features/web/kkiapay_web.dart +++ b/lib/src/features/web/kkiapay_web.dart @@ -1,8 +1,10 @@ import 'dart:js' as js; import 'dart:async'; import 'package:flutter/cupertino.dart'; +import 'package:flutter_web_plugins/flutter_web_plugins.dart'; import '../../../kkiapay_flutter_sdk_platform_interface.dart'; +import '../../../kkiapay_flutter_sdk_web.dart'; import '../../utils/config.dart'; import '../mobile/kkiapay.dart'; @@ -12,7 +14,15 @@ class KKiaPayWeb extends KkiapayFlutterSdkPlatform { /// Constructs KKiaPayWeb(); - static Future pay (KKiaPay paymentRequest, BuildContext context, Function(dynamic, BuildContext) callback) async { + static void registerWith(Registrar registrar) { + KkiapayFlutterSdkPlatform.instance = KkiapayFlutterSdkWeb(); + } + + @override + Future pay ( + KKiaPay paymentRequest, + BuildContext context, + Function(dynamic, BuildContext) callback) async { final data = js.JsObject.jsify({ 'amount': paymentRequest.amount.toString(), 'key': paymentRequest.apikey.toString(), diff --git a/pubspec.yaml b/pubspec.yaml index 6369f6a..b71eb1a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: kkiapay_flutter_sdk description: KKiaPay allows businesses to safely receive payments by mobile money, credit card and bank account. -version: 1.3.0 +version: 1.3.1 homepage: "https://kkiapay.me/" environment: diff --git a/test/kkiapay_flutter_sdk_method_channel_test.dart b/test/kkiapay_flutter_sdk_method_channel_test.dart index 695bb8e..d14b1fc 100644 --- a/test/kkiapay_flutter_sdk_method_channel_test.dart +++ b/test/kkiapay_flutter_sdk_method_channel_test.dart @@ -21,7 +21,4 @@ void main() { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(channel, null); }); - test('getPlatformVersion', () async { - expect(await platform.getPlatformVersion(), '42'); - }); } diff --git a/test/kkiapay_flutter_sdk_test.dart b/test/kkiapay_flutter_sdk_test.dart index d429932..bed7b71 100644 --- a/test/kkiapay_flutter_sdk_test.dart +++ b/test/kkiapay_flutter_sdk_test.dart @@ -1,6 +1,8 @@ +import 'package:flutter/src/widgets/framework.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:kkiapay_flutter_sdk/kkiapay_flutter_sdk_platform_interface.dart'; import 'package:kkiapay_flutter_sdk/kkiapay_flutter_sdk_method_channel.dart'; +import 'package:kkiapay_flutter_sdk/src/features/mobile/kkiapay.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; class MockKkiapayFlutterSdkPlatform @@ -9,6 +11,12 @@ class MockKkiapayFlutterSdkPlatform @override Future getPlatformVersion() => Future.value('42'); + + @override + Future pay(KKiaPay paymentRequest, BuildContext context, Function(dynamic p1, BuildContext p2) callback) { + // TODO: implement pay + throw UnimplementedError(); + } } void main() {