Compare commits
2 Commits
9a7f4a5245
...
e1dacaadcb
| Author | SHA1 | Date | |
|---|---|---|---|
| e1dacaadcb | |||
| 1e1f749148 |
@ -30,6 +30,11 @@
|
||||
|
||||
<!-- Permission for exact alarms on Android 12+ -->
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
||||
|
||||
<!-- Permissions for background auto settlement -->
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
|
||||
<!-- android:noHistory="true"-->
|
||||
<!-- android:excludeFromRecents="true"-->
|
||||
|
||||
@ -455,8 +455,8 @@ public class MainActivity extends AppCompatActivity implements
|
||||
payDetail.setAmount(totalAmount);
|
||||
payDetail.setTradeAnswerCode("000");
|
||||
|
||||
// Note: QR transactions list is not passed to avoid serialization issues
|
||||
// The settlement summary is sufficient for the receipt
|
||||
|
||||
sharedViewModel.setAmount(POSUtil.getInstance().getDecimalAmountSeparatorFormat(totalAmount));
|
||||
sharedViewModel.payDetails.setValue(qrTransList);
|
||||
sharedViewModel.payDetail.setValue(payDetail);
|
||||
sharedViewModel.transactionsType.setValue(com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.MMQR_SETTLEMENT);
|
||||
|
||||
@ -238,7 +238,7 @@ public class MainFragment extends DataBindingFragment {
|
||||
sharedViewModel.setManualEntryStatus(SystemParamsOperation.getInstance().getManualEntryStatus());
|
||||
|
||||
|
||||
generateMockQR();
|
||||
// generateMockQR();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -401,7 +401,7 @@ public class MainFragment extends DataBindingFragment {
|
||||
}
|
||||
|
||||
} else if (PrintHelper.getInstance().paperRollStatus() == 0) {
|
||||
LogUtil.d(TAG,"Printer not found!");
|
||||
LogUtil.d(TAG,"Printer not found! ");
|
||||
// showDeclineDialog(getResourceString(R.string.txt_alert_printer_not_found));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,17 @@
|
||||
package com.utsmm.kbz.service;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.PowerManager;
|
||||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import com.utsmm.kbz.R;
|
||||
import com.utsmyanmar.paylibs.utils.LogUtil;
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation;
|
||||
|
||||
@ -14,18 +20,41 @@ import java.util.Calendar;
|
||||
public class AutoAlarmReceiver extends BroadcastReceiver {
|
||||
|
||||
private static final String TAG = AutoAlarmReceiver.class.getSimpleName();
|
||||
private static final String WAKE_LOCK_TAG = "KBZAutoSettle::AlarmWakeLock";
|
||||
private static final String NOTIFICATION_CHANNEL_ID = "AUTO_SETTLEMENT_ALARM";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
scheduleNextDayAlarm(context);
|
||||
LogUtil.d(TAG, "AutoAlarmReceiver triggered at: " + new java.util.Date().toString());
|
||||
|
||||
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG);
|
||||
wakeLock.acquire(60000);
|
||||
|
||||
try {
|
||||
Intent serviceIntent = new Intent(context, AutoSettleService.class);
|
||||
context.startService(serviceIntent);
|
||||
LogUtil.d(TAG, "AutoSettleService started successfully");
|
||||
} catch (Exception e) {
|
||||
LogUtil.e(TAG, "Failed to start AutoSettleService: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
showAlarmTriggeredNotification(context);
|
||||
|
||||
scheduleNextDayAlarm(context);
|
||||
|
||||
try {
|
||||
Intent serviceIntent = new Intent(context, AutoSettleService.class);
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
context.startForegroundService(serviceIntent);
|
||||
LogUtil.d(TAG, "AutoSettleService started as foreground service");
|
||||
} else {
|
||||
context.startService(serviceIntent);
|
||||
LogUtil.d(TAG, "AutoSettleService started successfully");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.e(TAG, "Failed to start AutoSettleService: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
} finally {
|
||||
// Release wake lock
|
||||
if (wakeLock.isHeld()) {
|
||||
wakeLock.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,7 +107,6 @@ public class AutoAlarmReceiver extends BroadcastReceiver {
|
||||
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
|
||||
);
|
||||
|
||||
// Schedule next day's alarm
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||
if (alarmManager.canScheduleExactAlarms()) {
|
||||
@ -97,4 +125,32 @@ public class AutoAlarmReceiver extends BroadcastReceiver {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void showAlarmTriggeredNotification(Context context) {
|
||||
try {
|
||||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
NotificationChannel channel = new NotificationChannel(
|
||||
NOTIFICATION_CHANNEL_ID,
|
||||
"Auto Settlement Alarms",
|
||||
NotificationManager.IMPORTANCE_HIGH
|
||||
);
|
||||
channel.setDescription("Notifications for auto settlement alarm triggers");
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
|
||||
.setSmallIcon(R.drawable.ic_launcher_foreground)
|
||||
.setContentTitle("Auto Settlement Triggered")
|
||||
.setContentText("Auto settlement alarm triggered at " + new java.util.Date().toString())
|
||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||
.setAutoCancel(true);
|
||||
|
||||
notificationManager.notify(1001, builder.build());
|
||||
|
||||
} catch (Exception e) {
|
||||
LogUtil.e(TAG, "Failed to show alarm notification: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,8 +3,10 @@ package com.utsmm.kbz.service;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.text.TextUtils;
|
||||
@ -14,6 +16,11 @@ import androidx.core.app.NotificationCompat;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.utsmm.kbz.MainActivity;
|
||||
|
||||
import com.utsmm.kbz.util.EReceiptUtil;
|
||||
import com.utsmyanmar.baselib.network.model.e_receipt.EReceiptRequest;
|
||||
import com.utsmyanmar.baselib.repo.Repository;
|
||||
import com.utsmm.kbz.BuildConfig;
|
||||
import com.utsmm.kbz.R;
|
||||
@ -22,10 +29,34 @@ import com.utsmm.kbz.ui.settlement.SettlementViewModel;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
import retrofit2.HttpException;
|
||||
|
||||
import com.utsmyanmar.paylibs.Constant;
|
||||
import com.utsmyanmar.paylibs.isobuilder.ISOMode;
|
||||
import com.utsmyanmar.paylibs.isobuilder.builderx.ISOMsgX;
|
||||
import com.utsmyanmar.paylibs.isobuilder.builderx.ISOVersion;
|
||||
import com.utsmyanmar.paylibs.model.MsgField;
|
||||
import com.utsmyanmar.paylibs.model.PayDetail;
|
||||
import com.utsmyanmar.paylibs.model.SettleData;
|
||||
import com.utsmyanmar.paylibs.model.TradeData;
|
||||
import com.utsmyanmar.paylibs.network.ISOCallback;
|
||||
import com.utsmyanmar.paylibs.network.ISOSocket;
|
||||
import com.utsmyanmar.paylibs.utils.LogUtil;
|
||||
import com.utsmyanmar.paylibs.utils.MessageType;
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation;
|
||||
import com.utsmyanmar.paylibs.utils.enums.HostName;
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.BitmapConfig;
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionType;
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType;
|
||||
import com.utsmyanmar.paylibs.utils.params.Params;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
@AndroidEntryPoint
|
||||
public class AutoSettleService extends Service {
|
||||
@ -49,9 +80,38 @@ public class AutoSettleService extends Service {
|
||||
@Inject
|
||||
Repository repository;
|
||||
|
||||
|
||||
|
||||
public static final String NOTIFICATION_CHANNEL_ID = "10001";
|
||||
private final static String default_notification_channel_id = "default";
|
||||
|
||||
private void startForegroundService() {
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
|
||||
// Create notification channel for Android 8+
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
NotificationChannel channel = new NotificationChannel(
|
||||
NOTIFICATION_CHANNEL_ID,
|
||||
"Auto Settlement Service",
|
||||
NotificationManager.IMPORTANCE_LOW // Use LOW importance for foreground service
|
||||
);
|
||||
channel.setDescription("Auto settlement background service");
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
|
||||
// Create foreground notification
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
|
||||
.setSmallIcon(R.drawable.ic_launcher_foreground)
|
||||
.setContentTitle("Auto Settlement Active")
|
||||
.setContentText("Processing scheduled settlement...")
|
||||
.setPriority(NotificationCompat.PRIORITY_LOW)
|
||||
.setOngoing(true) // Make it non-dismissible
|
||||
.setAutoCancel(false);
|
||||
|
||||
// Start foreground service
|
||||
startForeground(1002, builder.build());
|
||||
}
|
||||
|
||||
private void createNotification() {
|
||||
NotificationManager mNotificationManager = (NotificationManager)getSystemService( NOTIFICATION_SERVICE ) ;
|
||||
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext() , default_notification_channel_id ) ;
|
||||
@ -83,7 +143,14 @@ public class AutoSettleService extends Service {
|
||||
LogUtil.d(TAG, "<<<<<<<<<<<<<<< Auto Settlement Service Started >>>>>>>>>>>>>>>>.");
|
||||
|
||||
try {
|
||||
// Start as foreground service for Android 8+
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
startForegroundService();
|
||||
}
|
||||
|
||||
sendDataToViewModel("Auto settlement initiated");
|
||||
|
||||
// Also create regular notification
|
||||
createNotification();
|
||||
|
||||
if (SystemParamsOperation.getInstance().getSettlementStatus()) {
|
||||
@ -109,20 +176,19 @@ public class AutoSettleService extends Service {
|
||||
}
|
||||
|
||||
final ISOMsgX isoMsgX = new ISOMsgX.ISOMsgXBuilder(
|
||||
com.utsmyanmar.paylibs.isobuilder.builderx.ISOVersion.VERSION_1993,
|
||||
com.utsmyanmar.paylibs.isobuilder.ISOMode.BOTH_HEADER_TPDU,
|
||||
com.utsmyanmar.paylibs.utils.enums.HostName.BPC
|
||||
ISOVersion.VERSION_1993,
|
||||
ISOMode.BOTH_HEADER_TPDU,
|
||||
HostName.BPC
|
||||
).build();
|
||||
|
||||
regularSettlementObserver = new Observer<java.util.List<com.utsmyanmar.paylibs.model.PayDetail>>() {
|
||||
regularSettlementObserver = new Observer<List<PayDetail>>() {
|
||||
@Override
|
||||
public void onChanged(java.util.List<com.utsmyanmar.paylibs.model.PayDetail> list) {
|
||||
public void onChanged(List<PayDetail> list) {
|
||||
if (regularSettlementCompleted) {
|
||||
return;
|
||||
}
|
||||
regularSettlementCompleted = true;
|
||||
|
||||
// Remove observer immediately to prevent infinite loop
|
||||
repository.getSettlementPOS().removeObserver(this);
|
||||
|
||||
int saleCount = 0;
|
||||
@ -135,33 +201,33 @@ public class AutoSettleService extends Service {
|
||||
long caAmount = 0L;
|
||||
|
||||
if (list != null && !list.isEmpty()) {
|
||||
for (com.utsmyanmar.paylibs.model.PayDetail pay : list) {
|
||||
if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.SALE && !pay.isCanceled) {
|
||||
for (PayDetail pay : list) {
|
||||
if (pay.getTransactionType() == TransactionType.SALE && !pay.isCanceled) {
|
||||
saleCount++;
|
||||
saleAmount += pay.getAmount();
|
||||
} else if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.PRE_SALE_COMPLETE && !pay.isCanceled) {
|
||||
} else if (pay.getTransactionType() == TransactionType.PRE_SALE_COMPLETE && !pay.isCanceled) {
|
||||
preCount++;
|
||||
preAmount += pay.getAmount();
|
||||
} else if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.REFUND) {
|
||||
} else if (pay.getTransactionType() == TransactionType.REFUND) {
|
||||
refundCount++;
|
||||
refundAmount += pay.getAmount();
|
||||
} else if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.CASH_ADVANCE) {
|
||||
} else if (pay.getTransactionType() == TransactionType.CASH_ADVANCE) {
|
||||
caCount++;
|
||||
caAmount += pay.getAmount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
com.utsmyanmar.paylibs.model.TradeData tradeData = com.utsmyanmar.paylibs.utils.params.Params.newTrade(true);
|
||||
com.utsmyanmar.paylibs.model.PayDetail payDetail = tradeData.getPayDetail();
|
||||
TradeData tradeData = Params.newTrade(true);
|
||||
PayDetail payDetail = tradeData.getPayDetail();
|
||||
|
||||
String bitmap = com.utsmyanmar.paylibs.utils.iso_utils.BitmapConfig.BPC_SETTLEMENT;
|
||||
payDetail.setTransType(com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.SETTLEMENT.name);
|
||||
payDetail.setTransactionType(com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.SETTLEMENT);
|
||||
payDetail.setProcessCode(com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.SETTLEMENT.processCode);
|
||||
payDetail.setBatchNo(com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation.getInstance().getCurrentBatchNum());
|
||||
String bitmap = BitmapConfig.BPC_SETTLEMENT;
|
||||
payDetail.setTransType(TransactionsType.SETTLEMENT.name);
|
||||
payDetail.setTransactionType(TransactionType.SETTLEMENT);
|
||||
payDetail.setProcessCode(TransactionsType.SETTLEMENT.processCode);
|
||||
payDetail.setBatchNo(SystemParamsOperation.getInstance().getCurrentBatchNum());
|
||||
|
||||
com.utsmyanmar.paylibs.model.SettleData settleData = new com.utsmyanmar.paylibs.model.SettleData(
|
||||
SettleData settleData = new SettleData(
|
||||
saleCount, saleAmount, preCount, preAmount, refundCount, refundAmount, caCount, caAmount);
|
||||
payDetail.setSettleDataObj(settleData);
|
||||
|
||||
@ -171,24 +237,24 @@ public class AutoSettleService extends Service {
|
||||
long creditTotal = saleAmount + preAmount + caAmount;
|
||||
long subTotal = creditTotal - refundAmount;
|
||||
if (subTotal < 0L) {
|
||||
settlementData = "D" + String.format(java.util.Locale.getDefault(), "%012d", Math.abs(subTotal));
|
||||
settlementData = "D" + String.format(Locale.getDefault(), "%012d", Math.abs(subTotal));
|
||||
} else {
|
||||
settlementData = "C" + String.format(java.util.Locale.getDefault(), "%012d", subTotal);
|
||||
settlementData = "C" + String.format(Locale.getDefault(), "%012d", subTotal);
|
||||
}
|
||||
} else {
|
||||
settlementData = "C" + String.format(java.util.Locale.getDefault(), "%012d", totalAmount);
|
||||
settlementData = "C" + String.format(Locale.getDefault(), "%012d", totalAmount);
|
||||
}
|
||||
payDetail.setSettleData(settlementData);
|
||||
payDetail.setAmount(totalAmount);
|
||||
|
||||
tradeData.setPayDetail(payDetail);
|
||||
tradeData.setField60(com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation.getInstance().getCurrentBatchNum());
|
||||
tradeData.setField60(SystemParamsOperation.getInstance().getCurrentBatchNum());
|
||||
|
||||
byte[] sendBytes = isoMsgX.buildISOPackets(tradeData, bitmap, com.utsmyanmar.paylibs.utils.MessageType.SETTLEMENT);
|
||||
com.utsmyanmar.paylibs.network.ISOSocket.getInstance().enqueue(sendBytes, sendBytes.length, false, new com.utsmyanmar.paylibs.network.ISOCallback() {
|
||||
byte[] sendBytes = isoMsgX.buildISOPackets(tradeData, bitmap, MessageType.SETTLEMENT);
|
||||
ISOSocket.getInstance().enqueue(sendBytes, sendBytes.length, false, new ISOCallback() {
|
||||
@Override
|
||||
public void onReceive(byte[] bytes, int length) {
|
||||
java.util.Map<String, com.utsmyanmar.paylibs.model.MsgField> responseMap = isoMsgX.parseISOPackets(bytes, length);
|
||||
Map<String, MsgField> responseMap = isoMsgX.parseISOPackets(bytes, length);
|
||||
if (responseMap != null) {
|
||||
String resultStr = "";
|
||||
try {
|
||||
@ -199,7 +265,7 @@ public class AutoSettleService extends Service {
|
||||
return;
|
||||
}
|
||||
payDetail.setTradeAnswerCode(resultStr);
|
||||
if (TextUtils.equals(resultStr, com.utsmyanmar.paylibs.Constant.ANSWER_CODE_ACCEPT) || TextUtils.equals(resultStr, com.utsmyanmar.paylibs.Constant.ANSWER_CODE_APPROVED)) {
|
||||
if (TextUtils.equals(resultStr, Constant.ANSWER_CODE_ACCEPT) || TextUtils.equals(resultStr, Constant.ANSWER_CODE_APPROVED)) {
|
||||
payDetail.setIsNeedReversal(false);
|
||||
} else if (TextUtils.equals(resultStr, "95") || TextUtils.equals(resultStr, "095")) {
|
||||
payDetail.setIsNeedReversal(true);
|
||||
@ -209,8 +275,8 @@ public class AutoSettleService extends Service {
|
||||
|
||||
@Override
|
||||
public void onError(String msg) {
|
||||
com.utsmyanmar.paylibs.network.ISOSocket.getInstance().switchIp();
|
||||
com.utsmyanmar.paylibs.network.ISOSocket.getInstance().enqueue(sendBytes, sendBytes.length, false, this);
|
||||
ISOSocket.getInstance().switchIp();
|
||||
ISOSocket.getInstance().enqueue(sendBytes, sendBytes.length, false, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -218,14 +284,14 @@ public class AutoSettleService extends Service {
|
||||
LogUtil.d(TAG, "Auto settlement transaction completed successfully");
|
||||
|
||||
if (list != null && !list.isEmpty()) {
|
||||
for (com.utsmyanmar.paylibs.model.PayDetail p : list) {
|
||||
for (PayDetail p : list) {
|
||||
repository.deletePayDetail(p);
|
||||
}
|
||||
}
|
||||
repository.insertPayDetail(payDetail);
|
||||
|
||||
try {
|
||||
com.utsmyanmar.paylibs.model.PayDetail cleanPayDetail = new com.utsmyanmar.paylibs.model.PayDetail();
|
||||
PayDetail cleanPayDetail = new PayDetail();
|
||||
cleanPayDetail.setTransType(payDetail.getTransType());
|
||||
cleanPayDetail.setTransactionType(payDetail.getTransactionType());
|
||||
cleanPayDetail.setProcessCode(payDetail.getProcessCode());
|
||||
@ -235,31 +301,12 @@ public class AutoSettleService extends Service {
|
||||
cleanPayDetail.setTradeAnswerCode(payDetail.getTradeAnswerCode());
|
||||
cleanPayDetail.setIsNeedReversal(payDetail.getIsNeedReversal());
|
||||
|
||||
Intent uiIntent = new Intent(getApplicationContext(), com.utsmm.kbz.MainActivity.class);
|
||||
uiIntent.putExtra("AUTO_SETTLEMENT", true);
|
||||
uiIntent.putExtra("EXTRA_TRANSACTION_TYPE", com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.SETTLEMENT.value);
|
||||
uiIntent.putExtra("EXTRA_PAY_DETAIL", cleanPayDetail);
|
||||
uiIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
startActivity(uiIntent);
|
||||
|
||||
LogUtil.d(TAG, "MainActivity started successfully with auto settlement result");
|
||||
// Use notification-based approach to reliably launch the app
|
||||
launchAppWithSettlementResult("AUTO_SETTLEMENT", cleanPayDetail, null);
|
||||
|
||||
} catch (Exception e) {
|
||||
LogUtil.e(TAG, "Error starting MainActivity: " + e.getMessage());
|
||||
LogUtil.e(TAG, "Error launching app with settlement result: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
|
||||
try {
|
||||
Intent fallbackIntent = new Intent(getApplicationContext(), com.utsmm.kbz.MainActivity.class);
|
||||
fallbackIntent.putExtra("AUTO_SETTLEMENT", true);
|
||||
fallbackIntent.putExtra("EXTRA_TRANSACTION_TYPE", com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.SETTLEMENT.value);
|
||||
fallbackIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
startActivity(fallbackIntent);
|
||||
|
||||
LogUtil.d(TAG, "MainActivity started with fallback approach");
|
||||
|
||||
} catch (Exception fallbackException) {
|
||||
LogUtil.e(TAG, "Fallback also failed: " + fallbackException.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
checkIfBothSettlementsComplete();
|
||||
@ -276,15 +323,14 @@ public class AutoSettleService extends Service {
|
||||
return;
|
||||
}
|
||||
|
||||
qrSettlementObserver = new Observer<java.util.List<com.utsmyanmar.paylibs.model.PayDetail>>() {
|
||||
qrSettlementObserver = new Observer<List<PayDetail>>() {
|
||||
@Override
|
||||
public void onChanged(java.util.List<com.utsmyanmar.paylibs.model.PayDetail> payDetailList) {
|
||||
public void onChanged(List<PayDetail> payDetailList) {
|
||||
if (qrSettlementCompleted) {
|
||||
return;
|
||||
}
|
||||
qrSettlementCompleted = true;
|
||||
|
||||
// Remove observer immediately to prevent infinite loop
|
||||
repository.getTransactionHistory().removeObserver(this);
|
||||
|
||||
if (payDetailList != null) {
|
||||
@ -293,28 +339,26 @@ public class AutoSettleService extends Service {
|
||||
int qrRefundCount = 0;
|
||||
long qrRefundAmount = 0;
|
||||
|
||||
java.util.ArrayList<com.utsmyanmar.paylibs.model.PayDetail> qrTransactionsList = new java.util.ArrayList<>();
|
||||
java.util.ArrayList<com.utsmyanmar.paylibs.model.PayDetail> qrTransListAll = new java.util.ArrayList<>();
|
||||
ArrayList<PayDetail> qrTransactionsList = new ArrayList<>();
|
||||
ArrayList<PayDetail> qrTransListAll = new ArrayList<>();
|
||||
|
||||
try {
|
||||
for (com.utsmyanmar.paylibs.model.PayDetail payDetail : payDetailList) {
|
||||
// Filter for successful QR transactions only
|
||||
if ((payDetail.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.MMQR.value
|
||||
|| payDetail.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.MMQR_REFUND.value)
|
||||
for (PayDetail payDetail : payDetailList) {
|
||||
if ((payDetail.getTransactionType() == TransactionsType.MMQR.value
|
||||
|| payDetail.getTransactionType() == TransactionsType.MMQR_REFUND.value)
|
||||
&& payDetail.getQrTransStatus() == 1) {
|
||||
|
||||
qrTransactionsList.add(payDetail);
|
||||
|
||||
if (payDetail.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.MMQR.value) {
|
||||
if (payDetail.getTransactionType() == TransactionsType.MMQR.value) {
|
||||
qrSaleCount++;
|
||||
qrSaleAmount += payDetail.getAmount();
|
||||
} else if (payDetail.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.MMQR_REFUND.value) {
|
||||
} else if (payDetail.getTransactionType() == TransactionsType.MMQR_REFUND.value) {
|
||||
qrRefundCount++;
|
||||
qrRefundAmount += payDetail.getAmount();
|
||||
}
|
||||
} else if (payDetail.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.MMQR.value
|
||||
|| payDetail.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.MMQR_REFUND.value) {
|
||||
// Include all QR transactions for deletion (successful and failed)
|
||||
} else if (payDetail.getTransactionType() == TransactionsType.MMQR.value
|
||||
|| payDetail.getTransactionType() == TransactionsType.MMQR_REFUND.value) {
|
||||
qrTransListAll.add(payDetail);
|
||||
}
|
||||
}
|
||||
@ -333,14 +377,14 @@ public class AutoSettleService extends Service {
|
||||
SystemParamsOperation.getInstance().getIncrementBatchNo();
|
||||
|
||||
// Create settlement data for QR transactions
|
||||
com.utsmyanmar.paylibs.model.SettleData settleData = new com.utsmyanmar.paylibs.model.SettleData(
|
||||
SettleData settleData = new SettleData(
|
||||
qrSaleCount, qrSaleAmount, 0, 0L, qrRefundCount, qrRefundAmount, 0, 0L);
|
||||
|
||||
com.utsmyanmar.paylibs.model.TradeData tradeData = com.utsmyanmar.paylibs.utils.params.Params.newTrade(false);
|
||||
com.utsmyanmar.paylibs.model.PayDetail payDetail = tradeData.getPayDetail();
|
||||
TradeData tradeData = Params.newTrade(false);
|
||||
PayDetail payDetail = tradeData.getPayDetail();
|
||||
payDetail.setSettleDataObj(settleData);
|
||||
payDetail.setTransactionType(com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.MMQR_SETTLEMENT.value);
|
||||
payDetail.setTransType(com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.MMQR_SETTLEMENT.name);
|
||||
payDetail.setTransactionType(TransactionsType.MMQR_SETTLEMENT.value);
|
||||
payDetail.setTransType(TransactionsType.MMQR_SETTLEMENT.name);
|
||||
payDetail.setAmount(totalAmount);
|
||||
payDetail.setTradeAnswerCode("000");
|
||||
payDetail.setBatchNo(SystemParamsOperation.getInstance().getCurrentBatchNum());
|
||||
@ -349,42 +393,38 @@ public class AutoSettleService extends Service {
|
||||
repository.insertPayDetail(payDetail);
|
||||
|
||||
// Delete settled QR transactions
|
||||
for (com.utsmyanmar.paylibs.model.PayDetail pay : qrTransactionsList) {
|
||||
for (PayDetail pay : qrTransactionsList) {
|
||||
repository.deletePayDetail(pay);
|
||||
}
|
||||
|
||||
// Delete all other QR transactions (failed ones)
|
||||
for (com.utsmyanmar.paylibs.model.PayDetail pay : qrTransListAll) {
|
||||
for (PayDetail pay : qrTransListAll) {
|
||||
repository.deletePayDetail(pay);
|
||||
}
|
||||
|
||||
// Push e-receipt data
|
||||
// Push e-receipt data using repository directly
|
||||
try {
|
||||
com.utsmyanmar.baselib.network.model.e_receipt.EReceiptRequest request =
|
||||
com.utsmm.kbz.util.EReceiptUtil.getInstance().generateQRSettlement(payDetail);
|
||||
LogUtil.d(TAG, "QR Settlement e-receipt data prepared");
|
||||
EReceiptRequest request = EReceiptUtil.getInstance().generateQRSettlement(payDetail);
|
||||
sendEReceipt(request);
|
||||
LogUtil.d(TAG, "QR Settlement e-receipt data prepared and sent");
|
||||
} catch (Exception e) {
|
||||
LogUtil.e(TAG, "Error preparing QR settlement e-receipt: " + e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
// Start MainActivity with QR settlement data for automatic printing
|
||||
Intent uiIntent = new Intent(getApplicationContext(), com.utsmm.kbz.MainActivity.class);
|
||||
uiIntent.putExtra("AUTO_QR_SETTLEMENT", true);
|
||||
uiIntent.putExtra("EXTRA_TRANSACTION_TYPE", com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.MMQR_SETTLEMENT.value);
|
||||
uiIntent.putExtra("QR_SALE_COUNT", qrSaleCount);
|
||||
uiIntent.putExtra("QR_SALE_AMOUNT", qrSaleAmount);
|
||||
uiIntent.putExtra("QR_REFUND_COUNT", qrRefundCount);
|
||||
uiIntent.putExtra("QR_REFUND_AMOUNT", qrRefundAmount);
|
||||
uiIntent.putExtra("QR_TOTAL_AMOUNT", totalAmount);
|
||||
uiIntent.putExtra("QR_TRANS_LIST", qrTransactionsList);
|
||||
uiIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
startActivity(uiIntent);
|
||||
|
||||
LogUtil.d(TAG, "MainActivity started successfully with QR auto settlement result");
|
||||
// Create QR settlement data bundle
|
||||
Bundle qrData = new Bundle();
|
||||
qrData.putInt("QR_SALE_COUNT", qrSaleCount);
|
||||
qrData.putLong("QR_SALE_AMOUNT", qrSaleAmount);
|
||||
qrData.putInt("QR_REFUND_COUNT", qrRefundCount);
|
||||
qrData.putLong("QR_REFUND_AMOUNT", qrRefundAmount);
|
||||
qrData.putLong("QR_TOTAL_AMOUNT", totalAmount);
|
||||
qrData.putSerializable("QR_TRANS_LIST", qrTransactionsList);
|
||||
// Use notification-based approach to reliably launch the app
|
||||
launchAppWithSettlementResult("AUTO_QR_SETTLEMENT", null, qrData);
|
||||
|
||||
} catch (Exception e) {
|
||||
LogUtil.e(TAG, "Error starting MainActivity for QR settlement: " + e.getMessage());
|
||||
LogUtil.e(TAG, "Error launching app for QR settlement: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@ -402,7 +442,6 @@ public class AutoSettleService extends Service {
|
||||
}
|
||||
|
||||
private void checkIfBothSettlementsComplete() {
|
||||
// Stop service only when both settlements are processed (or skipped if no data)
|
||||
if (regularSettlementCompleted && qrSettlementCompleted) {
|
||||
LogUtil.d(TAG, "Both settlements completed, stopping service");
|
||||
stopSelf();
|
||||
@ -438,6 +477,96 @@ public class AutoSettleService extends Service {
|
||||
repository.getTransactionHistory().removeObserver(qrSettlementObserver);
|
||||
}
|
||||
|
||||
LogUtil.d(TAG, "AutoSettleService destroyed and cleaned up");
|
||||
}
|
||||
|
||||
private void launchAppWithSettlementResult(String settlementType,
|
||||
PayDetail payDetail,
|
||||
Bundle qrData) {
|
||||
try {
|
||||
Intent launchIntent = new Intent(this, MainActivity.class);
|
||||
launchIntent.putExtra(settlementType, true);
|
||||
|
||||
if ("AUTO_SETTLEMENT".equals(settlementType) && payDetail != null) {
|
||||
launchIntent.putExtra("EXTRA_TRANSACTION_TYPE", TransactionsType.SETTLEMENT.value);
|
||||
launchIntent.putExtra("EXTRA_PAY_DETAIL", payDetail);
|
||||
} else if ("AUTO_QR_SETTLEMENT".equals(settlementType) && qrData != null) {
|
||||
launchIntent.putExtra("EXTRA_TRANSACTION_TYPE", TransactionsType.MMQR_SETTLEMENT.value);
|
||||
launchIntent.putExtras(qrData);
|
||||
}
|
||||
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(
|
||||
this,
|
||||
(int) System.currentTimeMillis(),
|
||||
launchIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
|
||||
);
|
||||
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
NotificationChannel channel = new NotificationChannel(
|
||||
"SETTLEMENT_COMPLETE",
|
||||
"Settlement Complete",
|
||||
NotificationManager.IMPORTANCE_HIGH
|
||||
);
|
||||
channel.setDescription("Auto settlement completion notifications");
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "SETTLEMENT_COMPLETE")
|
||||
.setSmallIcon(R.drawable.ic_launcher_foreground)
|
||||
.setContentTitle("Auto Settlement Complete")
|
||||
.setContentText("Tap to view settlement results and print receipt")
|
||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(pendingIntent)
|
||||
.setFullScreenIntent(pendingIntent, true);
|
||||
notificationManager.notify(2001, builder.build());
|
||||
|
||||
LogUtil.d(TAG, " Settlement complete notification created - will launch app when tapped");
|
||||
|
||||
try {
|
||||
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP |
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP |
|
||||
Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
|
||||
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
|
||||
startActivity(launchIntent);
|
||||
} catch (Exception directException) {
|
||||
LogUtil.d(TAG, "Direct launch failed (expected on modern Android), notification approach will handle it");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
LogUtil.e(TAG, "Error creating settlement notification: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void sendEReceipt(EReceiptRequest request) {
|
||||
try {
|
||||
LogUtil.d(TAG, "Sending e-receipt: " + new Gson().toJson(request));
|
||||
|
||||
repository.sendReceipt(request)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
response -> LogUtil.d(TAG, "E-Receipt sent successfully: " + response.getMessage()),
|
||||
error -> {
|
||||
if (error instanceof HttpException) {
|
||||
HttpException httpEx = (HttpException) error;
|
||||
try {
|
||||
String errorJson = httpEx.response().errorBody().string();
|
||||
LogUtil.e(TAG, "E-Receipt error: " + errorJson);
|
||||
} catch (Exception e) {
|
||||
LogUtil.e(TAG, "E-Receipt send failed: " + error.getMessage());
|
||||
}
|
||||
} else {
|
||||
LogUtil.e(TAG, "E-Receipt send failed: " + error.getMessage());
|
||||
}
|
||||
}
|
||||
);
|
||||
} catch (Exception e) {
|
||||
LogUtil.e(TAG, "Error sending e-receipt: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -27,6 +27,7 @@ import com.utsmyanmar.paylibs.Constant;
|
||||
import com.utsmyanmar.paylibs.model.PayDetail;
|
||||
import com.utsmyanmar.paylibs.print.PaperRollStatusCallback;
|
||||
import com.utsmyanmar.paylibs.print.PrintHelper;
|
||||
import com.utsmyanmar.paylibs.print.printx.PrintXStatus;
|
||||
import com.utsmyanmar.paylibs.utils.PrintStatus;
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation;
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType;
|
||||
@ -210,7 +211,7 @@ public class TransactionResultFragment extends DataBindingFragment implements Da
|
||||
startPrintProcess(true);
|
||||
downloadParameters(siriusReq, TMSUpdate.UPDATE);
|
||||
// showSuccessDialog(getResourceString(R.string.txt_configs_are_updated));
|
||||
navigateToMainScreen();
|
||||
// navigateToMainScreen();
|
||||
}
|
||||
|
||||
private void handleQRPaySuccessTransaction(PayDetail payDetail, SiriusRequest siriusReq) {
|
||||
@ -320,7 +321,17 @@ public class TransactionResultFragment extends DataBindingFragment implements Da
|
||||
@Override
|
||||
public void printerReady() {
|
||||
if(isSettlement) {
|
||||
sharedViewModel.startPrintSettlement();
|
||||
sharedViewModel.startPrintSettlement(new PrintXStatus() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
isCardInside();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
handleForEmptyPaperRoll(isSettlement);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
sharedViewModel.startPrintProcess();
|
||||
@ -328,26 +339,7 @@ public class TransactionResultFragment extends DataBindingFragment implements Da
|
||||
|
||||
@Override
|
||||
public void paperRollIsEmpty() {
|
||||
cancelTimeout();
|
||||
|
||||
showPrinterAlertDialog(getResourceString(R.string.txt_paper_roll_not_ready), new DialogCallback() {
|
||||
@Override
|
||||
public void onClickCancel() {
|
||||
|
||||
dismissPrinterAlertDialog();
|
||||
isCardInside();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClickRetry() {
|
||||
dismissPrinterAlertDialog();
|
||||
startPrintProcess(isSettlement);
|
||||
|
||||
}
|
||||
});
|
||||
if(SystemParamsOperation.getInstance().isAlertSound()) {
|
||||
startSound(getResourceString(R.string.txt_audio_printer_alert));
|
||||
}
|
||||
handleForEmptyPaperRoll(isSettlement);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -374,6 +366,30 @@ public class TransactionResultFragment extends DataBindingFragment implements Da
|
||||
});
|
||||
}
|
||||
|
||||
private void handleForEmptyPaperRoll(boolean isSettle) {
|
||||
cancelTimeout();
|
||||
|
||||
showPrinterAlertDialog(getResourceString(R.string.txt_paper_roll_not_ready), new DialogCallback() {
|
||||
@Override
|
||||
public void onClickCancel() {
|
||||
|
||||
dismissPrinterAlertDialog();
|
||||
isCardInside();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClickRetry() {
|
||||
dismissPrinterAlertDialog();
|
||||
startPrintProcess(isSettle);
|
||||
|
||||
}
|
||||
});
|
||||
if(SystemParamsOperation.getInstance().isAlertSound()) {
|
||||
startSound(getResourceString(R.string.txt_audio_printer_alert));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void alertPaperRoll(String title, String message) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
|
||||
builder.setTitle(title)
|
||||
|
||||
@ -396,49 +396,29 @@ public class SharedViewModel extends ViewModel {
|
||||
|
||||
}
|
||||
|
||||
public void startPrintSettlement() {
|
||||
public void startPrintSettlement(PrintXStatus printXStatus) {
|
||||
if(payDetail.getValue() == null) return;
|
||||
if(payDetail.getValue().getTransactionType() == TransactionsType.SETTLEMENT.value) {
|
||||
startPrintProcessSettlement();
|
||||
startPrintProcessSettlement(printXStatus);
|
||||
} else {
|
||||
startPrintProcessQRSettlement();
|
||||
startPrintProcessQRSettlement(printXStatus);
|
||||
}
|
||||
}
|
||||
|
||||
public void startPrintProcessSettlement() {
|
||||
public void startPrintProcessSettlement(PrintXStatus printXStatus) {
|
||||
|
||||
if(payDetail.getValue() == null) return;
|
||||
|
||||
PrintXReceipt.getInstance().printSmileSettlementReport(payDetail.getValue(), new PrintXStatus() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
|
||||
}
|
||||
});
|
||||
PrintXReceipt.getInstance().printSmileSettlementReport(payDetail.getValue(),printXStatus);
|
||||
}
|
||||
|
||||
private void startPrintProcessQRSettlement() {
|
||||
private void startPrintProcessQRSettlement(PrintXStatus printXStatus) {
|
||||
|
||||
|
||||
|
||||
if(payDetail.getValue() == null && payDetails.getValue() == null) return;
|
||||
|
||||
PrintXReceipt.getInstance().printQRSettlementReport(payDetail.getValue(),payDetails.getValue(), new PrintXStatus() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
|
||||
}
|
||||
});
|
||||
PrintXReceipt.getInstance().printQRSettlementReport(payDetail.getValue(),payDetails.getValue(), printXStatus);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -14,6 +14,7 @@ import com.utsmyanmar.baselib.network.model.e_receipt.EReceiptRequest;
|
||||
import com.utsmyanmar.baselib.util.DataBindingConfig;
|
||||
import com.utsmyanmar.paylibs.model.PayDetail;
|
||||
import com.utsmyanmar.paylibs.model.TradeData;
|
||||
import com.utsmyanmar.paylibs.print.printx.PrintXStatus;
|
||||
import com.utsmyanmar.paylibs.sign_on.EchoTestProcess;
|
||||
import com.utsmyanmar.paylibs.sign_on.SignOnListener;
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation;
|
||||
@ -391,7 +392,17 @@ public class SettlementTransactionFragment extends DataBindingFragment implement
|
||||
settlementViewModel.startSettlementProcess();
|
||||
showLoadingDialog("Sending ...");
|
||||
} else if(sharedViewModel.getTransMenu().getValue() == TransMenu.REVIEW_BATCH) {
|
||||
sharedViewModel.startPrintSettlement();
|
||||
sharedViewModel.startPrintSettlement(new PrintXStatus() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
|
||||
}
|
||||
});
|
||||
} else if(sharedViewModel.getTransMenu().getValue() == TransMenu.LAST_SETTLEMENT) {
|
||||
routeId = R.id.action_settlementTransactionFragment_to_reprintReceiptFragment;
|
||||
safeNavigateToRouteId();
|
||||
|
||||
@ -4,6 +4,9 @@ import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
@ -220,6 +223,10 @@ public class TMSProcessFragment extends DataBindingFragment {
|
||||
CurrencyType currencyType = SystemParamsOperation.getInstance().getCurrencyType();
|
||||
sharedViewModel.set_currencyText(currencyType.name);
|
||||
// tmsProcessViewModel.loadEmvParameters();
|
||||
|
||||
// Check and request battery optimization exemption before scheduling alarm
|
||||
requestBatteryOptimizationExemption();
|
||||
|
||||
scheduleAutoSettlement();
|
||||
navigateToMain();
|
||||
}
|
||||
@ -327,4 +334,40 @@ public class TMSProcessFragment extends DataBindingFragment {
|
||||
}
|
||||
}
|
||||
|
||||
private void requestBatteryOptimizationExemption() {
|
||||
try {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
||||
PowerManager powerManager = (PowerManager) requireContext().getSystemService(Context.POWER_SERVICE);
|
||||
String packageName = requireContext().getPackageName();
|
||||
|
||||
if (!powerManager.isIgnoringBatteryOptimizations(packageName)) {
|
||||
LogUtil.d(TAG, "Requesting battery optimization exemption for reliable alarms");
|
||||
|
||||
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
||||
intent.setData(Uri.parse("package:" + packageName));
|
||||
|
||||
try {
|
||||
startActivity(intent);
|
||||
LogUtil.d(TAG, "Battery optimization exemption dialog opened");
|
||||
} catch (Exception e) {
|
||||
LogUtil.e(TAG, "Failed to open battery optimization dialog: " + e.getMessage());
|
||||
|
||||
// Fallback: Open battery optimization settings page
|
||||
try {
|
||||
Intent fallbackIntent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
|
||||
startActivity(fallbackIntent);
|
||||
LogUtil.d(TAG, "Battery optimization settings opened as fallback");
|
||||
} catch (Exception fallbackException) {
|
||||
LogUtil.e(TAG, "Fallback also failed: " + fallbackException.getMessage());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LogUtil.d(TAG, "App is already exempted from battery optimizations");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.e(TAG, "Error checking battery optimization status: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ public class EReceiptUtil {
|
||||
private static EReceiptUtil instance;
|
||||
|
||||
|
||||
public static EReceiptUtil getInstance(){
|
||||
public static EReceiptUtil getInstance() {
|
||||
|
||||
instance = new EReceiptUtil();
|
||||
|
||||
@ -36,7 +36,8 @@ public class EReceiptUtil {
|
||||
private String packageName;
|
||||
private String qrTerminalId;
|
||||
private String qrMerchantId;
|
||||
private EReceiptUtil(){
|
||||
|
||||
private EReceiptUtil() {
|
||||
terminalId = SystemParamsOperation.getInstance().getTerminalId();
|
||||
merchantId = SystemParamsOperation.getInstance().getMerchantId();
|
||||
traceNo = SystemParamsOperation.getInstance().getCurrentSerialNum();
|
||||
@ -80,23 +81,21 @@ public class EReceiptUtil {
|
||||
|
||||
// need to add payment identifier field too
|
||||
|
||||
if(status == TransResultStatus.SUCCESS) {
|
||||
if (status == TransResultStatus.SUCCESS) {
|
||||
request.setDE4(amount);
|
||||
request.setDescription("qr pay success");
|
||||
request.setDE39("A");
|
||||
} else if(status == TransResultStatus.TIME_OUT) {
|
||||
} else if (status == TransResultStatus.TIME_OUT) {
|
||||
request.setDE4("0");
|
||||
request.setDescription("qr timeout");
|
||||
request.setDE39("D");
|
||||
} else if(status == TransResultStatus.FAIL) {
|
||||
} else if (status == TransResultStatus.FAIL) {
|
||||
request.setDE4("0");
|
||||
request.setDescription("qr failed");
|
||||
request.setDE39("E");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
@ -139,23 +138,21 @@ public class EReceiptUtil {
|
||||
|
||||
// need to add payment identifier field too
|
||||
|
||||
if(status == TransResultStatus.SUCCESS) {
|
||||
if (status == TransResultStatus.SUCCESS) {
|
||||
request.setDE4(amount);
|
||||
request.setDescription("qr refund success");
|
||||
request.setDE39("A");
|
||||
} else if(status == TransResultStatus.TIME_OUT) {
|
||||
} else if (status == TransResultStatus.TIME_OUT) {
|
||||
request.setDE4("0");
|
||||
request.setDescription("qr refund timeout");
|
||||
request.setDE39("D");
|
||||
} else if(status == TransResultStatus.FAIL) {
|
||||
} else if (status == TransResultStatus.FAIL) {
|
||||
request.setDE4("0");
|
||||
request.setDescription("qr refund failed");
|
||||
request.setDE39("E");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
@ -173,7 +170,7 @@ public class EReceiptUtil {
|
||||
request.setDE7(currentTimeStamp);
|
||||
request.setDE11(payDetail.getVoucherNo());
|
||||
|
||||
if(payDetail.getTransactionType() == TransactionsType.SETTLEMENT.value) {
|
||||
if (payDetail.getTransactionType() == TransactionsType.SETTLEMENT.value) {
|
||||
SettleData settleData = payDetail.getSettleDataObj();
|
||||
|
||||
long totalAmt = settleData.getSaleAmount() + settleData.getRefundAmount() + settleData.getPreAuthCompAmount() + settleData.getCashAdvanceAmount();
|
||||
@ -182,14 +179,14 @@ public class EReceiptUtil {
|
||||
request.setDE4(totalAmount);
|
||||
|
||||
|
||||
request.setDE63_01(settleData.getSaleCount()+"");
|
||||
request.setDE63_02(settleData.getSaleAmount()+"");
|
||||
request.setDE63_03(settleData.getRefundCount()+"");
|
||||
request.setDE63_04(settleData.getRefundAmount()+"");
|
||||
request.setDE63_05(settleData.getPreAuthCompCount()+"");
|
||||
request.setDE63_06(settleData.getPreAuthCompAmount()+"");
|
||||
request.setDE63_07(settleData.getCashAdvanceCount()+"");
|
||||
request.setDE63_08(settleData.getCashAdvanceAmount()+"");
|
||||
request.setDE63_01(settleData.getSaleCount() + "");
|
||||
request.setDE63_02(settleData.getSaleAmount() + "");
|
||||
request.setDE63_03(settleData.getRefundCount() + "");
|
||||
request.setDE63_04(settleData.getRefundAmount() + "");
|
||||
request.setDE63_05(settleData.getPreAuthCompCount() + "");
|
||||
request.setDE63_06(settleData.getPreAuthCompAmount() + "");
|
||||
request.setDE63_07(settleData.getCashAdvanceCount() + "");
|
||||
request.setDE63_08(settleData.getCashAdvanceAmount() + "");
|
||||
invoiceNo = SystemParamsOperation.getInstance().getIncrementInvoiceNum();
|
||||
request.setBatchNumber(batchNumber);
|
||||
request.setInvoiceNumber(invoiceNo);
|
||||
@ -210,7 +207,7 @@ public class EReceiptUtil {
|
||||
request.setInvoiceNumber(payDetail.getInvoiceNo());
|
||||
request.setCardLabel("MPU");
|
||||
|
||||
if(payDetail.getTradeAnswerCode().equals("000") || payDetail.getTradeAnswerCode().equals("00") ) {
|
||||
if (payDetail.getTradeAnswerCode().equals("000") || payDetail.getTradeAnswerCode().equals("00")) {
|
||||
|
||||
request.setDescription("success");
|
||||
request.setDE39("A");
|
||||
@ -248,52 +245,27 @@ public class EReceiptUtil {
|
||||
request.setTerminalId(terminalId);//terminalId is not tid
|
||||
request.setShortCode(qrMerchantId);
|
||||
|
||||
if(payDetail.getTransactionType() == TransactionsType.SETTLEMENT.value) {
|
||||
SettleData settleData = payDetail.getSettleDataObj();
|
||||
SettleData settleData = payDetail.getSettleDataObj();
|
||||
|
||||
long totalAmt = settleData.getSaleAmount() + settleData.getRefundAmount() + settleData.getPreAuthCompAmount() + settleData.getCashAdvanceAmount();
|
||||
double realTotalAmount = totalAmt / 100.0;
|
||||
String totalAmount = df.format(realTotalAmount);
|
||||
request.setDE4(totalAmount);
|
||||
long totalAmt = settleData.getSaleAmount() + settleData.getRefundAmount();
|
||||
double realTotalAmount = totalAmt / 100.0;
|
||||
String totalAmount = df.format(realTotalAmount);
|
||||
request.setDE4(totalAmount);
|
||||
|
||||
|
||||
request.setDE63_01(settleData.getSaleCount()+"");
|
||||
request.setDE63_02(settleData.getSaleAmount()+"");
|
||||
request.setDE63_03(settleData.getRefundCount()+"");
|
||||
request.setDE63_04(settleData.getRefundAmount()+"");
|
||||
request.setDE63_05(settleData.getPreAuthCompCount()+"");
|
||||
request.setDE63_06(settleData.getPreAuthCompAmount()+"");
|
||||
request.setDE63_07(settleData.getCashAdvanceCount()+"");
|
||||
request.setDE63_08(settleData.getCashAdvanceAmount()+"");
|
||||
invoiceNo = SystemParamsOperation.getInstance().getIncrementInvoiceNum();
|
||||
request.setBatchNumber(batchNumber);
|
||||
request.setInvoiceNumber(invoiceNo);
|
||||
request.setDescription("success");
|
||||
request.setDE39("A");
|
||||
request.setDE37("0000");
|
||||
request.setDE49("MMK");
|
||||
} else {
|
||||
request.setDE2(POSUtil.getInstance().getCardNumMasking(payDetail.getCardNo()));
|
||||
request.setDE63_01(settleData.getSaleCount() + "");
|
||||
request.setDE63_02(settleData.getSaleAmount() + "");
|
||||
request.setDE63_03(settleData.getRefundCount() + "");
|
||||
request.setDE63_04(settleData.getRefundAmount() + "");
|
||||
|
||||
request.setDE4(amount);
|
||||
invoiceNo = SystemParamsOperation.getInstance().getIncrementInvoiceNum();
|
||||
request.setBatchNumber(batchNumber);
|
||||
request.setInvoiceNumber(invoiceNo);
|
||||
request.setDescription("success");
|
||||
request.setDE39("A");
|
||||
request.setDE37("0000");
|
||||
request.setDE49("MMK");
|
||||
|
||||
|
||||
request.setDE37(payDetail.getReferNo());
|
||||
request.setDE38(payDetail.getApprovalCode());
|
||||
// will check it later for currency code
|
||||
request.setDE49("MMK");
|
||||
request.setInvoiceNumber(payDetail.getInvoiceNo());
|
||||
request.setCardLabel("MPU");
|
||||
|
||||
if(payDetail.getTradeAnswerCode().equals("000") || payDetail.getTradeAnswerCode().equals("00") ) {
|
||||
|
||||
request.setDescription("success");
|
||||
request.setDE39("A");
|
||||
} else {
|
||||
request.setDescription(BaseErrorCode.getErrorMessage(payDetail.getTradeAnswerCode()));
|
||||
request.setDE39("E");
|
||||
}
|
||||
}
|
||||
request.setDE41(terminalId);
|
||||
request.setDE42(merchantId);
|
||||
|
||||
@ -304,25 +276,25 @@ public class EReceiptUtil {
|
||||
}
|
||||
|
||||
public String convertTransactionType(int transactionType) {
|
||||
if(transactionType == TransactionsType.SALE.value) {
|
||||
if (transactionType == TransactionsType.SALE.value) {
|
||||
return "S";
|
||||
} else if(transactionType == TransactionsType.VOID.value) {
|
||||
} else if (transactionType == TransactionsType.VOID.value) {
|
||||
return "V";
|
||||
} else if(transactionType == TransactionsType.PRE_AUTH_SALE.value) {
|
||||
} else if (transactionType == TransactionsType.PRE_AUTH_SALE.value) {
|
||||
return "P";
|
||||
} else if(transactionType == TransactionsType.PRE_AUTH_VOID.value) {
|
||||
} else if (transactionType == TransactionsType.PRE_AUTH_VOID.value) {
|
||||
return "PV";
|
||||
} else if(transactionType == TransactionsType.PRE_AUTH_COMPLETE.value) {
|
||||
} else if (transactionType == TransactionsType.PRE_AUTH_COMPLETE.value) {
|
||||
return "PC";
|
||||
} else if(transactionType == TransactionsType.PRE_AUTH_COMPLETE_VOID.value) {
|
||||
} else if (transactionType == TransactionsType.PRE_AUTH_COMPLETE_VOID.value) {
|
||||
return "PCV";
|
||||
} else if(transactionType == TransactionsType.CASH_OUT.value) {
|
||||
} else if (transactionType == TransactionsType.CASH_OUT.value) {
|
||||
return "CAV";
|
||||
} else if(transactionType == TransactionsType.REFUND.value) {
|
||||
} else if (transactionType == TransactionsType.REFUND.value) {
|
||||
return "R";
|
||||
} else if(transactionType == TransactionsType.SETTLEMENT.value) {
|
||||
} else if (transactionType == TransactionsType.SETTLEMENT.value) {
|
||||
return "ST";
|
||||
} else if(transactionType == TransactionsType.MMQR_SETTLEMENT.value) {
|
||||
} else if (transactionType == TransactionsType.MMQR_SETTLEMENT.value) {
|
||||
return "ST";
|
||||
}
|
||||
return "E";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user