duel currency in pre-auth

This commit is contained in:
moon 2026-03-31 12:44:11 +06:30
parent 7531e7edda
commit 07227ca9bb
4 changed files with 95 additions and 49 deletions

View File

@ -9,12 +9,14 @@ import com.utsmm.kbz.MainViewModel;
import com.utsmm.kbz.R; import com.utsmm.kbz.R;
import com.utsmm.kbz.config.Constants; import com.utsmm.kbz.config.Constants;
import com.utsmm.kbz.ui.core_viewmodel.SharedViewModel; import com.utsmm.kbz.ui.core_viewmodel.SharedViewModel;
import com.utsmm.kbz.util.CurrencySelectionHelper;
public class DashboardPreAuthBottomSheet extends DataBindingBottomSheetFragment { public class DashboardPreAuthBottomSheet extends DataBindingBottomSheetFragment {
private MainViewModel mainViewModel; private MainViewModel mainViewModel;
private SharedViewModel sharedViewModel; private SharedViewModel sharedViewModel;
private CurrencySelectionHelper currencySelectionHelper;
private static final int hostId = Constants.NAV_HOST_ID; private static final int hostId = Constants.NAV_HOST_ID;
private int routeId; private int routeId;
@ -24,6 +26,7 @@ public class DashboardPreAuthBottomSheet extends DataBindingBottomSheetFragment
protected void initViewModel() { protected void initViewModel() {
mainViewModel = getFragmentScopeViewModel(MainViewModel.class); mainViewModel = getFragmentScopeViewModel(MainViewModel.class);
sharedViewModel = getFragmentScopeViewModel(SharedViewModel.class); sharedViewModel = getFragmentScopeViewModel(SharedViewModel.class);
currencySelectionHelper = new CurrencySelectionHelper(this, sharedViewModel);
} }
@Override @Override
@ -52,10 +55,11 @@ public class DashboardPreAuthBottomSheet extends DataBindingBottomSheetFragment
} else if (checkTid()) { } else if (checkTid()) {
showDeclineDialog("Please Download Config!"); showDeclineDialog("Please Download Config!");
} else { } else {
showCurrencyChooserForCardFlow(() -> {
sharedViewModel.transactionsType.setValue(TransactionsType.PRE_AUTH_SALE); sharedViewModel.transactionsType.setValue(TransactionsType.PRE_AUTH_SALE);
routeId = R.id.action_dashboardPreAuthBottomSheet_to_inputAmountFragment; routeId = R.id.action_dashboardPreAuthBottomSheet_to_inputAmountFragment;
safeRouteTo(currentId,routeId,hostId); safeRouteTo(currentId, routeId, hostId);
});
} }
} }
@ -65,10 +69,11 @@ public class DashboardPreAuthBottomSheet extends DataBindingBottomSheetFragment
} else if (checkTid()) { } else if (checkTid()) {
showDeclineDialog("Please Download Config!"); showDeclineDialog("Please Download Config!");
} else { } else {
showCurrencyChooserForCardFlow(() -> {
sharedViewModel.transactionsType.setValue(TransactionsType.PRE_AUTH_COMPLETE); sharedViewModel.transactionsType.setValue(TransactionsType.PRE_AUTH_COMPLETE);
routeId = R.id.action_dashboardPreAuthBottomSheet_to_inputPasswordFragment; routeId = R.id.action_dashboardPreAuthBottomSheet_to_inputPasswordFragment;
safeRouteTo(currentId,routeId,hostId); safeRouteTo(currentId, routeId, hostId);
});
} }
} }
@ -86,4 +91,8 @@ public class DashboardPreAuthBottomSheet extends DataBindingBottomSheetFragment
} }
} }
} }
private void showCurrencyChooserForCardFlow(Runnable onSelected) {
currencySelectionHelper.showCardCurrencyChooser(onSelected);
}
} }

View File

@ -10,6 +10,7 @@ import com.utsmm.kbz.MainViewModel;
import com.utsmm.kbz.R; import com.utsmm.kbz.R;
import com.utsmm.kbz.config.Constants; import com.utsmm.kbz.config.Constants;
import com.utsmm.kbz.ui.core_viewmodel.SharedViewModel; import com.utsmm.kbz.ui.core_viewmodel.SharedViewModel;
import com.utsmm.kbz.util.CurrencySelectionHelper;
public class DashboardPreAuthCancelBottomSheet extends DataBindingBottomSheetFragment { public class DashboardPreAuthCancelBottomSheet extends DataBindingBottomSheetFragment {
@ -17,6 +18,7 @@ public class DashboardPreAuthCancelBottomSheet extends DataBindingBottomSheetFra
private MainViewModel mainViewModel; private MainViewModel mainViewModel;
private SharedViewModel sharedViewModel; private SharedViewModel sharedViewModel;
private CurrencySelectionHelper currencySelectionHelper;
private int currentId = R.id.dashboardPreAuthCancelBottomSheet; private int currentId = R.id.dashboardPreAuthCancelBottomSheet;
private int routeId; private int routeId;
@ -26,6 +28,7 @@ public class DashboardPreAuthCancelBottomSheet extends DataBindingBottomSheetFra
protected void initViewModel() { protected void initViewModel() {
mainViewModel = getFragmentScopeViewModel(MainViewModel.class); mainViewModel = getFragmentScopeViewModel(MainViewModel.class);
sharedViewModel = getFragmentScopeViewModel(SharedViewModel.class); sharedViewModel = getFragmentScopeViewModel(SharedViewModel.class);
currencySelectionHelper = new CurrencySelectionHelper(this, sharedViewModel);
} }
@Override @Override
@ -61,12 +64,13 @@ public class DashboardPreAuthCancelBottomSheet extends DataBindingBottomSheetFra
} else if (checkTid()) { } else if (checkTid()) {
showDeclineDialog("Please Download Config!"); showDeclineDialog("Please Download Config!");
} else { } else {
showCurrencyChooserForCardFlow(() -> {
sharedViewModel.transactionsType.setValue(TransactionsType.PRE_AUTH_VOID); sharedViewModel.transactionsType.setValue(TransactionsType.PRE_AUTH_VOID);
sharedViewModel.setTransMenu(TransMenu.PRE_AUTH_FULL_VOID); sharedViewModel.setTransMenu(TransMenu.PRE_AUTH_FULL_VOID);
sharedViewModel.amount.postValue(null); sharedViewModel.amount.postValue(null);
routeId = R.id.action_dashboardPreAuthCancelBottomSheet_to_inputPasswordFragment; routeId = R.id.action_dashboardPreAuthCancelBottomSheet_to_inputPasswordFragment;
safeRouteTo(currentId,routeId,hostId); safeRouteTo(currentId, routeId, hostId);
});
} }
} }
@ -82,14 +86,19 @@ public class DashboardPreAuthCancelBottomSheet extends DataBindingBottomSheetFra
} else if (checkTid()) { } else if (checkTid()) {
showDeclineDialog("Please Download Config!"); showDeclineDialog("Please Download Config!");
} else { } else {
showCurrencyChooserForCardFlow(() -> {
sharedViewModel.transactionsType.setValue(TransactionsType.PRE_AUTH_VOID); sharedViewModel.transactionsType.setValue(TransactionsType.PRE_AUTH_VOID);
sharedViewModel.setTransMenu(TransMenu.PRE_AUTH_PARTIAL_VOID); sharedViewModel.setTransMenu(TransMenu.PRE_AUTH_PARTIAL_VOID);
sharedViewModel.amount.postValue(null); sharedViewModel.amount.postValue(null);
routeId = R.id.action_dashboardPreAuthCancelBottomSheet_to_inputPasswordFragment; routeId = R.id.action_dashboardPreAuthCancelBottomSheet_to_inputPasswordFragment;
safeRouteTo(currentId,routeId,hostId); safeRouteTo(currentId, routeId, hostId);
});
} }
} }
} }
private void showCurrencyChooserForCardFlow(Runnable onSelected) {
currencySelectionHelper.showCardCurrencyChooser(onSelected);
}
} }

View File

@ -192,14 +192,12 @@ public class DashboardTransFragment extends DataBindingFragment {
} else if (checkTid()) { } else if (checkTid()) {
showDeclineDialog("Please Download Config!"); showDeclineDialog("Please Download Config!");
} else { } else {
showCurrencyChooserForCardFlow(() -> {
sharedViewModel.setTransactionsType(TransactionsType.VOID); sharedViewModel.setTransactionsType(TransactionsType.VOID);
// sharedViewModel.transMenu.postValue(TransMenu.TRANSACTIONS); // sharedViewModel.transMenu.postValue(TransMenu.TRANSACTIONS);
sharedViewModel.setTransMenu(TransMenu.TRANSACTIONS); sharedViewModel.setTransMenu(TransMenu.TRANSACTIONS);
routeId = R.id.action_dashboardTransFragment_to_inputPasswordFragment; routeId = R.id.action_dashboardTransFragment_to_inputPasswordFragment;
safeRouteTo(currentId,routeId,hostId); safeRouteTo(currentId,routeId,hostId);
});
} }
} }
@ -214,9 +212,11 @@ public class DashboardTransFragment extends DataBindingFragment {
} }
public void onClickRefund() { public void onClickRefund() {
showCurrencyChooserForCardFlow(() -> {
sharedViewModel.setTransactionsType(TransactionsType.REFUND); sharedViewModel.setTransactionsType(TransactionsType.REFUND);
routeId = R.id.action_dashboardTransFragment_to_inputPasswordFragment; routeId = R.id.action_dashboardTransFragment_to_inputPasswordFragment;
safeRouteTo(currentId,routeId,hostId); safeRouteTo(currentId, routeId, hostId);
});
} }
public void onClickPreAuth () { public void onClickPreAuth () {
@ -235,19 +235,23 @@ public class DashboardTransFragment extends DataBindingFragment {
} }
public void onClickPreAuthCancel () { public void onClickPreAuthCancel () {
showCurrencyChooserForCardFlow(() -> {
sharedViewModel.setTransactionsType(TransactionsType.PRE_AUTH_VOID); sharedViewModel.setTransactionsType(TransactionsType.PRE_AUTH_VOID);
sharedViewModel.setTransMenu(TransMenu.PRE_AUTH_FULL_VOID); sharedViewModel.setTransMenu(TransMenu.PRE_AUTH_FULL_VOID);
sharedViewModel.amount.postValue("0"); // null to 0 sharedViewModel.amount.postValue("0"); // null to 0
// sharedViewModel.amount.postValue(null); // sharedViewModel.amount.postValue(null);
routeId = R.id.action_dashboardTransFragment_to_inputPasswordFragment; routeId = R.id.action_dashboardTransFragment_to_inputPasswordFragment;
safeRouteTo(currentId,routeId,hostId); safeRouteTo(currentId, routeId, hostId);
});
} }
public void onClickPreAuthComp () { public void onClickPreAuthComp () {
showCurrencyChooserForCardFlow(() -> {
sharedViewModel.setTransactionsType(TransactionsType.PRE_AUTH_COMPLETE); sharedViewModel.setTransactionsType(TransactionsType.PRE_AUTH_COMPLETE);
routeId = R.id.action_dashboardTransFragment_to_inputPasswordFragment; routeId = R.id.action_dashboardTransFragment_to_inputPasswordFragment;
safeRouteTo(currentId,routeId,hostId); safeRouteTo(currentId, routeId, hostId);
});
} }

View File

@ -22,9 +22,16 @@ import java.util.List;
public class CurrencySelectionHelper { public class CurrencySelectionHelper {
private static boolean globalPrimaryHostCached = false;
private static String globalPrimaryHostName = "";
private static String globalPrimaryTid = "";
private static String globalPrimaryMid = "";
private static String globalPrimaryIp = "";
private static String globalPrimarySecIp = "";
private static CurrencyType globalPrimaryCurrency = CurrencyType.MMK;
private final Fragment fragment; private final Fragment fragment;
private final SharedViewModel sharedViewModel; private final SharedViewModel sharedViewModel;
private boolean primaryHostCached = false;
private String primaryHostName = ""; private String primaryHostName = "";
private String primaryTid = ""; private String primaryTid = "";
private String primaryMid = ""; private String primaryMid = "";
@ -115,18 +122,35 @@ public class CurrencySelectionHelper {
} }
private void cachePrimaryCardHostIfNeeded() { private void cachePrimaryCardHostIfNeeded() {
if (primaryHostCached) { SystemParamsOperation sp = SystemParamsOperation.getInstance();
return; String currentHostName = sp.getHostName();
String secondaryHostName = sp.getThirdHostName();
boolean currentIsSecondary = !TextUtils.isEmpty(secondaryHostName)
&& secondaryHostName.equals(currentHostName);
if (!currentIsSecondary) {
globalPrimaryHostName = currentHostName;
globalPrimaryTid = sp.getTerminalId();
globalPrimaryMid = sp.getMerchantId();
globalPrimaryIp = sp.getIpAddress();
globalPrimarySecIp = sp.getSecIpAddress();
CurrencyType activeCurrency = sp.getCurrencyType();
globalPrimaryCurrency = activeCurrency == null ? CurrencyType.MMK : activeCurrency;
globalPrimaryHostCached = true;
} }
primaryHostName = SystemParamsOperation.getInstance().getHostName(); if (!globalPrimaryHostCached) {
primaryTid = SystemParamsOperation.getInstance().getTerminalId(); CurrencyType activeCurrency = sp.getCurrencyType();
primaryMid = SystemParamsOperation.getInstance().getMerchantId(); globalPrimaryCurrency = activeCurrency == null ? CurrencyType.MMK : activeCurrency;
primaryIp = SystemParamsOperation.getInstance().getIpAddress(); globalPrimaryHostCached = true;
primarySecIp = SystemParamsOperation.getInstance().getSecIpAddress(); }
CurrencyType activeCurrency = SystemParamsOperation.getInstance().getCurrencyType();
primaryCurrency = activeCurrency == null ? CurrencyType.MMK : activeCurrency; primaryHostName = globalPrimaryHostName;
primaryHostCached = true; primaryTid = globalPrimaryTid;
primaryMid = globalPrimaryMid;
primaryIp = globalPrimaryIp;
primarySecIp = globalPrimarySecIp;
primaryCurrency = globalPrimaryCurrency;
} }
private CurrencyType toCurrencyType(String value) { private CurrencyType toCurrencyType(String value) {