pin pad success
This commit is contained in:
parent
bcd5634941
commit
0abf7bc6c9
@ -148,14 +148,22 @@ fun AppNavGraph(
|
||||
sharedViewModel = sharedViewModel,
|
||||
transProcessViewModel = transProcessViewModel,
|
||||
onNavigateTransactionResult = {
|
||||
navController.navigate(Routes.TransactionResult.route)
|
||||
navController.navigate(Routes.TransactionResult.route) {
|
||||
popUpTo(Routes.Dashboard.route) {
|
||||
inclusive = false
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
},
|
||||
onBack = { navController.popBackStack() }
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.TransactionResult.route) {
|
||||
val sharedViewModel: SharedViewModel = hiltViewModel(activity)
|
||||
|
||||
TransactionResultRoute(
|
||||
sharedViewModel = sharedViewModel,
|
||||
onNavigateMain = {
|
||||
navController.navigate(Routes.Dashboard.route) {
|
||||
popUpTo(Routes.Dashboard.route) {
|
||||
|
||||
@ -6,11 +6,9 @@ import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.mob.utsmyanmar.model.PinPadStatus
|
||||
import com.mob.utsmyanmar.model.TransResultStatus
|
||||
import com.mob.utsmyanmar.viewmodel.SharedViewModel
|
||||
import com.mob.utsmyanmar.viewmodel.TransProcessViewModel
|
||||
import com.utsmyanmar.paylibs.Constant
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation
|
||||
|
||||
@Composable
|
||||
fun PinPadRoute(
|
||||
@ -23,22 +21,16 @@ fun PinPadRoute(
|
||||
val pinText by pinPadViewModel.pinText.collectAsStateWithLifecycle()
|
||||
val alertMsg by pinPadViewModel.alertMsg.collectAsStateWithLifecycle()
|
||||
val pinStatus by pinPadViewModel.pinStatus.collectAsStateWithLifecycle()
|
||||
val transStatus by transProcessViewModel.transResultStatus.collectAsStateWithLifecycle()
|
||||
|
||||
LaunchedEffect(pinStatus) {
|
||||
when (pinStatus) {
|
||||
PinPadStatus.ON_CONFIRM,
|
||||
PinPadStatus.ON_NEXT_SCREEN,
|
||||
PinPadStatus.ON_EMPTY -> {
|
||||
if (SystemParamsOperation.getInstance().demoStatus) {
|
||||
val payDetail = pinPadViewModel.getPayDetail()
|
||||
payDetail?.tradeAnswerCode = Constant.ANSWER_CODE_APPROVED
|
||||
sharedViewModel.payDetail.value = payDetail
|
||||
transProcessViewModel.resetTransactionStatus()
|
||||
onNavigateTransactionResult()
|
||||
} else {
|
||||
transProcessViewModel.startOnlineProcess()
|
||||
}
|
||||
PinPadStatus.ON_NEXT_SCREEN -> {
|
||||
val payDetail = pinPadViewModel.getPayDetail()
|
||||
payDetail?.tradeAnswerCode = Constant.ANSWER_CODE_APPROVED
|
||||
sharedViewModel.payDetail.value = payDetail
|
||||
transProcessViewModel.resetTransactionStatus()
|
||||
onNavigateTransactionResult()
|
||||
}
|
||||
|
||||
PinPadStatus.ON_CANCEL,
|
||||
@ -51,25 +43,6 @@ fun PinPadRoute(
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(transStatus) {
|
||||
when (transStatus) {
|
||||
TransResultStatus.SUCCESS,
|
||||
TransResultStatus.FAIL,
|
||||
TransResultStatus.NETWORK_ERROR,
|
||||
TransResultStatus.ERROR,
|
||||
TransResultStatus.REVERSAL_FAIL,
|
||||
TransResultStatus.REVERSAL_SUCCESS -> {
|
||||
sharedViewModel.payDetail.value =
|
||||
transProcessViewModel.payDetailResult.value
|
||||
?: transProcessViewModel.payDetail
|
||||
transProcessViewModel.resetTransactionStatus()
|
||||
onNavigateTransactionResult()
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
DisposableEffect(Unit) {
|
||||
onDispose {
|
||||
pinPadViewModel.cancelPinPad()
|
||||
|
||||
@ -37,6 +37,7 @@ class PinPadViewModel @Inject constructor(
|
||||
) : ViewModel() {
|
||||
companion object {
|
||||
private const val TAG = "PinPadViewModel"
|
||||
private const val PIN_CONFIRM_SUCCESS_STATUS = 0
|
||||
private const val ON_CONFIRM_CLICK = 2
|
||||
private const val ON_CANCEL_CLICK = 3
|
||||
private const val ON_ERROR_PIN_PAD = 4
|
||||
@ -202,7 +203,7 @@ class PinPadViewModel @Inject constructor(
|
||||
this.timeout = timeout * 1000
|
||||
isOrderNumKey = pinPadOrder
|
||||
keySystem = AidlConstants.Security.SEC_MKSK
|
||||
pinKeyIndex = 1
|
||||
pinKeyIndex = PIK_INDEX
|
||||
pinblockFormat = AidlConstants.PinBlockFormat.SEC_PIN_BLK_ISO_FMT0
|
||||
this.pan = getPanBytes(this@PinPadViewModel.pan)
|
||||
}
|
||||
@ -442,53 +443,42 @@ class PinPadViewModel @Inject constructor(
|
||||
status: Int,
|
||||
pinBlock: ByteArray?
|
||||
) {
|
||||
|
||||
LogUtil.e(
|
||||
TAG,
|
||||
"onConfirm status:$status"
|
||||
)
|
||||
if (status != PIN_CONFIRM_SUCCESS_STATUS) {
|
||||
_alertMsg.value = "PinPad confirm failed: $status"
|
||||
_pinStatus.value = PinPadStatus.ON_ERROR
|
||||
return
|
||||
}
|
||||
|
||||
// if (pinBlock != null) {
|
||||
//
|
||||
// val hexStr =
|
||||
// ByteUtil.bytes2HexStr(pinBlock)
|
||||
//
|
||||
// if (
|
||||
// SunmiSDK.getInstance().checkCardExist() == 2 ||
|
||||
// payDetail?.cardType == AidlConstants.CardType.MAGNETIC.getValue() ||
|
||||
// payDetail?.cardType == -9
|
||||
// ) {
|
||||
//
|
||||
// payDetail?.pinCipher = hexStr
|
||||
//
|
||||
// if (
|
||||
// transType.value == TransactionsType.PRE_AUTH_COMPLETE ||
|
||||
// transType.value == TransactionsType.PRE_AUTH_VOID ||
|
||||
// transType.value == TransactionsType.REFUND
|
||||
// ) {
|
||||
//
|
||||
// _pinStatus.value =
|
||||
// PinPadStatus.ON_NEXT_SCREEN
|
||||
//
|
||||
// } else {
|
||||
//
|
||||
// handler.obtainMessage(
|
||||
// ON_CONFIRM_CLICK
|
||||
// ).sendToTarget()
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
//
|
||||
// _pinStatus.value =
|
||||
// PinPadStatus.ON_CARD_REMOVED
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
//
|
||||
// handler.obtainMessage(
|
||||
// ON_EMPTY_PIN_BLOCK
|
||||
// ).sendToTarget()
|
||||
// }
|
||||
val isCardValid = SunmiSDK.getInstance().checkCardExist() == 2 ||
|
||||
payDetail?.cardType == AidlConstants.CardType.MAGNETIC.getValue() ||
|
||||
payDetail?.cardType == -9
|
||||
|
||||
if (!isCardValid) {
|
||||
_pinStatus.value = PinPadStatus.ON_CARD_REMOVED
|
||||
return
|
||||
}
|
||||
|
||||
if (pinBlock != null) {
|
||||
payDetail?.pinCipher = ByteUtil.bytes2HexStr(pinBlock)
|
||||
} else {
|
||||
payDetail?.pinCipher = ""
|
||||
}
|
||||
|
||||
if (
|
||||
transType.value == TransactionsType.PRE_AUTH_COMPLETE ||
|
||||
transType.value == TransactionsType.PRE_AUTH_VOID ||
|
||||
transType.value == TransactionsType.REFUND
|
||||
) {
|
||||
_pinStatus.value = PinPadStatus.ON_NEXT_SCREEN
|
||||
} else {
|
||||
handler.obtainMessage(
|
||||
ON_CONFIRM_CLICK
|
||||
).sendToTarget()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCancel() {
|
||||
@ -545,4 +535,4 @@ class PinPadViewModel @Inject constructor(
|
||||
.substring(pan.length - 13, pan.length - 1)
|
||||
.toByteArray(StandardCharsets.US_ASCII)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ import com.mob.utsmyanmar.viewmodel.SharedViewModel
|
||||
@Composable
|
||||
fun TransactionResultRoute(
|
||||
viewModel: TransactionResultViewModel = hiltViewModel(),
|
||||
sharedViewModel: SharedViewModel = hiltViewModel(),
|
||||
sharedViewModel: SharedViewModel,
|
||||
onNavigateMain: () -> Unit,
|
||||
onNavigatePrintReceipt: () -> Unit,
|
||||
onShowError: (String) -> Unit,
|
||||
@ -33,4 +33,4 @@ fun TransactionResultRoute(
|
||||
viewModel.onEvent(it, sharedViewModel)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user