corrected refund flow
This commit is contained in:
parent
28d4672878
commit
476e1d9eaa
10
.idea/migrations.xml
Normal file
10
.idea/migrations.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectMigrations">
|
||||||
|
<option name="MigrateToGradleLocalJavaHome">
|
||||||
|
<set>
|
||||||
|
<option value="$PROJECT_DIR$" />
|
||||||
|
</set>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@ -144,7 +144,7 @@ public class InputPasswordFragment extends DataBindingFragment implements DataBi
|
|||||||
switch (Objects.requireNonNull(sharedViewModel.transactionsType.getValue())) {
|
switch (Objects.requireNonNull(sharedViewModel.transactionsType.getValue())) {
|
||||||
case MMQR_REFUND:
|
case MMQR_REFUND:
|
||||||
inputPasswordViewModel.passwordType.setValue(InputPasswordType.SYSTEM);
|
inputPasswordViewModel.passwordType.setValue(InputPasswordType.SYSTEM);
|
||||||
routeId = R.id.action_inputPasswordFragment_to_qrRefundList;
|
routeId = R.id.action_inputPasswordFragment_to_QRRefundProcessFragment;
|
||||||
break;
|
break;
|
||||||
case PRE_AUTH_COMPLETE_VOID:
|
case PRE_AUTH_COMPLETE_VOID:
|
||||||
inputPasswordViewModel.passwordType.setValue(InputPasswordType.SYSTEM);
|
inputPasswordViewModel.passwordType.setValue(InputPasswordType.SYSTEM);
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import androidx.lifecycle.MutableLiveData;
|
|||||||
import androidx.lifecycle.ViewModel;
|
import androidx.lifecycle.ViewModel;
|
||||||
|
|
||||||
import com.kizzy.xpay.util.Sign;
|
import com.kizzy.xpay.util.Sign;
|
||||||
|
import com.utsmm.kbz.ui.qr_pay.QRRefund;
|
||||||
import com.utsmyanmar.baselib.network.model.DemoQRRequest;
|
import com.utsmyanmar.baselib.network.model.DemoQRRequest;
|
||||||
import com.utsmyanmar.baselib.network.model.DemoQRResponse;
|
import com.utsmyanmar.baselib.network.model.DemoQRResponse;
|
||||||
import com.utsmyanmar.baselib.network.model.DemoQRReturnRequest;
|
import com.utsmyanmar.baselib.network.model.DemoQRReturnRequest;
|
||||||
@ -66,6 +67,7 @@ public class KPayViewModel extends ViewModel {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private String generateRandomTwoChars() {
|
private String generateRandomTwoChars() {
|
||||||
// You can reuse the existing character set and SecureRandom instance
|
// You can reuse the existing character set and SecureRandom instance
|
||||||
StringBuilder randomChars = new StringBuilder(3);
|
StringBuilder randomChars = new StringBuilder(3);
|
||||||
@ -292,6 +294,16 @@ public class KPayViewModel extends ViewModel {
|
|||||||
private TradeData tradeData;
|
private TradeData tradeData;
|
||||||
private PayDetail payDetail;
|
private PayDetail payDetail;
|
||||||
|
|
||||||
|
private QRRefund qrRefund;
|
||||||
|
|
||||||
|
public QRRefund getQrRefund() {
|
||||||
|
return qrRefund;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQrRefund(QRRefund qrRefund) {
|
||||||
|
this.qrRefund = qrRefund;
|
||||||
|
}
|
||||||
|
|
||||||
public void setTradeData(TradeData tradeData){
|
public void setTradeData(TradeData tradeData){
|
||||||
this.tradeData = tradeData;
|
this.tradeData = tradeData;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -136,8 +136,8 @@ public class QRPayFragment extends DataBindingFragment {
|
|||||||
|
|
||||||
private void onClickRefund(){
|
private void onClickRefund(){
|
||||||
sharedViewModel.setTransactionsType(TransactionsType.MMQR_REFUND);
|
sharedViewModel.setTransactionsType(TransactionsType.MMQR_REFUND);
|
||||||
// routeId = R.id.action_qrFragment_to_qr_refund_list;
|
routeId = R.id.action_qrFragment_to_qr_refund_list;
|
||||||
routeId = R.id.action_qrFragment_to_inputPasswordFragment;
|
// routeId = R.id.action_qrFragment_to_inputPasswordFragment;
|
||||||
safeNavigateToRouteId();
|
safeNavigateToRouteId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
49
app/src/main/java/com/utsmm/kbz/ui/qr_pay/QRRefund.java
Normal file
49
app/src/main/java/com/utsmm/kbz/ui/qr_pay/QRRefund.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package com.utsmm.kbz.ui.qr_pay;
|
||||||
|
|
||||||
|
public class QRRefund {
|
||||||
|
|
||||||
|
private String referenceNo;
|
||||||
|
private String refundAmount;
|
||||||
|
private String originalAmount;
|
||||||
|
private String reason;
|
||||||
|
|
||||||
|
public QRRefund(String referenceNo, String refundAmount, String originalAmount, String reason) {
|
||||||
|
this.referenceNo = referenceNo;
|
||||||
|
this.refundAmount = refundAmount;
|
||||||
|
this.originalAmount = originalAmount;
|
||||||
|
this.reason = reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReferenceNo() {
|
||||||
|
return referenceNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReferenceNo(String referenceNo) {
|
||||||
|
this.referenceNo = referenceNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRefundAmount() {
|
||||||
|
return refundAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRefundAmount(String refundAmount) {
|
||||||
|
this.refundAmount = refundAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOriginalAmount() {
|
||||||
|
return originalAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOriginalAmount(String originalAmount) {
|
||||||
|
this.originalAmount = originalAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReason() {
|
||||||
|
return reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReason(String reason) {
|
||||||
|
this.reason = reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -13,12 +13,9 @@ import androidx.annotation.Nullable;
|
|||||||
|
|
||||||
import com.utsmm.kbz.ui.kpay.KPayViewModel;
|
import com.utsmm.kbz.ui.kpay.KPayViewModel;
|
||||||
import com.utsmyanmar.baselib.fragment.DataBindingFragment;
|
import com.utsmyanmar.baselib.fragment.DataBindingFragment;
|
||||||
import com.utsmyanmar.baselib.network.model.KPayRefund;
|
|
||||||
import com.utsmyanmar.baselib.util.DataBindingConfig;
|
import com.utsmyanmar.baselib.util.DataBindingConfig;
|
||||||
import com.utsmyanmar.paylibs.model.PayDetail;
|
import com.utsmyanmar.paylibs.model.PayDetail;
|
||||||
import com.utsmyanmar.paylibs.model.TradeData;
|
import com.utsmyanmar.paylibs.model.TradeData;
|
||||||
import com.utsmyanmar.paylibs.system.SystemDateTime;
|
|
||||||
import com.utsmyanmar.paylibs.utils.POSUtil;
|
|
||||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation;
|
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation;
|
||||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType;
|
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType;
|
||||||
import com.utsmm.kbz.BR;
|
import com.utsmm.kbz.BR;
|
||||||
@ -31,14 +28,13 @@ import com.utsmm.kbz.util.ecr.CoreUtils;
|
|||||||
|
|
||||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
||||||
import io.reactivex.rxjava3.disposables.Disposable;
|
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||||
import com.utsmyanmar.paylibs.utils.LogUtil;
|
import com.utsmyanmar.paylibs.utils.LogUtil;
|
||||||
|
|
||||||
public class QRRefundDetailFragment extends DataBindingFragment {
|
public class QRRefundDetailFragment extends DataBindingFragment {
|
||||||
|
|
||||||
private SharedViewModel sharedViewModel;
|
private SharedViewModel sharedViewModel;
|
||||||
private KPayViewModel KPayViewModel;
|
private KPayViewModel kPayViewModel;
|
||||||
private int routeId;
|
private int routeId;
|
||||||
|
|
||||||
|
|
||||||
@ -53,8 +49,7 @@ public class QRRefundDetailFragment extends DataBindingFragment {
|
|||||||
|
|
||||||
private boolean isPartialRefund = false;
|
private boolean isPartialRefund = false;
|
||||||
|
|
||||||
CompositeDisposable refundDisposable = new CompositeDisposable();
|
|
||||||
CompositeDisposable retrieveUpdateDisposable = new CompositeDisposable();
|
|
||||||
|
|
||||||
private static final String TAG = com.utsmm.kbz.ui.kpay.QRRefundFragment.class.getSimpleName();
|
private static final String TAG = com.utsmm.kbz.ui.kpay.QRRefundFragment.class.getSimpleName();
|
||||||
|
|
||||||
@ -64,13 +59,13 @@ public class QRRefundDetailFragment extends DataBindingFragment {
|
|||||||
@Override
|
@Override
|
||||||
protected void initViewModel() {
|
protected void initViewModel() {
|
||||||
sharedViewModel = getFragmentScopeViewModel(SharedViewModel.class);
|
sharedViewModel = getFragmentScopeViewModel(SharedViewModel.class);
|
||||||
KPayViewModel = getFragmentScopeViewModel(KPayViewModel.class);
|
kPayViewModel = getFragmentScopeViewModel(KPayViewModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DataBindingConfig getDataBindingConfig() {
|
protected DataBindingConfig getDataBindingConfig() {
|
||||||
return new DataBindingConfig(R.layout.fragment_qr_refund_detail, BR.sharedViewModel, sharedViewModel)
|
return new DataBindingConfig(R.layout.fragment_qr_refund_detail, BR.sharedViewModel, sharedViewModel)
|
||||||
.addBindingParam(BR.kPayViewModel, KPayViewModel)
|
.addBindingParam(BR.kPayViewModel, kPayViewModel)
|
||||||
.addBindingParam(BR.click, new ClickEvent());
|
.addBindingParam(BR.click, new ClickEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,15 +96,10 @@ public class QRRefundDetailFragment extends DataBindingFragment {
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
setToolBarTitleWithBackIcon("KPay Refund");
|
setToolBarTitleWithBackIcon("KPay Refund");
|
||||||
KPayViewModel.invalidAmountMsg.setValue("");
|
kPayViewModel.invalidAmountMsg.setValue("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroyView() {
|
|
||||||
super.onDestroyView();
|
|
||||||
refundDisposable.dispose();
|
|
||||||
retrieveUpdateDisposable.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
@ -165,130 +155,6 @@ public class QRRefundDetailFragment extends DataBindingFragment {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processKPayRefund(String referenceNo, String refundAmount, String originalAmount, String reason) {
|
|
||||||
String merchantId = TransactionUtil.getInstance().getQRMerchantId();
|
|
||||||
|
|
||||||
// Generate unique refund request ID
|
|
||||||
String refundRequestId = referenceNo + "R";
|
|
||||||
|
|
||||||
showLoadingDialog("Processing refund...");
|
|
||||||
|
|
||||||
// Create KPay refund request
|
|
||||||
KPayRefund.RefundRequest refundRequest = KPayViewModel.createRefundRequest(
|
|
||||||
refundRequestId,
|
|
||||||
referenceNo,
|
|
||||||
merchantId,
|
|
||||||
refundAmount,
|
|
||||||
reason != null ? reason : "Refund request"
|
|
||||||
);
|
|
||||||
|
|
||||||
Disposable refundDi = KPayViewModel.kPayRefund(refundRequest)
|
|
||||||
.subscribeOn(Schedulers.io())
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe(
|
|
||||||
response -> {
|
|
||||||
dismissLoadingDialog();
|
|
||||||
handleRefundResponse(response, referenceNo);
|
|
||||||
},
|
|
||||||
throwable -> {
|
|
||||||
dismissLoadingDialog();
|
|
||||||
LogUtil.e(TAG, "Refund error: " + throwable.getMessage());
|
|
||||||
showDeclineDialog("Refund failed!\nCommunication Error!");
|
|
||||||
ecrActionCancel("Refund failed");
|
|
||||||
navigateToMain();
|
|
||||||
},
|
|
||||||
() -> LogUtil.d(TAG, "Refund request completed")
|
|
||||||
);
|
|
||||||
|
|
||||||
refundDisposable.add(refundDi);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleRefundResponse(KPayRefund.RefundResponse response, String referenceNo) {
|
|
||||||
if (response != null && response.getResponse() != null && "REFUND_SUCCESS".equalsIgnoreCase(response.getResponse().getRefundStatus())) {
|
|
||||||
LogUtil.d(TAG, "Refund successful!");
|
|
||||||
|
|
||||||
String refundAmount = response.getResponse().getRefundAmount();
|
|
||||||
|
|
||||||
String dateTime = SystemDateTime.getTodayDateFormat() + " " + SystemDateTime.getTodayTimeFormat();
|
|
||||||
payDetail.setAmount(refundAmount == null ? 0 : POSUtil.getInstance().convertAmount(refundAmount));
|
|
||||||
payDetail.setOriginalTransDate(dateTime);
|
|
||||||
payDetail.setQrTransStatus(1);
|
|
||||||
payDetail.setQrReferNo(referenceNo);
|
|
||||||
payDetail.setReferNo(referenceNo);
|
|
||||||
payDetail.setIsCanceled(true);
|
|
||||||
|
|
||||||
retrievedUpdatePayDetail(referenceNo);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
LogUtil.d(TAG, "Refund failed!");
|
|
||||||
payDetail.setQrTransStatus(-1);
|
|
||||||
payDetail.setQrReferNo(referenceNo);
|
|
||||||
payDetail.setReferNo(referenceNo);
|
|
||||||
|
|
||||||
String errorMsg = "Refund failed";
|
|
||||||
if (response != null && response.getResponse() != null && response.getResponse().getMsg() != null) {
|
|
||||||
errorMsg = response.getResponse().getMsg();
|
|
||||||
}
|
|
||||||
payDetail.setTradeResultDes(errorMsg);
|
|
||||||
|
|
||||||
sharedViewModel.payDetail.setValue(payDetail);
|
|
||||||
navigateToNext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void retrievedUpdatePayDetail(String refNum) {
|
|
||||||
LogUtil.d(TAG, "Trying to update Database!");
|
|
||||||
retrieveUpdateDisposable.add(KPayViewModel.searchPayByRefNum(refNum)
|
|
||||||
.subscribeOn(Schedulers.io())
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe(oldPay -> {
|
|
||||||
LogUtil.d(TAG, "Inside the subscribe!");
|
|
||||||
if (oldPay != null) {
|
|
||||||
oldPay.setIsCanceled(true);
|
|
||||||
payDetail.setQrTransId(oldPay.getQrTransId());
|
|
||||||
payDetail.setCustomerMobile(oldPay.getCustomerMobile());
|
|
||||||
sharedViewModel.updatePayDetail(oldPay);
|
|
||||||
}
|
|
||||||
updateData();
|
|
||||||
navigateToNext();
|
|
||||||
},
|
|
||||||
onError -> {
|
|
||||||
LogUtil.d(TAG, "On error Unable to retrieve PayDetail");
|
|
||||||
updateData();
|
|
||||||
navigateToNext();
|
|
||||||
},
|
|
||||||
() -> {
|
|
||||||
LogUtil.d(TAG, "No data found! navigating to Result Page!");
|
|
||||||
updateData();
|
|
||||||
navigateToNext();
|
|
||||||
}
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateData() {
|
|
||||||
KPayViewModel.insertPayDetail(payDetail);
|
|
||||||
sharedViewModel.payDetail.postValue(payDetail);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void navigateToMain() {
|
|
||||||
routeId = R.id.action_QRRefundDetail_to_nav_main;
|
|
||||||
safeNavigateToRouteId();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void navigateToNext() {
|
|
||||||
routeId = R.id.action_QRRefundDetail_to_transactionResultFragment;
|
|
||||||
safeNavigateToRouteId();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ecrActionCancel(String msg) {
|
|
||||||
if (sharedViewModel.isEcr.getValue() != null) {
|
|
||||||
if (sharedViewModel.isEcr.getValue()) {
|
|
||||||
sharedViewModel.isEcr.postValue(false);
|
|
||||||
CoreUtils.getInstance(sharedViewModel).responseRejectMsg(msg);
|
|
||||||
sharedViewModel.isEcrFinished.postValue(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ClickEvent {
|
public class ClickEvent {
|
||||||
|
|
||||||
@ -297,14 +163,14 @@ public class QRRefundDetailFragment extends DataBindingFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onConfirm() {
|
public void onConfirm() {
|
||||||
KPayViewModel.invalidAmountMsg.setValue("");
|
kPayViewModel.invalidAmountMsg.setValue("");
|
||||||
|
|
||||||
String referenceNo = etReferenceNo.getText().toString().trim();
|
String referenceNo = etReferenceNo.getText().toString().trim();
|
||||||
String refundReason = etRefundReason.getText().toString().trim();
|
String refundReason = etRefundReason.getText().toString().trim();
|
||||||
|
|
||||||
// Validate reference number
|
// Validate reference number
|
||||||
if (referenceNo.isEmpty()) {
|
if (referenceNo.isEmpty()) {
|
||||||
KPayViewModel.invalidAmountMsg.setValue("Enter reference number");
|
kPayViewModel.invalidAmountMsg.setValue("Enter reference number");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,12 +180,12 @@ public class QRRefundDetailFragment extends DataBindingFragment {
|
|||||||
String refundAmountStr = etRefundAmount.getText().toString().trim();
|
String refundAmountStr = etRefundAmount.getText().toString().trim();
|
||||||
|
|
||||||
if (originalAmountStr.isEmpty()) {
|
if (originalAmountStr.isEmpty()) {
|
||||||
KPayViewModel.invalidAmountMsg.setValue("Enter original amount");
|
kPayViewModel.invalidAmountMsg.setValue("Enter original amount");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (refundAmountStr.isEmpty()) {
|
if (refundAmountStr.isEmpty()) {
|
||||||
KPayViewModel.invalidAmountMsg.setValue("Enter refund amount");
|
kPayViewModel.invalidAmountMsg.setValue("Enter refund amount");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,31 +193,38 @@ public class QRRefundDetailFragment extends DataBindingFragment {
|
|||||||
double refundAmount = Double.parseDouble(refundAmountStr);
|
double refundAmount = Double.parseDouble(refundAmountStr);
|
||||||
|
|
||||||
if (originalAmount <= 0) {
|
if (originalAmount <= 0) {
|
||||||
KPayViewModel.invalidAmountMsg.setValue("Enter valid original amount");
|
kPayViewModel.invalidAmountMsg.setValue("Enter valid original amount");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (refundAmount <= 0) {
|
if (refundAmount <= 0) {
|
||||||
KPayViewModel.invalidAmountMsg.setValue("Enter valid refund amount");
|
kPayViewModel.invalidAmountMsg.setValue("Enter valid refund amount");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (refundAmount > originalAmount) {
|
if (refundAmount > originalAmount) {
|
||||||
KPayViewModel.invalidAmountMsg.setValue("Refund amount cannot exceed original amount");
|
kPayViewModel.invalidAmountMsg.setValue("Refund amount cannot exceed original amount");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
processKPayRefund(referenceNo, refundAmountStr, originalAmountStr, refundReason);
|
|
||||||
|
QRRefund qrRefund = new QRRefund(referenceNo, refundAmountStr, originalAmountStr, refundReason);
|
||||||
|
|
||||||
|
kPayViewModel.setQrRefund(qrRefund);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Original amount refund - no amount validation needed
|
QRRefund qrRefund = new QRRefund(referenceNo, "0", etOriginalAmount.getText().toString().trim(), refundReason);
|
||||||
processKPayRefund(referenceNo, "0", String.valueOf( etOriginalAmount.getText().toString().trim()), refundReason);
|
|
||||||
|
kPayViewModel.setQrRefund(qrRefund);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kPayViewModel.setPayDetail(payDetail);
|
||||||
|
|
||||||
|
navigateToPassword();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void navigateToPassword(){
|
public void navigateToPassword(){
|
||||||
sharedViewModel.transactionsType.setValue(TransactionsType.MMQR_REFUND);
|
routeId = R.id.action_QRRefundDetail_to_inputPasswordFragment;
|
||||||
routeId = R.id.action_qrRefundPasswordFragment_to_inputPasswordFragment;
|
safeNavigateToRouteId();
|
||||||
safeRouteTo(currentId,routeId,hostId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,215 @@
|
|||||||
|
package com.utsmm.kbz.ui.qr_pay;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.utsmm.kbz.BR;
|
||||||
|
import com.utsmm.kbz.R;
|
||||||
|
import com.utsmm.kbz.config.Constants;
|
||||||
|
import com.utsmm.kbz.ui.core_viewmodel.SharedViewModel;
|
||||||
|
import com.utsmm.kbz.ui.kpay.KPayViewModel;
|
||||||
|
import com.utsmm.kbz.ui.kpay.QRRefundFragment;
|
||||||
|
import com.utsmm.kbz.util.TransactionUtil;
|
||||||
|
import com.utsmm.kbz.util.ecr.CoreUtils;
|
||||||
|
import com.utsmyanmar.baselib.fragment.DataBindingFragment;
|
||||||
|
import com.utsmyanmar.baselib.network.model.KPayRefund;
|
||||||
|
import com.utsmyanmar.baselib.util.DataBindingConfig;
|
||||||
|
import com.utsmyanmar.paylibs.model.PayDetail;
|
||||||
|
import com.utsmyanmar.paylibs.system.SystemDateTime;
|
||||||
|
import com.utsmyanmar.paylibs.utils.LogUtil;
|
||||||
|
import com.utsmyanmar.paylibs.utils.POSUtil;
|
||||||
|
|
||||||
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||||
|
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
||||||
|
import io.reactivex.rxjava3.disposables.Disposable;
|
||||||
|
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||||
|
|
||||||
|
public class QRRefundProcessFragment extends DataBindingFragment {
|
||||||
|
|
||||||
|
private static final String TAG = QRRefundProcessFragment.class.getSimpleName();
|
||||||
|
private SharedViewModel sharedViewModel;
|
||||||
|
private KPayViewModel kPayViewModel;
|
||||||
|
|
||||||
|
private PayDetail payDetail;
|
||||||
|
|
||||||
|
private QRRefund qrRefund;
|
||||||
|
private static final int hostId = Constants.NAV_HOST_ID;
|
||||||
|
private int routeId;
|
||||||
|
private static final int currentId = R.id.QRRefundProcessFragment;
|
||||||
|
|
||||||
|
CompositeDisposable retrieveUpdateDisposable = new CompositeDisposable();
|
||||||
|
CompositeDisposable refundDisposable = new CompositeDisposable();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initViewModel() {
|
||||||
|
sharedViewModel = getFragmentScopeViewModel(SharedViewModel.class);
|
||||||
|
kPayViewModel = getFragmentScopeViewModel(KPayViewModel.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected DataBindingConfig getDataBindingConfig() {
|
||||||
|
return new DataBindingConfig(R.layout.fragment_qr_refund_process, BR.sharedViewModel, sharedViewModel)
|
||||||
|
.addBindingParam(BR.kPayViewModel, kPayViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
retrieveUpdateDisposable.dispose();
|
||||||
|
refundDisposable.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int currentId() {
|
||||||
|
return currentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int hostId() {
|
||||||
|
return hostId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int routeId() {
|
||||||
|
return routeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
|
initData();
|
||||||
|
|
||||||
|
processKPayRefund(qrRefund.getReferenceNo(), qrRefund.getRefundAmount(), qrRefund.getOriginalAmount(), qrRefund.getReason());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initData() {
|
||||||
|
payDetail = kPayViewModel.getPayDetail();
|
||||||
|
qrRefund = kPayViewModel.getQrRefund();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processKPayRefund(String referenceNo, String refundAmount, String originalAmount, String reason) {
|
||||||
|
String merchantId = TransactionUtil.getInstance().getQRMerchantId();
|
||||||
|
|
||||||
|
// Generate unique refund request ID
|
||||||
|
String refundRequestId = referenceNo + "R";
|
||||||
|
|
||||||
|
|
||||||
|
// Create KPay refund request
|
||||||
|
KPayRefund.RefundRequest refundRequest = kPayViewModel.createRefundRequest(
|
||||||
|
refundRequestId,
|
||||||
|
referenceNo,
|
||||||
|
merchantId,
|
||||||
|
refundAmount,
|
||||||
|
reason != null ? reason : "Refund request"
|
||||||
|
);
|
||||||
|
|
||||||
|
Disposable refundDi = kPayViewModel.kPayRefund(refundRequest)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(
|
||||||
|
response -> {
|
||||||
|
handleRefundResponse(response, referenceNo);
|
||||||
|
},
|
||||||
|
throwable -> {
|
||||||
|
LogUtil.e(TAG, "Refund error: " + throwable.getMessage());
|
||||||
|
showDeclineDialog("Refund failed!\nCommunication Error!");
|
||||||
|
ecrActionCancel("Refund failed");
|
||||||
|
navigateToMain();
|
||||||
|
},
|
||||||
|
() -> LogUtil.d(TAG, "Refund request completed")
|
||||||
|
);
|
||||||
|
|
||||||
|
refundDisposable.add(refundDi);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleRefundResponse(KPayRefund.RefundResponse response, String referenceNo) {
|
||||||
|
if (response != null && response.getResponse() != null && "REFUND_SUCCESS".equalsIgnoreCase(response.getResponse().getRefundStatus())) {
|
||||||
|
LogUtil.d(TAG, "Refund successful!");
|
||||||
|
|
||||||
|
String refundAmount = response.getResponse().getRefundAmount();
|
||||||
|
|
||||||
|
String dateTime = SystemDateTime.getTodayDateFormat() + " " + SystemDateTime.getTodayTimeFormat();
|
||||||
|
payDetail.setAmount(refundAmount == null ? 0 : POSUtil.getInstance().convertAmount(refundAmount));
|
||||||
|
payDetail.setOriginalTransDate(dateTime);
|
||||||
|
payDetail.setQrTransStatus(1);
|
||||||
|
payDetail.setQrReferNo(referenceNo);
|
||||||
|
payDetail.setReferNo(referenceNo);
|
||||||
|
payDetail.setIsCanceled(true);
|
||||||
|
|
||||||
|
retrievedUpdatePayDetail(referenceNo);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
LogUtil.d(TAG, "Refund failed!");
|
||||||
|
payDetail.setQrTransStatus(-1);
|
||||||
|
payDetail.setQrReferNo(referenceNo);
|
||||||
|
payDetail.setReferNo(referenceNo);
|
||||||
|
|
||||||
|
String errorMsg = "Refund failed";
|
||||||
|
if (response != null && response.getResponse() != null && response.getResponse().getMsg() != null) {
|
||||||
|
errorMsg = response.getResponse().getMsg();
|
||||||
|
}
|
||||||
|
payDetail.setTradeResultDes(errorMsg);
|
||||||
|
|
||||||
|
sharedViewModel.payDetail.setValue(payDetail);
|
||||||
|
navigateToNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void retrievedUpdatePayDetail(String refNum) {
|
||||||
|
LogUtil.d(TAG, "Trying to update Database!");
|
||||||
|
retrieveUpdateDisposable.add(kPayViewModel.searchPayByRefNum(refNum)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(oldPay -> {
|
||||||
|
LogUtil.d(TAG, "Inside the subscribe!");
|
||||||
|
if (oldPay != null) {
|
||||||
|
oldPay.setIsCanceled(true);
|
||||||
|
payDetail.setQrTransId(oldPay.getQrTransId());
|
||||||
|
payDetail.setCustomerMobile(oldPay.getCustomerMobile());
|
||||||
|
sharedViewModel.updatePayDetail(oldPay);
|
||||||
|
}
|
||||||
|
updateData();
|
||||||
|
navigateToNext();
|
||||||
|
},
|
||||||
|
onError -> {
|
||||||
|
LogUtil.d(TAG, "On error Unable to retrieve PayDetail");
|
||||||
|
updateData();
|
||||||
|
navigateToNext();
|
||||||
|
},
|
||||||
|
() -> {
|
||||||
|
LogUtil.d(TAG, "No data found! navigating to Result Page!");
|
||||||
|
updateData();
|
||||||
|
navigateToNext();
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateData() {
|
||||||
|
kPayViewModel.insertPayDetail(payDetail);
|
||||||
|
sharedViewModel.payDetail.postValue(payDetail);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void navigateToNext() {
|
||||||
|
routeId = R.id.action_QRRefundProcessFragment_to_transactionResultFragment;
|
||||||
|
safeNavigateToRouteId();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void navigateToMain() {
|
||||||
|
routeId = R.id.action_QRRefundProcessFragment_to_nav_main;
|
||||||
|
safeNavigateToRouteId();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ecrActionCancel(String msg) {
|
||||||
|
if (sharedViewModel.isEcr.getValue() != null) {
|
||||||
|
if (sharedViewModel.isEcr.getValue()) {
|
||||||
|
sharedViewModel.isEcr.postValue(false);
|
||||||
|
CoreUtils.getInstance(sharedViewModel).responseRejectMsg(msg);
|
||||||
|
sharedViewModel.isEcrFinished.postValue(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
44
app/src/main/res/layout/fragment_qr_refund_process.xml
Normal file
44
app/src/main/res/layout/fragment_qr_refund_process.xml
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<data>
|
||||||
|
<variable
|
||||||
|
name="sharedViewModel"
|
||||||
|
type="com.utsmm.kbz.ui.core_viewmodel.SharedViewModel" />
|
||||||
|
<variable
|
||||||
|
name="kPayViewModel"
|
||||||
|
type="com.utsmm.kbz.ui.kpay.KPayViewModel" />
|
||||||
|
</data>
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:fontFamily="@font/rubik_regular"
|
||||||
|
android:text="@string/txt_processing_refund"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
android:textSize="20sp"
|
||||||
|
app:layout_constraintEnd_toEndOf="@+id/lav_thumbUp"
|
||||||
|
app:layout_constraintStart_toStartOf="@+id/lav_thumbUp"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/lav_thumbUp" />
|
||||||
|
|
||||||
|
|
||||||
|
<com.airbnb.lottie.LottieAnimationView
|
||||||
|
android:id="@+id/lav_thumbUp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="300dp"
|
||||||
|
android:layout_margin="8dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:lottie_autoPlay="true"
|
||||||
|
app:lottie_fileName="lottie_processing_card.json"
|
||||||
|
app:lottie_loop="true" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
</layout>
|
||||||
@ -341,6 +341,12 @@
|
|||||||
app:popUpToInclusive="true"
|
app:popUpToInclusive="true"
|
||||||
android:id="@+id/action_inputPasswordFragment_to_qrRefundList"
|
android:id="@+id/action_inputPasswordFragment_to_qrRefundList"
|
||||||
app:destination="@id/qrRefundList" />
|
app:destination="@id/qrRefundList" />
|
||||||
|
<action
|
||||||
|
app:launchSingleTop="true"
|
||||||
|
app:popUpTo="@+id/inputPasswordFragment"
|
||||||
|
app:popUpToInclusive="true"
|
||||||
|
android:id="@+id/action_inputPasswordFragment_to_QRRefundProcessFragment"
|
||||||
|
app:destination="@id/QRRefundProcessFragment" />
|
||||||
|
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
@ -1148,9 +1154,27 @@
|
|||||||
<!-- app:destination="@id/inputAmountFragment" />-->
|
<!-- app:destination="@id/inputAmountFragment" />-->
|
||||||
<action
|
<action
|
||||||
app:launchSingleTop="true"
|
app:launchSingleTop="true"
|
||||||
app:popUpTo="@+id/QRRefundPasswordFragment"
|
app:popUpTo="@+id/qrRefundDetail"
|
||||||
app:popUpToInclusive="true"
|
app:popUpToInclusive="true"
|
||||||
android:id="@+id/action_qrRefundPasswordFragment_to_inputPasswordFragment"
|
android:id="@+id/action_QRRefundDetail_to_inputPasswordFragment"
|
||||||
app:destination="@id/inputPasswordFragment" />
|
app:destination="@id/inputPasswordFragment" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
<fragment
|
||||||
|
tools:layout="@layout/fragment_qr_refund_process"
|
||||||
|
android:id="@+id/QRRefundProcessFragment"
|
||||||
|
android:name="com.utsmm.kbz.ui.qr_pay.QRRefundProcessFragment"
|
||||||
|
android:label="QRRefundProcessFragment" >
|
||||||
|
<action
|
||||||
|
app:launchSingleTop="true"
|
||||||
|
app:popUpTo="@+id/QRRefundProcessFragment"
|
||||||
|
app:popUpToInclusive="true"
|
||||||
|
android:id="@+id/action_QRRefundProcessFragment_to_transactionResultFragment"
|
||||||
|
app:destination="@id/transactionResultFragment" />
|
||||||
|
<action
|
||||||
|
app:launchSingleTop="true"
|
||||||
|
app:popUpTo="@+id/QRRefundProcessFragment"
|
||||||
|
app:popUpToInclusive="true"
|
||||||
|
android:id="@+id/action_QRRefundProcessFragment_to_nav_main"
|
||||||
|
app:destination="@id/nav_main" />
|
||||||
|
</fragment>
|
||||||
</navigation>
|
</navigation>
|
||||||
@ -362,6 +362,7 @@
|
|||||||
<string name="alert_sound_title">Alert Sound</string>
|
<string name="alert_sound_title">Alert Sound</string>
|
||||||
<string name="title_echo">Echo Test</string>
|
<string name="title_echo">Echo Test</string>
|
||||||
<string name="txt_processing_card">Processing card, please wait...</string>
|
<string name="txt_processing_card">Processing card, please wait...</string>
|
||||||
|
<string name="txt_processing_refund">Processing refund, please wait...</string>
|
||||||
<string name="title_processing_card">Processing Card</string>
|
<string name="title_processing_card">Processing Card</string>
|
||||||
<string name="title_log_on">Log-On</string>
|
<string name="title_log_on">Log-On</string>
|
||||||
<string name="title_log_off">Log-Off</string>
|
<string name="title_log_off">Log-Off</string>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user