update refund certificate download logic

This commit is contained in:
MooN 2025-12-28 13:42:24 +06:30
parent e1dacaadcb
commit 062533662f
8 changed files with 131 additions and 40 deletions

View File

@ -18,15 +18,20 @@ public class QRPayViewModel extends ViewModel {
private final Repository repository;
private final LiveData<List<PayDetail>> refundableHistory;
private final RefundCertificateManager refundCertificateManager;
private final MutableLiveData<PayDetail> _payDetail = new MutableLiveData<>();
public LiveData<PayDetail> payDetail = _payDetail;
@Inject
public QRPayViewModel(Repository repository){
public QRPayViewModel(
Repository repository,
RefundCertificateManager refundCertificateManager
){
this.repository = repository;
this.refundableHistory = repository.getRefundableQRHistory();
this.refundCertificateManager = refundCertificateManager;
}
public LiveData<List<PayDetail>> getRefundableQrHistory(){
@ -37,6 +42,10 @@ public class QRPayViewModel extends ViewModel {
_payDetail.setValue(payDetail);
}
public void checkCertificateFiles(){
refundCertificateManager.updateCertificateFiles();
}
public Runnable onCancel;
public Runnable onConfirm;
}

View File

@ -80,6 +80,7 @@ public class QRRefundFragment extends DataBindingFragment {
recyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
recyclerView.setAdapter(adapter);
emptyStateView = view.findViewById(R.id.emptyStateSectionRefund);
qrPayViewModel.checkCertificateFiles();
observeData();
}

View File

@ -0,0 +1,71 @@
package com.utsmm.kbz.ui.qr_pay;
import android.util.Log;
import com.utsmm.kbz.util.DownloadUtil;
import com.utsmyanmar.baselib.util.EReceiptHelper;
import com.utsmyanmar.paylibs.utils.LogUtil;
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation;
import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public class RefundCertificateManager {
private static final String TAG = RefundCertificateManager.class.getSimpleName();
private static final String CERTIFICATE_FILENAME = "refund_client_certificate";
private static final String CERTIFICATE_CLIENT = "refund_client_certificate";
// String tmsAddress = SystemParamsOperation.getInstance().getTmsAddress(); //for uat
String tmsAddress = SystemParamsOperation.getInstance().getTmsAddress() + "/api/v1";
String downloadAddress = tmsAddress + "/file/download?filePath=";
String certificate_url = SystemParamsOperation.getInstance().getCertificateUrl();
String certificate_client = SystemParamsOperation.getInstance().getCertificateClientUrl();
private static final String E_RECEIPT_SECRET = com.utsmyanmar.baselib.BuildConfig.ERECEIPT_SECRET;
String timestamp = String.valueOf(System.currentTimeMillis());
@Inject
public RefundCertificateManager(){}
public void updateCertificateFiles(){
String signature = generateSignature(timestamp);
DownloadUtil.downloadCertificateRx(
downloadAddress + certificate_url,
CERTIFICATE_FILENAME,
timestamp,
signature,
path -> {
if(path != null){
SystemParamsOperation.getInstance().setCertClientFilePath(path);
LogUtil.d(TAG, "Cert file path saved in SystemParams => " + path);
}else{
LogUtil.e(TAG, "Failed to download certificate file");
}
}
);
DownloadUtil.downloadCertificateRx(
downloadAddress + certificate_client,
CERTIFICATE_CLIENT,
timestamp,
signature,
path -> {
if(path != null){
SystemParamsOperation.getInstance().setCertClientFilePath(path);
LogUtil.d(TAG, "Cert client file path saved in SystemParams => " + path);
}else{
LogUtil.e(TAG, "Failed to download certificate client file");
}
}
);
}
private static String generateSignature(String timestamp) {
LogUtil.d(TAG, "timestamp " + timestamp);
String bodyString = "{}";
String dataToHash = bodyString + E_RECEIPT_SECRET + timestamp;
return EReceiptHelper.sha256(dataToHash);
}
}

View File

@ -625,51 +625,20 @@ public class TMSSetupsImpl implements TMSSetups{
SystemParamsOperation.getInstance().setQrRefundEnable(parseBoolean(data));
} else if (TextUtils.equals(name, "tpdu_value")){
SystemParamsOperation.getInstance().setTpduValue(data);
} else if (TextUtils.equals(name, "certificate_file")){
}
else if(TextUtils.equals(name, "certificate_file")){
if (TextUtils.isEmpty(data)) {
LogUtil.e(TAG, "certificate_file value NULL from TMS");
continue;
}
String tmsAddress = SystemParamsOperation.getInstance().getTmsAddress();
if (TextUtils.isEmpty(tmsAddress)) {
LogUtil.e(TAG, "TMS address is NULL — cannot download certificate");
continue; // or return;
SystemParamsOperation.getInstance().setCertificateUrl(data);
}
// String url = tmsAddress+"/file/download?filePath="+data;
String url = tmsAddress+"/api/v1/file/download?filePath="+data; //for local
DownloadUtil.downloadCertificateRx(url, "certificate_file", timestamp, signature, path -> {
if(path != null){
SystemParamsOperation.getInstance().setCertFilePath(path);
LogUtil.d(TAG, "Cert file path saved in SystemParams => " + path);
}else{
LogUtil.e(TAG, "Failed to download certificate file");
}
});
} else if (TextUtils.equals(name, "certificate_client")){
else if(TextUtils.equals(name, "certificate_client")){
if (TextUtils.isEmpty(data)) {
LogUtil.e(TAG, "certificate_file value NULL from TMS");
continue;
}
String tmsAddress = SystemParamsOperation.getInstance().getTmsAddress();
if (TextUtils.isEmpty(tmsAddress)) {
LogUtil.e(TAG, "TMS address is NULL — cannot download certificate");
continue; // or return;
}
// String url = tmsAddress+"/file/download?filePath="+data;
String url = tmsAddress+"/api/v1/file/download?filePath="+data; //for local
DownloadUtil.downloadCertificateRx(url, "certificate_client" , timestamp, signature, path -> {
if(path != null){
SystemParamsOperation.getInstance().setCertClientFilePath(path);
LogUtil.d(TAG, "Cert client file path saved in SystemParams => " + path);
}else{
LogUtil.e(TAG, "Failed to download certificate client file");
}
});
SystemParamsOperation.getInstance().setCertificateClientUrl(data);
}
else if (TextUtils.equals(name, "certificate_password")) {
SystemParamsOperation.getInstance().setCertificatePassword(data);

View File

@ -389,6 +389,7 @@ public class NetworkModule {
//@Reusable
//@KPayRefundRetrofit
@Provides
@Singleton
@KPayRefundRetrofit
public Retrofit provideKPayRefundRetrofit(@ApplicationContext Context context) {

View File

@ -29,5 +29,5 @@ android.useAndroidX=true
android.nonTransitiveRClass=true
# Disable Android Studio's Jetifier to avoid conflicts
android.enableJetifier=false
#ERECEIPT_SECRET=y812J21lhha11OS
ERECEIPT_SECRET=8f4df38d1001bcc4620b5c736c66a03eef4653eb3ba31105faa2f2ee294c4a46
ERECEIPT_SECRET=y812J21lhha11OS
#ERECEIPT_SECRET=8f4df38d1001bcc4620b5c736c66a03eef4653eb3ba31105faa2f2ee294c4a46

View File

@ -1698,4 +1698,26 @@ public class SystemParamsOperation {
SystemParamsSettings paramsSettings = getSystemParamsSettings();
return paramsSettings.getMerchantAddress3();
}
public void setCertificateUrl(String url) {
SystemParamsSettings paramsSettings = getSystemParamsSettings();
paramsSettings.setCertificateUrl(url);
saveSystemParamsSettings(paramsSettings);
}
public String getCertificateUrl(){
SystemParamsSettings paramsSettings = getSystemParamsSettings();
return paramsSettings.getCertificateUrl();
}
public String getCertificateClientUrl() {
SystemParamsSettings paramsSettings = getSystemParamsSettings();
return paramsSettings.getCertificateClientUrl();
}
public void setCertificateClientUrl(String url) {
SystemParamsSettings paramsSettings = getSystemParamsSettings();
paramsSettings.setCertificateClientUrl(url);
saveSystemParamsSettings(paramsSettings);
}
}

View File

@ -255,6 +255,8 @@ public class SystemParamsSettings implements Serializable {
private String certClientFilePath = "";
private String certificatePassword = "";
private String terminalIdForEreceipt = "";
private String certificateUrl = "";
private String certificateClientUrl = "";
public boolean isQrPartialRefundEnable(){
return qrPartialRefundEnable;
@ -1038,6 +1040,22 @@ public class SystemParamsSettings implements Serializable {
return secHostId;
}
public void setCertificateUrl(String url) {
this.certificateUrl = url;
}
public String getCertificateUrl(){
return certificateUrl;
}
public String getCertificateClientUrl() {
return certificateClientUrl;
}
public void setCertificateClientUrl(String url) {
this.certificateClientUrl = url;
}
/* // 流水号起始
private String serialNum = Configs.getInstance().SERIAL_NUM();
// 批次号起始