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

mq secure added

parent 94c58a71
......@@ -69,7 +69,7 @@ class Api {
List<String> listTypeUrl = getListTypeUrl();
int indexTypeUrl = listTypeUrl.indexWhere(
(element) => jsonDecode(element)['url_type'] == urlType,
(element) => jsonDecode(element)['url_type'] == urlType && jsonDecode(element)['url_type'] != typeUrlSatu,
);
if (indexTypeUrl != -1) {
......@@ -835,6 +835,8 @@ class Api {
if (jsonObject != false) {
if (jsonObject['status'].toString().toLowerCase() == 'ok' &&
jsonObject['msg'] == 'Bill ditemukan') {
List<Bill> bill = [];
List<PaymentList> paymentList = [];
// List<MemberInfo> memberInfo = [];
......@@ -939,6 +941,7 @@ class Api {
}
}
}
Api.changePayment();
return bill;
} else {
return [];
......@@ -1163,7 +1166,6 @@ class Api {
String sessionId = getSessionId();
String signString = signApi();
int sessionC = getSessionCounter();
try {
Map data = {
"session_id": sessionId,
......@@ -1340,6 +1342,8 @@ class Api {
"from": fromByod,
"type_order": typeOrder,
"type_url": getUrlType(),
"customer_lat": getLatitude(),
"customer_long": getLongitude(),
};
var bodies = jsonEncode(data);
// var apiResult = await http.post(Uri.parse(urlCheckout), body: bodies);
......@@ -2279,4 +2283,55 @@ class Api {
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) {
return 'Bayar';
} else if (orderState == orderStateCanceled) {
return 'Transaksi Dibatalkan';
} else if (orderState == orderStateDone) {
return 'Buat Pesanan Baru';
} else {
return 'Bayar';
}
......
......@@ -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
/// notifications of published updates to each subscribed topic.
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
context.read<ViewBillBloc>().getBill();
if (debug) {
logd('CHECK TOPIC', 'TOPIC MASUK::$topic , MESSAGE::$mqMessage');
}
} else {
if (debug) {
logd('CHECK TOPIC',
'TOPIC TIDAK SAMA, YANG MASUK::$topic , MESSAGE::$pt');
}
}
});
// 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
// context.read<ViewBillBloc>().getBill();
// if (debug) {
// logd('CHECK TOPIC', 'TOPIC MASUK::$topic , MESSAGE::$mqMessage');
// }
// } else {
// if (debug) {
// logd('CHECK TOPIC',
// 'TOPIC TIDAK SAMA, YANG MASUK::$topic , MESSAGE::$pt');
// }
// }
// });
// final builder = MqttClientPayloadBuilder();
// builder.addString('Hello from mqtt_client');
// mqClient.publishMessage(topic, MqttQos.exactlyOnce, builder.payload!);
......
......@@ -17,7 +17,6 @@ import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_strategy/url_strategy.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_list.dart';
......@@ -37,7 +36,6 @@ import 'bloc/view_bill.dart';
import 'package:flutter/services.dart' as bundle_root;
import 'bloc/voucher_list.dart';
import 'ui/webview/webview.dart';
late SharedPreferences prefs;
bool isExcelso = false;
......
......@@ -18,6 +18,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:geolocator/geolocator.dart';
import 'package:intl/intl.dart';
import 'package:mqtt_client/mqtt_client.dart';
import 'package:uuid/uuid.dart';
import '../../api/api.dart';
......@@ -27,10 +28,13 @@ import '../../bloc/feedback_option.dart';
import '../../bloc/outlet_detail.dart';
import '../../bloc/view_bill.dart';
import '../../bloc/voucher_list.dart';
import '../../helper/logger.dart';
import '../../helper/mq.dart';
import '../../helper/widget/button_dialog.dart';
import '../../helper/widget/emoticon_rate_new.dart';
import '../../helper/widget/open_url.dart';
import '../../helper/widget/thousand_formatter.dart';
import '../../main.dart';
import '../../models/bill.dart';
import '../../models/member_info.dart';
import '../build_version.dart';
......@@ -44,7 +48,7 @@ import 'list_order.dart';
import 'rincian_pembayaran.dart';
import 'shimmer_bill.dart';
class ViewBillNew extends StatelessWidget {
class ViewBillNew extends StatefulWidget {
// const ViewBillNew({Key? key}) : super(key: key);
final bool isHistory;
......@@ -67,8 +71,14 @@ class ViewBillNew extends StatelessWidget {
this.isRepeatViewBill = false,
}) : super(key: key);
@override
State<ViewBillNew> createState() => _ViewBillNewState();
}
class _ViewBillNewState extends State<ViewBillNew> {
// final RefreshController _refreshController =
// RefreshController(initialRefresh: false);
Future<void> getBillTwice(BuildContext context) async {
context.read<ViewBillBloc>().getBill();
}
......@@ -83,11 +93,11 @@ class ViewBillNew extends StatelessWidget {
}
void getBillFunc(BuildContext context) {
if (!isHistory) {
if (!widget.isHistory) {
getBillTwice(context).then((_) {
if (getTypeOrder() == typeOrderDelivery) {
getAddressTwice(context).then((_) {
if (isRepeatViewBill) {
if (widget.isRepeatViewBill) {
Future.delayed(const Duration(milliseconds: 2000), () async {
getBillTwice(context);
});
......@@ -97,18 +107,45 @@ class ViewBillNew extends StatelessWidget {
});
} else {
context.read<ViewBillBloc>().getBill(
orderIdH: orderId,
branchCodeH: branchCodeH,
brandCodeH: brandCodeH,
tableNumberH: tableNumberH,
tokenH: token,
userNameH: userName,
orderIdH: widget.orderId,
branchCodeH: widget.branchCodeH,
brandCodeH: widget.brandCodeH,
tableNumberH: widget.tableNumberH,
tokenH: widget.token,
userNameH: widget.userName,
);
}
}
@override
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<ViewBillBloc>().backToDefault();
getBillFunc(context);
......@@ -181,7 +218,7 @@ class ViewBillNew extends StatelessWidget {
),
"branch_code": branchCode,
"brand": brandCode,
"token": token,
"token": widget.token,
};
String historySave = jsonEncode(historyOrder);
listHistoryOrder.add(historySave);
......@@ -199,7 +236,7 @@ class ViewBillNew extends StatelessWidget {
),
"branch_code": branchCode,
"brand": brandCode,
"token": token,
"token": widget.token,
};
String historySave = jsonEncode(historyOrder);
listHistoryOrder.add(historySave);
......@@ -291,7 +328,7 @@ class ViewBillNew extends StatelessWidget {
ratingModal(
context,
dataBill,
isHistory,
widget.isHistory,
orderId: orderId,
);
}
......@@ -346,7 +383,7 @@ Mohon menuju kasir untuk meminta bukti pembayaran''';
dataBill: dataBill,
outStandingAll: outStandingAll,
totalDiscount: totalDiscount,
isHistory: isHistory,
isHistory: widget.isHistory,
customerName: customerName,
outStandingIndividu: outStandingIndividu,
paymentMode: paymentMode,
......@@ -369,7 +406,7 @@ Mohon menuju kasir untuk meminta bukti pembayaran''';
branchCode: branchCode,
brandCode: brandCode,
customerName: customerName,
isHistory: isHistory,
isHistory: widget.isHistory,
historyOrder: historyOrder,
),
widthScreen: currentScreen,
......@@ -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 {
......
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