refreshOrderPending method
dynamic
refreshOrderPending(
- BuildContext context, {
- required String entityId,
- required String couponTransactionId,
- required Function onStatusChange,
Implementation
refreshOrderPending(
BuildContext context, {
required String entityId,
required String couponTransactionId,
required Function onStatusChange,
}) async {
Helper.progressDialog(context, "Please wait..");
String requestTime = DateTime.now().toString();
try {
dio
.put(
'${ApiConstant.posBFF}mbaas-core-services-svc/coupons/action/refresh',
data: json.encode(
{
"entityId": entityId,
"couponTransactionId": couponTransactionId,
},
),
options: Options(
headers: {
'X-User-Id': SecureStorageService.readSecureData(
SecureStorageService.xUserId,
),
'X-User-Name': SecureStorageService.readSecureData(
SecureStorageService.xUserName,
),
'Accept-Language': storage.read("selected_language") ?? "en",
'x-request-txn-id': UDID.uDID,
'x-trace-id': UDID.uDIDTraceId,
"Authorization": "Bearer ${SecureStorageService.readSecureData(
SecureStorageService.accessToken,
)}",
},
),
)
.then((response) {
UDID.setTraceId(
response.headers.map[Constants.traceIdKey]?[0] ?? "",
);
Helper.logEvent(
"RESPONSE_EVENT",
success: true,
endPoint: "mbaas-core-services-svc/coupons/action/refresh",
responseDate: DateTime.now().toString(),
screenName: "couponHistory",
buttonName: "orderPendingRefreshButton",
requestDate: requestTime,
);
Helper.close();
if (response.data != null &&
response.data.toString().trim().isNotEmpty) {
final refreshResponse = PendingOrderRefreshResponse.fromJson(
response.data is Map ? response.data : json.decode(response.data),
);
// Check the status
if (refreshResponse.status?.trim().toUpperCase() == 'POS200' &&
refreshResponse.data?.isStatusChanged == true) {
onStatusChange();
} else {
final hasError = refreshResponse.errors?.isNotEmpty == true;
final error = hasError ? refreshResponse.errors![0] : null;
Helper.popUpDialog(
isPayment: true,
headingText:
error?.code ?? localization.translate("oopsPaymentFailed"),
subHeading: error?.localeMessage ??
localization.translate("oopsPaymentFailedSubMsg"),
onButtonTap: Helper.close,
buttonText: localization.translate("close"),
);
}
}
}).catchError((error) {
ConditionalLogs().customLog("$error");
Helper.close();
if (error is DioException) {
UDID.setTraceId(
error.response?.headers.map[Constants.traceIdKey]
?.elementAtOrNull(0) ??
"",
);
Helper.logEvent(
"ERROR_EVENT",
failure: true,
requestDate: requestTime,
endPoint: "mbaas-core-services-svc/coupons/action/refresh",
responseDate: DateTime.now().toString(),
screenName: "couponHistory",
buttonName: "orderPendingRefreshButton",
error: error,
);
}
MainController mainController = Get.put(MainController());
mainController.showErrorPopup();
});
} catch (err, stacktrace) {
ConditionalLogs().customLog("$stacktrace");
Helper.close();
if (err is DioException) {
UDID.setTraceId(
err.response?.headers.map[Constants.traceIdKey]?.elementAtOrNull(0) ??
"",
);
Helper.logEvent(
"ERROR_EVENT",
failure: true,
requestDate: requestTime,
endPoint: "mbaas-core-services-svc/coupons/action/refresh",
responseDate: DateTime.now().toString(),
screenName: "couponHistory",
buttonName: "orderPendingRefreshButton",
error: err,
);
}
}
}