auth m4bank release
parent
ef10080cd2
commit
39153af143
|
|
@ -20,7 +20,7 @@
|
||||||
android:label="Аман Касса"
|
android:label="Аман Касса"
|
||||||
android:roundIcon="@mipmap/ic_launcher_rounded"
|
android:roundIcon="@mipmap/ic_launcher_rounded"
|
||||||
android:usesCleartextTraffic="true">
|
android:usesCleartextTraffic="true">
|
||||||
<activity android:name=".bank.BankActivity" android:theme="@android:style/Theme.Black.NoTitleBar"></activity>
|
<activity android:name=".activities.BankActivity" android:theme="@android:style/Theme.Black.NoTitleBar"></activity>
|
||||||
<activity android:name=".bank.M4BankActivity" android:theme="@android:style/Theme.Light.NoTitleBar"></activity>
|
<activity android:name=".bank.M4BankActivity" android:theme="@android:style/Theme.Light.NoTitleBar"></activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
|
|
|
||||||
|
|
@ -1,77 +0,0 @@
|
||||||
package kz.com.aman.kassa.bank;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import io.flutter.plugin.common.MethodCall;
|
|
||||||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
|
|
||||||
import io.flutter.plugin.common.MethodChannel.Result;
|
|
||||||
import kz.com.aman.kassa.bank.permissions.PermissionsManager;
|
|
||||||
import kz.com.aman.kassa.bank.permissions.PermissionsManagerImpl;
|
|
||||||
import ru.m4bank.mpos.library.M4BankMposClientInterfaceFacade;
|
|
||||||
|
|
||||||
public class BankNfcPlugins implements MethodCallHandler {
|
|
||||||
//main activity
|
|
||||||
private Activity activity;
|
|
||||||
|
|
||||||
private String timer;
|
|
||||||
|
|
||||||
//main client all work with him
|
|
||||||
private M4BankMposClientInterfaceFacade clientInterface;
|
|
||||||
//permissions
|
|
||||||
private PermissionsManager permissionsManager;
|
|
||||||
|
|
||||||
public BankNfcPlugins(Activity activity) {
|
|
||||||
this.activity = activity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMethodCall(MethodCall call, Result result) {
|
|
||||||
switch (call.method) {
|
|
||||||
case "init":
|
|
||||||
PermissionsManager.PermissionsCheckResultHandler permissionsCheckResultHandler =
|
|
||||||
new PermissionsManager.PermissionsCheckResultHandler() {
|
|
||||||
@Override
|
|
||||||
public void onPermissionsGranted() {
|
|
||||||
System.out.println("granted");
|
|
||||||
activity.runOnUiThread(() -> Toast.makeText(activity, "Granted", Toast.LENGTH_SHORT).show());
|
|
||||||
//init();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPermissionsDeclined() {
|
|
||||||
System.out.println("Declined");
|
|
||||||
//init();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
permissionsManager = new PermissionsManagerImpl(this.activity);
|
|
||||||
permissionsManager.checkPermissions(permissionsCheckResultHandler);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(timer==null){
|
|
||||||
timer = "inited)";
|
|
||||||
activity.runOnUiThread(() -> Toast.makeText(activity, "Initialize", Toast.LENGTH_SHORT).show());
|
|
||||||
} else {
|
|
||||||
activity.runOnUiThread(() -> Toast.makeText(activity, "Already Initialize", Toast.LENGTH_SHORT).show());
|
|
||||||
}
|
|
||||||
|
|
||||||
result.success("pong - 3");
|
|
||||||
break;
|
|
||||||
case "get":
|
|
||||||
final List<Object> json = new ArrayList<>();
|
|
||||||
for (int i =0; i < 2 ; i++) {
|
|
||||||
json.add("{\"name:\":\"test\" }"); // Map<String, Object> entries
|
|
||||||
}
|
|
||||||
result.success(json);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
result.notImplemented();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Other methods elided.
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
package kz.com.aman.kassa.handler;
|
||||||
|
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import io.flutter.plugin.common.MethodChannel;
|
||||||
|
import kz.com.aman.kassa.MainActivity;
|
||||||
|
import kz.com.aman.kassa.bank.M4BankActivity;
|
||||||
|
import kz.com.aman.kassa.plugins.BankNfcPlugins;
|
||||||
|
import ru.m4bank.mpos.library.external.authorization.AuthorizationCallbackHandler;
|
||||||
|
import ru.m4bank.mpos.service.authorization.network.AuthorizationResponse;
|
||||||
|
|
||||||
|
|
||||||
|
public class AuthorizationHandlerImpl implements AuthorizationCallbackHandler {
|
||||||
|
private final BankNfcPlugins plugin;
|
||||||
|
private final String login;
|
||||||
|
private final String password;
|
||||||
|
private final MethodChannel.Result result;
|
||||||
|
|
||||||
|
public AuthorizationHandlerImpl(BankNfcPlugins plugin, MethodChannel.Result result, String login, String password) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.login = login;
|
||||||
|
this.password = password;
|
||||||
|
this.result =result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoginAndPasswordRequested() {
|
||||||
|
plugin.getClientInterface().getAuthorizationManager().sendLoginAndPassword(this.login, this.password);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCompleted(ru.m4bank.mpos.service.result.Result result) {
|
||||||
|
this.result.success("onCompleted-1:" + result.getResultType() );
|
||||||
|
plugin.getActivity().runOnUiThread(() -> Toast.makeText(plugin.getActivity(), result.getResultType() + " " + (result.getDescription() == null ? "" : result.getDescription()),
|
||||||
|
Toast.LENGTH_SHORT).show());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onWrongApiCalled() {
|
||||||
|
plugin.getActivity().runOnUiThread(() -> Toast.makeText(plugin.getActivity(), "Wrong method has been called", Toast.LENGTH_SHORT).show());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRepeat(int attemptNumber) {
|
||||||
|
plugin.getActivity().runOnUiThread(() -> Toast.makeText(plugin.getActivity(), "Repeat attempt number " + attemptNumber, Toast.LENGTH_SHORT).show());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCompleted(ru.m4bank.mpos.service.result.Result result, AuthorizationResponse authorizationResponse) {
|
||||||
|
this.result.success("onCompleted-2:" + result.getResultType() );
|
||||||
|
plugin.getActivity().runOnUiThread(() -> Toast.makeText(plugin.getActivity(), result.getResultType() + " " + (result.getDescription() == null ? "" : result.getDescription()),
|
||||||
|
Toast.LENGTH_SHORT).show());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package kz.com.aman.kassa.handler;
|
||||||
|
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import io.flutter.plugin.common.MethodChannel;
|
||||||
|
import kz.com.aman.kassa.MainActivity;
|
||||||
|
import ru.m4bank.mpos.library.external.configuration.CheckConnectionCallbackHandler;
|
||||||
|
import ru.m4bank.mpos.service.result.CheckConnectionExternalResult;
|
||||||
|
|
||||||
|
public class ConnectionCheckHandlerImpl implements CheckConnectionCallbackHandler {
|
||||||
|
private final MainActivity activity;
|
||||||
|
private final MethodChannel.Result result;
|
||||||
|
|
||||||
|
public ConnectionCheckHandlerImpl(MainActivity activity, MethodChannel.Result result) {
|
||||||
|
this.activity = activity;
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCompleted(CheckConnectionExternalResult result) {
|
||||||
|
this.result.success("success");
|
||||||
|
activity.runOnUiThread(() -> Toast.makeText(activity, result.getResultType() + " " + (result.getDescription() == null ? "" : result.getDescription()) + " " + result.isOnlineRegistration(), Toast.LENGTH_SHORT).show());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onWrongApiCalled() {
|
||||||
|
this.result.success("error");
|
||||||
|
activity.runOnUiThread(() -> Toast.makeText(activity, "Wrong method has been called", Toast.LENGTH_SHORT).show());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,159 @@
|
||||||
|
package kz.com.aman.kassa.plugins;
|
||||||
|
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import io.flutter.plugin.common.MethodCall;
|
||||||
|
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
|
||||||
|
import io.flutter.plugin.common.MethodChannel.Result;
|
||||||
|
import kz.com.aman.kassa.MainActivity;
|
||||||
|
import kz.com.aman.kassa.bank.DeviceTypeDefiner;
|
||||||
|
import kz.com.aman.kassa.bank.SessionExpiringCallbackHandlerImpl;
|
||||||
|
import kz.com.aman.kassa.bank.builders.SslConfigurationBuilder;
|
||||||
|
import kz.com.aman.kassa.bank.permissions.PermissionsManager;
|
||||||
|
import kz.com.aman.kassa.bank.permissions.PermissionsManagerImpl;
|
||||||
|
import kz.com.aman.kassa.handler.AuthorizationHandlerImpl;
|
||||||
|
import kz.com.aman.kassa.handler.ConnectionCheckHandlerImpl;
|
||||||
|
import ru.m4bank.mpos.library.M4BankMposClient;
|
||||||
|
import ru.m4bank.mpos.library.M4BankMposClientInterfaceFacade;
|
||||||
|
import ru.m4bank.mpos.library.M4BankMposParameters;
|
||||||
|
import ru.m4bank.mpos.library.external.authorization.AuthorizationCallbackHandler;
|
||||||
|
import ru.m4bank.mpos.service.authorization.network.AuthorizationResponse;
|
||||||
|
import ru.m4bank.mpos.service.commons.data.ConfigurationSettings;
|
||||||
|
import ru.m4bank.mpos.service.commons.data.NetworkConfiguration;
|
||||||
|
import ru.m4bank.mpos.service.commons.data.TerminalConfiguration;
|
||||||
|
import ru.m4bank.mpos.service.network.Format;
|
||||||
|
import ru.m4bank.mpos.service.network.ServerChoose;
|
||||||
|
|
||||||
|
|
||||||
|
public class BankNfcPlugins implements MethodCallHandler {
|
||||||
|
//main activity
|
||||||
|
private MainActivity activity;
|
||||||
|
|
||||||
|
private String timer;
|
||||||
|
|
||||||
|
//main client all work with him
|
||||||
|
private M4BankMposClientInterfaceFacade clientInterface;
|
||||||
|
//permissions
|
||||||
|
private PermissionsManager permissionsManager;
|
||||||
|
|
||||||
|
public M4BankMposClientInterfaceFacade getClientInterface() {
|
||||||
|
return this.clientInterface;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MainActivity getActivity() {
|
||||||
|
return this.activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BankNfcPlugins(MainActivity activity) {
|
||||||
|
this.activity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMethodCall(MethodCall call, Result result) {
|
||||||
|
switch (call.method) {
|
||||||
|
case "init":
|
||||||
|
init(call, result);
|
||||||
|
break;
|
||||||
|
case "connection":
|
||||||
|
connection(result);
|
||||||
|
break;
|
||||||
|
case "auth":
|
||||||
|
authentication(call, result);
|
||||||
|
break;
|
||||||
|
case "get":
|
||||||
|
final List<Object> json = new ArrayList<>();
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
json.add("{\"name:\":\"test\" }"); // Map<String, Object> entries
|
||||||
|
}
|
||||||
|
result.success(json);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
result.notImplemented();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void init(MethodCall call, Result result) {
|
||||||
|
String serverUrl = call.argument("serverUrl");
|
||||||
|
try {
|
||||||
|
PermissionsManager.PermissionsCheckResultHandler permissionsCheckResultHandler =
|
||||||
|
new PermissionsManager.PermissionsCheckResultHandler() {
|
||||||
|
@Override
|
||||||
|
public void onPermissionsGranted() {
|
||||||
|
System.out.println("granted");
|
||||||
|
activity.runOnUiThread(() -> Toast.makeText(activity, "Granted", Toast.LENGTH_SHORT).show());
|
||||||
|
start(serverUrl);
|
||||||
|
result.success("ok");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPermissionsDeclined() {
|
||||||
|
result.success("declined");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
permissionsManager = new PermissionsManagerImpl(this.activity);
|
||||||
|
permissionsManager.checkPermissions(permissionsCheckResultHandler);
|
||||||
|
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
result.error("1", e.getMessage(), e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//start after all permissions granted
|
||||||
|
private void start(String serverUrl) {
|
||||||
|
clientInterface = M4BankMposClient.getInstance(
|
||||||
|
new M4BankMposParameters(
|
||||||
|
Format.JSON,
|
||||||
|
"rus",
|
||||||
|
null,
|
||||||
|
this.activity,
|
||||||
|
new SessionExpiringCallbackHandlerImpl(),
|
||||||
|
"appName",
|
||||||
|
ServerChoose.API_5_0,
|
||||||
|
new ConfigurationSettings
|
||||||
|
.Builder()
|
||||||
|
.printerUsed(true)
|
||||||
|
.umkaEnabled(true)
|
||||||
|
.networkConfiguration(createNetworkConfiguration(serverUrl))
|
||||||
|
.terminalConfiguration(createTerminalConfiguration())
|
||||||
|
.build())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void connection(Result result) {
|
||||||
|
clientInterface.getConfigurationManager()
|
||||||
|
.checkConnection(
|
||||||
|
new ConnectionCheckHandlerImpl(this.activity, result));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void authentication(MethodCall call, Result result) {
|
||||||
|
String login = call.argument("login");
|
||||||
|
String password = call.argument("password");
|
||||||
|
clientInterface.getAuthorizationManager().authorize(new AuthorizationHandlerImpl(this, result, login, password) );
|
||||||
|
}
|
||||||
|
|
||||||
|
//terminal config
|
||||||
|
private TerminalConfiguration createTerminalConfiguration() {
|
||||||
|
return new TerminalConfiguration.Builder()
|
||||||
|
.energySaverModeTime(150)
|
||||||
|
.pinLengthsArray(new byte[]{4, 6})
|
||||||
|
.shutDownModeTime(300)
|
||||||
|
.deviceType(new DeviceTypeDefiner().define())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
//network config
|
||||||
|
private NetworkConfiguration createNetworkConfiguration(String serverUrl) {
|
||||||
|
return new NetworkConfiguration.Builder()
|
||||||
|
.sslConfiguration(SslConfigurationBuilder.buildAllTrustConfiguration(serverUrl))
|
||||||
|
.serverUrl(serverUrl)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ import io.flutter.embedding.engine.FlutterEngine
|
||||||
import io.flutter.plugin.common.MethodChannel
|
import io.flutter.plugin.common.MethodChannel
|
||||||
import io.flutter.plugins.GeneratedPluginRegistrant
|
import io.flutter.plugins.GeneratedPluginRegistrant
|
||||||
import kz.com.aman.kassa.bank.M4BankActivity
|
import kz.com.aman.kassa.bank.M4BankActivity
|
||||||
import kz.com.aman.kassa.bank.BankNfcPlugins
|
import kz.com.aman.kassa.plugins.BankNfcPlugins
|
||||||
|
|
||||||
|
|
||||||
class MainActivity: FlutterActivity() {
|
class MainActivity: FlutterActivity() {
|
||||||
|
|
@ -19,7 +19,7 @@ class MainActivity: FlutterActivity() {
|
||||||
|
|
||||||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
|
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
|
||||||
GeneratedPluginRegistrant.registerWith(flutterEngine);
|
GeneratedPluginRegistrant.registerWith(flutterEngine);
|
||||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, BANK_CHANNEL).setMethodCallHandler(BankNfcPlugins(this.activity));
|
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, BANK_CHANNEL).setMethodCallHandler(BankNfcPlugins(this));
|
||||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, ACTIVITY_CHANNEL).setMethodCallHandler {
|
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, ACTIVITY_CHANNEL).setMethodCallHandler {
|
||||||
// Note: this method is invoked on the main thread.
|
// Note: this method is invoked on the main thread.
|
||||||
call, result ->
|
call, result ->
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package kz.com.aman.kassa.bank;
|
package kz.com.aman.kassa.activities;
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@color/design_default_color_background"
|
android:background="@color/design_default_color_background"
|
||||||
tools:context=".bank.BankActivity"
|
tools:context=".activities.BankActivity"
|
||||||
>
|
>
|
||||||
|
|
||||||
<androidx.appcompat.widget.LinearLayoutCompat
|
<androidx.appcompat.widget.LinearLayoutCompat
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,11 @@ class _BankViewState extends State<BankView> {
|
||||||
MethodChannel('channel:com.amanKassa/bank');
|
MethodChannel('channel:com.amanKassa/bank');
|
||||||
static const MethodChannel _activity =
|
static const MethodChannel _activity =
|
||||||
MethodChannel('channel:com.amanKassa/activity');
|
MethodChannel('channel:com.amanKassa/activity');
|
||||||
String value;
|
String initValue;
|
||||||
|
String connectionValue;
|
||||||
|
String authValue;
|
||||||
bool loading = false;
|
bool loading = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
@ -22,17 +25,33 @@ class _BankViewState extends State<BankView> {
|
||||||
}
|
}
|
||||||
|
|
||||||
load() async {
|
load() async {
|
||||||
setState(() {
|
String result = await _channel.invokeMethod('init', <String, dynamic>{
|
||||||
loading = true;
|
'serverUrl': 'http://185.98.84.231:2000',
|
||||||
});
|
});
|
||||||
String result = await _channel.invokeMethod('init');
|
setState(() {
|
||||||
|
initValue = result ?? 'none';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
connect() async {
|
||||||
|
String result = await _channel.invokeMethod("connection");
|
||||||
setState(() {
|
setState(() {
|
||||||
value = result ?? 'none';
|
connectionValue = result;
|
||||||
loading = false;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auth() async {
|
||||||
|
String result = await _channel.invokeMethod("auth",
|
||||||
|
<String, dynamic>{'login': 'uvaissov@gmail.com', 'password': '1234'});
|
||||||
|
setState(() {
|
||||||
|
authValue = result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
activity() async {
|
||||||
|
String result = await _activity.invokeMethod("start");
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
|
@ -43,22 +62,17 @@ class _BankViewState extends State<BankView> {
|
||||||
body: loading
|
body: loading
|
||||||
? Container(child: Center(child: CircularProgressIndicator()))
|
? Container(child: Center(child: CircularProgressIndicator()))
|
||||||
: SingleChildScrollView(
|
: SingleChildScrollView(
|
||||||
child: Column(
|
child: Center(
|
||||||
children: <Widget>[
|
child: Column(
|
||||||
Container(
|
children: <Widget>[
|
||||||
margin: const EdgeInsets.all(8.0),
|
Text('init: $initValue'),
|
||||||
child: Text(value),
|
Text('connection: $connectionValue'),
|
||||||
),
|
Text('auth: $authValue'),
|
||||||
RaisedButton(
|
RaisedButton(child: Text('Connect'), onPressed: connect),
|
||||||
child: Text('Press'),
|
RaisedButton(child: Text('Auth'), onPressed: auth),
|
||||||
onPressed: () async {
|
RaisedButton(child: Text('Press'), onPressed: activity),
|
||||||
String result = await _activity.invokeMethod("start");
|
],
|
||||||
print('invokeMethod: $result');
|
),
|
||||||
setState(() {
|
|
||||||
loading = false;
|
|
||||||
});
|
|
||||||
})
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue