Skip to content

Commit

Permalink
version: 1.3.1-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Shek863 committed Jul 15, 2024
1 parent 630e7ea commit a9475bf
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 58 deletions.
11 changes: 0 additions & 11 deletions .flutter-plugins

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.3.1

- Rebase web logic onto platform interface

## 1.3.0

- Update License
Expand Down
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
},
),
)
Expand Down
13 changes: 4 additions & 9 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -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());
Expand Down Expand Up @@ -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: () {
Expand All @@ -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);
},
),
)
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.3.0"
version: "1.3.1"
leak_tracker:
dependency: transitive
description:
Expand Down
3 changes: 0 additions & 3 deletions lib/kkiapay.dart

This file was deleted.

11 changes: 6 additions & 5 deletions lib/kkiapay_flutter_sdk.dart
Original file line number Diff line number Diff line change
@@ -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';
5 changes: 0 additions & 5 deletions lib/kkiapay_flutter_sdk_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,4 @@ class MethodChannelKkiapayFlutterSdk extends KkiapayFlutterSdkPlatform {
@visibleForTesting
final methodChannel = const MethodChannel('kkiapay_flutter_sdk');

@override
Future<String?> getPlatformVersion() async {
final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
return version;
}
}
7 changes: 5 additions & 2 deletions lib/kkiapay_flutter_sdk_platform_interface.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -23,7 +24,9 @@ abstract class KkiapayFlutterSdkPlatform extends PlatformInterface {
_instance = instance;
}

Future<String?> getPlatformVersion() {
/// Init kkiapay payment interface
Future pay (KKiaPay paymentRequest, BuildContext context, Function(dynamic, BuildContext) callback) async {
throw UnimplementedError('platformVersion() has not been implemented.');
}

}
51 changes: 45 additions & 6 deletions lib/kkiapay_flutter_sdk_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -17,10 +18,48 @@ class KkiapayFlutterSdkWeb extends KkiapayFlutterSdkPlatform {
KkiapayFlutterSdkPlatform.instance = KkiapayFlutterSdkWeb();
}

/// Returns a [String] containing the version of the platform.
@override
Future<String?> 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]);
}

}
1 change: 0 additions & 1 deletion lib/kkiapay_web.dart

This file was deleted.

12 changes: 11 additions & 1 deletion lib/src/features/web/kkiapay_web.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
3 changes: 0 additions & 3 deletions test/kkiapay_flutter_sdk_method_channel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,4 @@ void main() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(channel, null);
});

test('getPlatformVersion', () async {
expect(await platform.getPlatformVersion(), '42');
});
}
8 changes: 8 additions & 0 deletions test/kkiapay_flutter_sdk_test.dart
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,6 +11,12 @@ class MockKkiapayFlutterSdkPlatform

@override
Future<String?> getPlatformVersion() => Future.value('42');

@override
Future pay(KKiaPay paymentRequest, BuildContext context, Function(dynamic p1, BuildContext p2) callback) {
// TODO: implement pay
throw UnimplementedError();
}
}

void main() {
Expand Down

0 comments on commit a9475bf

Please sign in to comment.