QR settlement completed

This commit is contained in:
kizzy 2025-12-09 05:58:09 +07:00
parent f91ae09be7
commit b92f9bfe4e
15 changed files with 177 additions and 20 deletions

File diff suppressed because one or more lines are too long

View File

@ -166,7 +166,7 @@ public class TransactionResultFragment extends DataBindingFragment implements Da
if (isNonApprovedTrade(payDetail) && isNonWavepayTransaction(transactionType)) {
startPrintProcess(false);
isCardInside();
} else if (transactionType == TransactionsType.SETTLEMENT) {
} else if (transactionType == TransactionsType.SETTLEMENT || transactionType == TransactionsType.MMQR_SETTLEMENT) {
handleSettlementTransaction(siriusReq);
} else if (isWavePayNonSuccessTransaction(transactionType, payDetail)) {
// startPrintProcess(false);
@ -208,7 +208,7 @@ public class TransactionResultFragment extends DataBindingFragment implements Da
private void handleSettlementTransaction(SiriusRequest siriusReq) {
startPrintProcess(true);
downloadParameters(siriusReq, TMSUpdate.UPDATE);
showSuccessDialog(getResourceString(R.string.txt_configs_are_updated));
// showSuccessDialog(getResourceString(R.string.txt_configs_are_updated));
navigateToMainScreen();
}

View File

@ -302,14 +302,20 @@ public class QRTransactionFragment extends DataBindingFragment implements DataBi
* trans is success !*/
// String transStatus = response.getTransactionStatus();
// String transTime = response.getResponse().;
if(response.getResponse().getWalletIdentifier() != null) {
payDetail.setCustomerMobile(response.getResponse().getWalletIdentifier());
} else {
payDetail.setCustomerMobile("KBZ PAY");
}
payDetail.setCustomerMobile("KBZ PAY");
payDetail.setTC(response.getResponse().getTradeStatus());
payDetail.setQrReferNo(refLabel);
payDetail.setQrTransId(response.getResponse().getMmOrderId());
payDetail.setReferNo(refLabel);
payDetail.setApprovalCode(response.getResponse().getMmOrderId());
payDetail.setQrTransStatus(1);
payDetail.setOriginalTransDate(response.getResponse().getPaySuccessTime());
payDetail.setTradeDateAndTime(response.getResponse().getPaySuccessTime());
retrievedUpdatePayDetail(refLabel, payDetail,false);

View File

@ -140,13 +140,15 @@ public class QRRefundProcessFragment extends DataBindingFragment {
String refundAmount = response.getResponse().getRefundAmount();
String dateTime = SystemDateTime.getTodayDateFormat() + " " + SystemDateTime.getTodayTimeFormat();
payDetail.setTC(response.getResponse().getRefundStatus());
payDetail.setAmount(refundAmount == null ? 0 : POSUtil.getInstance().convertAmount(refundAmount));
payDetail.setOriginalTransDate(dateTime);
payDetail.setQrTransStatus(1);
payDetail.setQrReferNo(referenceNo);
payDetail.setReferNo(referenceNo);
payDetail.setIsCanceled(true);
payDetail.setCustomerMobile(response.getResponse().getWalletIdentifier());
payDetail.setTradeDateAndTime(response.getResponse().getRefundTime());
EReceiptRequest request = EReceiptUtil.getInstance().generateQRRefundReceipt(sharedViewModel.payDetail.getValue(), TransResultStatus.SUCCESS);
sharedViewModel.pushReceipt(request);

View File

@ -154,7 +154,6 @@ public class QRSettlementTransactionFragment extends DataBindingFragment impleme
settlementViewModel.isNoData.setValue(false);
}
// Set settlement data for display
setupSettlementDisplayData();
} else {
@ -198,6 +197,11 @@ public class QRSettlementTransactionFragment extends DataBindingFragment impleme
payDetail.setTransactionType(TransactionsType.MMQR_SETTLEMENT.value);
payDetail.setTransType(TransactionsType.MMQR_SETTLEMENT.name);
payDetail.setAmount(totalAmount);
payDetail.setTradeAnswerCode("000");
sharedViewModel.insertPayDetail(payDetail);
sharedViewModel.setAmount(String.valueOf(qrSaleAmount - qrRefundAmount));
sharedViewModel.payDetail.setValue(payDetail);
sharedViewModel.payDetails.setValue(qrTransactionsList);
}
@ -209,8 +213,11 @@ public class QRSettlementTransactionFragment extends DataBindingFragment impleme
}
private void navigateToResult() {
routeId = R.id.action_QRSettlementTransactionFragment_to_transactionResultFragment;
safeNavigateToRouteId();
delayFunctionCall(()->{
routeId = R.id.action_QRSettlementTransactionFragment_to_transactionResultFragment;
safeNavigateToRouteId();
},500);
}
private void updateData() {
@ -238,7 +245,6 @@ public class QRSettlementTransactionFragment extends DataBindingFragment impleme
public void onConfirm() {
if (!qrTransactionsList.isEmpty()) {
for (PayDetail payDetail : qrTransactionsList) {
// Mark as settled or delete based on your business logic
settlementViewModel.deletePayDetail(payDetail);
}

View File

@ -391,7 +391,7 @@ public class SettlementTransactionFragment extends DataBindingFragment implement
settlementViewModel.startSettlementProcess();
showLoadingDialog("Sending ...");
} else if(sharedViewModel.getTransMenu().getValue() == TransMenu.REVIEW_BATCH) {
sharedViewModel.startPrintProcessSettlement();
sharedViewModel.startPrintSettlement();
} else if(sharedViewModel.getTransMenu().getValue() == TransMenu.LAST_SETTLEMENT) {
routeId = R.id.action_settlementTransactionFragment_to_reprintReceiptFragment;
safeNavigateToRouteId();

View File

@ -4,6 +4,12 @@ import org.junit.Test;
import static org.junit.Assert.*;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
/**
* Example local unit test, which will execute on the development machine (host).
*
@ -16,5 +22,25 @@ public class ExampleUnitTest {
}
public static String formatTimestampToGMT630(long timestampMillis) {
ZoneId gmt630Zone = ZoneId.of("+06:30");
String pattern = "d MMM yyyy hh:mm a";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern, Locale.US);
Instant instant = Instant.ofEpochSecond(timestampMillis);
ZonedDateTime zonedDateTime = instant.atZone(gmt630Zone);
return zonedDateTime.format(formatter);
}
@Test
public void testTimeStamp() {
long timestamp = 1765228580;
String dateTime = formatTimestampToGMT630(timestamp);
System.out.println("Formatted Date and Time: " + dateTime);
}
}

View File

@ -242,6 +242,9 @@ public class KPayQRQueryRequest {
@SerializedName("sign_type")
private String signType;
@SerializedName("Wallet_identifier")
private String walletIdentifier;
public Response() {
}
@ -307,6 +310,8 @@ public class KPayQRQueryRequest {
public String getPaySuccessTime() { return paySuccessTime; }
public String getWalletIdentifier() { return walletIdentifier; }
public void setPaySuccessTime(String paySuccessTime) { this.paySuccessTime = paySuccessTime; }
public void setMmOrderId(String mmOrderId) { this.mmOrderId = mmOrderId;}
@ -350,6 +355,10 @@ public class KPayQRQueryRequest {
public void setSignType(String signType) {
this.signType = signType;
}
public void setWalletIdentifier(String walletIdentifier) {
this.walletIdentifier = walletIdentifier;
}
}
public boolean checkResponse() {

View File

@ -289,6 +289,9 @@ public class KPayRefund {
@SerializedName("refund_currency")
private String refundCurrency;
@SerializedName("Wallet_identifier")
private String walletIdentifier;
public RefundResp() {
}
@ -366,6 +369,8 @@ public class KPayRefund {
return refundCurrency;
}
public String getWalletIdentifier() {return walletIdentifier; }
public void setMsg(String msg) {
this.msg = msg;
}
@ -421,6 +426,10 @@ public class KPayRefund {
public void setRefundCurrency(String refundCurrency) {
this.refundCurrency = refundCurrency;
}
public void setWalletIdentifier(String walletIdentifier) {
this.walletIdentifier = walletIdentifier;
}
}
}

Binary file not shown.

View File

@ -11,6 +11,10 @@ import com.sunmi.pay.hardware.aidl.AidlConstants;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import com.utsmyanmar.paylibs.utils.LogUtil;
@ -222,6 +226,31 @@ public class PrintUtils {
return formatter.format(amounts);
}
public String getSeparatorOnlyNumberFormat(long amount) {
if (amount == 0) return "0";
DecimalFormat formatter = new DecimalFormat("#,###");
int x = 2;
BigDecimal unscaled = new BigDecimal(amount);
BigDecimal scaled = unscaled.scaleByPowerOfTen(-x);
double amounts = Double.parseDouble(scaled.toString());
return formatter.format(amounts);
}
public String formatTimestamp(long timestampMillis) {
ZoneId gmt630Zone = ZoneId.of("+06:30");
String pattern = "d MMM yyyy hh:mm a";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern, Locale.US);
Instant instant = Instant.ofEpochSecond(timestampMillis);
ZonedDateTime zonedDateTime = instant.atZone(gmt630Zone);
return zonedDateTime.format(formatter);
}
public String getCardHolderName(String cardHolderName) {
if (cardHolderName != null) {
return cardHolderName.replaceAll("\\s{2,}", "").trim();

View File

@ -43,6 +43,7 @@ import java.util.stream.Collectors;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.disposables.Disposable;
import com.utsmyanmar.paylibs.utils.LogUtil;
public abstract class BaseXPrint {
@ -82,9 +83,6 @@ public abstract class BaseXPrint {
protected FontEntity fontBig = new FontEntity(DotMatrixFontEnum.CH_SONG_24X24, DotMatrixFontEnum.ASC_SONG_12X24, false, true);
public static byte[] boldOn() {
byte[] result = new byte[3];
result[0] = 0x1B;
@ -109,8 +107,9 @@ public abstract class BaseXPrint {
// LogUtil.d(TAG, Arrays.toString(returnText));
// printer.setTypeface(Typeface.DEFAULT);
Resources resources = PayLibsUtils.getInstance().context.getResources();
printer.setTypeface(Typeface.createFromAsset(PayLibsUtils.getInstance().context.getAssets(), "rubik_medium.ttf"));
printer.setTypeface(Typeface.createFromAsset(PayLibsUtils.getInstance().context.getAssets(), "consolas.ttf"));
printer.setGray(getGrayLevel());
}
private GrayLevelEnum getGrayLevel() {
@ -186,6 +185,11 @@ public abstract class BaseXPrint {
}
protected void dashBreakEnding() {
printer.appendPrnStr("--------X----------X----------", fontNormal, AlignEnum.LEFT);
}
protected void breakingLine() {
printer.appendPrnStr("******************************", fontNormal, AlignEnum.LEFT);
@ -589,6 +593,10 @@ public abstract class BaseXPrint {
printer.printColumnsString(new String[]{"TOTAL(MMK)", countStringFormat(totalCount), PrintUtils.getInstance().getSeparatorNumberFormat(totalAmount)}, new int[]{3, 1, 2}, new int[]{0, 1, 2}, innerResultCallback);
}*/
protected void printString(String text) {
printer.appendPrnStr(text, fontNormal, AlignEnum.LEFT);
}
protected void print2ColumnsString(String first, String second) {
printer.appendPrnStr(first + " " + second, fontNormal, AlignEnum.LEFT);
}
@ -681,6 +689,39 @@ public abstract class BaseXPrint {
emptyLine(2);
}
protected void printQRSettlementTransDetail(List<PayDetail> lists) {
long totalAmount = 0;
long refundTotal = 0;
for (PayDetail pay : lists) {
printString("Trans Id: " + pay.getQrTransId());
printString("Status : " + pay.getTC());
printString("Date : " + PrintUtils.getInstance().formatTimestamp(Long.parseLong(pay.getTradeDateAndTime())));
printString("Amount : " + "MMK " + PrintUtils.getInstance().getSeparatorOnlyNumberFormat(pay.getAmount()));
if (pay.getTransactionType() == TransactionsType.MMQR_REFUND.value) {
refundTotal += pay.getAmount();
} else {
totalAmount += pay.getAmount();
}
emptyLine(1);
}
dashBreak();
print2ColumnsString("Refund Total:MMK", PrintUtils.getInstance().getSeparatorOnlyNumberFormat(refundTotal));
dashBreak();
print2ColumnsString("Sale Total:MMK", PrintUtils.getInstance().getSeparatorOnlyNumberFormat(totalAmount));
dashBreakEnding();
emptyLine(2);
}
private void printErrorBlock(String msg) {
@ -729,8 +770,6 @@ public abstract class BaseXPrint {
printer.appendPrnStr(cvmText, fontBold, AlignEnum.CENTER);
// if (payDetail.getIsFreeSign()) {
// printer.printText("NO SIGNATURE REQUIRED", innerResultCallback);
// } else {
@ -849,7 +888,7 @@ public abstract class BaseXPrint {
protected void startPrintNex() {
if(printer.getStatus() != SdkResult.Success) {
if (printer.getStatus() != SdkResult.Success) {
callbackStatus.onFailure();
}

View File

@ -41,7 +41,7 @@ public class PrintXImpl extends BaseXPrint implements PrintX {
SimpleDateFormat dfm = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss", Locale.getDefault());
currentTime = dfm.format(new Date());
BitmapFactory.Options opts = new BitmapFactory.Options();
bitmap = BitmapFactory.decodeResource(resources, R.drawable.print_kbz_logo, opts);
bitmap = BitmapFactory.decodeResource(resources, R.drawable.print_kbz_logo_new, opts);
}
@ -214,7 +214,7 @@ public class PrintXImpl extends BaseXPrint implements PrintX {
printLogo();
printMerchantHeader();
printTransHeader(payDetail);
printTransDetailReport(list,HostType.QR);
printQRSettlementTransDetail(list);
printTransFooterSummary();
emptyLine(1);

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -4,6 +4,8 @@ import org.junit.Test;
import static org.junit.Assert.*;
import com.utsmyanmar.paylibs.print.PrintUtils;
/**
* Example local unit test, which will execute on the development machine (host).
*
@ -14,4 +16,14 @@ public class ExampleUnitTest {
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
@Test
public void testSeparatorOnlyNumberFormat() {
long num = 500000;
String converted = PrintUtils.getInstance().getSeparatorOnlyNumberFormat(num);
System.out.println("Converted Number: " + converted);
}
}