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.config.Constants;
import com.utsmm.kbz.ui.core_viewmodel.SharedViewModel;
import com.utsmm.kbz.util.CurrencySelectionHelper;
public class DashboardPreAuthBottomSheet extends DataBindingBottomSheetFragment {
private MainViewModel mainViewModel;
private SharedViewModel sharedViewModel;
private CurrencySelectionHelper currencySelectionHelper;
private static final int hostId = Constants.NAV_HOST_ID;
private int routeId;
@ -24,6 +26,7 @@ public class DashboardPreAuthBottomSheet extends DataBindingBottomSheetFragment
protected void initViewModel() {
mainViewModel = getFragmentScopeViewModel(MainViewModel.class);
sharedViewModel = getFragmentScopeViewModel(SharedViewModel.class);
currencySelectionHelper = new CurrencySelectionHelper(this, sharedViewModel);
}
@Override
@ -52,10 +55,11 @@ public class DashboardPreAuthBottomSheet extends DataBindingBottomSheetFragment
} else if (checkTid()) {
showDeclineDialog("Please Download Config!");
} else {
sharedViewModel.transactionsType.setValue(TransactionsType.PRE_AUTH_SALE);
routeId = R.id.action_dashboardPreAuthBottomSheet_to_inputAmountFragment;
safeRouteTo(currentId,routeId,hostId);
showCurrencyChooserForCardFlow(() -> {
sharedViewModel.transactionsType.setValue(TransactionsType.PRE_AUTH_SALE);
routeId = R.id.action_dashboardPreAuthBottomSheet_to_inputAmountFragment;
safeRouteTo(currentId, routeId, hostId);
});
}
}
@ -65,10 +69,11 @@ public class DashboardPreAuthBottomSheet extends DataBindingBottomSheetFragment
} else if (checkTid()) {
showDeclineDialog("Please Download Config!");
} else {
sharedViewModel.transactionsType.setValue(TransactionsType.PRE_AUTH_COMPLETE);
routeId = R.id.action_dashboardPreAuthBottomSheet_to_inputPasswordFragment;
safeRouteTo(currentId,routeId,hostId);
showCurrencyChooserForCardFlow(() -> {
sharedViewModel.transactionsType.setValue(TransactionsType.PRE_AUTH_COMPLETE);
routeId = R.id.action_dashboardPreAuthBottomSheet_to_inputPasswordFragment;
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.config.Constants;
import com.utsmm.kbz.ui.core_viewmodel.SharedViewModel;
import com.utsmm.kbz.util.CurrencySelectionHelper;
public class DashboardPreAuthCancelBottomSheet extends DataBindingBottomSheetFragment {
@ -17,6 +18,7 @@ public class DashboardPreAuthCancelBottomSheet extends DataBindingBottomSheetFra
private MainViewModel mainViewModel;
private SharedViewModel sharedViewModel;
private CurrencySelectionHelper currencySelectionHelper;
private int currentId = R.id.dashboardPreAuthCancelBottomSheet;
private int routeId;
@ -26,6 +28,7 @@ public class DashboardPreAuthCancelBottomSheet extends DataBindingBottomSheetFra
protected void initViewModel() {
mainViewModel = getFragmentScopeViewModel(MainViewModel.class);
sharedViewModel = getFragmentScopeViewModel(SharedViewModel.class);
currencySelectionHelper = new CurrencySelectionHelper(this, sharedViewModel);
}
@Override
@ -61,12 +64,13 @@ public class DashboardPreAuthCancelBottomSheet extends DataBindingBottomSheetFra
} else if (checkTid()) {
showDeclineDialog("Please Download Config!");
} else {
sharedViewModel.transactionsType.setValue(TransactionsType.PRE_AUTH_VOID);
sharedViewModel.setTransMenu(TransMenu.PRE_AUTH_FULL_VOID);
sharedViewModel.amount.postValue(null);
routeId = R.id.action_dashboardPreAuthCancelBottomSheet_to_inputPasswordFragment;
safeRouteTo(currentId,routeId,hostId);
showCurrencyChooserForCardFlow(() -> {
sharedViewModel.transactionsType.setValue(TransactionsType.PRE_AUTH_VOID);
sharedViewModel.setTransMenu(TransMenu.PRE_AUTH_FULL_VOID);
sharedViewModel.amount.postValue(null);
routeId = R.id.action_dashboardPreAuthCancelBottomSheet_to_inputPasswordFragment;
safeRouteTo(currentId, routeId, hostId);
});
}
}
@ -82,14 +86,19 @@ public class DashboardPreAuthCancelBottomSheet extends DataBindingBottomSheetFra
} else if (checkTid()) {
showDeclineDialog("Please Download Config!");
} else {
sharedViewModel.transactionsType.setValue(TransactionsType.PRE_AUTH_VOID);
sharedViewModel.setTransMenu(TransMenu.PRE_AUTH_PARTIAL_VOID);
sharedViewModel.amount.postValue(null);
routeId = R.id.action_dashboardPreAuthCancelBottomSheet_to_inputPasswordFragment;
safeRouteTo(currentId,routeId,hostId);
showCurrencyChooserForCardFlow(() -> {
sharedViewModel.transactionsType.setValue(TransactionsType.PRE_AUTH_VOID);
sharedViewModel.setTransMenu(TransMenu.PRE_AUTH_PARTIAL_VOID);
sharedViewModel.amount.postValue(null);
routeId = R.id.action_dashboardPreAuthCancelBottomSheet_to_inputPasswordFragment;
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()) {
showDeclineDialog("Please Download Config!");
} else {
showCurrencyChooserForCardFlow(() -> {
sharedViewModel.setTransactionsType(TransactionsType.VOID);
sharedViewModel.setTransactionsType(TransactionsType.VOID);
// sharedViewModel.transMenu.postValue(TransMenu.TRANSACTIONS);
sharedViewModel.setTransMenu(TransMenu.TRANSACTIONS);
sharedViewModel.setTransMenu(TransMenu.TRANSACTIONS);
routeId = R.id.action_dashboardTransFragment_to_inputPasswordFragment;
safeRouteTo(currentId,routeId,hostId);
});
routeId = R.id.action_dashboardTransFragment_to_inputPasswordFragment;
safeRouteTo(currentId,routeId,hostId);
}
}
@ -214,9 +212,11 @@ public class DashboardTransFragment extends DataBindingFragment {
}
public void onClickRefund() {
sharedViewModel.setTransactionsType(TransactionsType.REFUND);
routeId = R.id.action_dashboardTransFragment_to_inputPasswordFragment;
safeRouteTo(currentId,routeId,hostId);
showCurrencyChooserForCardFlow(() -> {
sharedViewModel.setTransactionsType(TransactionsType.REFUND);
routeId = R.id.action_dashboardTransFragment_to_inputPasswordFragment;
safeRouteTo(currentId, routeId, hostId);
});
}
public void onClickPreAuth () {
@ -235,19 +235,23 @@ public class DashboardTransFragment extends DataBindingFragment {
}
public void onClickPreAuthCancel () {
sharedViewModel.setTransactionsType(TransactionsType.PRE_AUTH_VOID);
sharedViewModel.setTransMenu(TransMenu.PRE_AUTH_FULL_VOID);
sharedViewModel.amount.postValue("0"); // null to 0
// sharedViewModel.amount.postValue(null);
routeId = R.id.action_dashboardTransFragment_to_inputPasswordFragment;
safeRouteTo(currentId,routeId,hostId);
showCurrencyChooserForCardFlow(() -> {
sharedViewModel.setTransactionsType(TransactionsType.PRE_AUTH_VOID);
sharedViewModel.setTransMenu(TransMenu.PRE_AUTH_FULL_VOID);
sharedViewModel.amount.postValue("0"); // null to 0
// sharedViewModel.amount.postValue(null);
routeId = R.id.action_dashboardTransFragment_to_inputPasswordFragment;
safeRouteTo(currentId, routeId, hostId);
});
}
public void onClickPreAuthComp () {
sharedViewModel.setTransactionsType(TransactionsType.PRE_AUTH_COMPLETE);
routeId = R.id.action_dashboardTransFragment_to_inputPasswordFragment;
safeRouteTo(currentId,routeId,hostId);
showCurrencyChooserForCardFlow(() -> {
sharedViewModel.setTransactionsType(TransactionsType.PRE_AUTH_COMPLETE);
routeId = R.id.action_dashboardTransFragment_to_inputPasswordFragment;
safeRouteTo(currentId, routeId, hostId);
});
}

View File

@ -22,9 +22,16 @@ import java.util.List;
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 SharedViewModel sharedViewModel;
private boolean primaryHostCached = false;
private String primaryHostName = "";
private String primaryTid = "";
private String primaryMid = "";
@ -115,18 +122,35 @@ public class CurrencySelectionHelper {
}
private void cachePrimaryCardHostIfNeeded() {
if (primaryHostCached) {
return;
SystemParamsOperation sp = SystemParamsOperation.getInstance();
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();
primaryTid = SystemParamsOperation.getInstance().getTerminalId();
primaryMid = SystemParamsOperation.getInstance().getMerchantId();
primaryIp = SystemParamsOperation.getInstance().getIpAddress();
primarySecIp = SystemParamsOperation.getInstance().getSecIpAddress();
CurrencyType activeCurrency = SystemParamsOperation.getInstance().getCurrencyType();
primaryCurrency = activeCurrency == null ? CurrencyType.MMK : activeCurrency;
primaryHostCached = true;
if (!globalPrimaryHostCached) {
CurrencyType activeCurrency = sp.getCurrencyType();
globalPrimaryCurrency = activeCurrency == null ? CurrencyType.MMK : activeCurrency;
globalPrimaryHostCached = true;
}
primaryHostName = globalPrimaryHostName;
primaryTid = globalPrimaryTid;
primaryMid = globalPrimaryMid;
primaryIp = globalPrimaryIp;
primarySecIp = globalPrimarySecIp;
primaryCurrency = globalPrimaryCurrency;
}
private CurrencyType toCurrencyType(String value) {