api start
parent
228ffd1400
commit
fb63b8acb2
|
|
@ -1,5 +1,7 @@
|
||||||
package kz.com.aman.kassa.plugins;
|
package kz.com.aman.kassa.plugins;
|
||||||
|
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -14,7 +16,13 @@ import kz.com.aman.kassa.MainActivity;
|
||||||
|
|
||||||
import kz.com.aman.kassa.model.AmanDao;
|
import kz.com.aman.kassa.model.AmanDao;
|
||||||
|
|
||||||
|
enum OperationType {
|
||||||
|
PAYMENT, // payment
|
||||||
|
REFUND, // return
|
||||||
|
REVERSAL, // cancel
|
||||||
|
CLOSE_DAY, // closing of the trading day
|
||||||
|
OPERATIONS_LIST // get the list of operations
|
||||||
|
}
|
||||||
|
|
||||||
public class BankNfcPlugins implements MethodCallHandler {
|
public class BankNfcPlugins implements MethodCallHandler {
|
||||||
|
|
||||||
|
|
@ -136,7 +144,8 @@ public class BankNfcPlugins implements MethodCallHandler {
|
||||||
|
|
||||||
private void init(MethodCall call, Result result) {
|
private void init(MethodCall call, Result result) {
|
||||||
String serverUrl = call.argument("serverUrl");
|
String serverUrl = call.argument("serverUrl");
|
||||||
start(serverUrl);
|
String token = call.argument("token");
|
||||||
|
start(token);
|
||||||
AmanDao<String> dao = new AmanDao<>();
|
AmanDao<String> dao = new AmanDao<>();
|
||||||
dao.setSuccess(true);
|
dao.setSuccess(true);
|
||||||
dao.setMsg("OK");
|
dao.setMsg("OK");
|
||||||
|
|
@ -145,7 +154,7 @@ public class BankNfcPlugins implements MethodCallHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
//start after all permissions granted
|
//start after all permissions granted
|
||||||
private void start(String serverUrl) {
|
private void start(String token) {
|
||||||
// clientInterface = M4BankMposClient.getInstance(
|
// clientInterface = M4BankMposClient.getInstance(
|
||||||
// new M4BankMposParameters(
|
// new M4BankMposParameters(
|
||||||
// Format.JSON,
|
// Format.JSON,
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,25 @@
|
||||||
package kz.com.aman.kassa
|
package kz.com.aman.kassa
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
|
import android.content.ComponentName
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Build
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.annotation.NonNull
|
import androidx.annotation.NonNull
|
||||||
import io.flutter.embedding.android.FlutterActivity
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
import io.flutter.embedding.engine.FlutterEngine
|
import io.flutter.embedding.engine.FlutterEngine
|
||||||
|
import io.flutter.plugin.common.MethodCall
|
||||||
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.plugins.BankNfcPlugins
|
import kz.com.aman.kassa.bank.JsonForTests
|
||||||
|
import kz.com.aman.kassa.bank.OperationType
|
||||||
|
|
||||||
|
|
||||||
class MainActivity: FlutterActivity() {
|
class MainActivity: FlutterActivity() {
|
||||||
private val EXTERNAL_INPUT_DATA_KEY = "ru.m4bank.ExternalApplication.InputDataKey";
|
private val externalApplicationRequestCode = 207
|
||||||
private val EXTERNAL_RESULT_DATA_KEY = "ru.m4bank.ExternalApplication.ResultDataKey";
|
private val EXTERNAL_OPERATION_TYPE_KEY = "ru.m4bank.ExternalApplication.OperationTypeKey"
|
||||||
private val EXTERNAL_OPERATION_TYPE_KEY = "ru.m4bank.ExternalApplication.OperationTypeKey";
|
private val EXTERNAL_INPUT_DATA_KEY = "ru.m4bank.ExternalApplication.InputDataKey"
|
||||||
|
private val EXTERNAL_RESULT_DATA_KEY = "ru.m4bank.ExternalApplication.ResultDataKey"
|
||||||
|
|
||||||
private val BANK_CHANNEL = "channel:com.amanKassa/bank"
|
private val BANK_CHANNEL = "channel:com.amanKassa/bank"
|
||||||
private val ACTIVITY_CHANNEL = "channel:com.amanKassa/activity"
|
private val ACTIVITY_CHANNEL = "channel:com.amanKassa/activity"
|
||||||
|
|
@ -22,20 +28,79 @@ 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));
|
//MethodChannel(flutterEngine.dartExecutor.binaryMessenger, BANK_CHANNEL).setMethodCallHandler(BankNfcPlugins(this));
|
||||||
|
|
||||||
|
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, BANK_CHANNEL).setMethodCallHandler(MethodChannel.MethodCallHandler { call, result ->
|
||||||
|
_result = result;
|
||||||
|
if(call.method == "init") {
|
||||||
|
operationPayment(call);
|
||||||
|
} else if(call.method == "version") {
|
||||||
|
result.success(Build.VERSION.SDK_INT.toString())
|
||||||
|
} else {
|
||||||
|
result.notImplemented()
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getOperationList(call: MethodCall) {
|
||||||
|
val token: String = call.argument<String>("token").toString()
|
||||||
|
val operationParameters = createOperationParameters(token);
|
||||||
|
println(operationParameters.toString());
|
||||||
|
println(JsonForTests.getOperationsListJson(token));
|
||||||
|
startOperation(OperationType.OPERATIONS_LIST,
|
||||||
|
JsonForTests.getOperationsListJson(operationParameters.authToken))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun operationPayment(call: MethodCall) {
|
||||||
|
val token = call.argument<String>("token").toString()
|
||||||
|
val operationParameters = createOperationParameters(token);
|
||||||
|
println(operationParameters.toString());
|
||||||
|
println(JsonForTests.getPaymentCardJson(operationParameters.authToken));
|
||||||
|
startOperation(OperationType.PAYMENT, JsonForTests.getPaymentCardJson(operationParameters.authToken))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private fun createOperationParameters(token: String): OperationParameters {
|
||||||
|
return OperationParameters(authToken = token, operDay = "", terminalId = "", transNum = "");
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startOperation(operationType: OperationType, inputJsonData: String?) {
|
||||||
|
val intent = Intent()
|
||||||
|
intent.component = ComponentName("ru.m4bank.softpos.halyk", "ru.m4bank.feature.externalapplication.ExternalApplicationActivity")
|
||||||
|
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||||
|
//intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||||
|
intent.putExtra(EXTERNAL_OPERATION_TYPE_KEY, operationType.code)
|
||||||
|
intent.putExtra(EXTERNAL_INPUT_DATA_KEY, inputJsonData)
|
||||||
|
startActivityForResult(intent, externalApplicationRequestCode)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
super.onActivityResult(requestCode, resultCode, data)
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
if(requestCode == 8989) {
|
if(requestCode == externalApplicationRequestCode) {
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
println("---------------");
|
||||||
_result.success(data?.getStringExtra("result"))
|
println(requestCode);
|
||||||
} else if (resultCode == Activity.RESULT_CANCELED) {
|
println(resultCode);
|
||||||
_result.error("008", "123","aaa")
|
println(data);
|
||||||
} else
|
if (data != null) {
|
||||||
_result.success(null)
|
println(data.getStringExtra(EXTERNAL_RESULT_DATA_KEY))
|
||||||
|
};
|
||||||
|
println("---------------");
|
||||||
|
if (requestCode == externalApplicationRequestCode && resultCode == Activity.RESULT_OK && data != null) {
|
||||||
|
println(data.getStringExtra(EXTERNAL_RESULT_DATA_KEY));
|
||||||
|
Toast.makeText(this, data.getStringExtra(EXTERNAL_RESULT_DATA_KEY), Toast.LENGTH_LONG).show()
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, "Error while apps connecting", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
// if (resultCode == Activity.RESULT_OK) {
|
||||||
|
// _result.success(data?.getStringExtra("result"))
|
||||||
|
// } else if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
|
// _result.error("008", "123","aaa")
|
||||||
|
// } else
|
||||||
|
// _result.success(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -44,3 +109,5 @@ class MainActivity: FlutterActivity() {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class OperationParameters(val authToken: String, val terminalId: String, val operDay: String, val transNum: String)
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
package kz.com.aman.kassa.bank;
|
||||||
|
|
||||||
|
data class ExternalPackage(val packageName: String, val activityName: String)
|
||||||
|
|
@ -0,0 +1,138 @@
|
||||||
|
package kz.com.aman.kassa.bank;
|
||||||
|
|
||||||
|
object JsonForTests {
|
||||||
|
|
||||||
|
fun getPaymentCardJson(authToken: String): String {
|
||||||
|
return """{
|
||||||
|
"credentials" : {
|
||||||
|
"authorizationToken": "$authToken"
|
||||||
|
},
|
||||||
|
"operationData" : {
|
||||||
|
"instrument": "CARD",
|
||||||
|
"amountData" : {
|
||||||
|
"currencyCode": "398",
|
||||||
|
"amount": "6000",
|
||||||
|
"amountExponent": "2"
|
||||||
|
},
|
||||||
|
"goods" : {
|
||||||
|
"product": [{
|
||||||
|
"name": "Печеньки",
|
||||||
|
"price": "3000",
|
||||||
|
"quantity": "2",
|
||||||
|
"quantityExponent": "0",
|
||||||
|
"taxRate": "TAX_20",
|
||||||
|
"accountingSubject": "PRODUCT"
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}"""
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getPaymentCashJson(authToken: String): String {
|
||||||
|
return """{
|
||||||
|
"credentials" : {
|
||||||
|
"authorizationToken": "$authToken"
|
||||||
|
},
|
||||||
|
"operationData" : {
|
||||||
|
"instrument": "CASH",
|
||||||
|
"amountData" : {
|
||||||
|
"currencyCode": "643",
|
||||||
|
"amount": "6000",
|
||||||
|
"amountExponent": "2"
|
||||||
|
},
|
||||||
|
"goods" : {
|
||||||
|
"product": [{
|
||||||
|
"name": "Печеньки",
|
||||||
|
"price": "3000",
|
||||||
|
"quantity": "2",
|
||||||
|
"quantityExponent": "0",
|
||||||
|
"taxRate": "TAX_20",
|
||||||
|
"accountingSubject": "PRODUCT"
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}"""
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getRefundCardJson(authToken: String, terminalId: String, operDay: String, transNum: String): String {
|
||||||
|
return """{
|
||||||
|
"credentials" :{
|
||||||
|
"authorizationToken": "$authToken"
|
||||||
|
},
|
||||||
|
"operationData" :{
|
||||||
|
"instrument": "CARD",
|
||||||
|
"amountData" : {
|
||||||
|
"currencyCode": "643",
|
||||||
|
"amount": "6000",
|
||||||
|
"amountExponent": "2"
|
||||||
|
},
|
||||||
|
"parentTransaction" : {
|
||||||
|
"terminalId": "$terminalId",
|
||||||
|
"operationDay": "$operDay",
|
||||||
|
"transactionNumber": "$transNum"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}"""
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getRefundCashJson(authToken: String, terminalId: String, operDay: String, transNum: String): String {
|
||||||
|
return """{
|
||||||
|
"credentials" :{
|
||||||
|
"authorizationToken": "$authToken"
|
||||||
|
},
|
||||||
|
"operationData" :{
|
||||||
|
"instrument": "CASH",
|
||||||
|
"amountData" : {
|
||||||
|
"currencyCode": "643",
|
||||||
|
"amount": "6000",
|
||||||
|
"amountExponent": "2"
|
||||||
|
},
|
||||||
|
"parentTransaction" : {
|
||||||
|
"terminalId": "$terminalId",
|
||||||
|
"operationDay": "$operDay",
|
||||||
|
"transactionNumber": "$transNum"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}"""
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getReversalJson(authToken: String, terminalId: String, operDay: String, transNum: String): String {
|
||||||
|
return """{
|
||||||
|
"credentials" : {
|
||||||
|
"authorizationToken": "$authToken"
|
||||||
|
},
|
||||||
|
"operationData" : {
|
||||||
|
"parentTransaction" : {
|
||||||
|
"terminalId": "$terminalId",
|
||||||
|
"operationDay": "$operDay",
|
||||||
|
"transactionNumber": "$transNum"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}"""
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getCloseDayJson(authToken: String): String {
|
||||||
|
return """{
|
||||||
|
"credentials" : {
|
||||||
|
"authorizationToken": "$authToken"
|
||||||
|
}
|
||||||
|
}"""
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getOperationsListJson(authToken: String): String {
|
||||||
|
return """{
|
||||||
|
"credentials" : {
|
||||||
|
"authorizationToken": "$authToken"
|
||||||
|
},
|
||||||
|
"operationData": {
|
||||||
|
"params": {
|
||||||
|
"offset": "0",
|
||||||
|
"limit": "20"
|
||||||
|
},
|
||||||
|
"filter": {
|
||||||
|
"transactionTypes": [PAYMENT, REFUND]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package kz.com.aman.kassa.bank;
|
||||||
|
|
||||||
|
enum class OperationType(val code: String) {
|
||||||
|
PAYMENT("PAYMENT"),
|
||||||
|
REFUND("REFUND"),
|
||||||
|
REVERSAL("REVERSAL"),
|
||||||
|
CLOSE_DAY("CLOSE_DAY"),
|
||||||
|
OPERATIONS_LIST("OPERATIONS_LIST")
|
||||||
|
}
|
||||||
|
|
@ -4,12 +4,17 @@ import 'package:aman_kassa_flutter/core/locator.dart';
|
||||||
import 'package:aman_kassa_flutter/core/models/aman_dao.dart';
|
import 'package:aman_kassa_flutter/core/models/aman_dao.dart';
|
||||||
import 'package:aman_kassa_flutter/core/models/close_day_data.dart';
|
import 'package:aman_kassa_flutter/core/models/close_day_data.dart';
|
||||||
import 'package:aman_kassa_flutter/core/models/halyk_post_session.dart';
|
import 'package:aman_kassa_flutter/core/models/halyk_post_session.dart';
|
||||||
import 'package:aman_kassa_flutter/core/models/response.dart';
|
|
||||||
import 'package:aman_kassa_flutter/core/models/transaction_item.dart';
|
import 'package:aman_kassa_flutter/core/models/transaction_item.dart';
|
||||||
import 'package:aman_kassa_flutter/core/services/ApiService.dart';
|
import 'package:aman_kassa_flutter/core/services/ApiService.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:intent/action.dart';
|
||||||
|
import 'package:intent/extra.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
|
import 'package:intent/intent.dart';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BankService extends BaseService {
|
class BankService extends BaseService {
|
||||||
final ApiService _api = locator<ApiService>();
|
final ApiService _api = locator<ApiService>();
|
||||||
static const String _url = 'http://195.200.74.83:5000';
|
static const String _url = 'http://195.200.74.83:5000';
|
||||||
|
|
@ -40,10 +45,34 @@ class BankService extends BaseService {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Future<bool> init() async {
|
Future<bool> init({String token}) async {
|
||||||
|
|
||||||
|
//Intent intent = new Intent ();
|
||||||
|
// intent.setComponent (new ComponentName ("ru.m4bank.softpos", "ru.m4bank.feature.externalapplication.ExternalApplicationActivity"));
|
||||||
|
// intent.setFlags (Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
|
// intent.putExtra (OPERATION_TYPE_KEY, operationType);
|
||||||
|
// operationType - see the section "List of supported operations" intent.putExtra (INPUT_DATA_KEY, inputJsonData);
|
||||||
|
// inputJsonData - json string containing input data for the operation startActivityForResult (intent, INTENT_REQUEST_CODE);
|
||||||
|
// INTENT_REQUEST_CODE - the value specified by the user API is used to filter the received result in onActivityResult
|
||||||
|
// List<String> result;
|
||||||
|
// try {
|
||||||
|
// Intent intent = Intent()
|
||||||
|
// ..setAction(Action.ACTION_ALL_APPS)
|
||||||
|
// ..putExtra("ru.m4bank.softpos", "ru.m4bank.feature.externalapplication.ExternalApplicationActivity")
|
||||||
|
// ..putExtra("ru.m4bank.ExternalApplication.OperationTypeKey", "OPERATIONS_LIST");
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// result = await intent.startActivityForResult();
|
||||||
|
// } catch (e, stack) {
|
||||||
|
// log.e("BankService", e, stack);
|
||||||
|
// }
|
||||||
|
// log.i(result);
|
||||||
|
//
|
||||||
|
// return true;
|
||||||
try {
|
try {
|
||||||
String response = await _channel.invokeMethod('init', <String, dynamic>{
|
String response = await _channel.invokeMethod('init', <String, dynamic>{
|
||||||
'serverUrl': _url,
|
'serverUrl': _url,
|
||||||
|
'token': token
|
||||||
});
|
});
|
||||||
AmanDao dao = AmanDao.fromJson(json.decode(response));
|
AmanDao dao = AmanDao.fromJson(json.decode(response));
|
||||||
log.i('${dao.success} - ${dao.msg}');
|
log.i('${dao.success} - ${dao.msg}');
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,17 @@ class _PaymentNfcViewState extends State<PaymentNfcView> {
|
||||||
//права доступа
|
//права доступа
|
||||||
HalykPosSession session = await _bankService.renewToken(token: token, login: bankState.login, password: bankState.password);
|
HalykPosSession session = await _bankService.renewToken(token: token, login: bankState.login, password: bankState.password);
|
||||||
log.i(session);
|
log.i(session);
|
||||||
if ('1' == '1') {
|
if (session.token ==null) {
|
||||||
|
setState(() {
|
||||||
|
status = 4;
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Инициализация
|
||||||
|
bool initialized = await _bankService.init(token: session.token);
|
||||||
|
log.i(initialized);
|
||||||
|
if (1 == 1) {
|
||||||
setState(() {
|
setState(() {
|
||||||
status = 4;
|
status = 4;
|
||||||
});
|
});
|
||||||
|
|
@ -87,14 +97,14 @@ class _PaymentNfcViewState extends State<PaymentNfcView> {
|
||||||
|
|
||||||
|
|
||||||
//права доступа
|
//права доступа
|
||||||
bool success = await _bankService.permissions();
|
// bool success = await _bankService.permissions();
|
||||||
log.i(success);
|
// log.i(success);
|
||||||
if (!success) {
|
// if (!success) {
|
||||||
setState(() {
|
// setState(() {
|
||||||
status = 4;
|
// status = 4;
|
||||||
});
|
// });
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
var today = new DateTime.now();
|
var today = new DateTime.now();
|
||||||
|
|
@ -108,15 +118,15 @@ class _PaymentNfcViewState extends State<PaymentNfcView> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Инициализация
|
// //Инициализация
|
||||||
bool initialized = await _bankService.init();
|
// bool initialized = await _bankService.init();
|
||||||
log.i(initialized);
|
// log.i(initialized);
|
||||||
if (!initialized) {
|
// if (!initialized) {
|
||||||
setState(() {
|
// setState(() {
|
||||||
status = 4;
|
// status = 4;
|
||||||
});
|
// });
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue