Commit 22fec12f authored by Jasa Digital's avatar Jasa Digital

mq secure added

parent 94c58a71
...@@ -69,7 +69,7 @@ class Api { ...@@ -69,7 +69,7 @@ class Api {
List<String> listTypeUrl = getListTypeUrl(); List<String> listTypeUrl = getListTypeUrl();
int indexTypeUrl = listTypeUrl.indexWhere( int indexTypeUrl = listTypeUrl.indexWhere(
(element) => jsonDecode(element)['url_type'] == urlType, (element) => jsonDecode(element)['url_type'] == urlType && jsonDecode(element)['url_type'] != typeUrlSatu,
); );
if (indexTypeUrl != -1) { if (indexTypeUrl != -1) {
...@@ -835,6 +835,8 @@ class Api { ...@@ -835,6 +835,8 @@ class Api {
if (jsonObject != false) { if (jsonObject != false) {
if (jsonObject['status'].toString().toLowerCase() == 'ok' && if (jsonObject['status'].toString().toLowerCase() == 'ok' &&
jsonObject['msg'] == 'Bill ditemukan') { jsonObject['msg'] == 'Bill ditemukan') {
List<Bill> bill = []; List<Bill> bill = [];
List<PaymentList> paymentList = []; List<PaymentList> paymentList = [];
// List<MemberInfo> memberInfo = []; // List<MemberInfo> memberInfo = [];
...@@ -939,6 +941,7 @@ class Api { ...@@ -939,6 +941,7 @@ class Api {
} }
} }
} }
Api.changePayment();
return bill; return bill;
} else { } else {
return []; return [];
...@@ -1163,7 +1166,6 @@ class Api { ...@@ -1163,7 +1166,6 @@ class Api {
String sessionId = getSessionId(); String sessionId = getSessionId();
String signString = signApi(); String signString = signApi();
int sessionC = getSessionCounter(); int sessionC = getSessionCounter();
try { try {
Map data = { Map data = {
"session_id": sessionId, "session_id": sessionId,
...@@ -1340,6 +1342,8 @@ class Api { ...@@ -1340,6 +1342,8 @@ class Api {
"from": fromByod, "from": fromByod,
"type_order": typeOrder, "type_order": typeOrder,
"type_url": getUrlType(), "type_url": getUrlType(),
"customer_lat": getLatitude(),
"customer_long": getLongitude(),
}; };
var bodies = jsonEncode(data); var bodies = jsonEncode(data);
// var apiResult = await http.post(Uri.parse(urlCheckout), body: bodies); // var apiResult = await http.post(Uri.parse(urlCheckout), body: bodies);
...@@ -2279,4 +2283,55 @@ class Api { ...@@ -2279,4 +2283,55 @@ class Api {
return false; return false;
} }
} }
static Future<bool> changePayment() async {
String baseUrl = prefs.getString('baseUrl') ?? '';
String apiUrl;
apiUrl = "$baseUrl${endPoint}check_payment";
String branchCode = getBranchPref();
String brandCode = getBrand();
String role = getRole();
String cashierName = getCashierName();
String orderID = getOrderId();
String sessionId = getSessionId();
String signString = signApi();
int sessionC = getSessionCounter();
try {
Map data = {
"session_id": sessionId,
"count": sessionC,
"sign": signString,
"branch_code": branchCode,
"brand_code": brandCode,
"role": role,
"cashier_name": cashierName,
"from": fromByod,
"order_id": orderID,
"customer_name": getCustomerName(),
};
var bodies = jsonEncode(data);
var jsonObject = await httpPost(apiUrl, bodies, 'changePayment');
if (jsonObject != false) {
if (jsonObject['status'].toString().toLowerCase() == 'ok') {
return true;
} else {
EasyLoading.showToast(jsonObject['msg']);
return false;
}
} else {
EasyLoading.showToast('Something went wrong');
return false;
}
} catch (e) {
if (debug) {
logd('API CLASS ON API.DART, FUNGSI: changePayment, URL : $apiUrl',
'ERROR CONNECT TO SERVER, ERROR CATCH : $e');
}
EasyLoading.showToast('Cant connect to server');
return false;
}
}
} }
...@@ -373,6 +373,8 @@ String textButtonCheckout(int orderState) { ...@@ -373,6 +373,8 @@ String textButtonCheckout(int orderState) {
return 'Bayar'; return 'Bayar';
} else if (orderState == orderStateCanceled) { } else if (orderState == orderStateCanceled) {
return 'Transaksi Dibatalkan'; return 'Transaksi Dibatalkan';
} else if (orderState == orderStateDone) {
return 'Buat Pesanan Baru';
} else { } else {
return 'Bayar'; return 'Bayar';
} }
......
...@@ -75,25 +75,25 @@ Future<int> runMqTT(BuildContext context) async { ...@@ -75,25 +75,25 @@ Future<int> runMqTT(BuildContext context) async {
/// The client has a change notifier object(see the Observable class) which we then listen to to get /// The client has a change notifier object(see the Observable class) which we then listen to to get
/// notifications of published updates to each subscribed topic. /// notifications of published updates to each subscribed topic.
mqClient.updates!.listen((List<MqttReceivedMessage<MqttMessage?>>? c) { // mqClient.updates!.listen((List<MqttReceivedMessage<MqttMessage?>>? c) {
final recMess = c![0].payload as MqttPublishMessage; // final recMess = c![0].payload as MqttPublishMessage;
final pt = // final pt =
MqttPublishPayload.bytesToStringAsString(recMess.payload.message); // MqttPublishPayload.bytesToStringAsString(recMess.payload.message);
// print('Notifikasi masuk dari topic <${c[0].topic}>, isinya adalah: $pt '); // // print('Notifikasi masuk dari topic <${c[0].topic}>, isinya adalah: $pt ');
// print(''); // // print('');
if (c[0].topic == topic && pt == mqMessage) { // if (c[0].topic == topic && pt == mqMessage) {
// update bill disini // // update bill disini
context.read<ViewBillBloc>().getBill(); // context.read<ViewBillBloc>().getBill();
if (debug) { // if (debug) {
logd('CHECK TOPIC', 'TOPIC MASUK::$topic , MESSAGE::$mqMessage'); // logd('CHECK TOPIC', 'TOPIC MASUK::$topic , MESSAGE::$mqMessage');
} // }
} else { // } else {
if (debug) { // if (debug) {
logd('CHECK TOPIC', // logd('CHECK TOPIC',
'TOPIC TIDAK SAMA, YANG MASUK::$topic , MESSAGE::$pt'); // 'TOPIC TIDAK SAMA, YANG MASUK::$topic , MESSAGE::$pt');
} // }
} // }
}); // });
// final builder = MqttClientPayloadBuilder(); // final builder = MqttClientPayloadBuilder();
// builder.addString('Hello from mqtt_client'); // builder.addString('Hello from mqtt_client');
// mqClient.publishMessage(topic, MqttQos.exactlyOnce, builder.payload!); // mqClient.publishMessage(topic, MqttQos.exactlyOnce, builder.payload!);
......
...@@ -17,7 +17,6 @@ import 'package:flutter_easyloading/flutter_easyloading.dart'; ...@@ -17,7 +17,6 @@ import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_strategy/url_strategy.dart'; import 'package:url_strategy/url_strategy.dart';
import 'package:web_browser_detect/web_browser_detect.dart'; import 'package:web_browser_detect/web_browser_detect.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'bloc/branch_exist.dart'; import 'bloc/branch_exist.dart';
import 'bloc/branch_list.dart'; import 'bloc/branch_list.dart';
...@@ -37,7 +36,6 @@ import 'bloc/view_bill.dart'; ...@@ -37,7 +36,6 @@ import 'bloc/view_bill.dart';
import 'package:flutter/services.dart' as bundle_root; import 'package:flutter/services.dart' as bundle_root;
import 'bloc/voucher_list.dart'; import 'bloc/voucher_list.dart';
import 'ui/webview/webview.dart';
late SharedPreferences prefs; late SharedPreferences prefs;
bool isExcelso = false; bool isExcelso = false;
......
...@@ -18,6 +18,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; ...@@ -18,6 +18,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:geolocator/geolocator.dart'; import 'package:geolocator/geolocator.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:mqtt_client/mqtt_client.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
import '../../api/api.dart'; import '../../api/api.dart';
...@@ -27,10 +28,13 @@ import '../../bloc/feedback_option.dart'; ...@@ -27,10 +28,13 @@ import '../../bloc/feedback_option.dart';
import '../../bloc/outlet_detail.dart'; import '../../bloc/outlet_detail.dart';
import '../../bloc/view_bill.dart'; import '../../bloc/view_bill.dart';
import '../../bloc/voucher_list.dart'; import '../../bloc/voucher_list.dart';
import '../../helper/logger.dart';
import '../../helper/mq.dart';
import '../../helper/widget/button_dialog.dart'; import '../../helper/widget/button_dialog.dart';
import '../../helper/widget/emoticon_rate_new.dart'; import '../../helper/widget/emoticon_rate_new.dart';
import '../../helper/widget/open_url.dart'; import '../../helper/widget/open_url.dart';
import '../../helper/widget/thousand_formatter.dart'; import '../../helper/widget/thousand_formatter.dart';
import '../../main.dart';
import '../../models/bill.dart'; import '../../models/bill.dart';
import '../../models/member_info.dart'; import '../../models/member_info.dart';
import '../build_version.dart'; import '../build_version.dart';
...@@ -44,7 +48,7 @@ import 'list_order.dart'; ...@@ -44,7 +48,7 @@ import 'list_order.dart';
import 'rincian_pembayaran.dart'; import 'rincian_pembayaran.dart';
import 'shimmer_bill.dart'; import 'shimmer_bill.dart';
class ViewBillNew extends StatelessWidget { class ViewBillNew extends StatefulWidget {
// const ViewBillNew({Key? key}) : super(key: key); // const ViewBillNew({Key? key}) : super(key: key);
final bool isHistory; final bool isHistory;
...@@ -67,8 +71,14 @@ class ViewBillNew extends StatelessWidget { ...@@ -67,8 +71,14 @@ class ViewBillNew extends StatelessWidget {
this.isRepeatViewBill = false, this.isRepeatViewBill = false,
}) : super(key: key); }) : super(key: key);
@override
State<ViewBillNew> createState() => _ViewBillNewState();
}
class _ViewBillNewState extends State<ViewBillNew> {
// final RefreshController _refreshController = // final RefreshController _refreshController =
// RefreshController(initialRefresh: false);
Future<void> getBillTwice(BuildContext context) async { Future<void> getBillTwice(BuildContext context) async {
context.read<ViewBillBloc>().getBill(); context.read<ViewBillBloc>().getBill();
} }
...@@ -83,11 +93,11 @@ class ViewBillNew extends StatelessWidget { ...@@ -83,11 +93,11 @@ class ViewBillNew extends StatelessWidget {
} }
void getBillFunc(BuildContext context) { void getBillFunc(BuildContext context) {
if (!isHistory) { if (!widget.isHistory) {
getBillTwice(context).then((_) { getBillTwice(context).then((_) {
if (getTypeOrder() == typeOrderDelivery) { if (getTypeOrder() == typeOrderDelivery) {
getAddressTwice(context).then((_) { getAddressTwice(context).then((_) {
if (isRepeatViewBill) { if (widget.isRepeatViewBill) {
Future.delayed(const Duration(milliseconds: 2000), () async { Future.delayed(const Duration(milliseconds: 2000), () async {
getBillTwice(context); getBillTwice(context);
}); });
...@@ -97,18 +107,45 @@ class ViewBillNew extends StatelessWidget { ...@@ -97,18 +107,45 @@ class ViewBillNew extends StatelessWidget {
}); });
} else { } else {
context.read<ViewBillBloc>().getBill( context.read<ViewBillBloc>().getBill(
orderIdH: orderId, orderIdH: widget.orderId,
branchCodeH: branchCodeH, branchCodeH: widget.branchCodeH,
brandCodeH: brandCodeH, brandCodeH: widget.brandCodeH,
tableNumberH: tableNumberH, tableNumberH: widget.tableNumberH,
tokenH: token, tokenH: widget.token,
userNameH: userName, userNameH: widget.userName,
); );
} }
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
String topic = 'romi/byod/payment';
if (mqClient.updates != null) {
mqClient.updates!.listen((List<MqttReceivedMessage<MqttMessage?>>? c) {
final recMess = c![0].payload as MqttPublishMessage;
final pt =
MqttPublishPayload.bytesToStringAsString(recMess.payload.message);
// print('Notifikasi masuk dari topic <${c[0].topic}>, isinya adalah: $pt ');
// print('');
if (c[0].topic ==topic && pt == mqMessage) {
// update bill disini
setState(() {
});
if (debug) {
logd('CHECK TOPIC', 'TOPIC MASUK::$topic , MESSAGE::$mqMessage');
}
} else {
if (debug) {
logd('CHECK TOPIC',
'TOPIC TIDAK SAMA, YANG MASUK::$topic , MESSAGE::$pt');
}
}
});
}
context.read<FeedBackOptionBloc>().getOptionFeedback(); context.read<FeedBackOptionBloc>().getOptionFeedback();
context.read<ViewBillBloc>().backToDefault(); context.read<ViewBillBloc>().backToDefault();
getBillFunc(context); getBillFunc(context);
...@@ -181,7 +218,7 @@ class ViewBillNew extends StatelessWidget { ...@@ -181,7 +218,7 @@ class ViewBillNew extends StatelessWidget {
), ),
"branch_code": branchCode, "branch_code": branchCode,
"brand": brandCode, "brand": brandCode,
"token": token, "token": widget.token,
}; };
String historySave = jsonEncode(historyOrder); String historySave = jsonEncode(historyOrder);
listHistoryOrder.add(historySave); listHistoryOrder.add(historySave);
...@@ -199,7 +236,7 @@ class ViewBillNew extends StatelessWidget { ...@@ -199,7 +236,7 @@ class ViewBillNew extends StatelessWidget {
), ),
"branch_code": branchCode, "branch_code": branchCode,
"brand": brandCode, "brand": brandCode,
"token": token, "token": widget.token,
}; };
String historySave = jsonEncode(historyOrder); String historySave = jsonEncode(historyOrder);
listHistoryOrder.add(historySave); listHistoryOrder.add(historySave);
...@@ -291,7 +328,7 @@ class ViewBillNew extends StatelessWidget { ...@@ -291,7 +328,7 @@ class ViewBillNew extends StatelessWidget {
ratingModal( ratingModal(
context, context,
dataBill, dataBill,
isHistory, widget.isHistory,
orderId: orderId, orderId: orderId,
); );
} }
...@@ -346,7 +383,7 @@ Mohon menuju kasir untuk meminta bukti pembayaran'''; ...@@ -346,7 +383,7 @@ Mohon menuju kasir untuk meminta bukti pembayaran''';
dataBill: dataBill, dataBill: dataBill,
outStandingAll: outStandingAll, outStandingAll: outStandingAll,
totalDiscount: totalDiscount, totalDiscount: totalDiscount,
isHistory: isHistory, isHistory: widget.isHistory,
customerName: customerName, customerName: customerName,
outStandingIndividu: outStandingIndividu, outStandingIndividu: outStandingIndividu,
paymentMode: paymentMode, paymentMode: paymentMode,
...@@ -369,7 +406,7 @@ Mohon menuju kasir untuk meminta bukti pembayaran'''; ...@@ -369,7 +406,7 @@ Mohon menuju kasir untuk meminta bukti pembayaran''';
branchCode: branchCode, branchCode: branchCode,
brandCode: brandCode, brandCode: brandCode,
customerName: customerName, customerName: customerName,
isHistory: isHistory, isHistory: widget.isHistory,
historyOrder: historyOrder, historyOrder: historyOrder,
), ),
widthScreen: currentScreen, widthScreen: currentScreen,
...@@ -382,26 +419,6 @@ Mohon menuju kasir untuk meminta bukti pembayaran'''; ...@@ -382,26 +419,6 @@ Mohon menuju kasir untuk meminta bukti pembayaran''';
), ),
); );
} }
// Future<dynamic> ratingModal(
// BuildContext context, List<Bill> dataBill, bool isHistory,
// {String sessionID = ''}) {
// return showDialog(
// context: context,
// builder: (BuildContext context) => AlertDialog(
// title: defaultText(
// context,
// 'Bagaimana pengalaman anda bertransaksi di excelso ?',
// style: textStyleNormalFont(context),
// ),
// content: EmoticonRate(
// bill: dataBill[0],
// isHistory: isHistory,
// sessionId: sessionID,
// ),
// ),
// );
// }
} }
class CoreBill extends StatelessWidget { class CoreBill extends StatelessWidget {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment