From 5a1f086d78eba5045c0adc757400005731d300bc Mon Sep 17 00:00:00 2001 From: suvaissov Date: Wed, 26 May 2021 15:47:24 +0600 Subject: [PATCH] bug fixes on halyk payment --- .../kotlin/kz/com/aman/kassa/MainActivity.kt | 4 ++-- lib/core/models/halyk/halyk_response_dao.dart | 22 +++++++++++++++++++ lib/core/services/BankService.dart | 2 ++ lib/test/foo.dart | 4 ++++ lib/views/home/components/popup_menu.dart | 2 +- lib/views/home/tabs/AdditionalTab.dart | 2 +- lib/views/payment/halyk_pos_service.dart | 4 ++-- lib/views/payment/payment_view.dart | 20 ++++++++++++----- 8 files changed, 49 insertions(+), 11 deletions(-) diff --git a/android/app/src/main/kotlin/kz/com/aman/kassa/MainActivity.kt b/android/app/src/main/kotlin/kz/com/aman/kassa/MainActivity.kt index 0faae5b..c94650b 100644 --- a/android/app/src/main/kotlin/kz/com/aman/kassa/MainActivity.kt +++ b/android/app/src/main/kotlin/kz/com/aman/kassa/MainActivity.kt @@ -125,11 +125,11 @@ class MainActivity : FlutterActivity() { println("---------------") if (requestCode == externalApplicationRequestCode && resultCode == Activity.RESULT_OK && data != null) { println(data.getStringExtra(externalResultDataKey)) - Toast.makeText(this, data.getStringExtra(externalResultDataKey), Toast.LENGTH_LONG).show() + //Toast.makeText(this, data.getStringExtra(externalResultDataKey), Toast.LENGTH_LONG).show() _result.success(data.getStringExtra(externalResultDataKey)) } else { _result.error("008", "Error while apps connecting", "aaa") - Toast.makeText(this, "Error while apps connecting", Toast.LENGTH_SHORT).show() + //Toast.makeText(this, "Error while apps connecting", Toast.LENGTH_SHORT).show() } // if (resultCode == Activity.RESULT_OK) { // _result.success(data?.getStringExtra("result")) diff --git a/lib/core/models/halyk/halyk_response_dao.dart b/lib/core/models/halyk/halyk_response_dao.dart index c99c421..0a6c273 100644 --- a/lib/core/models/halyk/halyk_response_dao.dart +++ b/lib/core/models/halyk/halyk_response_dao.dart @@ -90,6 +90,7 @@ class ResultBean { int code; String description; HostResponseBean hostResponse; + ErrorResponseBean errorData; ResultBean({this.code, this.description}); @@ -99,6 +100,7 @@ class ResultBean { resultBean.code = map['code']; resultBean.description = map['description']; resultBean.hostResponse = HostResponseBean.fromMap(map['hostResponse']); + resultBean.errorData = ErrorResponseBean.fromMap(map['errorData']); return resultBean; } @@ -107,6 +109,7 @@ class ResultBean { "code": code, "description": description, "hostResponse": hostResponse, + "errorData": errorData, }; } @@ -125,6 +128,25 @@ class HostResponseBean { return hostResponseBean; } + Map toJson() => + { + "code": code, + "description": description, + }; +} + +class ErrorResponseBean { + int code; + String description; + + static ErrorResponseBean fromMap(Map map) { + if (map == null) return null; + ErrorResponseBean errorResponseBean = ErrorResponseBean(); + errorResponseBean.code = map['code']; + errorResponseBean.description = map['description']; + return errorResponseBean; + } + Map toJson() => { "code": code, diff --git a/lib/core/services/BankService.dart b/lib/core/services/BankService.dart index aa14fce..e642c8f 100644 --- a/lib/core/services/BankService.dart +++ b/lib/core/services/BankService.dart @@ -14,6 +14,7 @@ import '../models/aman_dao.dart'; class BankService extends BaseService { + int sdkVersion = 27; final ApiService _api = locator(); final MethodChannel _channel = MethodChannel('channel:com.amanKassa/bank'); @@ -60,6 +61,7 @@ class BankService extends BaseService { double total = amount * 100; log.i('total: $total, ${total.toInt()}'); String response = await _channel.invokeMethod("pay", {'amount': total.toInt(), 'token': token }); + log.i(response); HalykResponse dao = HalykResponse.fromMap(json.decode(response)); return dao; } catch (e, stack) { diff --git a/lib/test/foo.dart b/lib/test/foo.dart index 0a1b901..af26e58 100644 --- a/lib/test/foo.dart +++ b/lib/test/foo.dart @@ -15,4 +15,8 @@ void main() { String salt = '!=uF:w1N_Salh?1gVSJ#eGfJYHA(wS4D'; String hash = md5.convert(utf8.encode('uvaissov@gmail.com$salt')).toString(); print(hash); + + + String value = "100.0"; + print(double.parse(value)); } \ No newline at end of file diff --git a/lib/views/home/components/popup_menu.dart b/lib/views/home/components/popup_menu.dart index 7c6195c..c55bc13 100644 --- a/lib/views/home/components/popup_menu.dart +++ b/lib/views/home/components/popup_menu.dart @@ -32,7 +32,7 @@ class _PopupMenuState extends State { const Choice(title: 'Информация о ККМ', icon: Icons.info_outline, command: 'infokkm'), //if (version >= 24 ) // const Choice(title: 'Bank', icon: Icons.text_fields, command: 'bank'), - if (version >= 27 ) + if (version >= _bankService.sdkVersion ) const Choice(title: 'Настройка HalykPos', icon: Icons.phonelink_lock_outlined, command: 'tap2phone'), const Choice(title: 'Настройки', icon: Icons.settings, command: 'settings'), const Choice(title: 'Принтер', icon: Icons.print, command: 'print'), diff --git a/lib/views/home/tabs/AdditionalTab.dart b/lib/views/home/tabs/AdditionalTab.dart index 8c7b9c3..8b7e55c 100644 --- a/lib/views/home/tabs/AdditionalTab.dart +++ b/lib/views/home/tabs/AdditionalTab.dart @@ -227,7 +227,7 @@ class _AdditionalTabState extends State { }); int version = await _bankService.version(); - if (version < 27 ) { + if (version < _bankService.sdkVersion ) { setState(() { isClosePosBusy = false; }); diff --git a/lib/views/payment/halyk_pos_service.dart b/lib/views/payment/halyk_pos_service.dart index b70d904..6437acd 100644 --- a/lib/views/payment/halyk_pos_service.dart +++ b/lib/views/payment/halyk_pos_service.dart @@ -44,7 +44,7 @@ Future> paymentHalykPos(double total) async { ); return AmanDao(msg: response.result.description, success: true, data: cardData); } - return AmanDao(msg: response.result.description, success: false); + return AmanDao(msg: response.result.errorData !=null ? response.result.errorData.description : response.result.description, success: false); } Future> refundHalykPos(CardData refundData, double total) async { @@ -70,7 +70,7 @@ Future> refundHalykPos(CardData refundData, double total) asyn ); return AmanDao(msg: response.result.description, success: true, data: cardData); } - return AmanDao(msg: response.result.description, success: false); + return AmanDao(msg: response.result.errorData !=null ? response.result.errorData.description : response.result.description, success: false); } Future closeDayHalykPos() async { diff --git a/lib/views/payment/payment_view.dart b/lib/views/payment/payment_view.dart index 228d3c8..59be566 100644 --- a/lib/views/payment/payment_view.dart +++ b/lib/views/payment/payment_view.dart @@ -64,7 +64,7 @@ class _PaymentViewState extends State { _bankInit() async { int version = await _bankService.version(); - if (version >= 27) { + if (version >= _bankService.sdkVersion) { setState(() { isBankApiAccess = true; }); @@ -198,15 +198,25 @@ class _PaymentViewState extends State { if (!isBankApiAccess || widget.model.operationType != OperationTypePay) { return Container(); } - return StoreConnector( - converter: (store) => store.state.bankState, - builder: (_, state) { + return StoreConnector( + converter: (store) => store.state, + builder: (_, _state) { + BankState state = _state.bankState; + double _total; + if (widget.model.mode == SettingModeCalc) { + String value = totalCalc(_state.calcState.calcItems); + _total = double.parse(value); + } else { + String value = totalKassa(_state.kassaState.kassaItems); + _total = double.parse(value); + } + if (state.password == null || state.login == null || state.password.length < 1 || state.login.length < 1) { return Container(); } return InkWell( onTap: () async { - AmanDao data = await paymentHalykPos(100); + AmanDao data = await paymentHalykPos(_total); if (data.success) { pressPayment(widget.model.operationType, data.data); } else {