backend nfc release
parent
e0c4ade930
commit
8edcc2cdb3
|
|
@ -106,6 +106,9 @@ dependencies {
|
|||
androidTestImplementation 'androidx.test:runner:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
|
||||
|
||||
// https://mvnrepository.com/artifact/com.google.code.gson/gson
|
||||
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
|
||||
|
||||
|
||||
implementation 'com.android.support:multidex:1.0.3'
|
||||
//m4bank dependencies
|
||||
|
|
|
|||
|
|
@ -2,12 +2,16 @@ package kz.com.aman.kassa.handler;
|
|||
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
import kz.com.aman.kassa.MainActivity;
|
||||
import kz.com.aman.kassa.bank.M4BankActivity;
|
||||
import kz.com.aman.kassa.model.AmanDao;
|
||||
import kz.com.aman.kassa.plugins.BankNfcPlugins;
|
||||
import ru.m4bank.mpos.library.external.authorization.AuthorizationCallbackHandler;
|
||||
import ru.m4bank.mpos.service.authorization.network.AuthorizationResponse;
|
||||
import ru.m4bank.mpos.service.commons.data.ResultType;
|
||||
|
||||
|
||||
public class AuthorizationHandlerImpl implements AuthorizationCallbackHandler {
|
||||
|
|
@ -15,6 +19,7 @@ public class AuthorizationHandlerImpl implements AuthorizationCallbackHandler {
|
|||
private final String login;
|
||||
private final String password;
|
||||
private final MethodChannel.Result result;
|
||||
private final Gson gson = new Gson();
|
||||
|
||||
public AuthorizationHandlerImpl(BankNfcPlugins plugin, MethodChannel.Result result, String login, String password) {
|
||||
this.plugin = plugin;
|
||||
|
|
@ -31,9 +36,14 @@ public class AuthorizationHandlerImpl implements AuthorizationCallbackHandler {
|
|||
|
||||
@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());
|
||||
plugin.getActivity().runOnUiThread(() -> {
|
||||
Toast.makeText(plugin.getActivity(), result.getResultType() + " " + (result.getDescription() == null ? "" : result.getDescription()),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
AmanDao<String> dao = new AmanDao<>();
|
||||
dao.setSuccess(ResultType.SUCCESSFUL.equals(result.getResultType()));
|
||||
dao.setMsg(result.getResultType() + " " + (result.getDescription() == null ? "" : result.getDescription()));
|
||||
this.result.success(gson.toJson(dao));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -48,9 +58,14 @@ public class AuthorizationHandlerImpl implements AuthorizationCallbackHandler {
|
|||
|
||||
@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());
|
||||
|
||||
plugin.getActivity().runOnUiThread(() -> { Toast.makeText(plugin.getActivity(), result.getResultType() + " " + (result.getDescription() == null ? "" : result.getDescription()),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
AmanDao<String> dao = new AmanDao<>();
|
||||
dao.setSuccess(ResultType.SUCCESSFUL.equals(result.getResultType()));
|
||||
dao.setMsg(result.getResultType() + " " + (result.getDescription() == null ? "" : result.getDescription()));
|
||||
this.result.success(gson.toJson(dao));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,12 +5,15 @@ import android.widget.ArrayAdapter;
|
|||
import android.widget.Spinner;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
import kz.com.aman.kassa.bank.gui.CustomKeyBoardDilalog;
|
||||
import kz.com.aman.kassa.model.AmanDao;
|
||||
import kz.com.aman.kassa.plugins.BankNfcPlugins;
|
||||
import ru.m4bank.mpos.library.external.transactions.CardPaymentCallbackHandler;
|
||||
import ru.m4bank.mpos.service.commons.data.ResultType;
|
||||
|
|
@ -43,13 +46,14 @@ import timber.log.Timber;
|
|||
|
||||
public class CardPaymentHandlerImpl implements CardPaymentCallbackHandler<Result> {
|
||||
private final BankNfcPlugins plugin;
|
||||
private final MethodChannel.Result callbackResult;
|
||||
private final MethodChannel.Result result;
|
||||
private final Long amount;
|
||||
private CustomKeyBoardDilalog customKeyBoardDilalog;
|
||||
private TransactionTypeConv transactionTypeConv;
|
||||
private final Gson gson = new Gson();
|
||||
|
||||
public CardPaymentHandlerImpl(BankNfcPlugins plugin, MethodChannel.Result result, long amount) {
|
||||
this.callbackResult = result;
|
||||
this.result = result;
|
||||
this.plugin = plugin;
|
||||
this.amount = amount;
|
||||
customKeyBoardDilalog = new CustomKeyBoardDilalog();
|
||||
|
|
@ -223,12 +227,11 @@ public class CardPaymentHandlerImpl implements CardPaymentCallbackHandler<Result
|
|||
if (transactionErrorData.getError() != null) {
|
||||
plugin.getActivity().runOnUiThread(() -> Toast.makeText(plugin.getActivity(), transactionErrorData.getError().getDescription(), Toast.LENGTH_LONG).show());
|
||||
} else {
|
||||
//this.result1.error("3", ((AllError) errorHandler).name(), errorHandler.getDescription());
|
||||
System.out.println(String.format("+++++++++++ onError: %s, description: %s", ((AllError) errorHandler).name(), errorHandler.getFinalDescription()));
|
||||
|
||||
System.out.printf("----->---->---->onError: %s, description: %s", ((AllError) errorHandler).name(), errorHandler.getDescription());
|
||||
plugin.getActivity().runOnUiThread(() -> {
|
||||
this.callbackResult.success(String.format("+++++++++++ onError: %s, description: %s", ((AllError) errorHandler).name(), errorHandler.getFinalDescription()));
|
||||
AmanDao<String> dao = new AmanDao<>();
|
||||
dao.setSuccess(false);
|
||||
dao.setMsg(String.format("+++++++++++ onError: %s, description: %s", ((AllError) errorHandler).name(), errorHandler.getFinalDescription()));
|
||||
this.result.success(gson.toJson(dao));
|
||||
Toast.makeText(plugin.getActivity(), String.format("onError: %s, description: %s", ((AllError) errorHandler).name(), errorHandler.getFinalDescription()), Toast.LENGTH_LONG).show();
|
||||
});
|
||||
}
|
||||
|
|
@ -263,7 +266,10 @@ public class CardPaymentHandlerImpl implements CardPaymentCallbackHandler<Result
|
|||
System.out.println("----->---->---->onTransactionDataReceived");
|
||||
|
||||
plugin.getActivity().runOnUiThread(() -> {
|
||||
this.callbackResult.success("success");
|
||||
AmanDao<String> dao = new AmanDao<>();
|
||||
dao.setSuccess(true);
|
||||
dao.setMsg("OK");
|
||||
this.result.success(gson.toJson(dao));
|
||||
Toast.makeText(plugin.getActivity(), "Transaction data has been received", Toast.LENGTH_LONG)
|
||||
.show();
|
||||
});
|
||||
|
|
@ -341,7 +347,10 @@ public class CardPaymentHandlerImpl implements CardPaymentCallbackHandler<Result
|
|||
System.out.println("----->---->---->notAuthorized");
|
||||
|
||||
plugin.getActivity().runOnUiThread(() -> {
|
||||
this.callbackResult.success("notAuthorized");
|
||||
AmanDao<String> dao = new AmanDao<>();
|
||||
dao.setSuccess(false);
|
||||
dao.setMsg("notAuthorized");
|
||||
this.result.success(gson.toJson(dao));
|
||||
Toast.makeText(plugin.getActivity(), "notAuthorized", Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,16 @@ package kz.com.aman.kassa.handler;
|
|||
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
import kz.com.aman.kassa.MainActivity;
|
||||
import kz.com.aman.kassa.model.AmanDao;
|
||||
import ru.m4bank.mpos.library.external.configuration.CheckConnectionCallbackHandler;
|
||||
import ru.m4bank.mpos.service.result.CheckConnectionExternalResult;
|
||||
|
||||
public class ConnectionCheckHandlerImpl implements CheckConnectionCallbackHandler {
|
||||
private final Gson gson = new Gson();
|
||||
private final MainActivity activity;
|
||||
private final MethodChannel.Result result;
|
||||
|
||||
|
|
@ -18,15 +22,26 @@ public class ConnectionCheckHandlerImpl implements CheckConnectionCallbackHandle
|
|||
|
||||
@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());
|
||||
activity.runOnUiThread(() -> {
|
||||
Toast.makeText(activity, result.getResultType() + " " + (result.getDescription() == null ? "" : result.getDescription()) + " " + result.isOnlineRegistration(), Toast.LENGTH_SHORT).show();
|
||||
AmanDao<String> dao = new AmanDao<>();
|
||||
dao.setSuccess(true);
|
||||
dao.setMsg("OK");
|
||||
this.result.success(gson.toJson(dao));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onWrongApiCalled() {
|
||||
this.result.success("error");
|
||||
activity.runOnUiThread(() -> Toast.makeText(activity, "Wrong method has been called", Toast.LENGTH_SHORT).show());
|
||||
activity.runOnUiThread(() -> {
|
||||
Toast.makeText(activity, "Wrong method has been called", Toast.LENGTH_SHORT).show();
|
||||
AmanDao<String> dao = new AmanDao<>();
|
||||
dao.setSuccess(false);
|
||||
dao.setMsg("error");
|
||||
this.result.success(gson.toJson(dao));
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
package kz.com.aman.kassa.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AmanDao<E> {
|
||||
private boolean success;
|
||||
private String msg;
|
||||
private E data;
|
||||
private List<E> rows = new ArrayList<>();
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public E getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(E data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public List<E> getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
public void setRows(List<E> rows) {
|
||||
this.rows = rows;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,9 +3,13 @@ package kz.com.aman.kassa.plugins;
|
|||
import android.os.Build;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
|
||||
|
|
@ -20,6 +24,7 @@ import kz.com.aman.kassa.handler.AuthorizationHandlerImpl;
|
|||
import kz.com.aman.kassa.handler.CardPaymentHandlerImpl;
|
||||
import kz.com.aman.kassa.handler.ConnectionCheckHandlerImpl;
|
||||
import kz.com.aman.kassa.handler.TransactionDetailsHandlerImpl;
|
||||
import kz.com.aman.kassa.model.AmanDao;
|
||||
import ru.m4bank.mpos.library.M4BankMposClient;
|
||||
import ru.m4bank.mpos.library.M4BankMposClientInterfaceFacade;
|
||||
import ru.m4bank.mpos.library.M4BankMposParameters;
|
||||
|
|
@ -36,6 +41,9 @@ import ru.m4bank.mpos.service.network.ServerChoose;
|
|||
|
||||
|
||||
public class BankNfcPlugins implements MethodCallHandler {
|
||||
|
||||
private final Gson gson = new Gson();
|
||||
|
||||
//main activity
|
||||
private MainActivity activity;
|
||||
|
||||
|
|
@ -84,11 +92,13 @@ public class BankNfcPlugins implements MethodCallHandler {
|
|||
result.success("version: "+ Build.VERSION.SDK_INT);
|
||||
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);
|
||||
AmanDao<String> dao = new AmanDao<>();
|
||||
dao.setSuccess(true);
|
||||
dao.setMsg("Hello World");
|
||||
result.success(gson.toJson(dao));
|
||||
break;
|
||||
case "error":
|
||||
result.error("0-code","0-message", "0-details");
|
||||
break;
|
||||
default:
|
||||
result.notImplemented();
|
||||
|
|
@ -115,9 +125,16 @@ public class BankNfcPlugins implements MethodCallHandler {
|
|||
@Override
|
||||
public void onPermissionsGranted() {
|
||||
System.out.println("granted");
|
||||
activity.runOnUiThread(() -> Toast.makeText(activity, "Granted", Toast.LENGTH_SHORT).show());
|
||||
activity.runOnUiThread(() -> {
|
||||
Toast.makeText(activity, "Granted", Toast.LENGTH_SHORT).show();
|
||||
start(serverUrl);
|
||||
result.success("ok");
|
||||
AmanDao<String> dao = new AmanDao<>();
|
||||
dao.setSuccess(true);
|
||||
dao.setMsg("OK");
|
||||
result.success(gson.toJson(dao));
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -193,7 +210,10 @@ public class BankNfcPlugins implements MethodCallHandler {
|
|||
private void cancel(MethodCall call, Result result) {
|
||||
try {
|
||||
clientInterface.cancel();
|
||||
result.success("success");
|
||||
AmanDao<String> dao = new AmanDao<>();
|
||||
dao.setSuccess(true);
|
||||
dao.setMsg("OK");
|
||||
result.success(gson.toJson(dao));
|
||||
} catch (Exception e) {
|
||||
System.out.println("=============>ERROR:"+e.getMessage());
|
||||
result.error("2", e.getMessage(), e.getLocalizedMessage());
|
||||
|
|
@ -203,7 +223,10 @@ public class BankNfcPlugins implements MethodCallHandler {
|
|||
private void shutdown(MethodCall call, Result result) {
|
||||
try {
|
||||
clientInterface.shutdown();
|
||||
result.success("success");
|
||||
AmanDao<String> dao = new AmanDao<>();
|
||||
dao.setSuccess(true);
|
||||
dao.setMsg("OK");
|
||||
result.success(gson.toJson(dao));
|
||||
} catch (Exception e) {
|
||||
System.out.println("=============>ERROR:"+e.getMessage());
|
||||
result.error("2", e.getMessage(), e.getLocalizedMessage());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
class AmanDao<T> {
|
||||
final T data;
|
||||
//final List<T> rows;
|
||||
final String msg;
|
||||
final bool success;
|
||||
|
||||
AmanDao({this.data, this.success, this.msg});
|
||||
|
||||
|
||||
factory AmanDao.fromJson(Map<String, dynamic> data) {
|
||||
return AmanDao(
|
||||
data: data['data'],
|
||||
msg: data['msg'],
|
||||
success: data['success']);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:aman_kassa_flutter/core/models/aman_dao.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
|
|
@ -21,6 +24,8 @@ class _BankViewState extends State<BankView> {
|
|||
String shutdownValue;
|
||||
String versionValue;
|
||||
String transactionValue;
|
||||
String getValue;
|
||||
String errorValue;
|
||||
bool loading = false;
|
||||
|
||||
@override
|
||||
|
|
@ -83,8 +88,7 @@ class _BankViewState extends State<BankView> {
|
|||
cancel() async {
|
||||
String result;
|
||||
try {
|
||||
result =
|
||||
await _channel.invokeMethod("cancel");
|
||||
result = await _channel.invokeMethod("cancel");
|
||||
} catch (e) {
|
||||
result = (e.toString());
|
||||
}
|
||||
|
|
@ -96,8 +100,7 @@ class _BankViewState extends State<BankView> {
|
|||
shutdown() async {
|
||||
String result;
|
||||
try {
|
||||
result =
|
||||
await _channel.invokeMethod("shutdown");
|
||||
result = await _channel.invokeMethod("shutdown");
|
||||
} catch (e) {
|
||||
result = (e.toString());
|
||||
}
|
||||
|
|
@ -106,6 +109,34 @@ class _BankViewState extends State<BankView> {
|
|||
});
|
||||
}
|
||||
|
||||
get() async {
|
||||
String result;
|
||||
try {
|
||||
String response = await _channel.invokeMethod("get");
|
||||
AmanDao dao = AmanDao.fromJson(json.decode(response));
|
||||
result = '${dao.data} - ${dao.msg}';
|
||||
} catch (e) {
|
||||
result = (e.toString());
|
||||
}
|
||||
setState(() {
|
||||
getValue = result;
|
||||
});
|
||||
}
|
||||
|
||||
error() async {
|
||||
String result;
|
||||
try {
|
||||
String json = await _channel.invokeMethod("error");
|
||||
dynamic data = JsonDecoder().convert(json);
|
||||
result = data["msg"];
|
||||
} catch (e) {
|
||||
result = (e.toString());
|
||||
}
|
||||
setState(() {
|
||||
errorValue = result;
|
||||
});
|
||||
}
|
||||
|
||||
activity() async {
|
||||
String result = await _activity.invokeMethod("start");
|
||||
}
|
||||
|
|
@ -169,14 +200,32 @@ class _BankViewState extends State<BankView> {
|
|||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: <Widget>[
|
||||
Text('shutdown: $shutdownValue'),
|
||||
RaisedButton(child: Text('Shutdown'), onPressed: shutdown),
|
||||
RaisedButton(
|
||||
child: Text('Shutdown'), onPressed: shutdown),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: <Widget>[
|
||||
Text('transaction: $transactionValue'),
|
||||
RaisedButton(child: Text('Transaction'), onPressed: transaction),
|
||||
RaisedButton(
|
||||
child: Text('Transaction'), onPressed: transaction),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: <Widget>[
|
||||
Text('get: $getValue'),
|
||||
RaisedButton(
|
||||
child: Text('Get'), onPressed: get),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: <Widget>[
|
||||
Text('error: $errorValue'),
|
||||
RaisedButton(
|
||||
child: Text('Error'), onPressed: error),
|
||||
],
|
||||
),
|
||||
Text('pay: $payValue'),
|
||||
|
|
|
|||
Loading…
Reference in New Issue