Compare commits
No commits in common. "Password_screen" and "main" have entirely different histories.
Password_s
...
main
3
.gitignore
vendored
@ -14,6 +14,3 @@
|
||||
.cxx
|
||||
local.properties
|
||||
/.idea
|
||||
/.idea
|
||||
/sunmiui-lib
|
||||
/paysdk-lib
|
||||
|
||||
@ -57,6 +57,5 @@
|
||||
<option name="composableFile" value="true" />
|
||||
<option name="previewFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="UsePropertyAccessSyntax" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
||||
@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="temurin-21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.kotlin.compose)
|
||||
id("com.google.devtools.ksp")
|
||||
id("com.google.dagger.hilt.android")
|
||||
}
|
||||
|
||||
android {
|
||||
@ -46,13 +44,10 @@ dependencies {
|
||||
implementation(libs.androidx.activity.compose)
|
||||
implementation(libs.androidx.compose.foundation)
|
||||
implementation(libs.androidx.compose.material3)
|
||||
implementation(libs.androidx.compose.runtime)
|
||||
implementation(libs.androidx.compose.runtime.livedata)
|
||||
implementation(libs.androidx.compose.ui)
|
||||
implementation(libs.androidx.compose.ui.graphics)
|
||||
implementation(libs.androidx.compose.ui.tooling.preview)
|
||||
implementation(libs.androidx.core.ktx)
|
||||
implementation(libs.androidx.hilt.navigation.compose)
|
||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||
implementation(libs.androidx.navigation.compose)
|
||||
testImplementation(libs.junit)
|
||||
@ -62,29 +57,4 @@ dependencies {
|
||||
androidTestImplementation(libs.androidx.junit)
|
||||
debugImplementation(libs.androidx.compose.ui.test.manifest)
|
||||
debugImplementation(libs.androidx.compose.ui.tooling)
|
||||
implementation(libs.hilt.android.v2592)
|
||||
ksp(libs.hilt.android.compiler)
|
||||
implementation(libs.rxjava)
|
||||
implementation(libs.rxandroid)
|
||||
implementation(libs.retrofit)
|
||||
implementation(libs.converter.gson)
|
||||
// Core icons (usually included with material library)
|
||||
implementation( libs.androidx.compose.material.icons.core)
|
||||
// Extended icons (full set of icons)
|
||||
implementation(libs.androidx.compose.material.icons.extended)
|
||||
// splash screen
|
||||
implementation(libs.androidx.core.splashscreen)
|
||||
//image lib
|
||||
implementation("io.coil-kt.coil3:coil-compose:3.4.0")
|
||||
implementation("io.coil-kt.coil3:coil-network-okhttp:3.4.0")
|
||||
// local libs
|
||||
implementation(project(":baselib"))
|
||||
implementation(project(":mpulib"))
|
||||
implementation(project(":paylibs"))
|
||||
implementation(project(":paysdk-lib"))
|
||||
implementation(project(":qrgen-lib"))
|
||||
implementation(project(":sunmiui-lib"))
|
||||
implementation(project(":ecr"))
|
||||
implementation(project(":xpay"))
|
||||
implementation(project(":cmhl"))
|
||||
}
|
||||
@ -2,32 +2,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.telephony"
|
||||
android:required="false" />
|
||||
<uses-feature
|
||||
android:name="android.hardware.camera"
|
||||
android:required="false" />
|
||||
|
||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:ignore="QueryAllPackagesPermission" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="com.sunmi.perm.LED" />
|
||||
<uses-permission android:name="com.sunmi.perm.MSR" />
|
||||
<uses-permission android:name="com.sunmi.perm.ICC" />
|
||||
<uses-permission android:name="com.sunmi.perm.PINPAD" />
|
||||
<uses-permission android:name="com.sunmi.perm.SECURITY" />
|
||||
<uses-permission android:name="com.sunmi.perm.CONTACTLESS_CARD" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
|
||||
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||
|
||||
<application
|
||||
android:name="com.mob.utsmyanmar.MyApplication"
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
@ -37,11 +12,13 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.MOBPOS">
|
||||
<activity
|
||||
android:name="com.mob.utsmyanmar.MainActivity"
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name">
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.MOBPOS">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
## Working agreements
|
||||
|
||||
- use Scaffold and AppBar() in every main Screen
|
||||
@ -2,21 +2,16 @@ package com.mob.utsmyanmar
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.SystemBarStyle
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.mob.utsmyanmar.ui.navigation.AppNavGraph
|
||||
import com.mob.utsmyanmar.ui.theme.MOBPOSTheme
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@AndroidEntryPoint
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
installSplashScreen()
|
||||
super.onCreate(savedInstanceState)
|
||||
// enableEdgeToEdge()
|
||||
enableEdgeToEdge()
|
||||
setContent {
|
||||
MOBPOSTheme {
|
||||
val navController = rememberNavController()
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
package com.mob.utsmyanmar
|
||||
|
||||
|
||||
import com.mob.utsmyanmar.utils.AppContextHolder
|
||||
import com.utsmyanmar.baselib.BaseApplication
|
||||
import com.utsmyanmar.paylibs.network.ISOSocket
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
|
||||
@HiltAndroidApp
|
||||
class MyApplication : BaseApplication() {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
AppContextHolder.init(this)
|
||||
ISOSocket.getInstance().initContext(this)
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
package com.mob.utsmyanmar.config
|
||||
|
||||
import com.mob.utsmyanmar.R
|
||||
|
||||
object Constants {
|
||||
const val WALLET = "WALLET"
|
||||
const val MPU_CARD_SCHEME = "MPU"
|
||||
const val TIMEOUT = 30
|
||||
const val PROCESSING_TIMEOUT = 180
|
||||
const val PIN_PAD_TIMEOUT = 60
|
||||
const val REVERSAL = "REVERSAL"
|
||||
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
package com.mob.utsmyanmar.config
|
||||
|
||||
import com.sunmi.pay.hardware.aidl.security.SecurityOpt
|
||||
import com.sunmi.pay.hardware.aidlv2.emv.EMVOptV2
|
||||
import com.sunmi.pay.hardware.aidlv2.pinpad.PinPadOptV2
|
||||
import com.sunmi.pay.hardware.aidlv2.readcard.ReadCardOptV2
|
||||
import com.sunmi.pay.hardware.aidlv2.security.SecurityOptV2
|
||||
import com.sunmi.pay.hardware.aidlv2.system.BasicOptV2
|
||||
import com.utsmyanmar.baselib.BaseApplication
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class SunmiPayManager @Inject constructor() {
|
||||
private val app: BaseApplication?
|
||||
get() = BaseApplication.getInstance()
|
||||
|
||||
val pinPadOptV2: PinPadOptV2?
|
||||
get() = app?.mPinPadOptV2
|
||||
|
||||
val securityOptV2: SecurityOptV2?
|
||||
get() = app?.mSecurityOptV2
|
||||
|
||||
val readCardOptV2: ReadCardOptV2?
|
||||
get() = app?.mReadCardOptV2
|
||||
|
||||
val emvOptV2: EMVOptV2?
|
||||
get() = app?.mEMVOptV2
|
||||
|
||||
val basicOptV2: BasicOptV2?
|
||||
get() = BaseApplication.basicOptV2
|
||||
|
||||
val securityOpt: SecurityOpt?
|
||||
get() = app?.securityOpt
|
||||
|
||||
fun isReady(): Boolean {
|
||||
return pinPadOptV2 != null &&
|
||||
securityOptV2 != null &&
|
||||
readCardOptV2 != null &&
|
||||
emvOptV2 != null &&
|
||||
basicOptV2 != null
|
||||
}
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
package com.mob.utsmyanmar.model
|
||||
|
||||
enum class CardTransactionType {
|
||||
MPU, EMV, MAG, FALLBACK
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
package com.mob.utsmyanmar.model
|
||||
|
||||
enum class PinPadStatus {
|
||||
ON_CONFIRM,
|
||||
ON_CANCEL ,
|
||||
ON_EMPTY,
|
||||
ON_ERROR,
|
||||
ON_TIMEOUT,
|
||||
ON_NEXT_SCREEN,
|
||||
ON_CARD_REMOVED,
|
||||
ON_ERROR_DUKPT,
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
package com.mob.utsmyanmar.model
|
||||
|
||||
object ProcessCode {
|
||||
const val BALANCE_INQUIRY = "31"
|
||||
|
||||
const val SALE_PURCHASE = "00"
|
||||
|
||||
const val SALE_VOID = "02"
|
||||
|
||||
const val PRE_AUTH_SALE = "30"
|
||||
|
||||
const val PRE_AUTH_VOID = "30"
|
||||
|
||||
const val PRE_AUTH_COMPLETE = "30"
|
||||
|
||||
const val PRE_AUTH_COMPLETE_VOID = "30"
|
||||
|
||||
const val CASH_ADVANCE = "01" // 01-MPU 17-TTIP
|
||||
|
||||
const val FUND_TRANSFER = "61"
|
||||
|
||||
const val PIN_CHANGE = "70"
|
||||
|
||||
const val SETTLEMENT = "92"
|
||||
|
||||
const val SIGN_ON = "95"
|
||||
|
||||
const val CASH_DEPOSIT = "21"
|
||||
|
||||
const val REFUND = "20"
|
||||
|
||||
const val SMART = "00"
|
||||
|
||||
const val SAVING = "10"
|
||||
|
||||
const val CURRENT = "20"
|
||||
|
||||
const val TO_ACCOUNT = "00"
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
package com.mob.utsmyanmar.model
|
||||
|
||||
enum class SettlementType {
|
||||
NORMAL,
|
||||
CUT_OVER
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
package com.mob.utsmyanmar.model
|
||||
|
||||
enum class TransResultStatus {
|
||||
CLICK_CONFIRM,
|
||||
SUCCESS,
|
||||
FAIL,
|
||||
OFFLINE_SUCCESS,
|
||||
OFFLINE_FAILURE,
|
||||
SECONDARY,
|
||||
REVERSAL_PROCESS,
|
||||
REVERSAL_PREPARE,
|
||||
REVERSAL_SECONDARY,
|
||||
REVERSAL_THIRD,
|
||||
REVERSAL_FAIL,
|
||||
REVERSAL_SUCCESS,
|
||||
BEFORE_REVERSAL,
|
||||
PIN_PAD_CANCEL,
|
||||
PIN_PAD_CONFIRM,
|
||||
PIN_PAD_ERROR,
|
||||
PIN_MISMATCH,
|
||||
PIN_MISMATCH_END,
|
||||
REMOVED_CARD,
|
||||
EMV_ERROR,
|
||||
ERROR,
|
||||
RETRY_AGAIN,
|
||||
NEXT_SCREEN,
|
||||
EMPTY_PIN,
|
||||
NETWORK_ERROR
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
package com.mob.utsmyanmar.model
|
||||
|
||||
enum class TransactionStatus {
|
||||
ON_SUCCESS,
|
||||
ON_REVERSAL,
|
||||
ON_BATCH_UPLOAD,
|
||||
ON_FAIL,
|
||||
ON_ERROR,
|
||||
ON_SECONDARY,
|
||||
ON_DONE
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
package com.mob.utsmyanmar.model.ecr
|
||||
|
||||
enum class ECRResultStatus {
|
||||
USER_CANCEL,
|
||||
TIME_OUT,
|
||||
RESPONSE_RECEIVED
|
||||
}
|
||||
@ -1,89 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.amount
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import com.mob.utsmyanmar.model.ProcessCode
|
||||
import com.mob.utsmyanmar.viewmodel.SharedViewModel
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||
|
||||
@Composable
|
||||
fun AmountRoute(
|
||||
action: String,
|
||||
sharedViewModel: SharedViewModel,
|
||||
onBack: () -> Unit,
|
||||
onNavigateCardWaiting: () -> Unit
|
||||
) {
|
||||
AmountScreen(
|
||||
title = action.ifBlank { "Amount" },
|
||||
onBackClick = onBack,
|
||||
onChargeClick = { amount ->
|
||||
sharedViewModel.amount.value = amount
|
||||
sharedViewModel.setAmountExist(true)
|
||||
sharedViewModel.setCardDataExist(false)
|
||||
sharedViewModel.setTransMenu(null)
|
||||
val config = action.toTransactionConfig()
|
||||
sharedViewModel.transactionName.value = config.transactionName
|
||||
sharedViewModel.transactionsType.value = config.transactionType
|
||||
sharedViewModel.processCode.value = config.processCode
|
||||
|
||||
onNavigateCardWaiting()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private data class TransactionConfig(
|
||||
val transactionName: String,
|
||||
val transactionType: TransactionsType,
|
||||
val processCode: String
|
||||
)
|
||||
|
||||
private fun String.toTransactionConfig(): TransactionConfig {
|
||||
return when (trim().lowercase()) {
|
||||
"void" -> TransactionConfig(
|
||||
transactionName = "SALE",
|
||||
transactionType = TransactionsType.VOID,
|
||||
processCode = ProcessCode.SALE_VOID + ProcessCode.SMART + ProcessCode.TO_ACCOUNT
|
||||
)
|
||||
|
||||
"refund" -> TransactionConfig(
|
||||
transactionName = "REFUND",
|
||||
transactionType = TransactionsType.REFUND,
|
||||
processCode = ProcessCode.REFUND + ProcessCode.SMART + ProcessCode.TO_ACCOUNT
|
||||
)
|
||||
|
||||
"pre-auth" -> TransactionConfig(
|
||||
transactionName = "PRE_AUTH",
|
||||
transactionType = TransactionsType.PRE_AUTH_SALE,
|
||||
processCode = ProcessCode.PRE_AUTH_SALE + ProcessCode.SMART + ProcessCode.TO_ACCOUNT
|
||||
)
|
||||
|
||||
"pre-auth void" -> TransactionConfig(
|
||||
transactionName = "PRE_AUTH",
|
||||
transactionType = TransactionsType.PRE_AUTH_VOID,
|
||||
processCode = ProcessCode.PRE_AUTH_VOID + ProcessCode.SMART + ProcessCode.TO_ACCOUNT
|
||||
)
|
||||
|
||||
"pre-auth complete" -> TransactionConfig(
|
||||
transactionName = "PRE_AUTH_COMPLETE",
|
||||
transactionType = TransactionsType.PRE_AUTH_COMPLETE,
|
||||
processCode = ProcessCode.PRE_AUTH_COMPLETE + ProcessCode.SMART + ProcessCode.TO_ACCOUNT
|
||||
)
|
||||
|
||||
"pre-auth complete void" -> TransactionConfig(
|
||||
transactionName = "PRE_AUTH_COMPLETE",
|
||||
transactionType = TransactionsType.PRE_AUTH_COMPLETE_VOID,
|
||||
processCode = ProcessCode.PRE_AUTH_COMPLETE_VOID + ProcessCode.SMART + ProcessCode.TO_ACCOUNT
|
||||
)
|
||||
|
||||
"cash out" -> TransactionConfig(
|
||||
transactionName = "CASH_OUT",
|
||||
transactionType = TransactionsType.CASH_OUT,
|
||||
processCode = ProcessCode.CASH_ADVANCE + ProcessCode.SMART + ProcessCode.TO_ACCOUNT
|
||||
)
|
||||
|
||||
else -> TransactionConfig(
|
||||
transactionName = "SALE",
|
||||
transactionType = TransactionsType.SALE,
|
||||
processCode = ProcessCode.SALE_PURCHASE + ProcessCode.SMART + ProcessCode.TO_ACCOUNT
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -1,363 +1,362 @@
|
||||
package com.mob.utsmyanmar.ui.amount
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.statusBarsPadding
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowBackIosNew
|
||||
import androidx.compose.material.icons.rounded.Backspace
|
||||
import androidx.compose.material.icons.rounded.KeyboardArrowLeft
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.mob.utsmyanmar.ui.components.appbar.AppBar
|
||||
import com.mob.utsmyanmar.ui.preview.P2Preview
|
||||
import com.mob.utsmyanmar.ui.theme.Color
|
||||
import com.mob.utsmyanmar.ui.theme.MOBPOSTheme
|
||||
import com.mob.utsmyanmar.ui.theme.Primary
|
||||
import com.mob.utsmyanmar.ui.theme.White
|
||||
import com.mob.utsmyanmar.R
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun AmountScreen(
|
||||
title: String = "Amount",
|
||||
onBackClick: () -> Unit = {},
|
||||
onChargeClick: (String) -> Unit = {}
|
||||
action: String,
|
||||
onBackClick: () -> Unit,
|
||||
onCancelClick: () -> Unit = {},
|
||||
onNextClick: (String) -> Unit = {}
|
||||
) {
|
||||
var amount by remember { mutableStateOf("") }
|
||||
|
||||
var amount by remember {
|
||||
mutableStateOf("0")
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
AppBar(title = title, icon = Icons.Default.ArrowBackIosNew, onIconClick = onBackClick)
|
||||
}
|
||||
CenterAlignedTopAppBar(
|
||||
title = {
|
||||
Text(
|
||||
text = action.uppercase(),
|
||||
color = White,
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
},
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onBackClick) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.ic_left_arrow),
|
||||
contentDescription = "Back",
|
||||
modifier = Modifier.size(24.dp),
|
||||
tint = White
|
||||
)
|
||||
}
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = Primary
|
||||
)
|
||||
)
|
||||
},
|
||||
containerColor = White
|
||||
) { paddingValues ->
|
||||
|
||||
NumericEntryScreen(
|
||||
modifier = Modifier.padding(paddingValues),
|
||||
title = title,
|
||||
prompt = "Enter $title",
|
||||
displayValue = formatAmount(amount.ifEmpty { "0" }),
|
||||
supportingText = "Enter the amount to continue",
|
||||
confirmText = "Next",
|
||||
prefixLabel = "MMK",
|
||||
onBackClick = onBackClick,
|
||||
onCancelClick = onBackClick,
|
||||
onConfirmClick = {
|
||||
if (amount.isNotEmpty()) {
|
||||
onChargeClick(amount)
|
||||
}
|
||||
},
|
||||
onKeyClick = { value ->
|
||||
amount = appendAmountValue(amount, value)
|
||||
},
|
||||
onDeleteClick = {
|
||||
amount = amount.dropLast(1)
|
||||
},
|
||||
confirmEnabled = amount.isNotEmpty(),
|
||||
canDelete = amount.isNotEmpty()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun NumericEntryScreen(
|
||||
title: String,
|
||||
prompt: String,
|
||||
displayValue: String,
|
||||
supportingText: String,
|
||||
confirmText: String,
|
||||
onBackClick: () -> Unit,
|
||||
onCancelClick: () -> Unit,
|
||||
onConfirmClick: () -> Unit,
|
||||
onKeyClick: (String) -> Unit,
|
||||
onDeleteClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
prefixLabel: String? = null,
|
||||
errorMessage: String? = null,
|
||||
confirmEnabled: Boolean = true,
|
||||
canDelete: Boolean = true,
|
||||
keys: List<List<String>> = listOf(
|
||||
listOf("1", "2", "3"),
|
||||
listOf("4", "5", "6"),
|
||||
listOf("7", "8", "9"),
|
||||
listOf(".", "0", "00")
|
||||
)
|
||||
) {
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxSize()
|
||||
.background(Color.IvoryBeige)
|
||||
.navigationBarsPadding()
|
||||
.statusBarsPadding()
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 20.dp)
|
||||
.padding(paddingValues)
|
||||
.background(White)
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(horizontal = 24.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(
|
||||
text = prompt,
|
||||
color = Color.Gray,
|
||||
fontSize = 11.sp,
|
||||
modifier = Modifier.align(Alignment.CenterHorizontally)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
AmountBox(
|
||||
amount = formatTypedAmount(amount),
|
||||
height = 134.dp
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
|
||||
Row(
|
||||
modifier = Modifier.align(Alignment.CenterHorizontally),
|
||||
verticalAlignment = Alignment.Bottom
|
||||
) {
|
||||
if (!prefixLabel.isNullOrBlank()) {
|
||||
Text(
|
||||
text = prefixLabel,
|
||||
color = Color.LegacyRed,
|
||||
fontSize = 13.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
modifier = Modifier.padding(end = 10.dp, bottom = 6.dp)
|
||||
)
|
||||
Keypad(
|
||||
buttonHeight = 74.dp,
|
||||
buttonSpacing = 12.dp,
|
||||
onKeyClick = { key ->
|
||||
amount = handleAmountInput(amount, key)
|
||||
}
|
||||
|
||||
Text(
|
||||
text = displayValue,
|
||||
color = Color.LegacyRed,
|
||||
fontSize = 32.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
|
||||
Text(
|
||||
text = supportingText,
|
||||
color = if (errorMessage == null) Color.Gray else Color.Error,
|
||||
fontSize = 11.sp,
|
||||
modifier = Modifier.align(Alignment.CenterHorizontally)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(80.dp))
|
||||
|
||||
NumericKeypad(
|
||||
keys = keys,
|
||||
onKeyClick = onKeyClick
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
Spacer(modifier = Modifier.height(18.dp))
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
horizontalArrangement = Arrangement.spacedBy(14.dp)
|
||||
) {
|
||||
|
||||
Button(
|
||||
onClick = onCancelClick,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(56.dp),
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
.height(68.dp),
|
||||
shape = RoundedCornerShape(18.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = Color.White,
|
||||
contentColor = Color.LegacyRed
|
||||
)
|
||||
containerColor = White,
|
||||
contentColor = Primary
|
||||
),
|
||||
border = ButtonDefaults.outlinedButtonBorder
|
||||
) {
|
||||
Text("Cancel")
|
||||
Text(
|
||||
text = "Cancel",
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onConfirmClick,
|
||||
onClick = {
|
||||
onNextClick(normalizeAmount(amount))
|
||||
},
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(56.dp),
|
||||
enabled = confirmEnabled,
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
.height(68.dp),
|
||||
shape = RoundedCornerShape(18.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = Color.LegacyRed,
|
||||
contentColor = Color.White,
|
||||
disabledContainerColor = Color.LegacyRed.copy(alpha = 0.5f),
|
||||
disabledContentColor = Color.White
|
||||
containerColor = Primary,
|
||||
contentColor = White
|
||||
)
|
||||
) {
|
||||
Text(
|
||||
text = confirmText,
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Medium
|
||||
text = "Next",
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(18.dp))
|
||||
}
|
||||
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopEnd)
|
||||
.padding(top = 25.dp, end = 20.dp)
|
||||
.clickable(enabled = canDelete) {
|
||||
onDeleteClick()
|
||||
},
|
||||
shape = RoundedCornerShape(18.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = Color.White),
|
||||
elevation = CardDefaults.cardElevation(defaultElevation = 6.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Backspace,
|
||||
contentDescription = "Delete",
|
||||
tint = if (canDelete) Color.LegacyRed else Color.Gray,
|
||||
modifier = Modifier.padding(horizontal = 14.dp, vertical = 12.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun NumericKeypad(
|
||||
keys: List<List<String>>,
|
||||
onKeyClick: (String) -> Unit
|
||||
private fun AmountBox(
|
||||
amount: String,
|
||||
height: Dp
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalArrangement = Arrangement.spacedBy(6.dp)
|
||||
) {
|
||||
keys.forEach { row ->
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
||||
) {
|
||||
row.forEach { key ->
|
||||
KeypadButton(
|
||||
text = key,
|
||||
modifier = Modifier.weight(1f),
|
||||
onClick = { onKeyClick(key) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun KeypadButton(
|
||||
text: String,
|
||||
modifier: Modifier = Modifier,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
val enabled = text.isNotBlank()
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
.height(66.dp)
|
||||
.shadow(
|
||||
elevation = 2.dp,
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
clip = false
|
||||
)
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(height)
|
||||
.background(
|
||||
color = Color.White,
|
||||
shape = RoundedCornerShape(8.dp)
|
||||
color = Primary,
|
||||
shape = RoundedCornerShape(20.dp)
|
||||
)
|
||||
.clickable(enabled = enabled) { onClick() },
|
||||
contentAlignment = Alignment.Center
|
||||
.padding(horizontal = 24.dp),
|
||||
contentAlignment = Alignment.CenterEnd
|
||||
) {
|
||||
Text(
|
||||
text = text,
|
||||
color = if (enabled) Color.LegacyRed else Color.White,
|
||||
fontSize = 24.sp,
|
||||
fontWeight = FontWeight.Normal,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatAmount(value: String): String {
|
||||
val normalized = value.ifEmpty { "0" }
|
||||
val wholePart = normalized.substringBefore(".").ifEmpty { "0" }
|
||||
val groupedWholePart = "%,d".format(wholePart.toLongOrNull() ?: 0L)
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
|
||||
if (!normalized.contains(".")) {
|
||||
return groupedWholePart
|
||||
}
|
||||
Text(
|
||||
text = amount,
|
||||
color = White,
|
||||
fontSize = 30.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
val decimalPart = normalized.substringAfter(".", "")
|
||||
return if (normalized.endsWith(".")) {
|
||||
"$groupedWholePart."
|
||||
} else {
|
||||
"$groupedWholePart.$decimalPart"
|
||||
}
|
||||
}
|
||||
Spacer(modifier = Modifier.width(14.dp))
|
||||
|
||||
private fun appendAmountValue(current: String, value: String): String {
|
||||
if (value == ".") {
|
||||
if (current.contains(".")) return current
|
||||
return if (current.isEmpty()) "0." else "$current."
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.background(
|
||||
color = White,
|
||||
shape = RoundedCornerShape(10.dp)
|
||||
)
|
||||
.padding(
|
||||
horizontal = 16.dp,
|
||||
vertical = 6.dp
|
||||
)
|
||||
) {
|
||||
|
||||
val decimalIndex = current.indexOf('.')
|
||||
return if (decimalIndex >= 0) {
|
||||
val decimalPart = current.substring(decimalIndex + 1)
|
||||
val remainingDecimalDigits = 2 - decimalPart.length
|
||||
if (remainingDecimalDigits <= 0) {
|
||||
current
|
||||
} else {
|
||||
current + value.take(remainingDecimalDigits)
|
||||
}
|
||||
} else {
|
||||
val wholeDigitsCount = current.filter(Char::isDigit).length
|
||||
val remainingWholeDigits = 9 - wholeDigitsCount
|
||||
if (remainingWholeDigits <= 0) {
|
||||
current
|
||||
} else {
|
||||
current + value.take(remainingWholeDigits)
|
||||
Text(
|
||||
text = "MMK",
|
||||
color = Primary,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@P2Preview
|
||||
@Composable
|
||||
fun PreviewAmountScreen() {
|
||||
AmountScreen { }
|
||||
private fun Keypad(
|
||||
buttonHeight: Dp,
|
||||
buttonSpacing: Dp,
|
||||
onKeyClick: (String) -> Unit
|
||||
) {
|
||||
|
||||
val keys = listOf(
|
||||
listOf("1", "2", "3"),
|
||||
listOf("4", "5", "6"),
|
||||
listOf("7", "8", "9"),
|
||||
listOf(".", "0", "DEL")
|
||||
)
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(buttonSpacing)
|
||||
) {
|
||||
|
||||
keys.forEach { row ->
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
|
||||
row.forEach { key ->
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
onKeyClick(key)
|
||||
},
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(buttonHeight),
|
||||
shape = RoundedCornerShape(18.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = Primary,
|
||||
contentColor = White
|
||||
),
|
||||
contentPadding = PaddingValues(0.dp)
|
||||
) {
|
||||
|
||||
if (key == "DEL") {
|
||||
|
||||
Text(
|
||||
text = "⌫",
|
||||
fontSize = 26.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
} else {
|
||||
|
||||
Text(
|
||||
text = key,
|
||||
fontSize = 22.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleAmountInput(
|
||||
current: String,
|
||||
key: String
|
||||
): String {
|
||||
|
||||
return when (key.uppercase()) {
|
||||
|
||||
"DEL" -> {
|
||||
current
|
||||
.dropLast(1)
|
||||
.ifEmpty { "0" }
|
||||
}
|
||||
|
||||
"." -> {
|
||||
if (current.contains(".")) {
|
||||
current
|
||||
} else {
|
||||
"${current.ifEmpty { "0" }}."
|
||||
}
|
||||
}
|
||||
|
||||
in "0".."9" -> {
|
||||
val sanitizedCurrent = if (current == "0") "" else current
|
||||
|
||||
if (sanitizedCurrent.contains(".")) {
|
||||
val decimal = sanitizedCurrent.substringAfter(".")
|
||||
|
||||
if (decimal.length >= 2) {
|
||||
current
|
||||
} else {
|
||||
sanitizedCurrent + key
|
||||
}
|
||||
} else {
|
||||
val nextValue = sanitizedCurrent + key
|
||||
nextValue.trimStart('0').ifEmpty { "0" }
|
||||
}
|
||||
}
|
||||
|
||||
else -> current
|
||||
}
|
||||
}
|
||||
|
||||
private fun normalizeAmount(value: String): String {
|
||||
if (value.isBlank()) return "0.00"
|
||||
|
||||
val normalized = if (value.endsWith(".")) {
|
||||
value.dropLast(1)
|
||||
} else {
|
||||
value
|
||||
}
|
||||
|
||||
return when {
|
||||
normalized.isBlank() -> "0.00"
|
||||
normalized.contains(".") -> {
|
||||
val whole = normalized.substringBefore(".").ifEmpty { "0" }
|
||||
val decimal = normalized.substringAfter(".")
|
||||
|
||||
when (decimal.length) {
|
||||
0 -> "$whole.00"
|
||||
1 -> "$whole.${decimal}0"
|
||||
else -> "$whole.${decimal.take(2)}"
|
||||
}
|
||||
}
|
||||
else -> "${normalized}.00"
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatTypedAmount(value: String): String {
|
||||
if (!value.contains(".")) return "$value.00"
|
||||
|
||||
val whole = value.substringBefore(".").ifEmpty { "0" }
|
||||
val decimal = value.substringAfter(".")
|
||||
|
||||
return when (decimal.length) {
|
||||
0 -> "$whole."
|
||||
1 -> "$whole.${decimal}0"
|
||||
else -> "$whole.${decimal.take(2)}"
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
private fun PreviewNumericEntryScreen() {
|
||||
NumericEntryScreen(
|
||||
title = "Amount",
|
||||
prompt = "Enter Amount",
|
||||
displayValue = "12,500",
|
||||
supportingText = "Enter the amount to continue",
|
||||
confirmText = "Next",
|
||||
onBackClick = {},
|
||||
onCancelClick = {},
|
||||
onConfirmClick = {},
|
||||
onKeyClick = {},
|
||||
onDeleteClick = {},
|
||||
prefixLabel = "MMK",
|
||||
confirmEnabled = true,
|
||||
canDelete = true
|
||||
)
|
||||
private fun AmountScreenPreview() {
|
||||
|
||||
MOBPOSTheme {
|
||||
|
||||
AmountScreen(
|
||||
action = "Amount",
|
||||
onBackClick = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.cardwaiting
|
||||
|
||||
sealed interface CardWaitingEvent {
|
||||
data object GoManualEntry : CardWaitingEvent
|
||||
data object GoProcessingCard : CardWaitingEvent
|
||||
data object GoTimeout : CardWaitingEvent
|
||||
data object GoMain : CardWaitingEvent
|
||||
data object GoBack : CardWaitingEvent
|
||||
}
|
||||
@ -1,442 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.cardwaiting
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.statusBarsPadding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.KeyboardArrowLeft
|
||||
import androidx.compose.material.icons.rounded.Wifi
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.draw.rotate
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.mob.utsmyanmar.R
|
||||
import com.mob.utsmyanmar.ui.preview.P2Preview
|
||||
import com.mob.utsmyanmar.ui.theme.Color
|
||||
|
||||
@Composable
|
||||
fun CardWaitingScreen(
|
||||
viewModel: CardWaitingViewModel,
|
||||
amount: String,
|
||||
onManualEntry: () -> Unit,
|
||||
onProcessingCard: () -> Unit,
|
||||
onBack: () -> Unit,
|
||||
onMain: () -> Unit
|
||||
) {
|
||||
val uiState by viewModel.uiState.collectAsState()
|
||||
|
||||
LaunchedEffect(viewModel) {
|
||||
viewModel.events.collect { event ->
|
||||
when (event) {
|
||||
CardWaitingEvent.GoManualEntry -> onManualEntry()
|
||||
CardWaitingEvent.GoProcessingCard -> onProcessingCard()
|
||||
CardWaitingEvent.GoMain -> onMain()
|
||||
CardWaitingEvent.GoBack -> onBack()
|
||||
CardWaitingEvent.GoTimeout -> Unit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(viewModel) {
|
||||
viewModel.onScreenResume()
|
||||
}
|
||||
|
||||
DisposableEffect(viewModel) {
|
||||
onDispose {
|
||||
viewModel.onScreenPause()
|
||||
}
|
||||
}
|
||||
|
||||
BackHandler(enabled = uiState.canGoBack) {
|
||||
viewModel.onBackPressed()
|
||||
}
|
||||
|
||||
CardWaitingScreenContent(
|
||||
amount = amount,
|
||||
uiState = uiState,
|
||||
onBackClick = viewModel::onBackPressed,
|
||||
onManualEntryClick = viewModel::onManualEntryClick
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CardWaitingScreenContent(
|
||||
amount: String,
|
||||
uiState: CardWaitingUiState,
|
||||
onBackClick: () -> Unit,
|
||||
onManualEntryClick: () -> Unit
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(Color.IvoryBeige)
|
||||
.statusBarsPadding()
|
||||
.navigationBarsPadding()
|
||||
.padding(horizontal = 20.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(54.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
if (uiState.canGoBack) {
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier.align(Alignment.CenterStart)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.KeyboardArrowLeft,
|
||||
contentDescription = "Back",
|
||||
tint = Color.LegacyRed
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Text(
|
||||
text = "AMOUNT TO PAY",
|
||||
color = Color.Black,
|
||||
fontSize = 10.sp,
|
||||
fontWeight = FontWeight.Medium
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(6.dp))
|
||||
|
||||
Row(verticalAlignment = Alignment.Bottom) {
|
||||
Text(
|
||||
text = amount,
|
||||
color = Color.LegacyRed,
|
||||
fontSize = 30.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.width(6.dp))
|
||||
|
||||
Text(
|
||||
text = "MMK",
|
||||
color = Color.LegacyRed,
|
||||
fontSize = 10.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
modifier = Modifier.padding(bottom = 6.dp)
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(32.dp))
|
||||
|
||||
ContactlessCircle(isLoading = uiState.isLoading)
|
||||
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
|
||||
Text(
|
||||
text = when {
|
||||
uiState.isCardCaptured -> "Card Detected"
|
||||
uiState.isFallback -> "Swipe Your Card"
|
||||
else -> "Tap Your Card"
|
||||
},
|
||||
color = Color.LegacyRed,
|
||||
fontSize = 13.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
Text(
|
||||
text = if (uiState.isCardCaptured) {
|
||||
"Reader captured card data"
|
||||
} else {
|
||||
"Hold your card near the reader"
|
||||
},
|
||||
color = Color.Black,
|
||||
fontSize = 9.sp
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(14.dp))
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.weight(1f),
|
||||
color = Color.Gray.copy(alpha = 0.4f)
|
||||
)
|
||||
|
||||
Text(
|
||||
text = "OR",
|
||||
modifier = Modifier.padding(horizontal = 12.dp),
|
||||
color = Color.Gray,
|
||||
fontSize = 10.sp
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.weight(1f),
|
||||
color = Color.Gray.copy(alpha = 0.4f)
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
|
||||
InsertCardRow()
|
||||
|
||||
Spacer(modifier = Modifier.height(18.dp))
|
||||
|
||||
Text(
|
||||
text = uiState.alertMessage,
|
||||
color = Color.Black,
|
||||
fontSize = 11.sp,
|
||||
textAlign = TextAlign.Center,
|
||||
lineHeight = 16.sp
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(18.dp))
|
||||
|
||||
// StatusPanel(uiState = uiState)
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
ManualEntryAction(onManualEntryClick = onManualEntryClick)
|
||||
|
||||
Spacer(modifier = Modifier.height(18.dp))
|
||||
|
||||
CardLogoRow()
|
||||
|
||||
Spacer(modifier = Modifier.height(34.dp))
|
||||
|
||||
PoweredByMob()
|
||||
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ContactlessCircle(isLoading: Boolean) {
|
||||
Box(
|
||||
modifier = Modifier.size(190.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
CircleBorder(180, 0.1f)
|
||||
CircleBorder(150, 0.20f)
|
||||
|
||||
Surface(
|
||||
modifier = Modifier.size(108.dp),
|
||||
shape = CircleShape,
|
||||
color = Color.White,
|
||||
shadowElevation = 8.dp
|
||||
) {
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
if (isLoading) {
|
||||
CircularProgressIndicator(
|
||||
color = Color.LegacyRed,
|
||||
strokeWidth = 3.dp,
|
||||
modifier = Modifier.size(40.dp)
|
||||
)
|
||||
} else {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Wifi,
|
||||
contentDescription = null,
|
||||
tint = Color.LegacyRed,
|
||||
modifier = Modifier
|
||||
.size(72.dp)
|
||||
.rotate(90f)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CircleBorder(
|
||||
size: Int,
|
||||
alpha: Float
|
||||
) {
|
||||
Surface(
|
||||
modifier = Modifier
|
||||
.size(size.dp)
|
||||
.alpha(alpha),
|
||||
shape = CircleShape,
|
||||
border = BorderStroke(1.dp, Color.LegacyRed)
|
||||
) {}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun InsertCardRow() {
|
||||
Row(
|
||||
modifier = Modifier.height(44.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.ic_insert_card),
|
||||
contentDescription = null,
|
||||
tint = Color.LegacyRed,
|
||||
modifier = Modifier.size(28.dp)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.width(10.dp))
|
||||
|
||||
Column {
|
||||
Text(
|
||||
text = "Insert Your Card",
|
||||
color = Color.LegacyRed,
|
||||
fontSize = 11.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
Text(
|
||||
text = "Chip facing up",
|
||||
color = Color.Black,
|
||||
fontSize = 9.sp
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun StatusPanel(uiState: CardWaitingUiState) {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
color = Color.White,
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 14.dp, vertical = 12.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = when {
|
||||
uiState.isCardCaptured -> "Reader status"
|
||||
uiState.isLoading -> "Reader status"
|
||||
else -> "Ready for card"
|
||||
},
|
||||
color = Color.LegacyRed,
|
||||
fontSize = 12.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
Text(
|
||||
text = when {
|
||||
uiState.isCardCaptured -> "Captured"
|
||||
uiState.isLoading -> "Initializing"
|
||||
else -> "Waiting"
|
||||
},
|
||||
color = Color.Gray,
|
||||
fontSize = 11.sp
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ManualEntryAction(onManualEntryClick: () -> Unit) {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
color = Color.White,
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(Color.White)
|
||||
.clickable(onClick = onManualEntryClick)
|
||||
.padding(vertical = 16.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = "Manual Entry",
|
||||
color = Color.LegacyRed,
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CardLogoRow() {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
color = Color.White,
|
||||
shape = RoundedCornerShape(3.dp)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(42.dp)
|
||||
.padding(horizontal = 14.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text("VISA", fontSize = 22.sp, fontWeight = FontWeight.Bold)
|
||||
Text("MC", fontSize = 18.sp, fontWeight = FontWeight.Bold)
|
||||
Text("MPU", fontSize = 20.sp, fontWeight = FontWeight.Bold)
|
||||
Text("UnionPay", fontSize = 12.sp, fontWeight = FontWeight.Bold)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PoweredByMob() {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
text = "Powered by",
|
||||
color = Color.Gray,
|
||||
fontSize = 8.sp
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.width(4.dp))
|
||||
|
||||
Text(
|
||||
text = "MOB",
|
||||
color = Color.Gray,
|
||||
fontSize = 9.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@P2Preview
|
||||
@Composable
|
||||
fun PreviewCardWaitingScreen() {
|
||||
CardWaitingScreenContent(
|
||||
amount = "50,000",
|
||||
uiState = CardWaitingUiState(),
|
||||
onBackClick = {},
|
||||
onManualEntryClick = {}
|
||||
)
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.cardwaiting
|
||||
|
||||
data class CardWaitingUiState(
|
||||
val alertMessage: String = "Please insert, tap, or swipe card",
|
||||
val isLoading: Boolean = false,
|
||||
val isFallback: Boolean = false,
|
||||
val canGoBack: Boolean = true,
|
||||
val isCardCaptured: Boolean = false
|
||||
)
|
||||
@ -1,319 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.cardwaiting
|
||||
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.mob.utsmyanmar.model.CardTransactionType
|
||||
import com.mob.utsmyanmar.model.ecr.ECRResultStatus
|
||||
import com.mob.utsmyanmar.utils.CoreUtils
|
||||
import com.mob.utsmyanmar.viewmodel.CardReaderViewModel
|
||||
import com.mob.utsmyanmar.viewmodel.SharedViewModel
|
||||
import com.sunmi.pay.hardware.aidl.AidlConstants
|
||||
import com.utsmyanmar.checkxread.checkcard.CheckCardResultX
|
||||
import com.utsmyanmar.checkxread.util.CardTypeX
|
||||
import com.utsmyanmar.ecr.ECRHelper
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.receiveAsFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class CardWaitingViewModel(
|
||||
private val cardReadViewModel: CardReaderViewModel,
|
||||
private val sharedViewModel: SharedViewModel
|
||||
) : ViewModel() {
|
||||
|
||||
companion object {
|
||||
fun provideFactory(
|
||||
cardReadViewModel: CardReaderViewModel,
|
||||
sharedViewModel: SharedViewModel
|
||||
): ViewModelProvider.Factory {
|
||||
return object : ViewModelProvider.Factory {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
return CardWaitingViewModel(
|
||||
cardReadViewModel = cardReadViewModel,
|
||||
sharedViewModel = sharedViewModel
|
||||
) as T
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val _uiState = MutableStateFlow(CardWaitingUiState())
|
||||
val uiState = _uiState.asStateFlow()
|
||||
|
||||
private val _events = Channel<CardWaitingEvent>()
|
||||
val events = _events.receiveAsFlow()
|
||||
|
||||
private var retryCounter = 0
|
||||
private var fallbackCounter = 0
|
||||
private var fallbackEnabled = false
|
||||
private var readerInitJob: Job? = null
|
||||
|
||||
fun onScreenResume() {
|
||||
retryCounter = 0
|
||||
fallbackCounter = SystemParamsOperation.getInstance().fallbackCounter
|
||||
fallbackEnabled = SystemParamsOperation.getInstance().fallbackEnabled
|
||||
val isSaleTransaction = sharedViewModel.transactionsType.value == TransactionsType.SALE
|
||||
|
||||
_uiState.update {
|
||||
it.copy(canGoBack = !isSaleTransaction)
|
||||
}
|
||||
|
||||
if (sharedViewModel.transactionsType.value == TransactionsType.REFUND) {
|
||||
sharedViewModel.enableCardStatusIcon(false, false, false, false)
|
||||
} else {
|
||||
sharedViewModel.enableCardStatusIcon(true, true, true, false)
|
||||
}
|
||||
|
||||
val isFallback = sharedViewModel.getIsFallback().value == true
|
||||
if (isFallback) {
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
alertMessage = "Fallback!\nPlease stripe!",
|
||||
isFallback = true,
|
||||
isCardCaptured = false
|
||||
)
|
||||
}
|
||||
} else {
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
alertMessage = "Please insert, tap, or swipe card",
|
||||
isFallback = false,
|
||||
isLoading = false,
|
||||
isCardCaptured = false
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
startCardReadWhenReady(isFallback)
|
||||
}
|
||||
|
||||
fun onScreenPause() {
|
||||
readerInitJob?.cancel()
|
||||
stopCardReading()
|
||||
}
|
||||
|
||||
fun onBackPressed() {
|
||||
if (sharedViewModel.isEcr.value == true) {
|
||||
sharedViewModel.isEcr.postValue(false)
|
||||
CoreUtils.getInstance(sharedViewModel).responseRejectMsg("Transaction cancelled")
|
||||
sharedViewModel.isEcrFinished.postValue(true)
|
||||
}
|
||||
|
||||
stopCardReading()
|
||||
|
||||
viewModelScope.launch {
|
||||
_events.send(CardWaitingEvent.GoBack)
|
||||
}
|
||||
}
|
||||
|
||||
fun onManualEntryClick() {
|
||||
viewModelScope.launch {
|
||||
_events.send(CardWaitingEvent.GoManualEntry)
|
||||
}
|
||||
}
|
||||
|
||||
private fun startCardReadWhenReady(isFallback: Boolean) {
|
||||
readerInitJob?.cancel()
|
||||
readerInitJob = viewModelScope.launch {
|
||||
if (cardReadViewModel.isReaderReady()) {
|
||||
setupCardReadProcess(isFallback)
|
||||
return@launch
|
||||
}
|
||||
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
alertMessage = "Initializing card reader...",
|
||||
isLoading = true,
|
||||
isCardCaptured = false
|
||||
)
|
||||
}
|
||||
|
||||
repeat(10) {
|
||||
delay(300)
|
||||
if (cardReadViewModel.isReaderReady()) {
|
||||
_uiState.update { state ->
|
||||
state.copy(
|
||||
alertMessage = if (isFallback) {
|
||||
"Fallback!\nPlease stripe!"
|
||||
} else {
|
||||
"Please insert, tap, or swipe card"
|
||||
},
|
||||
isLoading = false,
|
||||
isCardCaptured = false
|
||||
)
|
||||
}
|
||||
setupCardReadProcess(isFallback)
|
||||
return@launch
|
||||
}
|
||||
}
|
||||
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
alertMessage = "Card reader unavailable.\nPlease wait and try again.",
|
||||
isLoading = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupCardReadProcess(isFallback: Boolean) {
|
||||
initCheckCard(isFallback)
|
||||
}
|
||||
|
||||
private fun initCheckCard(isFallback: Boolean) {
|
||||
var allType =
|
||||
AidlConstants.CardType.NFC.value or
|
||||
AidlConstants.CardType.IC.value or
|
||||
AidlConstants.CardType.MAGNETIC.value
|
||||
|
||||
if (isFallback) {
|
||||
allType = AidlConstants.CardType.MAGNETIC.value
|
||||
} else if (
|
||||
SystemParamsOperation.getInstance().isMagStripeEnabled &&
|
||||
!SystemParamsOperation.getInstance().isNfcEnabled
|
||||
) {
|
||||
allType =
|
||||
AidlConstants.CardType.IC.value or
|
||||
AidlConstants.CardType.MAGNETIC.value
|
||||
}
|
||||
|
||||
cardReadViewModel.startCheckXProcess(
|
||||
allType,
|
||||
65,
|
||||
object : CheckCardResultX {
|
||||
override fun onSuccess(cardType: CardTypeX, isMPU: Boolean) {
|
||||
Log.d("CardWaitingViewModel", "on success cardType=$cardType and isMpu=$isMPU")
|
||||
when {
|
||||
!isFallback && cardType == CardTypeX.MAG -> {
|
||||
if (SystemParamsOperation.getInstance().isMagStripeEnabled) {
|
||||
cardReadViewModel.setCardTransactionType(CardTransactionType.MAG)
|
||||
} else {
|
||||
_uiState.update {
|
||||
it.copy(alertMessage = "Mag stripe not allowed")
|
||||
}
|
||||
setupCardReadProcess(false)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
isFallback && cardType == CardTypeX.MAG -> {
|
||||
sharedViewModel.setEmvTrans(false)
|
||||
cardReadViewModel.setCardTransactionType(CardTransactionType.FALLBACK)
|
||||
}
|
||||
|
||||
cardType == CardTypeX.IC || cardType == CardTypeX.NFC -> {
|
||||
if (isMPU) {
|
||||
sharedViewModel.setEmvTrans(false)
|
||||
cardReadViewModel.setCardTransactionType(CardTransactionType.MPU)
|
||||
} else {
|
||||
cardReadViewModel.setCardData(cardType.value)
|
||||
cardReadViewModel.setCardTransactionType(CardTransactionType.EMV)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
viewModelScope.launch {
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
alertMessage = "Card detected.",
|
||||
isLoading = false,
|
||||
isCardCaptured = true
|
||||
)
|
||||
}
|
||||
_events.send(CardWaitingEvent.GoProcessingCard)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError(code: Int, message: String) {
|
||||
ecrActionCancel("Transaction cancelled")
|
||||
|
||||
viewModelScope.launch {
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
alertMessage = message,
|
||||
isLoading = false
|
||||
)
|
||||
}
|
||||
_events.send(CardWaitingEvent.GoMain)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCommError() {
|
||||
if (fallbackEnabled && retryCounter < fallbackCounter) {
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
alertMessage = "Card not detected!\nRemain Attempt - ${fallbackCounter - retryCounter}"
|
||||
)
|
||||
}
|
||||
retryCounter++
|
||||
setupCardReadProcess(false)
|
||||
return
|
||||
}
|
||||
|
||||
if (retryCounter == fallbackCounter) {
|
||||
_uiState.update {
|
||||
it.copy(alertMessage = "Fallback!\nPlease stripe!")
|
||||
}
|
||||
setupCardReadProcess(true)
|
||||
return
|
||||
}
|
||||
|
||||
ecrActionCancel("Transaction cancelled")
|
||||
|
||||
viewModelScope.launch {
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
alertMessage = "Chip not detected!",
|
||||
isLoading = false
|
||||
)
|
||||
}
|
||||
_events.send(CardWaitingEvent.GoMain)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun ecrActionCancel(msg: String) {
|
||||
if (sharedViewModel.isEcr.value != true) {
|
||||
return
|
||||
}
|
||||
|
||||
sharedViewModel.isEcr.postValue(false)
|
||||
sharedViewModel.isEcrFinished.postValue(true)
|
||||
|
||||
if (SystemParamsOperation.getInstance().isCMHLEnabled) {
|
||||
ECRHelper.send(
|
||||
CoreUtils.getInstance(sharedViewModel)
|
||||
.generateCMHLResponse(ECRResultStatus.USER_CANCEL)
|
||||
)
|
||||
|
||||
CoreUtils.getInstance(sharedViewModel).responseACKCMHL()
|
||||
return
|
||||
}
|
||||
|
||||
CoreUtils.getInstance(sharedViewModel).responseRejectMsg(msg)
|
||||
}
|
||||
|
||||
private fun stopCardReading() {
|
||||
sharedViewModel.setIsFallback(false)
|
||||
cardReadViewModel.cancelCheckCard()
|
||||
cardReadViewModel.resetOneTimeFlag()
|
||||
cardReadViewModel.cancelCheckXProcess()
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
readerInitJob?.cancel()
|
||||
stopCardReading()
|
||||
}
|
||||
}
|
||||
@ -1,59 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.components.appbar
|
||||
|
||||
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import com.mob.utsmyanmar.ui.theme.Color
|
||||
import com.mob.utsmyanmar.ui.theme.Primary
|
||||
import com.mob.utsmyanmar.ui.theme.White
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun AppBar(
|
||||
title: String,
|
||||
icon: ImageVector? = null,
|
||||
onIconClick: (() -> Unit)? = null,
|
||||
) {
|
||||
CenterAlignedTopAppBar(
|
||||
title = {
|
||||
Text(
|
||||
text = title,
|
||||
color = White,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
},
|
||||
|
||||
navigationIcon = {
|
||||
if (icon != null && onIconClick != null) {
|
||||
IconButton(
|
||||
onClick = onIconClick
|
||||
) {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = "App bar icon",
|
||||
tint = White
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = Color.LegacyRed
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun PreviewAppBar(){
|
||||
AppBar(
|
||||
title = "Title"
|
||||
)
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.dashboard
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
@Composable
|
||||
fun DashboardRoute(
|
||||
onNavigateAmount: (String) -> Unit,
|
||||
settlementEnabled: Boolean,
|
||||
wavePayEnabled: Boolean,
|
||||
) {
|
||||
DashboardScreen(
|
||||
settlementEnabled = settlementEnabled,
|
||||
wavePayEnabled = wavePayEnabled,
|
||||
onNavigateAmount = onNavigateAmount
|
||||
)
|
||||
}
|
||||
@ -1,13 +1,10 @@
|
||||
package com.mob.utsmyanmar.ui.dashboard
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Menu
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
@ -23,19 +20,23 @@ import com.mob.utsmyanmar.ui.theme.MOBPOSTheme
|
||||
import com.mob.utsmyanmar.ui.theme.*
|
||||
import kotlinx.coroutines.launch
|
||||
import com.mob.utsmyanmar.R
|
||||
import com.mob.utsmyanmar.ui.components.appbar.AppBar
|
||||
import com.utsmyanmar.paylibs.print.NewPrintReceipt
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun DashboardScreen(
|
||||
settlementEnabled: Boolean,
|
||||
wavePayEnabled: Boolean,
|
||||
onNavigateAmount: (String) -> Unit
|
||||
onAmountClick: (String) -> Unit,
|
||||
onTransactionClick: () -> Unit,
|
||||
onSettlementClick: () -> Unit,
|
||||
onHistoryClick: () -> Unit,
|
||||
onCardClick: () -> Unit,
|
||||
onWavePayClick: () -> Unit
|
||||
) {
|
||||
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
|
||||
ModalNavigationDrawer(
|
||||
drawerState = drawerState,
|
||||
drawerContent = {
|
||||
@ -67,6 +68,7 @@ fun DashboardScreen(
|
||||
.fillMaxWidth()
|
||||
.clickable {
|
||||
scope.launch { drawerState.close() }
|
||||
onTransactionClick()
|
||||
}
|
||||
.padding(horizontal = 24.dp, vertical = 14.dp),
|
||||
fontSize = 16.sp
|
||||
@ -77,6 +79,7 @@ fun DashboardScreen(
|
||||
.fillMaxWidth()
|
||||
.clickable {
|
||||
scope.launch { drawerState.close() }
|
||||
onHistoryClick()
|
||||
}
|
||||
.padding(horizontal = 24.dp, vertical = 14.dp),
|
||||
fontSize = 16.sp
|
||||
@ -87,6 +90,7 @@ fun DashboardScreen(
|
||||
.fillMaxWidth()
|
||||
.clickable(enabled = settlementEnabled) {
|
||||
scope.launch { drawerState.close() }
|
||||
onSettlementClick()
|
||||
}
|
||||
.padding(horizontal = 24.dp, vertical = 14.dp),
|
||||
color = if (settlementEnabled) Black else White,
|
||||
@ -98,6 +102,7 @@ fun DashboardScreen(
|
||||
.fillMaxWidth()
|
||||
.clickable(enabled = wavePayEnabled) {
|
||||
scope.launch { drawerState.close() }
|
||||
onWavePayClick()
|
||||
}
|
||||
.padding(horizontal = 24.dp, vertical = 14.dp),
|
||||
color = if (wavePayEnabled) Black else White,
|
||||
@ -108,14 +113,28 @@ fun DashboardScreen(
|
||||
) {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
AppBar(
|
||||
title = "Dashboard",
|
||||
icon = Icons.Default.Menu,
|
||||
onIconClick = {
|
||||
scope.launch {
|
||||
drawerState.open()
|
||||
CenterAlignedTopAppBar(
|
||||
title = {
|
||||
Text(text = "Dashboard", color = White, fontWeight = FontWeight.SemiBold)
|
||||
},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = {
|
||||
scope.launch {
|
||||
drawerState.open()
|
||||
}
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.ic_menu),
|
||||
contentDescription = "Menu Icon",
|
||||
tint = White
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = Primary
|
||||
)
|
||||
)
|
||||
}
|
||||
) { paddingValues ->
|
||||
@ -156,16 +175,6 @@ fun DashboardScreen(
|
||||
.padding(16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Button(
|
||||
onClick = { try {
|
||||
NewPrintReceipt.getInstance().testPrint()
|
||||
println("printing...")
|
||||
}catch (e: Exception){
|
||||
println("printing error $e")
|
||||
} }
|
||||
) {
|
||||
Text(text = "test")
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
@ -178,7 +187,7 @@ fun DashboardScreen(
|
||||
contentColor = Primary,
|
||||
iconTint = Primary,
|
||||
border = null,
|
||||
onClick = { onNavigateAmount("Sale") },
|
||||
onClick = { onAmountClick("Sale") },
|
||||
)
|
||||
SquareButton(
|
||||
title = "Sign On",
|
||||
@ -188,7 +197,7 @@ fun DashboardScreen(
|
||||
contentColor = Primary,
|
||||
iconTint = Primary,
|
||||
border = null,
|
||||
onClick = { onNavigateAmount("Sign On") }
|
||||
onClick = { onAmountClick("Sign On") }
|
||||
)
|
||||
}
|
||||
|
||||
@ -205,7 +214,7 @@ fun DashboardScreen(
|
||||
contentColor = Primary,
|
||||
iconTint = Primary,
|
||||
border = null,
|
||||
onClick = {}
|
||||
onClick = onSettlementClick
|
||||
)
|
||||
SquareButton(
|
||||
title = "Others",
|
||||
@ -215,7 +224,7 @@ fun DashboardScreen(
|
||||
contentColor = Primary,
|
||||
iconTint = Primary,
|
||||
border = null,
|
||||
onClick = {}
|
||||
onClick = onCardClick
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -232,7 +241,12 @@ private fun DashboardScreenPreview() {
|
||||
DashboardScreen(
|
||||
settlementEnabled = true,
|
||||
wavePayEnabled = true,
|
||||
onNavigateAmount = {}
|
||||
onAmountClick = {},
|
||||
onTransactionClick = {},
|
||||
onSettlementClick = {},
|
||||
onHistoryClick = {},
|
||||
onCardClick = {},
|
||||
onWavePayClick = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,612 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.dashboard
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.pager.HorizontalPager
|
||||
import androidx.compose.foundation.pager.rememberPagerState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.BarChart
|
||||
import androidx.compose.material.icons.filled.Check
|
||||
import androidx.compose.material.icons.filled.ChevronRight
|
||||
import androidx.compose.material.icons.filled.Dashboard
|
||||
import androidx.compose.material.icons.filled.GridView
|
||||
import androidx.compose.material.icons.filled.History
|
||||
import androidx.compose.material.icons.filled.Link
|
||||
import androidx.compose.material.icons.filled.Menu
|
||||
import androidx.compose.material.icons.filled.PointOfSale
|
||||
import androidx.compose.material.icons.filled.QrCode
|
||||
import androidx.compose.material.icons.filled.Sync
|
||||
import androidx.compose.material.icons.filled.Wallet
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.DrawerValue
|
||||
import androidx.compose.material3.ModalDrawerSheet
|
||||
import androidx.compose.material3.ModalNavigationDrawer
|
||||
import androidx.compose.material3.NavigationDrawerItem
|
||||
import androidx.compose.material3.NavigationDrawerItemDefaults
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.VerticalDivider
|
||||
import androidx.compose.material3.rememberDrawerState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import coil3.compose.AsyncImage
|
||||
import com.mob.utsmyanmar.R
|
||||
import com.mob.utsmyanmar.ui.components.appbar.AppBar
|
||||
import com.mob.utsmyanmar.ui.device_info.DeviceInfoViewModel
|
||||
import com.mob.utsmyanmar.ui.preview.P2Preview
|
||||
import com.mob.utsmyanmar.ui.theme.Color
|
||||
import com.sunmi.pay.hardware.aidl.AidlConstants
|
||||
import com.utsmyanmar.baselib.BaseApplication
|
||||
import com.utsmyanmar.paylibs.sign_on.EchoTestProcess
|
||||
import com.utsmyanmar.paylibs.sign_on.SignOnListener
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun DashboardScreen2(
|
||||
onNavigateAmount: (String) -> Unit = {},
|
||||
onNavigateSignOn: () -> Unit = {},
|
||||
onNavigateSeeMore: () -> Unit = {},
|
||||
onNavigateSettlement: () -> Unit = {},
|
||||
deviceInfoViewModel: DeviceInfoViewModel = viewModel()
|
||||
) {
|
||||
val deviceInfo by deviceInfoViewModel.uiState.collectAsState()
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
deviceInfoViewModel.loadDeviceInfo();
|
||||
}
|
||||
|
||||
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
|
||||
val scope = rememberCoroutineScope()
|
||||
val mainHandler = remember { Handler(Looper.getMainLooper()) }
|
||||
var showHostActionDialog by remember { mutableStateOf(false) }
|
||||
var activeHostAction by remember { mutableStateOf("Log-On") }
|
||||
var isHostActionRunning by remember { mutableStateOf(false) }
|
||||
var dialogMessage by remember { mutableStateOf("") }
|
||||
|
||||
val isOnline = true;
|
||||
|
||||
fun confirmationMessage(action: String) = "Do you want to start ${action.lowercase()}?"
|
||||
fun processingMessage(action: String) = "Sending ${action.lowercase()} request to host..."
|
||||
fun successMessage(action: String) = "$action success."
|
||||
fun failureMessage(action: String, resultCode: Int?) =
|
||||
"$action failed. Response code: ${resultCode ?: -1}"
|
||||
|
||||
fun networkFailureMessage(action: String) = "Network error during $action."
|
||||
fun openHostActionDialog(action: String) {
|
||||
activeHostAction = action
|
||||
isHostActionRunning = false
|
||||
dialogMessage = confirmationMessage(action)
|
||||
showHostActionDialog = true
|
||||
}
|
||||
|
||||
if (showHostActionDialog) {
|
||||
AlertDialog(
|
||||
onDismissRequest = {
|
||||
if (!isHostActionRunning) {
|
||||
showHostActionDialog = false
|
||||
}
|
||||
},
|
||||
title = {
|
||||
Text(
|
||||
text = activeHostAction,
|
||||
color = Color.LegacyRed,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
},
|
||||
text = {
|
||||
Text(text = dialogMessage)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
if (isHostActionRunning) return@TextButton
|
||||
|
||||
if (dialogMessage != confirmationMessage(activeHostAction)) {
|
||||
showHostActionDialog = false
|
||||
dialogMessage = confirmationMessage(activeHostAction)
|
||||
return@TextButton
|
||||
}
|
||||
|
||||
isHostActionRunning = true
|
||||
dialogMessage = processingMessage(activeHostAction)
|
||||
|
||||
val signOnProcess = EchoTestProcess.getInstance()
|
||||
val request = when (activeHostAction) {
|
||||
"Echo Test" -> signOnProcess.enqueue(false)
|
||||
"Log-Off" -> signOnProcess.enqueueLogOff()
|
||||
else -> signOnProcess.enqueueLogOn()
|
||||
}
|
||||
|
||||
request
|
||||
.startSignOn(object : SignOnListener {
|
||||
override fun onSuccessSignOn() {
|
||||
mainHandler.post {
|
||||
isHostActionRunning = false
|
||||
dialogMessage = successMessage(activeHostAction)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailureSignOn(resultCode: Int?) {
|
||||
mainHandler.post {
|
||||
isHostActionRunning = false
|
||||
mainHandler.post {
|
||||
isHostActionRunning = false
|
||||
dialogMessage =
|
||||
failureMessage(activeHostAction, resultCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun onNetworkFailSignOn(message: String?) {
|
||||
mainHandler.post {
|
||||
isHostActionRunning = false
|
||||
dialogMessage = message?.takeIf { it.isNotBlank() }
|
||||
?: networkFailureMessage(activeHostAction)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = when {
|
||||
isHostActionRunning -> "Processing"
|
||||
dialogMessage == confirmationMessage(activeHostAction) -> "Start"
|
||||
else -> "Close"
|
||||
},
|
||||
color = Color.LegacyRed
|
||||
)
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
if (!isHostActionRunning) {
|
||||
TextButton(
|
||||
onClick = {
|
||||
showHostActionDialog = false
|
||||
dialogMessage = confirmationMessage(activeHostAction)
|
||||
}
|
||||
) {
|
||||
Text(text = "Cancel", color = Color.Gray)
|
||||
}
|
||||
}
|
||||
},
|
||||
containerColor = Color.White
|
||||
)
|
||||
}
|
||||
|
||||
ModalNavigationDrawer(
|
||||
drawerState = drawerState,
|
||||
drawerContent = {
|
||||
ModalDrawerSheet(
|
||||
modifier = Modifier.fillMaxWidth(0.78f),
|
||||
drawerContainerColor = Color.White,
|
||||
drawerShape = RoundedCornerShape(topEnd = 24.dp, bottomEnd = 24.dp)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(Color.IvoryBeige)
|
||||
.padding(horizontal = 20.dp, vertical = 28.dp)
|
||||
) {
|
||||
Row() {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(80.dp)
|
||||
.clip(CircleShape)
|
||||
.background(Color.White),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(R.drawable.logo_mob),
|
||||
contentDescription = "mob logo",
|
||||
modifier = Modifier
|
||||
.size(100.dp)
|
||||
.padding(16.dp),
|
||||
contentScale = ContentScale.Fit
|
||||
)
|
||||
}
|
||||
|
||||
Column() {
|
||||
Text(
|
||||
text = "MOB Merchant",
|
||||
color = Color.CrimsonRed,
|
||||
fontSize = 12.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
Text(
|
||||
text = "S/N:${deviceInfo.serialNumber}",
|
||||
color = Color.Black,
|
||||
fontSize = 12.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
Text(
|
||||
text = if(isOnline) "Online" else "Offline",
|
||||
color = if(isOnline) Color.Success else Color.Error,
|
||||
fontSize = 12.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(10.dp))
|
||||
|
||||
DrawerItem("Log-On", Icons.Default.Dashboard) {
|
||||
scope.launch { drawerState.close() }
|
||||
openHostActionDialog("Log-On")
|
||||
}
|
||||
DrawerItem("Echo Test", Icons.Default.Sync) {
|
||||
scope.launch { drawerState.close() }
|
||||
openHostActionDialog("Echo Test")
|
||||
}
|
||||
DrawerItem("Log-Off", Icons.Default.Dashboard) {
|
||||
scope.launch { drawerState.close() }
|
||||
openHostActionDialog("Log-Off")
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
Scaffold(
|
||||
containerColor = Color.IvoryBeige,
|
||||
topBar = {
|
||||
AppBar(
|
||||
title = "Dashboard",
|
||||
icon = Icons.Default.Menu,
|
||||
onIconClick = { scope.launch { drawerState.open() } }
|
||||
)
|
||||
}
|
||||
) { paddingValues ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(paddingValues)
|
||||
.fillMaxSize()
|
||||
// .padding(horizontal = 16.dp)
|
||||
) {
|
||||
AdvertisingArea()
|
||||
SummaryCard()
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
MenuGrid(
|
||||
onNavigateAmount = onNavigateAmount,
|
||||
onNavigateSignOn = onNavigateSignOn,
|
||||
onNavigateSeeMore = onNavigateSeeMore,
|
||||
onNavigateSettlement = onNavigateSettlement
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DrawerItem(
|
||||
title: String,
|
||||
icon: ImageVector,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
NavigationDrawerItem(
|
||||
label = {
|
||||
Text(
|
||||
text = title,
|
||||
fontWeight = FontWeight.Medium
|
||||
)
|
||||
},
|
||||
selected = false,
|
||||
onClick = onClick,
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = title
|
||||
)
|
||||
},
|
||||
modifier = Modifier.padding(horizontal = 12.dp, vertical = 2.dp),
|
||||
colors = NavigationDrawerItemDefaults.colors(
|
||||
unselectedContainerColor = androidx.compose.ui.graphics.Color.Transparent,
|
||||
unselectedIconColor = Color.LegacyRed,
|
||||
unselectedTextColor = Color.Black
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AdvertisingArea() {
|
||||
|
||||
val imageArray = listOf(
|
||||
"https://i.ytimg.com/vi/eRUVxGRp1Ms/maxresdefault.jpg",
|
||||
"https://sunmi.ua/wp-content/themes/yootheme/cache/04/p6-3-en-04a68bb5.jpeg",
|
||||
"https://mma.prnewswire.com/media/2080956/SUNMI_3rd_generation_products_T3_PRO_series_V3_MIX.jpg?p=facebook"
|
||||
);
|
||||
val pageState = rememberPagerState(pageCount = { imageArray.size })
|
||||
|
||||
LaunchedEffect(pageState) {
|
||||
while (true) {
|
||||
delay(10000)
|
||||
val nextPage = (pageState.currentPage + 1) % imageArray.size;
|
||||
|
||||
pageState.animateScrollToPage(
|
||||
page = nextPage,
|
||||
animationSpec = tween(durationMillis = 700)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(170.dp),
|
||||
shape = RoundedCornerShape(0.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = Color.White),
|
||||
) {
|
||||
HorizontalPager(
|
||||
state = pageState,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
) { page ->
|
||||
AsyncImage(
|
||||
model = imageArray[page],
|
||||
contentDescription = "ads images",
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentScale = ContentScale.Crop
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SummaryCard() {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = Color.White),
|
||||
elevation = CardDefaults.cardElevation(4.dp)
|
||||
) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
SummaryItem(
|
||||
title = "Sales Today",
|
||||
value = "MMK 2,000,000",
|
||||
subtitle = "47 Transactions",
|
||||
icon = Icons.Default.BarChart,
|
||||
iconBg = Color.CrimsonRed
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
color = Color.Gray,
|
||||
modifier = Modifier.padding(vertical = 6.dp, horizontal = 6.dp)
|
||||
)
|
||||
|
||||
SummaryItem(
|
||||
title = "Settlement",
|
||||
value = "Completed",
|
||||
subtitle = "Today 11:00 PM",
|
||||
icon = Icons.Default.Check,
|
||||
iconBg = Color.CrimsonRed
|
||||
)
|
||||
}
|
||||
|
||||
VerticalDivider(color = Color.Gray, modifier = Modifier.height(160.dp))
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.weight(0.75f)
|
||||
.padding(start = 18.dp),
|
||||
horizontalAlignment = Alignment.Start
|
||||
) {
|
||||
Row(verticalAlignment = Alignment.Bottom) {
|
||||
Text(
|
||||
text = "Last Sync",
|
||||
fontSize = 12.sp
|
||||
)
|
||||
IconCircle(Icons.Default.Sync, Color.CrimsonRed)
|
||||
}
|
||||
|
||||
Spacer(Modifier.height(6.dp))
|
||||
|
||||
Text(
|
||||
text = "5 mins ago",
|
||||
fontSize = 18.sp,
|
||||
color = Color.LegacyRed,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SummaryItem(
|
||||
title: String,
|
||||
value: String,
|
||||
subtitle: String,
|
||||
icon: ImageVector,
|
||||
iconBg: androidx.compose.ui.graphics.Color
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.Top,
|
||||
modifier = Modifier.padding(6.dp)
|
||||
) {
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Text(title, fontSize = 12.sp)
|
||||
Text(
|
||||
value,
|
||||
fontSize = 14.sp,
|
||||
color = Color.LegacyRed,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
Text(subtitle, fontSize = 12.sp)
|
||||
}
|
||||
IconCircle(icon, iconBg)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun IconCircle(
|
||||
icon: ImageVector,
|
||||
color: androidx.compose.ui.graphics.Color
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(38.dp)
|
||||
.clip(CircleShape)
|
||||
.background(color.copy(alpha = 0.1f)),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = null,
|
||||
tint = color,
|
||||
modifier = Modifier.size(22.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MenuGrid(
|
||||
onNavigateAmount: (String) -> Unit,
|
||||
onNavigateSignOn: () -> Unit,
|
||||
onNavigateSeeMore: () -> Unit,
|
||||
onNavigateSettlement: () -> Unit
|
||||
) {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||
modifier = Modifier.padding(horizontal = 16.dp)
|
||||
) {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
MenuCard(
|
||||
title = "Sale",
|
||||
icon = Icons.Default.PointOfSale,
|
||||
modifier = Modifier.weight(1f),
|
||||
onClick = { onNavigateAmount("Sale") }
|
||||
)
|
||||
MenuCard("MMQR", Icons.Default.QrCode, Modifier.weight(1f))
|
||||
MenuCard("History", Icons.Default.History, Modifier.weight(1f))
|
||||
}
|
||||
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
MenuCard(
|
||||
"Sign On",
|
||||
Icons.Default.Link,
|
||||
Modifier.weight(1f),
|
||||
onClick = onNavigateSignOn
|
||||
)
|
||||
MenuCard(
|
||||
"Settlement",
|
||||
Icons.Default.Wallet,
|
||||
Modifier.weight(1f),
|
||||
onClick = onNavigateSettlement
|
||||
)
|
||||
MenuCard(
|
||||
"See More",
|
||||
Icons.Default.GridView,
|
||||
Modifier.weight(1f),
|
||||
onClick = onNavigateSeeMore
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MenuCard(
|
||||
title: String,
|
||||
icon: ImageVector,
|
||||
modifier: Modifier = Modifier,
|
||||
onClick: (() -> Unit)? = null
|
||||
) {
|
||||
Card(
|
||||
modifier = modifier
|
||||
.height(100.dp)
|
||||
.then(
|
||||
if (onClick != null) {
|
||||
Modifier.clickable(onClick = onClick)
|
||||
} else {
|
||||
Modifier
|
||||
}
|
||||
),
|
||||
shape = RoundedCornerShape(14.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = Color.White),
|
||||
elevation = CardDefaults.cardElevation(5.dp)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(6.dp)
|
||||
) {
|
||||
Column {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = title,
|
||||
tint = Color.LegacyRed,
|
||||
modifier = Modifier.size(50.dp)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
fontSize = 12.sp,
|
||||
color = Color.Black,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
Icon(
|
||||
imageVector = Icons.Default.ChevronRight,
|
||||
contentDescription = null,
|
||||
tint = Color.LegacyRed,
|
||||
modifier = Modifier.size(28.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@P2Preview
|
||||
@Composable
|
||||
fun PreviewDashboardScreen2() {
|
||||
DashboardScreen2()
|
||||
}
|
||||
@ -1,141 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.dashboard
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.items
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.AccountBalanceWallet
|
||||
import androidx.compose.material.icons.filled.CreditCard
|
||||
import androidx.compose.material.icons.filled.Lock
|
||||
import androidx.compose.material.icons.filled.LockOpen
|
||||
import androidx.compose.material.icons.filled.Replay
|
||||
import androidx.compose.material.icons.filled.SwapHoriz
|
||||
import androidx.compose.material.icons.filled.Undo
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.mob.utsmyanmar.ui.components.appbar.AppBar
|
||||
import com.mob.utsmyanmar.ui.preview.P2Preview
|
||||
import com.mob.utsmyanmar.ui.theme.Color
|
||||
|
||||
@Composable
|
||||
fun SeeMoreScreen(
|
||||
onBack: () -> Unit = {},
|
||||
onNavigateAmount: (String) -> Unit = {}
|
||||
) {
|
||||
val items = listOf(
|
||||
SeeMoreItem("Void", Icons.Default.Undo),
|
||||
SeeMoreItem("Refund", Icons.Default.Replay),
|
||||
SeeMoreItem("Pre-Auth", Icons.Default.Lock),
|
||||
SeeMoreItem("Pre-Auth Void", Icons.Default.LockOpen),
|
||||
SeeMoreItem("Pre-Auth Complete", Icons.Default.CreditCard),
|
||||
SeeMoreItem("Pre-Auth Complete Void", Icons.Default.SwapHoriz),
|
||||
SeeMoreItem("Cash Out", Icons.Default.AccountBalanceWallet)
|
||||
)
|
||||
|
||||
Scaffold(
|
||||
containerColor = Color.IvoryBeige,
|
||||
topBar = {
|
||||
AppBar(
|
||||
title = "See More",
|
||||
icon = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
onIconClick = onBack
|
||||
)
|
||||
}
|
||||
) { paddingValues ->
|
||||
LazyVerticalGrid(
|
||||
columns = GridCells.Fixed(2),
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues),
|
||||
contentPadding = PaddingValues(16.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
items(items) { item ->
|
||||
MoreMenuCard(
|
||||
title = item.title,
|
||||
icon = item.icon,
|
||||
onClick = { onNavigateAmount(item.title) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MoreMenuCard(
|
||||
title: String,
|
||||
icon: ImageVector,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(132.dp)
|
||||
.clickable(onClick = onClick),
|
||||
shape = RoundedCornerShape(18.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = Color.White),
|
||||
elevation = CardDefaults.cardElevation(4.dp)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(14.dp),
|
||||
verticalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.background(Color.CrimsonRed, RoundedCornerShape(14.dp))
|
||||
.padding(12.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = title,
|
||||
tint = Color.White
|
||||
)
|
||||
}
|
||||
|
||||
Text(
|
||||
text = title,
|
||||
color = Color.Black,
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
textAlign = TextAlign.Start
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private data class SeeMoreItem(
|
||||
val title: String,
|
||||
val icon: ImageVector
|
||||
)
|
||||
|
||||
@P2Preview
|
||||
@Composable
|
||||
private fun PreviewSeeMoreScreen() {
|
||||
SeeMoreScreen()
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.device_info
|
||||
|
||||
data class DeviceInfoUiState(
|
||||
val hardwareVersion: String = "",
|
||||
val firmwareVersion: String = "",
|
||||
val serialNumber: String = "",
|
||||
val deviceModel: String = "",
|
||||
val finalVersion: String = "",
|
||||
val isLoading: Boolean = false,
|
||||
val errorMessage: String? = null
|
||||
)
|
||||
@ -1,52 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.device_info
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.sunmi.pay.hardware.aidl.AidlConstants
|
||||
import com.utsmyanmar.baselib.BaseApplication
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
class DeviceInfoViewModel : ViewModel() {
|
||||
|
||||
private val _uiState = MutableStateFlow(DeviceInfoUiState())
|
||||
val uiState = _uiState.asStateFlow()
|
||||
|
||||
fun loadDeviceInfo() {
|
||||
_uiState.value = _uiState.value.copy(isLoading = true)
|
||||
|
||||
try {
|
||||
val hardwareVersion = getParams(AidlConstants.SysParam.HARDWARE_VERSION)
|
||||
val firmwareVersion = getParams(AidlConstants.SysParam.FIRMWARE_VERSION)
|
||||
val serialNo = getParams(AidlConstants.SysParam.SN)
|
||||
val deviceModel = getParams(AidlConstants.SysParam.DEVICE_MODEL)
|
||||
val finalVersion = SystemParamsOperation.getInstance().finalVersion ?: ""
|
||||
|
||||
_uiState.value = DeviceInfoUiState(
|
||||
hardwareVersion = hardwareVersion,
|
||||
firmwareVersion = firmwareVersion,
|
||||
serialNumber = serialNo,
|
||||
deviceModel = deviceModel,
|
||||
finalVersion = finalVersion,
|
||||
isLoading = false
|
||||
)
|
||||
|
||||
} catch (e: Exception) {
|
||||
_uiState.value = _uiState.value.copy(
|
||||
isLoading = false,
|
||||
errorMessage = e.message ?: "Failed to load device info"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getParams(name: String): String {
|
||||
return try {
|
||||
BaseApplication.getInstance()
|
||||
.basicOptBinder
|
||||
?.getSysParam(name)
|
||||
?: ""
|
||||
} catch (e: Exception) {
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,210 +1,34 @@
|
||||
package com.mob.utsmyanmar.ui.navigation
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.NavType
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.navArgument
|
||||
import com.mob.utsmyanmar.model.ProcessCode
|
||||
import com.mob.utsmyanmar.ui.amount.AmountRoute
|
||||
import com.mob.utsmyanmar.ui.cardwaiting.CardWaitingScreen
|
||||
import com.mob.utsmyanmar.ui.cardwaiting.CardWaitingViewModel
|
||||
import com.mob.utsmyanmar.ui.dashboard.DashboardScreen2
|
||||
import com.mob.utsmyanmar.ui.dashboard.SeeMoreScreen
|
||||
import com.mob.utsmyanmar.ui.pinpad.PinPadRoute
|
||||
import com.mob.utsmyanmar.ui.processing_card.ProcessingCardRoute
|
||||
import com.mob.utsmyanmar.ui.processing_card.ProcessingCardViewModel
|
||||
import com.mob.utsmyanmar.ui.print_receipt.PrintReceiptScreen
|
||||
import com.mob.utsmyanmar.ui.refund_rrn.InputRrnRoute
|
||||
import com.mob.utsmyanmar.ui.sign_on.SignOnResultScreen
|
||||
import com.mob.utsmyanmar.ui.sign_on.SignOnRoute
|
||||
import com.mob.utsmyanmar.ui.sending_to_host.ProcessingRoute
|
||||
import com.mob.utsmyanmar.ui.settlement.SettlementScreen
|
||||
import com.mob.utsmyanmar.ui.transaction_result.TransactionResultRoute
|
||||
import com.mob.utsmyanmar.ui.sale_void.TranDetailPage
|
||||
import com.mob.utsmyanmar.ui.sale_void.VoidViewModel
|
||||
import com.mob.utsmyanmar.ui.sale_void.VoidTraceScreen
|
||||
import com.mob.utsmyanmar.viewmodel.CardReaderViewModel
|
||||
import com.mob.utsmyanmar.viewmodel.EmvTransactionProcessViewModel
|
||||
import com.mob.utsmyanmar.ui.pinpad.PinPadViewModel
|
||||
import com.mob.utsmyanmar.viewmodel.SharedViewModel
|
||||
import com.mob.utsmyanmar.viewmodel.TransProcessViewModel
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||
import com.mob.utsmyanmar.ui.amount.AmountScreen
|
||||
import com.mob.utsmyanmar.ui.dashboard.DashboardScreen
|
||||
|
||||
@SuppressLint("ContextCastToActivity")
|
||||
@Composable
|
||||
fun AppNavGraph(
|
||||
navController: NavHostController
|
||||
) {
|
||||
val activity = LocalContext.current as ComponentActivity
|
||||
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = Routes.Dashboard.route
|
||||
) {
|
||||
composable(Routes.Dashboard.route) {
|
||||
val sharedViewModel: SharedViewModel = hiltViewModel(activity);
|
||||
DashboardScreen2(
|
||||
onNavigateAmount = { action ->
|
||||
if(action == "Sale"){
|
||||
sharedViewModel.transactionsType.value = TransactionsType.SALE;
|
||||
sharedViewModel.processCode.value = ProcessCode.SALE_PURCHASE + ProcessCode.SMART + ProcessCode.TO_ACCOUNT;
|
||||
}
|
||||
|
||||
navController.navigate(Routes.Amount.createRoute(action)) {
|
||||
launchSingleTop = true
|
||||
}
|
||||
DashboardScreen(
|
||||
settlementEnabled = true,
|
||||
wavePayEnabled = true,
|
||||
onAmountClick = { action ->
|
||||
navController.navigate(Routes.Amount.createRoute(action))
|
||||
},
|
||||
onNavigateSignOn = {
|
||||
navController.navigate(Routes.SignOn.route) {
|
||||
launchSingleTop = true
|
||||
}
|
||||
},
|
||||
onNavigateSeeMore = {
|
||||
navController.navigate(Routes.SeeMore.route) {
|
||||
launchSingleTop = true
|
||||
}
|
||||
},
|
||||
onNavigateSettlement = {
|
||||
navController.navigate(Routes.Settlement.route) {
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.SeeMore.route) {
|
||||
SeeMoreScreen(
|
||||
onBack = { navController.popBackStack() },
|
||||
onNavigateAmount = { action ->
|
||||
if (action == "Void") {
|
||||
navController.navigate(Routes.VoidTrace.route) {
|
||||
launchSingleTop = true
|
||||
}
|
||||
} else {
|
||||
navController.navigate(Routes.Amount.createRoute(action)) {
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.VoidTrace.route) {
|
||||
val voidViewModel: VoidViewModel = hiltViewModel()
|
||||
|
||||
VoidTraceScreen(
|
||||
voidViewModel = voidViewModel,
|
||||
onNavigateTranDetail = { trace ->
|
||||
navController.navigate(Routes.VoidTranDetail.createRoute(trace)) {
|
||||
launchSingleTop = true
|
||||
}
|
||||
},
|
||||
onBack = { navController.popBackStack() }
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.Settlement.route) {
|
||||
val sharedViewModel: SharedViewModel = hiltViewModel(activity)
|
||||
|
||||
SettlementScreen(
|
||||
sharedViewModel = sharedViewModel,
|
||||
onBack = { navController.popBackStack() },
|
||||
onStartSettlement = {
|
||||
sharedViewModel.transactionsType.value = com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.SETTLEMENT
|
||||
navController.navigate(Routes.Processing.route) {
|
||||
popUpTo(Routes.Settlement.route) {
|
||||
inclusive = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
composable(
|
||||
route = Routes.VoidTranDetail.route,
|
||||
arguments = listOf(
|
||||
navArgument("trace") {
|
||||
type = NavType.StringType
|
||||
}
|
||||
)
|
||||
) { backStackEntry ->
|
||||
val voidViewModel: VoidViewModel = hiltViewModel()
|
||||
val sharedViewModel: SharedViewModel = hiltViewModel(activity)
|
||||
val trace = backStackEntry.arguments?.getString("trace").orEmpty()
|
||||
|
||||
TranDetailPage(
|
||||
voidViewModel = voidViewModel,
|
||||
trace = trace,
|
||||
onBack = { navController.popBackStack() },
|
||||
onProceedVoid = { payDetail ->
|
||||
sharedViewModel.transactionsType.value = com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.VOID
|
||||
sharedViewModel.payDetail.value = payDetail
|
||||
navController.navigate(Routes.Processing.route) {
|
||||
popUpTo(Routes.VoidTranDetail.route) {
|
||||
inclusive = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.SignOn.route) {
|
||||
SignOnRoute(
|
||||
onBack = { navController.popBackStack() },
|
||||
onNavigateResult = { isSuccess, message ->
|
||||
navController.navigate(Routes.SignOnResult.createRoute(isSuccess, message)) {
|
||||
popUpTo(Routes.SignOn.route) {
|
||||
inclusive = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
composable(
|
||||
route = Routes.SignOnResult.route,
|
||||
arguments = listOf(
|
||||
navArgument("isSuccess") {
|
||||
type = NavType.BoolType
|
||||
},
|
||||
navArgument("message") {
|
||||
type = NavType.StringType
|
||||
}
|
||||
)
|
||||
) { backStackEntry ->
|
||||
val isSuccess = backStackEntry.arguments?.getBoolean("isSuccess") ?: false
|
||||
val message = backStackEntry.arguments?.getString("message").orEmpty()
|
||||
|
||||
SignOnResultScreen(
|
||||
isSuccess = isSuccess,
|
||||
message = message,
|
||||
onBack = { navController.popBackStack() },
|
||||
onDone = {
|
||||
navController.navigate(Routes.Dashboard.route) {
|
||||
popUpTo(Routes.Dashboard.route) {
|
||||
inclusive = false
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
},
|
||||
onRetry = {
|
||||
navController.navigate(Routes.SignOn.route) {
|
||||
popUpTo(Routes.SignOnResult.route) {
|
||||
inclusive = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
onTransactionClick = {},
|
||||
onSettlementClick = {},
|
||||
onHistoryClick = {},
|
||||
onCardClick = {},
|
||||
onWavePayClick = {}
|
||||
)
|
||||
}
|
||||
|
||||
@ -216,202 +40,10 @@ fun AppNavGraph(
|
||||
}
|
||||
)
|
||||
) { backStackEntry ->
|
||||
val sharedViewModel: SharedViewModel = hiltViewModel(activity)
|
||||
|
||||
AmountRoute(
|
||||
AmountScreen(
|
||||
action = backStackEntry.arguments?.getString("action").orEmpty(),
|
||||
sharedViewModel = sharedViewModel,
|
||||
onBack = { navController.popBackStack() },
|
||||
onNavigateCardWaiting = {
|
||||
navController.navigate(Routes.CardWaiting.route) {
|
||||
popUpTo(Routes.Amount.route) {
|
||||
inclusive = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.CardWaiting.route) {
|
||||
val sharedViewModel: SharedViewModel = hiltViewModel(activity)
|
||||
val cardReaderViewModel: CardReaderViewModel = hiltViewModel(activity)
|
||||
val cardWaitingViewModel: CardWaitingViewModel = viewModel(
|
||||
factory = CardWaitingViewModel.provideFactory(
|
||||
cardReadViewModel = cardReaderViewModel,
|
||||
sharedViewModel = sharedViewModel
|
||||
)
|
||||
)
|
||||
|
||||
CardWaitingScreen(
|
||||
viewModel = cardWaitingViewModel,
|
||||
amount = formatAmountForDisplay(sharedViewModel.amount.value),
|
||||
onManualEntry = {},
|
||||
onProcessingCard = {
|
||||
navController.navigate(Routes.ProcessingCard.route) {
|
||||
popUpTo(Routes.CardWaiting.route) {
|
||||
inclusive = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
},
|
||||
onBack = { navController.popBackStack() },
|
||||
onMain = {
|
||||
navController.navigate(Routes.Dashboard.route) {
|
||||
popUpTo(Routes.Dashboard.route) {
|
||||
inclusive = false
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.ProcessingCard.route) {
|
||||
val sharedViewModel: SharedViewModel = hiltViewModel(activity)
|
||||
val cardReaderViewModel: CardReaderViewModel = hiltViewModel(activity)
|
||||
val transProcessViewModel: TransProcessViewModel = hiltViewModel(activity)
|
||||
val pinPadViewModel: PinPadViewModel = hiltViewModel(activity)
|
||||
val emvTransactionViewModel: EmvTransactionProcessViewModel = hiltViewModel(activity)
|
||||
val processingCardViewModel: ProcessingCardViewModel = viewModel(
|
||||
factory = ProcessingCardViewModel.provideFactory(
|
||||
cardReadViewModel = cardReaderViewModel,
|
||||
sharedViewModel = sharedViewModel,
|
||||
transProcessViewModel = transProcessViewModel,
|
||||
pinPadViewModel = pinPadViewModel,
|
||||
emvTransactionViewModel = emvTransactionViewModel
|
||||
)
|
||||
)
|
||||
|
||||
ProcessingCardRoute(
|
||||
viewModel = processingCardViewModel,
|
||||
onNavigatePinPad = {
|
||||
pinPadViewModel.resetSessionState()
|
||||
navController.navigate(Routes.PinPad.route) {
|
||||
popUpTo(Routes.ProcessingCard.route) {
|
||||
inclusive = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
},
|
||||
onNavigateInputAmount = { navController.popBackStack(Routes.Amount.route, false) },
|
||||
onNavigateProcessing = {},
|
||||
onNavigateEmvTransaction = {},
|
||||
onNavigateError = {},
|
||||
onBack = { navController.popBackStack() },
|
||||
onShowDecline = {}
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.PinPad.route) {
|
||||
val sharedViewModel: SharedViewModel = hiltViewModel(activity)
|
||||
val pinPadViewModel: PinPadViewModel = hiltViewModel(activity)
|
||||
val transProcessViewModel: TransProcessViewModel = hiltViewModel(activity)
|
||||
|
||||
PinPadRoute(
|
||||
pinPadViewModel = pinPadViewModel,
|
||||
sharedViewModel = sharedViewModel,
|
||||
transProcessViewModel = transProcessViewModel,
|
||||
onNavigateInputRrn = {
|
||||
navController.navigate(Routes.InputRrn.route) {
|
||||
popUpTo(Routes.PinPad.route) {
|
||||
inclusive = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
},
|
||||
onNavigateProcessing = {
|
||||
navController.navigate(Routes.Processing.route) {
|
||||
popUpTo(Routes.PinPad.route) {
|
||||
inclusive = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
},
|
||||
onBack = { navController.popBackStack() }
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.InputRrn.route) {
|
||||
val sharedViewModel: SharedViewModel = hiltViewModel(activity)
|
||||
|
||||
InputRrnRoute(
|
||||
sharedViewModel = sharedViewModel,
|
||||
onBack = { navController.popBackStack() },
|
||||
onNavigateProcessing = {
|
||||
navController.navigate(Routes.Processing.route) {
|
||||
popUpTo(Routes.InputRrn.route) {
|
||||
inclusive = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.Processing.route) {
|
||||
val sharedViewModel: SharedViewModel = hiltViewModel(activity)
|
||||
val transProcessViewModel: TransProcessViewModel = hiltViewModel(activity)
|
||||
|
||||
ProcessingRoute(
|
||||
sharedViewModel = sharedViewModel,
|
||||
transProcessViewModel = transProcessViewModel,
|
||||
onNavigateTransactionResult = {
|
||||
navController.navigate(Routes.TransactionResult.route) {
|
||||
popUpTo(Routes.Processing.route) {
|
||||
inclusive = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.TransactionResult.route) {
|
||||
val sharedViewModel: SharedViewModel = hiltViewModel(activity)
|
||||
|
||||
TransactionResultRoute(
|
||||
sharedViewModel = sharedViewModel,
|
||||
onNavigateMain = {
|
||||
navController.navigate(Routes.Dashboard.route) {
|
||||
popUpTo(Routes.Dashboard.route) {
|
||||
inclusive = false
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
},
|
||||
onNavigatePrintReceipt = {
|
||||
navController.navigate(Routes.PrintReceipt.route) {
|
||||
popUpTo(Routes.TransactionResult.route) {
|
||||
inclusive = false
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
},
|
||||
onShowError = {},
|
||||
onShowSuccess = {},
|
||||
onShowPrinterDialog = {}
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.PrintReceipt.route) {
|
||||
PrintReceiptScreen(
|
||||
onPrint = {},
|
||||
onDone = {
|
||||
navController.navigate(Routes.Dashboard.route) {
|
||||
popUpTo(Routes.Dashboard.route) {
|
||||
inclusive = false
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
onBackClick = { navController.popBackStack() }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatAmountForDisplay(amount: String?): String {
|
||||
val normalizedAmount = amount.orEmpty()
|
||||
val value = normalizedAmount.toLongOrNull() ?: return normalizedAmount.ifBlank { "0" }
|
||||
return "%,d".format(value)
|
||||
}
|
||||
|
||||
@ -1,29 +1,8 @@
|
||||
package com.mob.utsmyanmar.ui.navigation
|
||||
|
||||
import android.net.Uri
|
||||
|
||||
sealed class Routes(val route: String) {
|
||||
data object Dashboard : Routes("dashboard")
|
||||
data object Amount : Routes("amount/{action}") {
|
||||
fun createRoute(action: String): String = "amount/${Uri.encode(action)}"
|
||||
fun createRoute(action: String): String = "amount/$action"
|
||||
}
|
||||
data object SeeMore : Routes("see_more")
|
||||
data object Settlement : Routes("settlement")
|
||||
data object VoidTrace : Routes("void_trace")
|
||||
data object VoidTranDetail : Routes("void_tran_detail/{trace}") {
|
||||
fun createRoute(trace: String): String = "void_tran_detail/${Uri.encode(trace)}"
|
||||
}
|
||||
data object SignOn : Routes("sign_on")
|
||||
data object SignOnResult : Routes("sign_on_result/{isSuccess}/{message}") {
|
||||
fun createRoute(isSuccess: Boolean, message: String): String {
|
||||
return "sign_on_result/$isSuccess/${Uri.encode(message)}"
|
||||
}
|
||||
}
|
||||
data object CardWaiting : Routes("card_waiting")
|
||||
data object ProcessingCard : Routes("processing_card")
|
||||
data object PinPad : Routes("pin_pad")
|
||||
data object InputRrn : Routes("input_rrn")
|
||||
data object Processing : Routes("processing")
|
||||
data object TransactionResult : Routes("transaction_result")
|
||||
data object PrintReceipt : Routes("print_receipt")
|
||||
}
|
||||
|
||||
@ -1,334 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.password_Input
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.statusBarsPadding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowBackIosNew
|
||||
import androidx.compose.material.icons.rounded.Backspace
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.mob.utsmyanmar.ui.components.appbar.AppBar
|
||||
import com.mob.utsmyanmar.ui.preview.P2Preview
|
||||
import com.mob.utsmyanmar.ui.theme.Color
|
||||
|
||||
|
||||
@Composable
|
||||
fun InputPassword(
|
||||
title: String = "Password",
|
||||
onBackClick: () -> Unit = {},
|
||||
onChargeClick: (String) -> Unit = {}
|
||||
) {
|
||||
var amount by remember { mutableStateOf("") }
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
AppBar(title = title, icon = Icons.Default.ArrowBackIosNew, onIconClick = onBackClick)
|
||||
},
|
||||
containerColor = Color.IvoryBeige
|
||||
) { paddingValues ->
|
||||
|
||||
NumericEntryScreen(
|
||||
modifier = Modifier.padding(paddingValues),
|
||||
title = title,
|
||||
prompt = "Enter $title",
|
||||
supportingText = "Enter your secure password",
|
||||
confirmText = "Next",
|
||||
prefixLabel = "* * * * * *",
|
||||
onBackClick = onBackClick,
|
||||
onCancelClick = onBackClick,
|
||||
onConfirmClick = {
|
||||
if (amount.isNotEmpty()) {
|
||||
onChargeClick(amount)
|
||||
}
|
||||
},
|
||||
onKeyClick = { value ->
|
||||
amount = appendAmountValue(amount, value)
|
||||
},
|
||||
onDeleteClick = {
|
||||
amount = amount.dropLast(1)
|
||||
},
|
||||
confirmEnabled = amount.isNotEmpty(),
|
||||
canDelete = amount.isNotEmpty()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun NumericEntryScreen(
|
||||
title: String,
|
||||
prompt: String,
|
||||
supportingText: String,
|
||||
confirmText: String,
|
||||
onBackClick: () -> Unit,
|
||||
onCancelClick: () -> Unit,
|
||||
onConfirmClick: () -> Unit,
|
||||
onKeyClick: (String) -> Unit,
|
||||
onDeleteClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
prefixLabel: String? = null,
|
||||
errorMessage: String? = null,
|
||||
confirmEnabled: Boolean = true,
|
||||
canDelete: Boolean = true,
|
||||
keys: List<List<String>> = listOf(
|
||||
listOf("1", "2", "3"),
|
||||
listOf("4", "5", "6"),
|
||||
listOf("7", "8", "9"),
|
||||
listOf( ".","0","00")
|
||||
)
|
||||
) {
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxSize()
|
||||
.background(Color.White)
|
||||
.navigationBarsPadding()
|
||||
.statusBarsPadding()
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 20.dp)
|
||||
) {
|
||||
Text(
|
||||
text = prompt,
|
||||
color = Color.Gray,
|
||||
fontSize = 11.sp,
|
||||
modifier = Modifier.align(Alignment.CenterHorizontally)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Row(
|
||||
modifier = Modifier.align(Alignment.CenterHorizontally),
|
||||
verticalAlignment = Alignment.Bottom
|
||||
) {
|
||||
if (!prefixLabel.isNullOrBlank()) {
|
||||
Text(
|
||||
text = prefixLabel,
|
||||
color = Color.LegacyRed,
|
||||
fontSize = 25.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
modifier = Modifier.padding(top = 25.dp)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
|
||||
Text(
|
||||
text = supportingText,
|
||||
color = if (errorMessage == null) Color.Gray else Color.LegacyRed,
|
||||
fontSize = 11.sp,
|
||||
modifier = Modifier.align(Alignment.CenterHorizontally)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(40.dp))
|
||||
|
||||
NumericKeypad(
|
||||
keys = keys,
|
||||
onKeyClick = onKeyClick
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Button(
|
||||
onClick = onCancelClick,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(56.dp),
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = Color.White,
|
||||
contentColor = Color.LegacyRed
|
||||
)
|
||||
) {
|
||||
Text("Cancel")
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onConfirmClick,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(56.dp),
|
||||
enabled = confirmEnabled,
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = Color.LegacyRed,
|
||||
contentColor = Color.White,
|
||||
disabledContainerColor = Color.LegacyRed.copy(alpha = 0.5f),
|
||||
disabledContentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text(
|
||||
text = confirmText,
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Medium
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(18.dp))
|
||||
}
|
||||
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopEnd)
|
||||
.padding(top = 32.dp, end = 20.dp)
|
||||
.clickable(enabled = canDelete) {
|
||||
onDeleteClick()
|
||||
},
|
||||
shape = RoundedCornerShape(18.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = Color.White),
|
||||
elevation = CardDefaults.cardElevation(defaultElevation = 6.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Backspace,
|
||||
contentDescription = "Delete",
|
||||
tint = if (canDelete) Color.LegacyRed else Color.Gray,
|
||||
modifier = Modifier.padding(horizontal = 14.dp, vertical = 12.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun NumericKeypad(
|
||||
keys: List<List<String>>,
|
||||
onKeyClick: (String) -> Unit
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalArrangement = Arrangement.spacedBy(6.dp)
|
||||
) {
|
||||
keys.forEach { row ->
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
||||
) {
|
||||
row.forEach { key ->
|
||||
KeypadButton(
|
||||
text = key,
|
||||
modifier = Modifier.weight(1f),
|
||||
onClick = { onKeyClick(key) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun KeypadButton(
|
||||
text: String,
|
||||
modifier: Modifier = Modifier,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
val enabled = text.isNotBlank()
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
.height(66.dp)
|
||||
.shadow(
|
||||
elevation = 2.dp,
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
clip = false
|
||||
)
|
||||
.background(
|
||||
color = Color.White,
|
||||
shape = RoundedCornerShape(8.dp)
|
||||
)
|
||||
.clickable(enabled = enabled) { onClick() },
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = text,
|
||||
color = if (enabled) Color.LegacyRed else Color.White,
|
||||
fontSize = 24.sp,
|
||||
fontWeight = FontWeight.Normal,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatAmount(value: String): String {
|
||||
val normalized = value.ifEmpty { "0" }
|
||||
val wholePart = normalized.substringBefore(".").ifEmpty { "0" }
|
||||
val groupedWholePart = "%,d".format(wholePart.toLongOrNull() ?: 0L)
|
||||
|
||||
if (!normalized.contains(".")) {
|
||||
return groupedWholePart
|
||||
}
|
||||
|
||||
val decimalPart = normalized.substringAfter(".", "")
|
||||
return if (normalized.endsWith(".")) {
|
||||
"$groupedWholePart."
|
||||
} else {
|
||||
"$groupedWholePart.$decimalPart"
|
||||
}
|
||||
}
|
||||
|
||||
private fun appendAmountValue(current: String, value: String): String {
|
||||
if (value == ".") {
|
||||
if (current.contains(".")) return current
|
||||
return if (current.isEmpty()) "0." else "$current."
|
||||
}
|
||||
|
||||
val decimalIndex = current.indexOf('.')
|
||||
return if (decimalIndex >= 0) {
|
||||
val decimalPart = current.substring(decimalIndex + 1)
|
||||
val remainingDecimalDigits = 2 - decimalPart.length
|
||||
if (remainingDecimalDigits <= 0) {
|
||||
current
|
||||
} else {
|
||||
current + value.take(remainingDecimalDigits)
|
||||
}
|
||||
} else {
|
||||
val wholeDigitsCount = current.filter(Char::isDigit).length
|
||||
val remainingWholeDigits = 9 - wholeDigitsCount
|
||||
if (remainingWholeDigits <= 0) {
|
||||
current
|
||||
} else {
|
||||
current + value.take(remainingWholeDigits)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@P2Preview
|
||||
@Composable
|
||||
fun PreviewInputPassword() {
|
||||
InputPassword()
|
||||
}
|
||||
@ -1,73 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.pinpad
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
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.viewmodel.SharedViewModel
|
||||
import com.mob.utsmyanmar.viewmodel.TransProcessViewModel
|
||||
import com.utsmyanmar.paylibs.Constant
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||
|
||||
@Composable
|
||||
fun PinPadRoute(
|
||||
pinPadViewModel: PinPadViewModel,
|
||||
sharedViewModel: SharedViewModel,
|
||||
transProcessViewModel: TransProcessViewModel,
|
||||
onNavigateInputRrn: () -> Unit,
|
||||
onNavigateProcessing: () -> Unit,
|
||||
onBack: () -> Unit
|
||||
) {
|
||||
val pinText by pinPadViewModel.pinText.collectAsStateWithLifecycle()
|
||||
val alertMsg by pinPadViewModel.alertMsg.collectAsStateWithLifecycle()
|
||||
val pinStatus by pinPadViewModel.pinStatus.collectAsStateWithLifecycle()
|
||||
val canGoBack = sharedViewModel.transactionsType.value != TransactionsType.SALE
|
||||
|
||||
BackHandler(enabled = canGoBack) {
|
||||
onBack()
|
||||
}
|
||||
|
||||
LaunchedEffect(pinStatus) {
|
||||
when (pinStatus) {
|
||||
PinPadStatus.ON_CONFIRM,
|
||||
PinPadStatus.ON_NEXT_SCREEN -> {
|
||||
val payDetail = pinPadViewModel.getPayDetail()
|
||||
payDetail?.tradeAnswerCode = Constant.ANSWER_CODE_APPROVED
|
||||
sharedViewModel.payDetail.value = payDetail
|
||||
transProcessViewModel.resetTransactionStatus()
|
||||
if (sharedViewModel.transactionsType.value == TransactionsType.REFUND) {
|
||||
onNavigateInputRrn()
|
||||
} else {
|
||||
onNavigateProcessing()
|
||||
}
|
||||
}
|
||||
|
||||
PinPadStatus.ON_CANCEL,
|
||||
PinPadStatus.ON_TIMEOUT,
|
||||
PinPadStatus.ON_CARD_REMOVED -> {
|
||||
onBack()
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
DisposableEffect(Unit) {
|
||||
onDispose {
|
||||
pinPadViewModel.cancelPinPad()
|
||||
}
|
||||
}
|
||||
|
||||
PinPadScreen(
|
||||
pinText = pinText,
|
||||
alertMessage = alertMsg,
|
||||
canGoBack = canGoBack,
|
||||
onBack = onBack,
|
||||
onKeyboardReady = { keyboard ->
|
||||
pinPadViewModel.startPinPadProcess(keyboard)
|
||||
}
|
||||
)
|
||||
}
|
||||
@ -1,181 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.pinpad
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import com.mob.utsmyanmar.R
|
||||
import com.mob.utsmyanmar.ui.theme.Black
|
||||
import com.mob.utsmyanmar.ui.theme.Primary
|
||||
import com.mob.utsmyanmar.ui.theme.White
|
||||
import com.utsmyanmar.baselib.ui.CustomPinPadKeyboard
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun PinPadScreen(
|
||||
pinText: String,
|
||||
alertMessage: String?,
|
||||
canGoBack: Boolean,
|
||||
onBack: () -> Unit,
|
||||
onKeyboardReady: (CustomPinPadKeyboard) -> Unit
|
||||
) {
|
||||
var keyboardView by remember { mutableStateOf<CustomPinPadKeyboard?>(null) }
|
||||
var isStarted by remember { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(keyboardView) {
|
||||
val keyboard = keyboardView ?: return@LaunchedEffect
|
||||
if (!isStarted) {
|
||||
isStarted = true
|
||||
onKeyboardReady(keyboard)
|
||||
}
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
CenterAlignedTopAppBar(
|
||||
title = {
|
||||
Text(
|
||||
text = "PIN ENTRY",
|
||||
color = White,
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
},
|
||||
navigationIcon = {
|
||||
if (canGoBack) {
|
||||
IconButton(onClick = onBack) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.ic_left_arrow),
|
||||
contentDescription = "Back",
|
||||
tint = White
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = Primary
|
||||
)
|
||||
)
|
||||
},
|
||||
containerColor = White
|
||||
) { paddingValues ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues)
|
||||
.background(White)
|
||||
.padding(24.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(
|
||||
color = Primary,
|
||||
shape = RoundedCornerShape(24.dp)
|
||||
)
|
||||
.padding(horizontal = 24.dp, vertical = 28.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Text(
|
||||
text = "Please Input PIN",
|
||||
color = White,
|
||||
fontSize = 22.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(14.dp))
|
||||
|
||||
Text(
|
||||
text = if (pinText.isBlank()) "------" else pinText,
|
||||
color = White,
|
||||
fontSize = 30.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
letterSpacing = 4.sp
|
||||
)
|
||||
|
||||
if (!alertMessage.isNullOrBlank()) {
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
Text(
|
||||
text = alertMessage,
|
||||
color = White,
|
||||
fontSize = 15.sp,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
|
||||
Text(
|
||||
text = "Enter your PIN on the secured keypad below.",
|
||||
color = Black,
|
||||
fontSize = 16.sp,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
|
||||
Box(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
AndroidView(
|
||||
factory = { context ->
|
||||
CustomPinPadKeyboard(context).also {
|
||||
keyboardView = it
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
Text(
|
||||
text = if (canGoBack) {
|
||||
"Cancel on device or use back to exit."
|
||||
} else {
|
||||
"Cancel on device to exit."
|
||||
},
|
||||
color = Black,
|
||||
fontSize = 14.sp,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,561 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.pinpad
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.RemoteException
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.view.ViewTreeObserver
|
||||
import android.widget.TextView
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.mob.utsmyanmar.config.Constants
|
||||
import com.mob.utsmyanmar.config.SunmiPayManager
|
||||
import com.mob.utsmyanmar.model.PinPadStatus
|
||||
import com.sunmi.pay.hardware.aidl.AidlConstants
|
||||
import com.sunmi.pay.hardware.aidlv2.AidlErrorCodeV2
|
||||
import com.sunmi.pay.hardware.aidlv2.bean.PinPadConfigV2
|
||||
import com.sunmi.pay.hardware.aidlv2.bean.PinPadDataV2
|
||||
import com.sunmi.pay.hardware.aidlv2.pinpad.PinPadListenerV2
|
||||
import com.sunmi.pay.hardware.aidlv2.pinpad.PinPadOptV2
|
||||
import com.utsmyanmar.baselib.ui.CustomPinPadKeyboard
|
||||
import com.utsmyanmar.checkxread.sdk.SunmiSDK
|
||||
import com.utsmyanmar.paylibs.model.PayDetail
|
||||
import com.utsmyanmar.paylibs.model.TradeData
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.ByteUtil
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import sunmi.sunmiui.utils.LogUtil
|
||||
import java.nio.charset.StandardCharsets
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class PinPadViewModel @Inject constructor(
|
||||
private val sunmiPayManager: SunmiPayManager
|
||||
) : 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
|
||||
private const val ON_NUMBER_CLICK = 5
|
||||
private const val ON_EMPTY_PIN_BLOCK = 6
|
||||
private const val ON_TIMEOUT_PIN_PAD = 7
|
||||
private const val ON_ERROR_DUKPT = 8
|
||||
}
|
||||
|
||||
private var mPinPadOptV2: PinPadOptV2? = null
|
||||
private var mPinType = 0
|
||||
private var mWidth = 239
|
||||
private var mHeight = 130
|
||||
private var mInterval = 1
|
||||
private var mKeyboardCoordinate = intArrayOf(0, 661)
|
||||
private var mCancelWidth = 112
|
||||
private var mCancelHeight = 112
|
||||
private var mCancelCoordinate = intArrayOf(0, 48)
|
||||
private var dukptIndex = 0
|
||||
private var tmkIndex = 9
|
||||
private val PIK_INDEX = 11
|
||||
private var tradeData: TradeData? = null
|
||||
private var payDetail: PayDetail? = null
|
||||
private var pan: String = ""
|
||||
|
||||
/*
|
||||
* UI States
|
||||
*/
|
||||
|
||||
private val _pinText = MutableStateFlow("")
|
||||
val pinText = _pinText.asStateFlow()
|
||||
|
||||
private val _alertMsg = MutableStateFlow<String?>(null)
|
||||
val alertMsg = _alertMsg.asStateFlow()
|
||||
|
||||
private val _errorCode = MutableStateFlow<Int?>(null)
|
||||
val errorCode = _errorCode.asStateFlow()
|
||||
|
||||
private val _transType = MutableStateFlow<TransactionsType?>(null)
|
||||
val transType = _transType.asStateFlow()
|
||||
|
||||
private val _pinStatus =
|
||||
MutableStateFlow<PinPadStatus?>(null)
|
||||
|
||||
val pinStatus = _pinStatus.asStateFlow()
|
||||
private var isTerminalStateReached = false
|
||||
|
||||
/*
|
||||
* Trade Data
|
||||
*/
|
||||
|
||||
fun setTradeData(tradeData: TradeData) {
|
||||
this.tradeData = tradeData
|
||||
|
||||
payDetail = tradeData.payDetail
|
||||
|
||||
pan = payDetail?.cardNo ?: ""
|
||||
}
|
||||
|
||||
fun getTradeData(): TradeData? {
|
||||
return tradeData
|
||||
}
|
||||
|
||||
fun setPayDetail(payDetail: PayDetail) {
|
||||
this.payDetail = payDetail
|
||||
|
||||
tradeData = TradeData().apply {
|
||||
this.payDetail = payDetail
|
||||
}
|
||||
}
|
||||
|
||||
fun getPayDetail(): PayDetail? {
|
||||
return payDetail
|
||||
}
|
||||
|
||||
fun setTransType(type: TransactionsType?) {
|
||||
_transType.value = type
|
||||
}
|
||||
|
||||
fun resetSessionState() {
|
||||
_pinText.value = ""
|
||||
_alertMsg.value = null
|
||||
_errorCode.value = null
|
||||
_pinStatus.value = null
|
||||
isTerminalStateReached = false
|
||||
}
|
||||
|
||||
/*
|
||||
* Pin Pad
|
||||
*/
|
||||
|
||||
fun startPinPadProcess(
|
||||
customPinPadKeyboard: CustomPinPadKeyboard
|
||||
) {
|
||||
resetSessionState()
|
||||
|
||||
// dukptIndex = SystemParamsOperation.getInstance().tmkIndex.toInt()
|
||||
if(!sunmiPayManager.isReady()){
|
||||
_alertMsg.value =
|
||||
"Sunmi Pay SDK is not ready"
|
||||
|
||||
_pinStatus.value =
|
||||
PinPadStatus.ON_ERROR
|
||||
|
||||
return
|
||||
}
|
||||
initData()
|
||||
// testInjectPIK()
|
||||
initPinPad(customPinPadKeyboard)
|
||||
}
|
||||
|
||||
private fun initData() {
|
||||
|
||||
mPinPadOptV2 = sunmiPayManager.pinPadOptV2
|
||||
|
||||
if (mPinPadOptV2 == null) {
|
||||
Log.d(TAG, "PinPad service are not ready!")
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
val result = mPinPadOptV2?.setAntiExhaustiveProtectionMode(3)
|
||||
|
||||
if ((result ?: -1) >= 0) {
|
||||
LogUtil.d(
|
||||
TAG,
|
||||
"Pin anti exhaustive result:$result"
|
||||
)
|
||||
} else {
|
||||
LogUtil.d(
|
||||
TAG, "Pin Anti Exhaustive failed"
|
||||
)
|
||||
}
|
||||
|
||||
} catch (e: RemoteException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
fun cancelPinPad() {
|
||||
try {
|
||||
if (!isTerminalStateReached) {
|
||||
mPinPadOptV2?.cancelInputPin()
|
||||
Log.d(TAG, "PinPad Canceled")
|
||||
}
|
||||
} catch (e: RemoteException) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Init Pin Pad
|
||||
*/
|
||||
|
||||
private fun initPinPad(
|
||||
customPinPadKeyboard: CustomPinPadKeyboard
|
||||
) {
|
||||
LogUtil.e(TAG, "Init Pin Pad PAN:$pan")
|
||||
|
||||
var timeout = Constants.PIN_PAD_TIMEOUT
|
||||
val pinPadOrder = !SystemParamsOperation.getInstance().isRandomPinPad
|
||||
|
||||
if (SunmiSDK.getInstance().checkCardExist() != 2) {
|
||||
timeout = Constants.TIMEOUT
|
||||
}
|
||||
|
||||
try {
|
||||
val config = PinPadConfigV2().apply {
|
||||
maxInput = 6
|
||||
minInput = 0
|
||||
pinPadType = 1 // custom keyboard
|
||||
algorithmType = 0
|
||||
pinType = mPinType
|
||||
this.timeout = timeout * 1000
|
||||
isOrderNumKey = pinPadOrder
|
||||
keySystem = AidlConstants.Security.SEC_MKSK
|
||||
pinKeyIndex = PIK_INDEX
|
||||
pinblockFormat = AidlConstants.PinBlockFormat.SEC_PIN_BLK_ISO_FMT0
|
||||
this.pan = getPanBytes(this@PinPadViewModel.pan)
|
||||
}
|
||||
|
||||
val result = mPinPadOptV2?.initPinPad(config, mPinPadListener)
|
||||
|
||||
LogUtil.e(TAG, "pinpad result:$result")
|
||||
|
||||
if (result.isNullOrEmpty()) {
|
||||
_alertMsg.value = "PinPad init failed"
|
||||
_pinStatus.value = PinPadStatus.ON_ERROR
|
||||
return
|
||||
}
|
||||
|
||||
getKeyboardCoordinate(result, customPinPadKeyboard)
|
||||
|
||||
_pinText.value = ""
|
||||
customPinPadKeyboard.keepScreenOn = true
|
||||
customPinPadKeyboard.setKeyBoard(result)
|
||||
customPinPadKeyboard.visibility = View.VISIBLE
|
||||
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
_alertMsg.value = e.message
|
||||
_pinStatus.value = PinPadStatus.ON_ERROR
|
||||
}
|
||||
}
|
||||
|
||||
private fun testInjectPIK() {
|
||||
try {
|
||||
val securityOptV2 = sunmiPayManager.securityOptV2 ?: return
|
||||
|
||||
val pik = ByteUtil.hexStr2Bytes(
|
||||
"33DD20C9A0B5B861F2914D44BC2AF055"
|
||||
)
|
||||
|
||||
val kcv = ByteUtil.hexStr2Bytes(
|
||||
"28DBDB489D28BC92"
|
||||
)
|
||||
|
||||
val code = securityOptV2.savePlaintextKey(
|
||||
AidlConstants.Security.KEY_TYPE_PIK,
|
||||
pik,
|
||||
kcv,
|
||||
AidlConstants.Security.KEY_ALG_TYPE_3DES,
|
||||
PIK_INDEX
|
||||
)
|
||||
|
||||
LogUtil.e(TAG, "saveTestPIK result:$code")
|
||||
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Keyboard
|
||||
*/
|
||||
|
||||
private fun getKeyboardCoordinate(
|
||||
keyBoardText: String,
|
||||
customPinPadKeyboard: CustomPinPadKeyboard
|
||||
) {
|
||||
|
||||
customPinPadKeyboard
|
||||
.viewTreeObserver
|
||||
.addOnGlobalLayoutListener(
|
||||
object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
|
||||
override fun onGlobalLayout() {
|
||||
|
||||
customPinPadKeyboard
|
||||
.viewTreeObserver
|
||||
.removeOnGlobalLayoutListener(this)
|
||||
|
||||
val textView: TextView =
|
||||
customPinPadKeyboard.key_0
|
||||
|
||||
textView.getLocationOnScreen(
|
||||
mKeyboardCoordinate
|
||||
)
|
||||
|
||||
mWidth = textView.width
|
||||
mHeight = textView.height
|
||||
|
||||
mInterval = 1
|
||||
|
||||
importPinPadData(keyBoardText)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun importPinPadData(text: String) {
|
||||
|
||||
val pinPadData = PinPadDataV2()
|
||||
|
||||
pinPadData.numX = mKeyboardCoordinate[0]
|
||||
pinPadData.numY = mKeyboardCoordinate[1]
|
||||
|
||||
pinPadData.numW = mWidth
|
||||
pinPadData.numH = mHeight
|
||||
|
||||
pinPadData.lineW = mInterval
|
||||
|
||||
pinPadData.cancelX = mCancelCoordinate[0]
|
||||
pinPadData.cancelY = mCancelCoordinate[1]
|
||||
|
||||
pinPadData.cancelW = mCancelWidth
|
||||
pinPadData.cancelH = mCancelHeight
|
||||
|
||||
pinPadData.lineW = 0
|
||||
|
||||
pinPadData.rows = 5
|
||||
pinPadData.clos = 3
|
||||
|
||||
keyMap(text, pinPadData)
|
||||
|
||||
try {
|
||||
mPinPadOptV2?.importPinPadData(pinPadData)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun keyMap(
|
||||
str: String,
|
||||
data: PinPadDataV2
|
||||
) {
|
||||
|
||||
data.keyMap = ByteArray(64)
|
||||
|
||||
var j = 0
|
||||
|
||||
for (i in 0 until 15) {
|
||||
|
||||
when (i) {
|
||||
|
||||
9, 12 -> {
|
||||
data.keyMap[i] = 0x1B
|
||||
}
|
||||
|
||||
13 -> {
|
||||
data.keyMap[i] = 0x0C
|
||||
}
|
||||
|
||||
11, 14 -> {
|
||||
data.keyMap[i] = 0x0D
|
||||
}
|
||||
|
||||
else -> {
|
||||
data.keyMap[i] =
|
||||
str[j].code.toByte()
|
||||
|
||||
j++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Password View
|
||||
*/
|
||||
|
||||
private fun showPasswordView(len: Int) {
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
repeat(len) {
|
||||
sb.append("*")
|
||||
}
|
||||
|
||||
_pinText.value = sb.toString()
|
||||
}
|
||||
|
||||
/*
|
||||
* Handler
|
||||
*/
|
||||
|
||||
private val handler =
|
||||
Handler(Looper.getMainLooper()) { msg ->
|
||||
when (msg.what) {
|
||||
ON_NUMBER_CLICK -> {
|
||||
showPasswordView(msg.arg1)
|
||||
}
|
||||
|
||||
ON_CONFIRM_CLICK -> {
|
||||
LogUtil.d(TAG, "ON CLICK CONFIRM")
|
||||
isTerminalStateReached = true
|
||||
_pinStatus.value = PinPadStatus.ON_CONFIRM
|
||||
}
|
||||
|
||||
ON_CANCEL_CLICK -> {
|
||||
LogUtil.d(TAG, "ON CLICK CANCEL")
|
||||
if (!isTerminalStateReached) {
|
||||
_pinStatus.value = PinPadStatus.ON_CANCEL
|
||||
}
|
||||
}
|
||||
|
||||
ON_ERROR_PIN_PAD -> {
|
||||
LogUtil.d(TAG, "ON ERROR CODE: ${msg.arg1}")
|
||||
_errorCode.value = msg.arg1
|
||||
isTerminalStateReached = true
|
||||
_pinStatus.value = PinPadStatus.ON_ERROR
|
||||
}
|
||||
|
||||
ON_EMPTY_PIN_BLOCK -> {
|
||||
_pinStatus.value = PinPadStatus.ON_EMPTY
|
||||
}
|
||||
|
||||
ON_TIMEOUT_PIN_PAD -> {
|
||||
isTerminalStateReached = true
|
||||
_pinStatus.value = PinPadStatus.ON_TIMEOUT
|
||||
}
|
||||
|
||||
ON_ERROR_DUKPT -> {
|
||||
_alertMsg.value = "Try Again!"
|
||||
isTerminalStateReached = true
|
||||
_pinStatus.value = PinPadStatus.ON_ERROR_DUKPT
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
/*
|
||||
* Listener
|
||||
*/
|
||||
|
||||
private val mPinPadListener =
|
||||
object : PinPadListenerV2.Stub() {
|
||||
|
||||
override fun onPinLength(len: Int) {
|
||||
handler.obtainMessage(
|
||||
ON_NUMBER_CLICK,
|
||||
len,
|
||||
0
|
||||
).sendToTarget()
|
||||
}
|
||||
|
||||
override fun onConfirm(
|
||||
status: Int,
|
||||
pinBlock: ByteArray?
|
||||
) {
|
||||
|
||||
LogUtil.e(
|
||||
TAG,
|
||||
"onConfirm status:$status and pinblock :${ByteUtil.bytes2HexStr(pinBlock)}"
|
||||
)
|
||||
if (status != PIN_CONFIRM_SUCCESS_STATUS) {
|
||||
_alertMsg.value = "PinPad confirm failed: $status"
|
||||
_pinStatus.value = PinPadStatus.ON_ERROR
|
||||
return
|
||||
}
|
||||
|
||||
val isCardValid = SunmiSDK.getInstance().checkCardExist() == 2 ||
|
||||
payDetail?.cardType == AidlConstants.CardType.MAGNETIC.getValue() ||
|
||||
payDetail?.cardType == -9
|
||||
|
||||
if (!isCardValid) {
|
||||
isTerminalStateReached = true
|
||||
_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
|
||||
) {
|
||||
isTerminalStateReached = true
|
||||
_pinStatus.value = PinPadStatus.ON_NEXT_SCREEN
|
||||
} else {
|
||||
handler.obtainMessage(
|
||||
ON_CONFIRM_CLICK
|
||||
).sendToTarget()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCancel() {
|
||||
if (!isTerminalStateReached) {
|
||||
handler.obtainMessage(
|
||||
ON_CANCEL_CLICK
|
||||
).sendToTarget()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError(code: Int) {
|
||||
|
||||
val msg =
|
||||
AidlErrorCodeV2
|
||||
.valueOf(code)
|
||||
.msg
|
||||
|
||||
LogUtil.d(
|
||||
TAG,
|
||||
"error code:$code - message :$msg"
|
||||
)
|
||||
|
||||
when (code) {
|
||||
|
||||
-60001 -> {
|
||||
handler.obtainMessage(
|
||||
ON_TIMEOUT_PIN_PAD
|
||||
).sendToTarget()
|
||||
}
|
||||
|
||||
-3025 -> {
|
||||
handler.obtainMessage(
|
||||
ON_ERROR_DUKPT
|
||||
).sendToTarget()
|
||||
}
|
||||
|
||||
else -> {
|
||||
handler.obtainMessage(
|
||||
ON_ERROR_PIN_PAD,
|
||||
code,
|
||||
code,
|
||||
code
|
||||
).sendToTarget()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getPanBytes(pan: String): ByteArray {
|
||||
|
||||
if (pan.length < 13) {
|
||||
return ByteArray(0)
|
||||
}
|
||||
|
||||
return pan
|
||||
.substring(pan.length - 13, pan.length - 1)
|
||||
.toByteArray(StandardCharsets.US_ASCII)
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.preview
|
||||
|
||||
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
|
||||
@Preview(
|
||||
name = "P2",
|
||||
device = "spec:width=720px,height=1440px,dpi=349",
|
||||
showBackground = true,
|
||||
showSystemUi = true
|
||||
)
|
||||
annotation class P2Preview
|
||||
|
||||
@Preview(
|
||||
name = "P3",
|
||||
device = "spec:width=720px,height=1440px,dpi=320",
|
||||
showBackground = true
|
||||
)
|
||||
annotation class P3Preview
|
||||
@ -1,264 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.print_receipt
|
||||
|
||||
import android.util.Log
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.animation.core.Animatable
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.mob.utsmyanmar.ui.components.appbar.AppBar
|
||||
import com.mob.utsmyanmar.ui.theme.Color
|
||||
import com.utsmyanmar.paylibs.print.PrintReceipt
|
||||
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun PrintReceiptScreen(
|
||||
onPrint: () -> Unit,
|
||||
onDone: () -> Unit
|
||||
) {
|
||||
|
||||
val scope = rememberCoroutineScope();
|
||||
val receiptOffsetY = remember {
|
||||
Animatable(0f);
|
||||
}
|
||||
val animationDuration = 3000;
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
AppBar(title = "Receipt")
|
||||
},
|
||||
containerColor = Color.IvoryBeige
|
||||
) { paddingValues ->
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(paddingValues)
|
||||
.fillMaxSize()
|
||||
.padding(16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
|
||||
ReceiptPreview(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.verticalScroll(rememberScrollState())
|
||||
.graphicsLayer{
|
||||
translationY = receiptOffsetY.value
|
||||
}
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
|
||||
OutlinedButton(
|
||||
onClick = onDone,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(50.dp),
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "Cancel",
|
||||
style = MaterialTheme.typography.bodyLarge.copy(
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Button(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(50.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = Color.LegacyRed,
|
||||
contentColor = Color.White,
|
||||
disabledContainerColor = Color.LegacyRed.copy(alpha = 0.5f),
|
||||
disabledContentColor = Color.White.copy(alpha = 0.5f),
|
||||
),
|
||||
shape = RoundedCornerShape(12.dp),
|
||||
onClick = {
|
||||
// onPrint()
|
||||
try {
|
||||
PrintReceipt.getInstance().printNow()
|
||||
scope.launch {
|
||||
launch {
|
||||
receiptOffsetY.animateTo(
|
||||
targetValue = -1500f,
|
||||
animationSpec = tween(
|
||||
durationMillis = animationDuration,
|
||||
easing = FastOutSlowInEasing
|
||||
)
|
||||
)
|
||||
}
|
||||
delay(5000)
|
||||
launch {
|
||||
receiptOffsetY.animateTo(
|
||||
targetValue = 0f,
|
||||
animationSpec = tween(
|
||||
durationMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
||||
Log.d("PrintReceipt", "error with $e")
|
||||
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = "Print",
|
||||
style = MaterialTheme.typography.bodyLarge.copy(
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
fun ReceiptPreview(
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(Color.White)
|
||||
.border(
|
||||
width = 1.dp,
|
||||
color = Color.Gray,
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
)
|
||||
.padding(20.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(
|
||||
text = "MOB POS",
|
||||
fontSize = 24.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontFamily = FontFamily.Monospace
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Text(
|
||||
text = "Transaction Receipt",
|
||||
fontSize = 14.sp,
|
||||
fontFamily = FontFamily.Monospace
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ReceiptDivider()
|
||||
ReceiptRow("Merchant", "MOB UTS Myanmar")
|
||||
ReceiptRow("Terminal ID", "POS001")
|
||||
ReceiptRow("Transaction", "SALE")
|
||||
ReceiptRow("Amount", "500.00 MMK")
|
||||
ReceiptRow("Card Type", "MPU")
|
||||
ReceiptRow("Card No", "1234 **** **** 5678")
|
||||
ReceiptRow("Status", "SUCCESS")
|
||||
ReceiptRow("Date", "13/05/2026")
|
||||
ReceiptRow("Time", "14:30:22")
|
||||
ReceiptRow("Ref No", "REF123456789")
|
||||
ReceiptDivider()
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Text(
|
||||
text = "Thank You",
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
fontFamily = FontFamily.Monospace
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
|
||||
Text(
|
||||
text = "Please keep this receipt",
|
||||
fontSize = 12.sp,
|
||||
fontFamily = FontFamily.Monospace
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ReceiptRow(
|
||||
label: String,
|
||||
value: String
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 6.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Text(
|
||||
text = label,
|
||||
fontSize = 13.sp,
|
||||
fontFamily = FontFamily.Monospace,
|
||||
color = Color.Gray
|
||||
)
|
||||
|
||||
Text(
|
||||
text = value,
|
||||
fontSize = 13.sp,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
fontFamily = FontFamily.Monospace
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ReceiptDivider() {
|
||||
Text(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 10.dp),
|
||||
text = "--------------------------------",
|
||||
fontFamily = FontFamily.Monospace,
|
||||
color = Color.Gray
|
||||
)
|
||||
}
|
||||
|
||||
@Preview(showBackground = true, showSystemUi = true)
|
||||
@Composable
|
||||
fun PreviewPrintReceiptScreen() {
|
||||
MaterialTheme {
|
||||
PrintReceiptScreen(
|
||||
onPrint = {},
|
||||
onDone = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.processing_card
|
||||
|
||||
sealed interface ProcessingCardEvent {
|
||||
data object StartProcess : ProcessingCardEvent
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.processing_card
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
|
||||
@Composable
|
||||
fun ProcessingCardRoute(
|
||||
viewModel: ProcessingCardViewModel,
|
||||
onNavigatePinPad: () -> Unit,
|
||||
onNavigateInputAmount: () -> Unit,
|
||||
onNavigateProcessing: () -> Unit,
|
||||
onNavigateEmvTransaction: () -> Unit,
|
||||
onNavigateError: (String) -> Unit,
|
||||
onBack: () -> Unit,
|
||||
onShowDecline: (String) -> Unit
|
||||
) {
|
||||
val state by viewModel.state.collectAsStateWithLifecycle()
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
viewModel.onEvent(ProcessingCardEvent.StartProcess)
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
viewModel.uiEvent.collect { event ->
|
||||
when (event) {
|
||||
ProcessingCardUiEvent.NavigateToPinPad -> onNavigatePinPad()
|
||||
ProcessingCardUiEvent.NavigateToInputAmount -> onNavigateInputAmount()
|
||||
ProcessingCardUiEvent.NavigateToProcessing -> onNavigateProcessing()
|
||||
ProcessingCardUiEvent.NavigateToEmvTransaction -> onNavigateEmvTransaction()
|
||||
is ProcessingCardUiEvent.NavigateToError -> onNavigateError(event.message)
|
||||
is ProcessingCardUiEvent.ShowDeclineAndBack -> {
|
||||
onShowDecline(event.message)
|
||||
onBack()
|
||||
}
|
||||
ProcessingCardUiEvent.Back -> onBack()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ProcessingCardScreen(state = state)
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.processing_card
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
|
||||
@Composable
|
||||
fun ProcessingCardScreen(
|
||||
state: ProcessingCardState
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
if (state.isLoading) {
|
||||
CircularProgressIndicator()
|
||||
}
|
||||
|
||||
Text(text = state.message)
|
||||
}
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.processing_card
|
||||
|
||||
data class ProcessingCardState(
|
||||
val title: String = "Processing Card",
|
||||
val message: String = "Please wait...",
|
||||
val isLoading: Boolean = true
|
||||
)
|
||||
@ -1,11 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.processing_card
|
||||
|
||||
sealed interface ProcessingCardUiEvent {
|
||||
data object NavigateToPinPad : ProcessingCardUiEvent
|
||||
data object NavigateToInputAmount : ProcessingCardUiEvent
|
||||
data object NavigateToProcessing : ProcessingCardUiEvent
|
||||
data object NavigateToEmvTransaction : ProcessingCardUiEvent
|
||||
data class NavigateToError(val message: String) : ProcessingCardUiEvent
|
||||
data class ShowDeclineAndBack(val message: String) : ProcessingCardUiEvent
|
||||
data object Back : ProcessingCardUiEvent
|
||||
}
|
||||
@ -1,267 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.processing_card
|
||||
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.mob.utsmyanmar.model.CardTransactionType
|
||||
import com.mob.utsmyanmar.utils.TransactionUtil
|
||||
import com.mob.utsmyanmar.viewmodel.CardReaderViewModel
|
||||
import com.mob.utsmyanmar.viewmodel.EmvTransactionProcessViewModel
|
||||
import com.mob.utsmyanmar.ui.pinpad.PinPadViewModel
|
||||
import com.mob.utsmyanmar.viewmodel.SharedViewModel
|
||||
import com.mob.utsmyanmar.viewmodel.TransProcessViewModel
|
||||
import com.utsmyanmar.checkxread.model.CardDataX
|
||||
import com.utsmyanmar.checkxread.readcard.MAGXReadCard
|
||||
import com.utsmyanmar.checkxread.readcard.MPUXReadCard
|
||||
import com.utsmyanmar.checkxread.readcard.ReadCardResultX
|
||||
import com.utsmyanmar.checkxread.util.CardTypeX
|
||||
import com.utsmyanmar.paylibs.model.PayDetail
|
||||
import com.utsmyanmar.paylibs.model.TradeData
|
||||
import com.utsmyanmar.paylibs.model.enums.TransCVM
|
||||
import com.utsmyanmar.paylibs.utils.POSUtil
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation
|
||||
import com.utsmyanmar.paylibs.utils.enums.TransMenu
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||
import com.utsmyanmar.paylibs.utils.params.Params
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.receiveAsFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import sunmi.sunmiui.utils.LogUtil
|
||||
|
||||
class ProcessingCardViewModel(
|
||||
private val cardReadViewModel: CardReaderViewModel,
|
||||
private val sharedViewModel: SharedViewModel,
|
||||
private val transProcessViewModel: TransProcessViewModel,
|
||||
private val pinPadViewModel: PinPadViewModel,
|
||||
private val emvTransactionViewModel: EmvTransactionProcessViewModel
|
||||
) : ViewModel() {
|
||||
|
||||
companion object {
|
||||
private val TAG = ProcessingCardViewModel::class.java.simpleName
|
||||
|
||||
fun provideFactory(
|
||||
cardReadViewModel: CardReaderViewModel,
|
||||
sharedViewModel: SharedViewModel,
|
||||
transProcessViewModel: TransProcessViewModel,
|
||||
pinPadViewModel: PinPadViewModel,
|
||||
emvTransactionViewModel: EmvTransactionProcessViewModel
|
||||
): ViewModelProvider.Factory {
|
||||
return object : ViewModelProvider.Factory {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
return ProcessingCardViewModel(
|
||||
cardReadViewModel = cardReadViewModel,
|
||||
sharedViewModel = sharedViewModel,
|
||||
transProcessViewModel = transProcessViewModel,
|
||||
pinPadViewModel = pinPadViewModel,
|
||||
emvTransactionViewModel = emvTransactionViewModel
|
||||
) as T
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val _state = MutableStateFlow(ProcessingCardState())
|
||||
val state = _state.asStateFlow()
|
||||
|
||||
private val _uiEvent = Channel<ProcessingCardUiEvent>()
|
||||
val uiEvent = _uiEvent.receiveAsFlow()
|
||||
|
||||
fun onEvent(event: ProcessingCardEvent) {
|
||||
when (event) {
|
||||
ProcessingCardEvent.StartProcess -> {
|
||||
resetEmvTransResult()
|
||||
checkCardTransactionType()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun resetEmvTransResult() {
|
||||
emvTransactionViewModel.resetTransactionStatus()
|
||||
}
|
||||
|
||||
private fun checkCardTransactionType() {
|
||||
when (cardReadViewModel.getCardTransactionType()) {
|
||||
CardTransactionType.MPU -> readMPUCard()
|
||||
CardTransactionType.EMV -> handlePreEmvProcess()
|
||||
CardTransactionType.FALLBACK -> readMAGStripe(
|
||||
isFallback = true,
|
||||
isNeedPin = true
|
||||
)
|
||||
|
||||
CardTransactionType.MAG -> readMAGStripe(
|
||||
isFallback = false,
|
||||
isNeedPin = true
|
||||
)
|
||||
|
||||
else -> {
|
||||
Log.d(
|
||||
"ProcessingCardViewModel",
|
||||
"error on CardTransactionType : ${cardReadViewModel.getCardTransactionType()}"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun readMPUCard() {
|
||||
cardReadViewModel.startReadXProcess(
|
||||
MPUXReadCard.getInstance(),
|
||||
object : ReadCardResultX {
|
||||
override fun onSuccess(cardDataX: CardDataX) {
|
||||
transProcessViewModel.setTransType(sharedViewModel.transactionsType.value)
|
||||
pinPadViewModel.setTransType(sharedViewModel.transactionsType.value)
|
||||
val tradeData = TransactionUtil.initMPUTransaction(cardDataX, CardTypeX.IC)
|
||||
transProcessViewModel.setTradeData(tradeData)
|
||||
pinPadViewModel.setTradeData(tradeData)
|
||||
|
||||
when {
|
||||
sharedViewModel._transMenu.value == TransMenu.PRE_AUTH_PARTIAL_VOID -> {
|
||||
sendUiEvent(
|
||||
ProcessingCardUiEvent.NavigateToError(
|
||||
"Function not supported"
|
||||
)
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
sharedViewModel.setCardDataExist(true)
|
||||
|
||||
if (sharedViewModel.getAmountExist().value == false) {
|
||||
sendUiEvent(ProcessingCardUiEvent.NavigateToInputAmount)
|
||||
} else {
|
||||
sendUiEvent(ProcessingCardUiEvent.NavigateToPinPad)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError(code: Int, message: String) {
|
||||
LogUtil.d(TAG, "Failure at $code message: $message")
|
||||
sharedViewModel.setCardDataExist(false)
|
||||
|
||||
sendUiEvent(
|
||||
ProcessingCardUiEvent.ShowDeclineAndBack(
|
||||
"FAILURE :$message"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun readMAGStripe(
|
||||
isFallback: Boolean,
|
||||
isNeedPin: Boolean
|
||||
) {
|
||||
cardReadViewModel.startReadXProcess(
|
||||
MAGXReadCard.getInstance(),
|
||||
object : ReadCardResultX {
|
||||
override fun onSuccess(cardDataX: CardDataX) {
|
||||
sharedViewModel.setEmvTrans(false)
|
||||
|
||||
if (isNeedPin) {
|
||||
transProcessViewModel.setTransType(sharedViewModel.transactionsType.value)
|
||||
pinPadViewModel.setTransType(sharedViewModel.transactionsType.value)
|
||||
|
||||
val tradeData = TransactionUtil.initMagStripeTransaction(cardDataX, isFallback)
|
||||
|
||||
transProcessViewModel.setTradeData(tradeData)
|
||||
pinPadViewModel.setTradeData(tradeData)
|
||||
} else {
|
||||
transProcessViewModel.setTransType(sharedViewModel.transactionsType.value)
|
||||
|
||||
val tradeData = TransactionUtil.initMagStripeTransaction(cardDataX, isFallback)
|
||||
val processCode = sharedViewModel.processCode.value
|
||||
val amount = sharedViewModel.amount.value
|
||||
val payDetail: PayDetail = tradeData.payDetail
|
||||
|
||||
payDetail.amount = POSUtil.getInstance().convertAmount(amount)
|
||||
|
||||
if (!TextUtils.equals(processCode, "")) {
|
||||
payDetail.processCode = processCode
|
||||
}
|
||||
|
||||
payDetail.transCVM = TransCVM.SIGNATURE
|
||||
transProcessViewModel.setTradeData(tradeData)
|
||||
}
|
||||
|
||||
when {
|
||||
sharedViewModel.getTransMenu().value == TransMenu.PRE_AUTH_PARTIAL_VOID -> {
|
||||
sharedViewModel.setTransMenu(null)
|
||||
sendUiEvent(
|
||||
ProcessingCardUiEvent.NavigateToError(
|
||||
"Function not supported"
|
||||
)
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
sharedViewModel.setCardDataExist(true)
|
||||
|
||||
if (
|
||||
sharedViewModel.getTransMenu().value != TransMenu.PRE_AUTH_FULL_VOID &&
|
||||
sharedViewModel.getAmountExist().value == false
|
||||
) {
|
||||
sendUiEvent(ProcessingCardUiEvent.NavigateToInputAmount)
|
||||
} else {
|
||||
if (isNeedPin) {
|
||||
sendUiEvent(ProcessingCardUiEvent.NavigateToPinPad)
|
||||
} else {
|
||||
sendUiEvent(ProcessingCardUiEvent.NavigateToProcessing)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError(code: Int, message: String) {
|
||||
LogUtil.d(TAG, "Failure at $code message: $message")
|
||||
|
||||
sendUiEvent(
|
||||
ProcessingCardUiEvent.ShowDeclineAndBack(
|
||||
"FAILURE :$message"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun handlePreEmvProcess() {
|
||||
emvTransactionViewModel.transType.value =
|
||||
sharedViewModel.transactionsType.value
|
||||
|
||||
if (SystemParamsOperation.getInstance().isEmvEnabled) {
|
||||
prepareEmvTransaction()
|
||||
sendUiEvent(ProcessingCardUiEvent.NavigateToEmvTransaction)
|
||||
} else {
|
||||
sendUiEvent(
|
||||
ProcessingCardUiEvent.NavigateToError(
|
||||
"Please enable EMV"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun prepareEmvTransaction() {
|
||||
sharedViewModel.setEmvTrans(true)
|
||||
|
||||
val cardType = cardReadViewModel.cardTypeData.value ?: return
|
||||
|
||||
val tradeData: TradeData = Params.newTrade(false)
|
||||
val payDetail = tradeData.payDetail
|
||||
|
||||
payDetail.cardType = cardType
|
||||
|
||||
emvTransactionViewModel.setTradeData(tradeData)
|
||||
}
|
||||
|
||||
private fun sendUiEvent(event: ProcessingCardUiEvent) {
|
||||
viewModelScope.launch {
|
||||
_uiEvent.send(event)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,77 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.refund_rrn
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import com.mob.utsmyanmar.ui.amount.NumericEntryScreen
|
||||
import com.mob.utsmyanmar.viewmodel.SharedViewModel
|
||||
import com.utsmyanmar.paylibs.utils.POSUtil
|
||||
|
||||
private const val RRN_MAX_LENGTH = 12
|
||||
|
||||
@Composable
|
||||
fun InputRrnRoute(
|
||||
sharedViewModel: SharedViewModel,
|
||||
onBack: () -> Unit,
|
||||
onNavigateProcessing: () -> Unit
|
||||
) {
|
||||
var rrn by rememberSaveable {
|
||||
mutableStateOf(sharedViewModel.rrNNo.value.orEmpty())
|
||||
}
|
||||
var errorMessage by rememberSaveable { mutableStateOf<String?>(null) }
|
||||
|
||||
NumericEntryScreen(
|
||||
title = "Input RRN",
|
||||
prompt = "Enter RRN",
|
||||
displayValue = rrn.ifEmpty { "0" },
|
||||
supportingText = errorMessage ?: "Enter the retrieval reference number to continue",
|
||||
confirmText = "Next",
|
||||
onBackClick = onBack,
|
||||
onCancelClick = onBack,
|
||||
onConfirmClick = {
|
||||
val trimmedRrn = rrn.trim()
|
||||
if (POSUtil.getInstance().checkNumberField(trimmedRrn)) {
|
||||
errorMessage = "Invalid RRN"
|
||||
return@NumericEntryScreen
|
||||
}
|
||||
|
||||
sharedViewModel.rrNNo.value = trimmedRrn
|
||||
sharedViewModel.payDetail.value?.let { payDetail ->
|
||||
payDetail.referNo = trimmedRrn
|
||||
sharedViewModel.payDetail.value = payDetail
|
||||
}
|
||||
onNavigateProcessing()
|
||||
},
|
||||
onKeyClick = { value ->
|
||||
rrn = appendRrnValue(rrn, value)
|
||||
errorMessage = null
|
||||
},
|
||||
onDeleteClick = {
|
||||
rrn = rrn.dropLast(1)
|
||||
errorMessage = null
|
||||
},
|
||||
confirmEnabled = rrn.isNotEmpty(),
|
||||
canDelete = rrn.isNotEmpty(),
|
||||
keys = listOf(
|
||||
listOf("1", "2", "3"),
|
||||
listOf("4", "5", "6"),
|
||||
listOf("7", "8", "9"),
|
||||
listOf("", "0", "00")
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private fun appendRrnValue(current: String, value: String): String {
|
||||
if (value.isBlank()) {
|
||||
return current
|
||||
}
|
||||
|
||||
val remainingDigits = RRN_MAX_LENGTH - current.length
|
||||
if (remainingDigits <= 0) {
|
||||
return current
|
||||
}
|
||||
|
||||
return current + value.take(remainingDigits)
|
||||
}
|
||||
@ -1,168 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.sale_void
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.mob.utsmyanmar.ui.components.appbar.AppBar
|
||||
import com.mob.utsmyanmar.ui.theme.Color
|
||||
import com.utsmyanmar.paylibs.model.PayDetail
|
||||
import com.utsmyanmar.paylibs.utils.POSUtil
|
||||
|
||||
@Composable
|
||||
fun TranDetailPage(
|
||||
voidViewModel: VoidViewModel,
|
||||
trace: String,
|
||||
onBack: () -> Unit,
|
||||
onProceedVoid: (PayDetail) -> Unit
|
||||
) {
|
||||
val transaction by voidViewModel.searchTransaction(trace).observeAsState()
|
||||
|
||||
Scaffold(
|
||||
containerColor = Color.IvoryBeige,
|
||||
topBar = {
|
||||
AppBar(
|
||||
title = "Transaction Detail",
|
||||
icon = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
onIconClick = onBack
|
||||
)
|
||||
}
|
||||
) { paddingValues ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues)
|
||||
.padding(16.dp)
|
||||
) {
|
||||
transaction?.let { payDetail ->
|
||||
TransactionDetailsCard(transaction = payDetail)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Text(
|
||||
text = "Review the transaction before proceeding to void.",
|
||||
color = Color.Gray,
|
||||
fontSize = 13.sp
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Button(
|
||||
onClick = onBack,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(56.dp),
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = Color.White,
|
||||
contentColor = Color.LegacyRed
|
||||
)
|
||||
) {
|
||||
Text("Back")
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = { onProceedVoid(payDetail) },
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(56.dp),
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = Color.LegacyRed,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("Void")
|
||||
}
|
||||
}
|
||||
} ?: Box(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = "Transaction not found.",
|
||||
color = Color.Gray,
|
||||
fontSize = 14.sp
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TransactionDetailsCard(transaction: PayDetail) {
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
colors = CardDefaults.cardColors(containerColor = Color.White)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "Previous Sale",
|
||||
color = Color.LegacyRed,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 16.sp
|
||||
)
|
||||
|
||||
DetailRow("Trace", transaction.voucherNo)
|
||||
DetailRow("Amount", POSUtil.getInstance().formatAmount(transaction.amount))
|
||||
DetailRow("Card No", transaction.cardNo)
|
||||
DetailRow("Reference", transaction.referNo)
|
||||
DetailRow("Approval", transaction.approvalCode.orEmpty())
|
||||
DetailRow("Date", transaction.tradeDate)
|
||||
DetailRow("Time", transaction.tradeTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DetailRow(
|
||||
label: String,
|
||||
value: String
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Text(
|
||||
text = label,
|
||||
color = Color.Gray,
|
||||
fontSize = 13.sp
|
||||
)
|
||||
Text(
|
||||
text = value.ifBlank { "-" },
|
||||
color = Color.Black,
|
||||
fontSize = 13.sp,
|
||||
fontWeight = FontWeight.Medium
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -1,313 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.sale_void
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material.icons.rounded.Backspace
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.mob.utsmyanmar.ui.components.appbar.AppBar
|
||||
import com.mob.utsmyanmar.ui.theme.Color
|
||||
import com.utsmyanmar.paylibs.model.PayDetail
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||
|
||||
@Composable
|
||||
fun VoidTraceScreen(
|
||||
voidViewModel: VoidViewModel,
|
||||
onNavigateTranDetail: (String) -> Unit,
|
||||
onBack: () -> Unit = {}
|
||||
) {
|
||||
val tag = "VoidTraceScreen"
|
||||
var traceNumber by remember { mutableStateOf("") }
|
||||
var searchedTrace by remember { mutableStateOf("") }
|
||||
var lastNavigatedTrace by remember { mutableStateOf<String?>(null) }
|
||||
val displayTraceNumber = traceNumber.padStart(6, '0').ifEmpty { "000000" }
|
||||
val recentTransactions by voidViewModel.getLastThreeTransactions().observeAsState(emptyList())
|
||||
|
||||
val transactionSource: LiveData<PayDetail?> = remember(searchedTrace) {
|
||||
if (searchedTrace.isBlank()) {
|
||||
MutableLiveData<PayDetail?>(null)
|
||||
} else {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
voidViewModel.getVoidTrans(
|
||||
TransactionsType.SALE.value,
|
||||
searchedTrace
|
||||
) as LiveData<PayDetail?>
|
||||
}
|
||||
}
|
||||
val transaction by transactionSource.observeAsState()
|
||||
val hasSearched = searchedTrace.isNotBlank()
|
||||
val headerMessage = if (hasSearched && transaction == null) {
|
||||
"Warning: no previous sale transaction found for trace $searchedTrace."
|
||||
} else {
|
||||
"Input trace number to find previous sale transaction."
|
||||
}
|
||||
val headerColor = if (hasSearched && transaction == null) {
|
||||
Color.LegacyRed
|
||||
} else {
|
||||
Color.Black
|
||||
}
|
||||
|
||||
LaunchedEffect(searchedTrace) {
|
||||
if (searchedTrace != lastNavigatedTrace) {
|
||||
lastNavigatedTrace = null
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(transaction?.voucherNo) {
|
||||
val matchedTrace = transaction?.voucherNo ?: return@LaunchedEffect
|
||||
if (lastNavigatedTrace == matchedTrace) return@LaunchedEffect
|
||||
lastNavigatedTrace = matchedTrace
|
||||
onNavigateTranDetail(matchedTrace)
|
||||
}
|
||||
|
||||
|
||||
LaunchedEffect(searchedTrace, transaction) {
|
||||
Log.d(
|
||||
tag,
|
||||
"Recent DB traces: ${
|
||||
recentTransactions.joinToString { detail ->
|
||||
"${detail.voucherNo}:${detail.transType}:${detail.tradeAnswerCode}"
|
||||
}
|
||||
}"
|
||||
)
|
||||
if (searchedTrace.isNotBlank()) {
|
||||
Log.d(
|
||||
tag,
|
||||
"Search trace=$searchedTrace result=${transaction?.voucherNo ?: "NOT_FOUND"}"
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
containerColor = Color.IvoryBeige,
|
||||
topBar = {
|
||||
AppBar(
|
||||
title = "Void",
|
||||
icon = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
onIconClick = onBack
|
||||
)
|
||||
}
|
||||
) { paddingValues ->
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 16.dp)
|
||||
) {
|
||||
Text(
|
||||
text = headerMessage,
|
||||
color = headerColor,
|
||||
fontSize = 14.sp
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(28.dp))
|
||||
|
||||
Text(
|
||||
text = "Trace Number",
|
||||
color = Color.Gray,
|
||||
fontSize = 11.sp,
|
||||
modifier = Modifier.align(Alignment.CenterHorizontally)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Text(
|
||||
text = displayTraceNumber,
|
||||
color = Color.LegacyRed,
|
||||
fontSize = 32.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
modifier = Modifier.align(Alignment.CenterHorizontally)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Text(
|
||||
text = "Enter 6-digit trace number",
|
||||
color = Color.Gray,
|
||||
fontSize = 11.sp,
|
||||
modifier = Modifier.align(Alignment.CenterHorizontally)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
|
||||
TraceNumberKeypad(
|
||||
onNumberClick = { value ->
|
||||
if (traceNumber.length < 6) {
|
||||
traceNumber = (traceNumber + value).take(6)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 18.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Button(
|
||||
onClick = onBack,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(56.dp),
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = Color.White,
|
||||
contentColor = Color.LegacyRed
|
||||
)
|
||||
) {
|
||||
Text("Cancel")
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
searchedTrace = traceNumber.padStart(6, '0')
|
||||
},
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(56.dp),
|
||||
enabled = traceNumber.isNotBlank(),
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = Color.LegacyRed,
|
||||
contentColor = Color.White,
|
||||
disabledContainerColor = Color.LegacyRed.copy(alpha = 0.5f),
|
||||
disabledContentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("Enter")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopEnd)
|
||||
.padding(top = 110.dp, end = 16.dp)
|
||||
.clickable(enabled = traceNumber.isNotEmpty()) {
|
||||
traceNumber = traceNumber.dropLast(1)
|
||||
},
|
||||
shape = RoundedCornerShape(18.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = Color.White),
|
||||
elevation = CardDefaults.cardElevation(defaultElevation = 6.dp)
|
||||
) {
|
||||
androidx.compose.material3.Icon(
|
||||
imageVector = Icons.Rounded.Backspace,
|
||||
contentDescription = "Delete",
|
||||
tint = if (traceNumber.isNotEmpty()) Color.LegacyRed else Color.Gray,
|
||||
modifier = Modifier.padding(horizontal = 14.dp, vertical = 12.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TraceNumberKeypad(
|
||||
onNumberClick: (String) -> Unit
|
||||
) {
|
||||
val keys = listOf(
|
||||
listOf("1", "2", "3"),
|
||||
listOf("4", "5", "6"),
|
||||
listOf("7", "8", "9"),
|
||||
listOf("", "0", "00")
|
||||
)
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalArrangement = Arrangement.spacedBy(6.dp)
|
||||
) {
|
||||
keys.forEach { row ->
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
||||
) {
|
||||
row.forEach { key ->
|
||||
if (key.isBlank()) {
|
||||
Spacer(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(66.dp)
|
||||
)
|
||||
} else {
|
||||
TraceKeypadButton(
|
||||
text = key,
|
||||
modifier = Modifier.weight(1f),
|
||||
onClick = { onNumberClick(key) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TraceKeypadButton(
|
||||
text: String,
|
||||
modifier: Modifier = Modifier,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
Box(
|
||||
modifier = modifier
|
||||
.height(66.dp)
|
||||
.shadow(
|
||||
elevation = 2.dp,
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
clip = false
|
||||
)
|
||||
.background(
|
||||
color = Color.White,
|
||||
shape = RoundedCornerShape(8.dp)
|
||||
)
|
||||
.clickable { onClick() },
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = text,
|
||||
color = Color.LegacyRed,
|
||||
fontSize = 24.sp,
|
||||
fontWeight = FontWeight.Normal,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -1,53 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.sale_void
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.utsmyanmar.baselib.repo.Repository
|
||||
import com.utsmyanmar.paylibs.model.PayDetail
|
||||
import com.utsmyanmar.paylibs.system.SingleLiveEvent
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class VoidViewModel @Inject constructor(
|
||||
private val repository: Repository
|
||||
) : ViewModel() {
|
||||
|
||||
val inputTrace = SingleLiveEvent<String>()
|
||||
val lists = SingleLiveEvent<List<PayDetail>>()
|
||||
|
||||
fun getVoidTransactions(transType: Int): LiveData<List<PayDetail>> {
|
||||
return repository.getVoidableTransactions(transType)
|
||||
}
|
||||
|
||||
fun getGenericVoidTransactions(
|
||||
transType: Int,
|
||||
voucherNo: String,
|
||||
isEmv: Boolean
|
||||
): LiveData<PayDetail> {
|
||||
return repository.getGenericVoidTransaction(transType, voucherNo, isEmv)
|
||||
}
|
||||
|
||||
fun getVoidTrans(transType: Int, voucherNo: String): LiveData<PayDetail> {
|
||||
return repository.getVoidTransaction(transType, voucherNo)
|
||||
}
|
||||
|
||||
fun observeVoidTrans(transType: Int) {
|
||||
getVoidTransactions(transType).observeForever(object : Observer<List<PayDetail>> {
|
||||
override fun onChanged(payDetails: List<PayDetail>) {
|
||||
if (lists.value == null) {
|
||||
lists.postValue(payDetails)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun searchTransaction(voucherNo: String): LiveData<PayDetail> {
|
||||
return repository.searchTransaction(voucherNo)
|
||||
}
|
||||
|
||||
fun getLastThreeTransactions(): LiveData<List<PayDetail>> {
|
||||
return repository.getLastThreeTransactions()
|
||||
}
|
||||
}
|
||||
@ -1,45 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.sending_to_host
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.mob.utsmyanmar.model.TransResultStatus
|
||||
import com.mob.utsmyanmar.viewmodel.SharedViewModel
|
||||
import com.mob.utsmyanmar.viewmodel.TransProcessViewModel
|
||||
import kotlinx.coroutines.delay
|
||||
import androidx.compose.runtime.getValue
|
||||
import com.mob.utsmyanmar.viewmodel.ProcessingTransaction
|
||||
|
||||
private const val MOCK_HOST_DELAY_MS = 2000L
|
||||
|
||||
@Composable
|
||||
fun ProcessingRoute(
|
||||
sharedViewModel: SharedViewModel,
|
||||
transProcessViewModel: TransProcessViewModel,
|
||||
onNavigateTransactionResult: () -> Unit
|
||||
) {
|
||||
|
||||
val transStatus by transProcessViewModel.transResultStatus.collectAsStateWithLifecycle()
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
transProcessViewModel.startOnlineProcess()
|
||||
}
|
||||
LaunchedEffect(transStatus) {
|
||||
// sharedViewModel.saveMockHostResultForTesting()
|
||||
// delay(MOCK_HOST_DELAY_MS)
|
||||
|
||||
|
||||
when(transStatus) {
|
||||
|
||||
|
||||
TransResultStatus.SUCCESS -> onNavigateTransactionResult()
|
||||
TransResultStatus.FAIL -> onNavigateTransactionResult()
|
||||
else -> {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
ProcessingScreen()
|
||||
}
|
||||
@ -1,87 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.sending_to_host
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.mob.utsmyanmar.ui.theme.Black
|
||||
import com.mob.utsmyanmar.ui.theme.Primary
|
||||
import com.mob.utsmyanmar.ui.theme.White
|
||||
|
||||
@Composable
|
||||
fun ProcessingScreen() {
|
||||
Scaffold(
|
||||
containerColor = White
|
||||
) { paddingValues ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues)
|
||||
.background(White)
|
||||
.padding(horizontal = 24.dp, vertical = 32.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(
|
||||
color = Primary,
|
||||
shape = RoundedCornerShape(24.dp)
|
||||
)
|
||||
.padding(horizontal = 24.dp, vertical = 32.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
CircularProgressIndicator(color = White)
|
||||
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
|
||||
Text(
|
||||
text = "Processing",
|
||||
color = White,
|
||||
fontSize = 24.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(10.dp))
|
||||
|
||||
Text(
|
||||
text = "Please wait while your transaction is being processed.",
|
||||
color = White,
|
||||
fontSize = 15.sp,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
|
||||
Text(
|
||||
text = "Transaction processing in progress.",
|
||||
color = Black,
|
||||
fontSize = 14.sp,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,194 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.settlement
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.mob.utsmyanmar.ui.components.appbar.AppBar
|
||||
import com.mob.utsmyanmar.ui.theme.Color
|
||||
import com.mob.utsmyanmar.viewmodel.SharedViewModel
|
||||
import com.utsmyanmar.paylibs.model.PayDetail
|
||||
import com.utsmyanmar.paylibs.utils.POSUtil
|
||||
|
||||
@Composable
|
||||
fun SettlementScreen(
|
||||
sharedViewModel: SharedViewModel,
|
||||
onBack: () -> Unit,
|
||||
onStartSettlement: () -> Unit
|
||||
) {
|
||||
val records by sharedViewModel.getSettlementRecords().observeAsState(emptyList())
|
||||
val totalAmount = records.sumOf { it.amount }
|
||||
|
||||
Scaffold(
|
||||
containerColor = Color.IvoryBeige,
|
||||
topBar = {
|
||||
AppBar(
|
||||
title = "Settlement",
|
||||
icon = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
onIconClick = onBack
|
||||
)
|
||||
}
|
||||
) { paddingValues ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues)
|
||||
.padding(16.dp)
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
colors = CardDefaults.cardColors(containerColor = Color.White)
|
||||
) {
|
||||
Column(modifier = Modifier.padding(18.dp)) {
|
||||
Text(
|
||||
text = "Settlement Summary",
|
||||
color = Color.LegacyRed,
|
||||
fontSize = 18.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
|
||||
SummaryRow("Record Count", records.size.toString())
|
||||
SummaryRow("Total Amount", POSUtil.getInstance().formatAmount(totalAmount))
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Text(
|
||||
text = "Unsettled Records",
|
||||
color = Color.Black,
|
||||
fontSize = 15.sp,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f),
|
||||
colors = CardDefaults.cardColors(containerColor = Color.White)
|
||||
) {
|
||||
if (records.isEmpty()) {
|
||||
Text(
|
||||
text = "No records available for settlement.",
|
||||
color = Color.Gray,
|
||||
fontSize = 14.sp,
|
||||
modifier = Modifier.padding(18.dp)
|
||||
)
|
||||
} else {
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.spacedBy(0.dp)
|
||||
) {
|
||||
items(records) { record ->
|
||||
SettlementRecordRow(record = record)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Button(
|
||||
onClick = onStartSettlement,
|
||||
enabled = records.isNotEmpty(),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(56.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = Color.LegacyRed,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("Start Settlement")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SummaryRow(
|
||||
label: String,
|
||||
value: String
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Text(
|
||||
text = label,
|
||||
color = Color.Gray,
|
||||
fontSize = 13.sp
|
||||
)
|
||||
Text(
|
||||
text = value,
|
||||
color = Color.Black,
|
||||
fontSize = 13.sp,
|
||||
fontWeight = FontWeight.Medium
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SettlementRecordRow(record: PayDetail) {
|
||||
Column(modifier = Modifier.padding(horizontal = 16.dp, vertical = 12.dp)) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Text(
|
||||
text = record.transType.ifBlank { "UNKNOWN" },
|
||||
color = Color.LegacyRed,
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
Text(
|
||||
text = POSUtil.getInstance().formatAmount(record.amount),
|
||||
color = Color.Black,
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
|
||||
Text(
|
||||
text = "Trace ${record.voucherNo.ifBlank { "-" }}",
|
||||
color = Color.Black,
|
||||
fontSize = 12.sp
|
||||
)
|
||||
Text(
|
||||
text = "Card ${record.cardNo.ifBlank { "-" }}",
|
||||
color = Color.Gray,
|
||||
fontSize = 12.sp
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
HorizontalDivider(color = Color.Gray.copy(alpha = 0.25f))
|
||||
}
|
||||
}
|
||||
@ -1,440 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.settlement
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.mob.utsmyanmar.config.Constants
|
||||
import com.mob.utsmyanmar.model.SettlementType
|
||||
import com.mob.utsmyanmar.model.TransactionStatus
|
||||
import com.utsmyanmar.baselib.repo.Repository
|
||||
import com.utsmyanmar.paylibs.Constant
|
||||
import com.utsmyanmar.paylibs.batch_upload.BatchListener
|
||||
import com.utsmyanmar.paylibs.batch_upload.BatchUploadProcess
|
||||
import com.utsmyanmar.paylibs.isobuilder.ISOMode
|
||||
import com.utsmyanmar.paylibs.isobuilder.builderx.ISOMsgX
|
||||
import com.utsmyanmar.paylibs.isobuilder.builderx.ISOVersion
|
||||
import com.utsmyanmar.paylibs.model.MsgField
|
||||
import com.utsmyanmar.paylibs.model.PayDetail
|
||||
import com.utsmyanmar.paylibs.model.SettleData
|
||||
import com.utsmyanmar.paylibs.model.TradeData
|
||||
import com.utsmyanmar.paylibs.network.ISOCallback
|
||||
import com.utsmyanmar.paylibs.network.ISOSocket
|
||||
import com.utsmyanmar.paylibs.utils.MessageType
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation
|
||||
import com.utsmyanmar.paylibs.utils.enums.HostName
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.BitmapConfig
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionType
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||
import com.utsmyanmar.paylibs.utils.params.Params
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.receiveAsFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import sunmi.sunmiui.utils.LogUtil
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
|
||||
data class SettlementUiState(
|
||||
val saleCount: Int = 0,
|
||||
val saleAmount: Long = 0L,
|
||||
|
||||
val preCount: Int = 0,
|
||||
val preAmount: Long = 0L,
|
||||
|
||||
val refundCount: Int = 0,
|
||||
val refundAmount: Long = 0L,
|
||||
|
||||
val caCount: Int = 0,
|
||||
val caAmount: Long = 0L,
|
||||
|
||||
val settlementType: SettlementType? = null,
|
||||
val isNoData: Boolean = false,
|
||||
val isSentData: Boolean = false,
|
||||
val bottomLayout: Int = 0,
|
||||
|
||||
val status: TransactionStatus? = null,
|
||||
val isLoading: Boolean = false
|
||||
)
|
||||
|
||||
sealed interface SettlementEvent {
|
||||
data class ShowStatus(val status: TransactionStatus) : SettlementEvent
|
||||
}
|
||||
|
||||
@HiltViewModel
|
||||
class SettlementViewModel @Inject constructor(
|
||||
private val repository: Repository
|
||||
) : ViewModel() {
|
||||
|
||||
companion object {
|
||||
private val TAG = SettlementViewModel::class.java.simpleName
|
||||
}
|
||||
|
||||
private var payDetail: PayDetail? = null
|
||||
private var payDetails: List<PayDetail>? = null
|
||||
|
||||
private val deleteTrans = arrayListOf<PayDetail>()
|
||||
|
||||
private var flag = false
|
||||
private var errorFlag = false
|
||||
private var isSecondCall = false
|
||||
private var batchIndex = 0
|
||||
|
||||
private var bitmap = ""
|
||||
|
||||
private val isoMsgX: ISOMsgX =
|
||||
ISOMsgX.ISOMsgXBuilder(
|
||||
ISOVersion.VERSION_1993,
|
||||
ISOMode.BOTH_HEADER_TPDU,
|
||||
HostName.BPC
|
||||
).build()
|
||||
|
||||
private val _uiState = MutableStateFlow(SettlementUiState())
|
||||
val uiState = _uiState.asStateFlow()
|
||||
|
||||
private val _events = Channel<SettlementEvent>(Channel.BUFFERED)
|
||||
val events = _events.receiveAsFlow()
|
||||
|
||||
fun getLastSettlement(voucherNo: String): LiveData<List<PayDetail>> {
|
||||
return repository.getLastSettlement(voucherNo)
|
||||
}
|
||||
|
||||
fun getSettlement(): LiveData<List<PayDetail>> {
|
||||
return repository.getSettlement()
|
||||
}
|
||||
|
||||
fun getSettlementPOS(): LiveData<List<PayDetail>> {
|
||||
return repository.getSettlementPOS()
|
||||
}
|
||||
|
||||
fun getDeleteTrans(batchNo: String): LiveData<List<PayDetail>> {
|
||||
return repository.getDeleteTrans(batchNo)
|
||||
}
|
||||
|
||||
fun getAdditionalSettlementPOS(): LiveData<List<PayDetail>> {
|
||||
return repository.getAdditionalSettlementPOS(
|
||||
SystemParamsOperation.getInstance().getCurrentBatchNum()
|
||||
)
|
||||
}
|
||||
|
||||
fun setPayDetails(list: List<PayDetail>) {
|
||||
payDetails = list
|
||||
}
|
||||
|
||||
fun setSettlementSummary(
|
||||
saleCount: Int,
|
||||
saleAmount: Long,
|
||||
preCount: Int,
|
||||
preAmount: Long,
|
||||
refundCount: Int,
|
||||
refundAmount: Long,
|
||||
caCount: Int,
|
||||
caAmount: Long
|
||||
) {
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
saleCount = saleCount,
|
||||
saleAmount = saleAmount,
|
||||
preCount = preCount,
|
||||
preAmount = preAmount,
|
||||
refundCount = refundCount,
|
||||
refundAmount = refundAmount,
|
||||
caCount = caCount,
|
||||
caAmount = caAmount
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun setSettlementType(type: SettlementType) {
|
||||
_uiState.update {
|
||||
it.copy(settlementType = type)
|
||||
}
|
||||
}
|
||||
|
||||
fun updatePayDetail(payDetail: PayDetail) {
|
||||
repository.updatePayDetail(payDetail)
|
||||
}
|
||||
|
||||
private fun insertPayDetail(payDetail: PayDetail) {
|
||||
repository.insertPayDetail(payDetail)
|
||||
}
|
||||
|
||||
private fun updateDB() {
|
||||
payDetails?.forEach { pay ->
|
||||
repository.deletePayDetail(pay)
|
||||
}
|
||||
|
||||
deleteTrans.forEach { pay ->
|
||||
repository.deletePayDetail(pay)
|
||||
}
|
||||
|
||||
payDetails = emptyList()
|
||||
deleteTrans.clear()
|
||||
}
|
||||
|
||||
fun startSettlementProcess() {
|
||||
_uiState.update {
|
||||
it.copy(isLoading = true)
|
||||
}
|
||||
|
||||
SystemParamsOperation.getInstance().getIncrementBatchNo()
|
||||
|
||||
requestOnlineProcessSettlement()
|
||||
}
|
||||
|
||||
fun startPrintSettlementProcess() {
|
||||
// PrintReceipt.getInstance().printSettlementReceiptPOS(...)
|
||||
}
|
||||
|
||||
fun testServiceClass() {
|
||||
LogUtil.d(TAG, "SettlementViewModel works!")
|
||||
}
|
||||
|
||||
private fun requestOnlineProcessSettlement() {
|
||||
val state = _uiState.value
|
||||
|
||||
val hostName = HostName.BPC
|
||||
val field60 = SystemParamsOperation.getInstance().getCurrentBatchNum()
|
||||
|
||||
val sale2Count = state.saleCount + state.preCount
|
||||
val sale2Amount = state.saleAmount + state.preAmount
|
||||
|
||||
val totalSaleCount = String.format(Locale.getDefault(), "%03d", sale2Count)
|
||||
val totalSaleAmount = String.format(Locale.getDefault(), "%010d00", sale2Amount)
|
||||
|
||||
val totalRefundCount = String.format(Locale.getDefault(), "%03d", state.refundCount)
|
||||
val totalRefundAmount = String.format(
|
||||
Locale.getDefault(),
|
||||
"%010d00",
|
||||
if (state.refundAmount == 0L) 0 else state.refundAmount
|
||||
)
|
||||
|
||||
val totalDebitSaleCount = String.format(Locale.getDefault(), "%03d", state.caCount)
|
||||
val totalDebitSaleAmount = String.format(
|
||||
Locale.getDefault(),
|
||||
"%010d00",
|
||||
if (state.caAmount == 0L) 0 else state.caAmount
|
||||
)
|
||||
|
||||
val totalERefundCount = String.format(Locale.getDefault(), "%03d", 0)
|
||||
val totalERefundAmount = String.format(Locale.getDefault(), "%010d00", 0)
|
||||
|
||||
val tradeData = Params.newTrade(true)
|
||||
val currentPayDetail = tradeData.payDetail
|
||||
|
||||
payDetail = currentPayDetail
|
||||
|
||||
bitmap = BitmapConfig.BPC_SETTLEMENT
|
||||
|
||||
currentPayDetail.transType = TransactionsType.SETTLEMENT.name
|
||||
currentPayDetail.transactionType = TransactionType.SETTLEMENT
|
||||
|
||||
if (!flag) {
|
||||
currentPayDetail.processCode = TransactionsType.SETTLEMENT.processCode
|
||||
} else {
|
||||
bitmap = BitmapConfig.BPC_SETTLEMENT_TRAILER
|
||||
currentPayDetail.processCode = "910000"
|
||||
}
|
||||
|
||||
currentPayDetail.batchNo = SystemParamsOperation.getInstance().getCurrentBatchNum()
|
||||
|
||||
currentPayDetail.settleList =
|
||||
"${state.saleCount}:${state.saleAmount}-" +
|
||||
"${state.caCount}:${state.caAmount}-" +
|
||||
"${state.refundCount}:${state.refundAmount}-" +
|
||||
"${state.preCount}:${state.preAmount}"
|
||||
|
||||
val settleData = SettleData(
|
||||
state.saleCount,
|
||||
state.saleAmount,
|
||||
state.preCount,
|
||||
state.preAmount,
|
||||
state.refundCount,
|
||||
state.refundAmount,
|
||||
state.caCount,
|
||||
state.caAmount
|
||||
)
|
||||
|
||||
currentPayDetail.settleDataObj = settleData
|
||||
|
||||
if (hostName == HostName.BPC) {
|
||||
val totalAmount =
|
||||
state.saleAmount + state.preAmount + state.refundAmount + state.caAmount
|
||||
|
||||
val settlementData = if (state.refundAmount != 0L) {
|
||||
val creditTotal = state.saleAmount + state.preAmount + state.caAmount
|
||||
val subTotal = creditTotal - state.refundAmount
|
||||
|
||||
if (subTotal < 0L) {
|
||||
"D" + String.format(Locale.getDefault(), "%012d", kotlin.math.abs(subTotal))
|
||||
} else {
|
||||
"C" + String.format(Locale.getDefault(), "%012d", subTotal)
|
||||
}
|
||||
} else {
|
||||
"C" + String.format(Locale.getDefault(), "%012d", totalAmount)
|
||||
}
|
||||
|
||||
currentPayDetail.settleData = settlementData
|
||||
currentPayDetail.amount = totalAmount
|
||||
} else {
|
||||
currentPayDetail.settleData =
|
||||
totalSaleCount +
|
||||
totalSaleAmount +
|
||||
totalRefundCount +
|
||||
totalRefundAmount +
|
||||
totalDebitSaleCount +
|
||||
totalDebitSaleAmount +
|
||||
totalERefundCount +
|
||||
totalERefundAmount
|
||||
}
|
||||
|
||||
tradeData.payDetail = currentPayDetail
|
||||
tradeData.field60 = field60
|
||||
|
||||
val sendBytes = isoMsgX.buildISOPackets(
|
||||
tradeData,
|
||||
bitmap,
|
||||
MessageType.SETTLEMENT
|
||||
)
|
||||
|
||||
LogUtil.d(TAG, "Starting SETTLEMENT process...")
|
||||
|
||||
ISOSocket.getInstance().enqueue(
|
||||
sendBytes,
|
||||
sendBytes.size,
|
||||
false,
|
||||
object : ISOCallback {
|
||||
|
||||
override fun onReceive(bytes: ByteArray, length: Int) {
|
||||
val responseMap: Map<String, MsgField>? =
|
||||
isoMsgX.parseISOPackets(bytes, length)
|
||||
|
||||
if (responseMap != null) {
|
||||
val resultStr = try {
|
||||
responseMap["F039"]?.dataStr.orEmpty()
|
||||
} catch (e: NullPointerException) {
|
||||
e.printStackTrace()
|
||||
currentPayDetail.isNeedReversal = true
|
||||
return
|
||||
}
|
||||
|
||||
currentPayDetail.tradeAnswerCode = resultStr
|
||||
|
||||
when {
|
||||
resultStr == Constant.ANSWER_CODE_ACCEPT ||
|
||||
resultStr == Constant.ANSWER_CODE_APPROVED -> {
|
||||
currentPayDetail.isNeedReversal = false
|
||||
}
|
||||
|
||||
resultStr == "95" || resultStr == "095" -> {
|
||||
currentPayDetail.isNeedReversal = !flag
|
||||
}
|
||||
}
|
||||
} else {
|
||||
errorFlag = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError(msg: String) {
|
||||
if (msg != Constants.REVERSAL) {
|
||||
if (!isSecondCall) {
|
||||
ISOSocket.getInstance().switchIp()
|
||||
|
||||
postStatus(TransactionStatus.ON_SECONDARY)
|
||||
|
||||
isSecondCall = true
|
||||
requestOnlineProcessSettlement()
|
||||
} else {
|
||||
postStatus(TransactionStatus.ON_ERROR)
|
||||
|
||||
currentPayDetail.isNeedReversal = true
|
||||
isSecondCall = false
|
||||
}
|
||||
} else {
|
||||
postStatus(TransactionStatus.ON_ERROR)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
if (currentPayDetail.isNeedReversal) {
|
||||
flag = true
|
||||
batchUploadProcess()
|
||||
} else {
|
||||
flag = false
|
||||
batchIndex = 0
|
||||
|
||||
updateDB()
|
||||
insertPayDetail(currentPayDetail)
|
||||
|
||||
if (errorFlag) {
|
||||
postStatus(TransactionStatus.ON_ERROR)
|
||||
} else {
|
||||
postStatus(TransactionStatus.ON_SUCCESS)
|
||||
}
|
||||
|
||||
_uiState.update {
|
||||
it.copy(isLoading = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun batchUploadProcess() {
|
||||
postStatus(TransactionStatus.ON_BATCH_UPLOAD)
|
||||
|
||||
val currentPayDetails = payDetails
|
||||
|
||||
if (currentPayDetails.isNullOrEmpty()) {
|
||||
requestOnlineProcessSettlement()
|
||||
return
|
||||
}
|
||||
|
||||
val uploadPayDetail = currentPayDetails[batchIndex]
|
||||
|
||||
val tradeData = TradeData().apply {
|
||||
payDetail = uploadPayDetail
|
||||
}
|
||||
|
||||
BatchUploadProcess.getInstance()
|
||||
.enqueue(tradeData)
|
||||
.startBatchUpload(object : BatchListener {
|
||||
|
||||
override fun onSuccessBatch() {
|
||||
if (batchIndex < currentPayDetails.size - 1) {
|
||||
LogUtil.d(TAG, "Pay detail size: ${currentPayDetails.size}")
|
||||
LogUtil.d(TAG, "Count value: $batchIndex")
|
||||
|
||||
batchIndex++
|
||||
batchUploadProcess()
|
||||
} else {
|
||||
requestOnlineProcessSettlement()
|
||||
}
|
||||
|
||||
LogUtil.e(TAG, "Batch Upload Success")
|
||||
}
|
||||
|
||||
override fun onFailBatch() {
|
||||
LogUtil.e(TAG, "Batch Upload Fail")
|
||||
postStatus(TransactionStatus.ON_ERROR)
|
||||
|
||||
_uiState.update {
|
||||
it.copy(isLoading = false)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun postStatus(status: TransactionStatus) {
|
||||
_uiState.update {
|
||||
it.copy(status = status)
|
||||
}
|
||||
|
||||
viewModelScope.launch {
|
||||
_events.send(SettlementEvent.ShowStatus(status))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,262 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.sign_on
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material.icons.filled.ErrorOutline
|
||||
import androidx.compose.material.icons.filled.Sync
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.mob.utsmyanmar.ui.components.appbar.AppBar
|
||||
import com.mob.utsmyanmar.ui.theme.Color as AppColor
|
||||
|
||||
@Composable
|
||||
fun SignOnRoute(
|
||||
onBack: () -> Unit,
|
||||
onNavigateResult: (Boolean, String) -> Unit,
|
||||
signOnViewModel: SignOnViewModel = viewModel()
|
||||
) {
|
||||
val state by signOnViewModel.uiState.collectAsState()
|
||||
|
||||
LaunchedEffect(signOnViewModel) {
|
||||
signOnViewModel.resultEvents.collect { result ->
|
||||
onNavigateResult(result.isSuccess, result.message)
|
||||
}
|
||||
}
|
||||
|
||||
SignOnScreen(
|
||||
state = state,
|
||||
onBack = onBack,
|
||||
onStartSignOn = signOnViewModel::startSignOn
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SignOnScreen(
|
||||
state: SignOnUiState,
|
||||
onBack: () -> Unit,
|
||||
onStartSignOn: () -> Unit
|
||||
) {
|
||||
Scaffold(
|
||||
containerColor = AppColor.IvoryBeige,
|
||||
topBar = {
|
||||
AppBar(
|
||||
title = "Sign On",
|
||||
icon = Icons.Default.ArrowBack,
|
||||
onIconClick = onBack
|
||||
)
|
||||
}
|
||||
) { paddingValues ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues)
|
||||
.padding(16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = AppColor.White),
|
||||
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(20.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Sync,
|
||||
contentDescription = null,
|
||||
tint = AppColor.LegacyRed,
|
||||
modifier = Modifier.height(42.dp)
|
||||
)
|
||||
Text(
|
||||
text = "Host Sign On",
|
||||
fontSize = 22.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = AppColor.LegacyRed
|
||||
)
|
||||
Text(
|
||||
text = "Run sign on and verify immediately whether the host accepted or rejected the terminal.",
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = AppColor.Gray
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = AppColor.White)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(20.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "Current Status",
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
color = AppColor.Black
|
||||
)
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(
|
||||
color = if (state.isLoading) AppColor.GoldenGlow.copy(alpha = 0.18f) else AppColor.SkylineBlue.copy(alpha = 0.12f),
|
||||
shape = RoundedCornerShape(16.dp)
|
||||
)
|
||||
.padding(16.dp)
|
||||
) {
|
||||
if (state.isLoading) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
CircularProgressIndicator(color = AppColor.LegacyRed)
|
||||
Text(text = state.statusText, color = AppColor.Black)
|
||||
}
|
||||
} else {
|
||||
Text(text = state.statusText, color = AppColor.Black)
|
||||
}
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onStartSignOn,
|
||||
enabled = !state.isLoading,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = AppColor.CrimsonRed,
|
||||
disabledContainerColor = AppColor.Gray
|
||||
)
|
||||
) {
|
||||
Text(text = if (state.isLoading) "Processing..." else "Start Sign On")
|
||||
}
|
||||
|
||||
if (state.canRetry) {
|
||||
OutlinedButton(
|
||||
onClick = onStartSignOn,
|
||||
enabled = !state.isLoading,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text(text = "Retry")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SignOnResultScreen(
|
||||
isSuccess: Boolean,
|
||||
message: String,
|
||||
onBack: () -> Unit,
|
||||
onDone: () -> Unit,
|
||||
onRetry: () -> Unit
|
||||
) {
|
||||
val accent = if (isSuccess) AppColor.Success else AppColor.LegacyRed
|
||||
val background = if (isSuccess) AppColor.Success.copy(alpha = 0.12f) else AppColor.CrimsonRed.copy(alpha = 0.12f)
|
||||
|
||||
Scaffold(
|
||||
containerColor = AppColor.IvoryBeige,
|
||||
topBar = {
|
||||
AppBar(
|
||||
title = "Sign On Result",
|
||||
icon = Icons.Default.ArrowBack,
|
||||
onIconClick = onBack
|
||||
)
|
||||
}
|
||||
) { paddingValues ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues)
|
||||
.padding(16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(24.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = AppColor.White)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(24.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.background(background, RoundedCornerShape(50))
|
||||
.padding(18.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = if (isSuccess) Icons.Default.CheckCircle else Icons.Default.ErrorOutline,
|
||||
contentDescription = null,
|
||||
tint = accent
|
||||
)
|
||||
}
|
||||
|
||||
Text(
|
||||
text = if (isSuccess) "Sign On Success" else "Sign On Failed",
|
||||
fontSize = 24.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = accent
|
||||
)
|
||||
|
||||
Text(
|
||||
text = message,
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = Color.Black
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
if (!isSuccess) {
|
||||
Button(
|
||||
onClick = onRetry,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
colors = ButtonDefaults.buttonColors(containerColor = AppColor.CrimsonRed)
|
||||
) {
|
||||
Text(text = "Try Again")
|
||||
}
|
||||
}
|
||||
|
||||
OutlinedButton(
|
||||
onClick = onDone,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text(text = "Back To Dashboard")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,92 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.sign_on
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.utsmyanmar.paylibs.sign_on.SignOnListener
|
||||
import com.utsmyanmar.paylibs.sign_on.SignOnProcess
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
data class SignOnUiState(
|
||||
val isLoading: Boolean = false,
|
||||
val statusText: String = "Ready to start sign on.",
|
||||
val canRetry: Boolean = false
|
||||
)
|
||||
|
||||
data class SignOnResult(
|
||||
val isSuccess: Boolean,
|
||||
val message: String
|
||||
)
|
||||
|
||||
class SignOnViewModel : ViewModel() {
|
||||
|
||||
private val _uiState = MutableStateFlow(SignOnUiState())
|
||||
val uiState: StateFlow<SignOnUiState> = _uiState.asStateFlow()
|
||||
|
||||
private val _resultEvents = MutableSharedFlow<SignOnResult>()
|
||||
val resultEvents: SharedFlow<SignOnResult> = _resultEvents.asSharedFlow()
|
||||
|
||||
fun startSignOn() {
|
||||
if (_uiState.value.isLoading) return
|
||||
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
isLoading = true,
|
||||
statusText = "Signing on to host...",
|
||||
canRetry = false
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
SignOnProcess.getInstance()
|
||||
.enqueue()
|
||||
.startSignOn(object : SignOnListener {
|
||||
override fun onSuccessSignOn() {
|
||||
dispatchResult(
|
||||
SignOnResult(
|
||||
isSuccess = true,
|
||||
message = "Sign on completed successfully."
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onFailureSignOn(resultCode: Int?) {
|
||||
dispatchResult(
|
||||
SignOnResult(
|
||||
isSuccess = false,
|
||||
message = "Sign on failed. Response code: ${resultCode ?: -1}"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
override fun onNetworkFailSignOn(message: String?) {
|
||||
dispatchResult(
|
||||
SignOnResult(
|
||||
isSuccess = false,
|
||||
message = message?.takeIf { it.isNotBlank() } ?: "Network error during sign on."
|
||||
)
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun dispatchResult(result: SignOnResult) {
|
||||
viewModelScope.launch {
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
isLoading = false,
|
||||
statusText = result.message,
|
||||
canRetry = !result.isSuccess
|
||||
)
|
||||
}
|
||||
_resultEvents.emit(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,22 +5,13 @@ import androidx.compose.ui.graphics.Color
|
||||
val Purple80 = Color(0xFFD0BCFF)
|
||||
val PurpleGrey80 = Color(0xFFCCC2DC)
|
||||
val Pink80 = Color(0xFFEFB8C8)
|
||||
|
||||
val Purple40 = Color(0xFF6650a4)
|
||||
val PurpleGrey40 = Color(0xFF625b71)
|
||||
val Pink40 = Color(0xFF7D5260)
|
||||
val Primary = Color(0xFFCA2027)
|
||||
val White = Color(0xFFFFFFFF)
|
||||
val Black = Color(0xFF000000)
|
||||
|
||||
object Color {
|
||||
val IvoryBeige = Color(0xFFFFF5E6)
|
||||
val LegacyRed = Color(0xFF6F0D1E)
|
||||
val CrimsonRed = Color(0xFFCD2029)
|
||||
val GoldenGlow = Color(0xFFFFCF66)
|
||||
val SkylineBlue = Color(0xFF47A2DA)
|
||||
val White = Color(0xFFFFFFFF)
|
||||
val Black = Color(0xFF000000)
|
||||
val Gray = Color(0xFF898989)
|
||||
val Success = Color(0xFF007E33)
|
||||
val Error = Color(0xFFCD2029)
|
||||
}
|
||||
val Primary = Color(0xFFCA2027)
|
||||
|
||||
val White = Color(0xFFFFFFFF)
|
||||
|
||||
val Black = Color(0xFF000000)
|
||||
@ -1,8 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.transaction_result
|
||||
|
||||
sealed interface TransactionResultEvent {
|
||||
data object Start: TransactionResultEvent
|
||||
data object BackClick: TransactionResultEvent
|
||||
data object RetryPrint: TransactionResultEvent
|
||||
data object PrintLater: TransactionResultEvent
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.transaction_result
|
||||
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.mob.utsmyanmar.viewmodel.SharedViewModel
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||
|
||||
@Composable
|
||||
fun TransactionResultRoute(
|
||||
viewModel: TransactionResultViewModel = hiltViewModel(),
|
||||
sharedViewModel: SharedViewModel,
|
||||
onNavigateMain: () -> Unit,
|
||||
onNavigatePrintReceipt: () -> Unit,
|
||||
onShowError: (String) -> Unit,
|
||||
onShowSuccess: (String) -> Unit,
|
||||
onShowPrinterDialog: (String) -> Unit
|
||||
) {
|
||||
val state by viewModel.state.collectAsStateWithLifecycle()
|
||||
val canGoBack = sharedViewModel.transactionsType.value != TransactionsType.SALE
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
viewModel.onEvent(
|
||||
TransactionResultEvent.Start,
|
||||
sharedViewModel
|
||||
)
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
viewModel.uiEvent.collect { event ->
|
||||
when (event) {
|
||||
TransactionResultUiEvent.NavigateMain -> onNavigateMain()
|
||||
TransactionResultUiEvent.NavigatePrintReceipt -> onNavigatePrintReceipt()
|
||||
is TransactionResultUiEvent.ShowError -> onShowError(event.message)
|
||||
is TransactionResultUiEvent.ShowSuccess -> onShowSuccess(event.message)
|
||||
is TransactionResultUiEvent.ShowPrinterDialog -> onShowPrinterDialog(event.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TransactionResultScreen(
|
||||
state = state,
|
||||
canGoBack = canGoBack,
|
||||
onEvent = {
|
||||
viewModel.onEvent(it, sharedViewModel)
|
||||
}
|
||||
)
|
||||
}
|
||||
@ -1,289 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.transaction_result
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.CalendarMonth
|
||||
import androidx.compose.material.icons.filled.Numbers
|
||||
import androidx.compose.material.icons.filled.Print
|
||||
import androidx.compose.material.icons.rounded.Check
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.mob.utsmyanmar.ui.preview.P2Preview
|
||||
import com.mob.utsmyanmar.ui.theme.Color
|
||||
import com.utsmyanmar.paylibs.print.PrintReceipt
|
||||
|
||||
|
||||
@Composable
|
||||
fun TransactionResultScreen(
|
||||
state: TransactionResultState,
|
||||
canGoBack: Boolean,
|
||||
onEvent: (TransactionResultEvent) -> Unit,
|
||||
) {
|
||||
BackHandler(enabled = canGoBack) {
|
||||
onEvent(TransactionResultEvent.BackClick)
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
containerColor = Color.IvoryBeige
|
||||
) { paddingValues ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(Color.IvoryBeige)
|
||||
.padding(paddingValues)
|
||||
.statusBarsPadding()
|
||||
.navigationBarsPadding()
|
||||
.padding(horizontal = 20.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
SuccessIcon()
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Text(
|
||||
text = state.title,
|
||||
color = Color.LegacyRed,
|
||||
fontSize = 24.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(6.dp))
|
||||
|
||||
Text(
|
||||
text = state.message.ifBlank { "Your payment has been processed successfully." },
|
||||
color = Color.Gray,
|
||||
fontSize = 13.sp,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(28.dp))
|
||||
|
||||
AmountCard(amount = "50,000")
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
InfoCard(
|
||||
date = "26 May 2026",
|
||||
time = "12:06 PM",
|
||||
transactionId = "1234568333"
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SuccessIcon() {
|
||||
Box(
|
||||
modifier = Modifier.size(132.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(132.dp)
|
||||
.background(
|
||||
color = Color.Success.copy(alpha = 0.12f),
|
||||
shape = CircleShape
|
||||
)
|
||||
)
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(96.dp)
|
||||
.background(
|
||||
color = Color.Success,
|
||||
shape = CircleShape
|
||||
),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Check,
|
||||
contentDescription = "Success",
|
||||
tint = Color.White,
|
||||
modifier = Modifier.size(64.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AmountCard(
|
||||
amount: String
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(130.dp)
|
||||
.shadow(
|
||||
elevation = 6.dp,
|
||||
shape = RoundedCornerShape(22.dp),
|
||||
clip = false
|
||||
),
|
||||
shape = RoundedCornerShape(22.dp),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = Color.White
|
||||
)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(vertical = 18.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(
|
||||
text = "PAID AMOUNT",
|
||||
color = Color.Gray,
|
||||
fontSize = 15.sp,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
|
||||
|
||||
Text(
|
||||
text = amount,
|
||||
color = Color.LegacyRed,
|
||||
fontSize = 30.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(6.dp))
|
||||
|
||||
Text(
|
||||
text = "MMK",
|
||||
color = Color.LegacyRed,
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun InfoCard(
|
||||
date: String,
|
||||
time: String,
|
||||
transactionId: String
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(130.dp)
|
||||
.shadow(
|
||||
elevation = 4.dp,
|
||||
shape = RoundedCornerShape(18.dp),
|
||||
clip = false
|
||||
),
|
||||
shape = RoundedCornerShape(18.dp),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = Color.White
|
||||
)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 18.dp),
|
||||
verticalArrangement = Arrangement.SpaceAround
|
||||
) {
|
||||
InfoItem(
|
||||
icon = Icons.Default.CalendarMonth,
|
||||
title = "Date & Time",
|
||||
value = date,
|
||||
subValue = time,
|
||||
// modifier = Modifier.weight(1f)
|
||||
)
|
||||
InfoItem(
|
||||
icon = Icons.Default.Numbers,
|
||||
title = "Transaction ID",
|
||||
value = transactionId,
|
||||
subValue = "",
|
||||
// modifier = Modifier.weight(1f)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun InfoItem(
|
||||
icon: ImageVector,
|
||||
title: String,
|
||||
value: String,
|
||||
subValue: String,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Row(
|
||||
modifier = modifier,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(46.dp)
|
||||
.background(
|
||||
color = Color.LegacyRed.copy(alpha = 0.1f),
|
||||
shape = CircleShape
|
||||
),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = null,
|
||||
tint = Color.LegacyRed,
|
||||
modifier = Modifier.size(25.dp)
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.width(10.dp))
|
||||
|
||||
Column {
|
||||
Text(
|
||||
text = title,
|
||||
color = Color.Gray,
|
||||
fontSize = 11.sp
|
||||
)
|
||||
|
||||
Text(
|
||||
text = value,
|
||||
color = Color.Black,
|
||||
fontSize = 13.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
if (subValue.isNotEmpty()) {
|
||||
Text(
|
||||
text = subValue,
|
||||
color = Color.Black,
|
||||
fontSize = 11.sp
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@P2Preview
|
||||
@Composable
|
||||
fun PreviewTransactionResultScreen() {
|
||||
TransactionResultScreen(
|
||||
state = TransactionResultState(
|
||||
"Success"
|
||||
),
|
||||
canGoBack = true,
|
||||
onEvent = {},
|
||||
)
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.transaction_result
|
||||
|
||||
data class TransactionResultState(
|
||||
val title: String = "Transaction Result",
|
||||
val message: String = "",
|
||||
val isLoading: Boolean = false
|
||||
)
|
||||
@ -1,9 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.transaction_result
|
||||
|
||||
sealed interface TransactionResultUiEvent {
|
||||
data object NavigateMain : TransactionResultUiEvent
|
||||
data object NavigatePrintReceipt : TransactionResultUiEvent
|
||||
data class ShowError(val message: String) : TransactionResultUiEvent
|
||||
data class ShowSuccess(val message: String) : TransactionResultUiEvent
|
||||
data class ShowPrinterDialog(val message: String) : TransactionResultUiEvent
|
||||
}
|
||||
@ -1,281 +0,0 @@
|
||||
package com.mob.utsmyanmar.ui.transaction_result
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.mob.utsmyanmar.model.ecr.ECRResultStatus
|
||||
import com.mob.utsmyanmar.utils.CoreUtils
|
||||
import com.mob.utsmyanmar.viewmodel.SharedViewModel
|
||||
import com.utsmyanmar.baselib.emv.EmvParamOperation
|
||||
import com.utsmyanmar.baselib.network.model.sirius.SiriusRequest
|
||||
import com.utsmyanmar.ecr.ECRHelper
|
||||
import com.utsmyanmar.ecr.ECRProcess
|
||||
import com.utsmyanmar.ecr.data.model.TransactionsResp
|
||||
import com.utsmyanmar.paylibs.Constant
|
||||
import com.utsmyanmar.paylibs.model.PayDetail
|
||||
import com.utsmyanmar.paylibs.print.PaperRollStatusCallback
|
||||
import com.utsmyanmar.paylibs.print.PrintHelper
|
||||
import com.utsmyanmar.paylibs.utils.PrintStatus
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.ByteUtil
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.receiveAsFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import sunmi.sunmiui.utils.LogUtil
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class TransactionResultViewModel @Inject constructor(
|
||||
private val emvParamOperation: EmvParamOperation
|
||||
) : ViewModel() {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "TransactionResultVM"
|
||||
private const val RESULT_TIMEOUT = 3000L
|
||||
}
|
||||
|
||||
private val _state = MutableStateFlow(TransactionResultState())
|
||||
val state = _state.asStateFlow()
|
||||
|
||||
private val _uiEvent = Channel<TransactionResultUiEvent>()
|
||||
val uiEvent = _uiEvent.receiveAsFlow()
|
||||
|
||||
private var started = false
|
||||
|
||||
fun onEvent(
|
||||
event: TransactionResultEvent,
|
||||
sharedViewModel: SharedViewModel
|
||||
) {
|
||||
when (event) {
|
||||
TransactionResultEvent.Start -> start(sharedViewModel)
|
||||
TransactionResultEvent.BackClick -> isCardInside()
|
||||
TransactionResultEvent.RetryPrint -> startPrintProcess(sharedViewModel, false)
|
||||
TransactionResultEvent.PrintLater -> isCardInside()
|
||||
}
|
||||
}
|
||||
|
||||
private fun start(sharedViewModel: SharedViewModel) {
|
||||
if (started) return
|
||||
started = true
|
||||
|
||||
sharedViewModel.setPrintStatus(PrintStatus.FIRST_PRINT)
|
||||
sharedViewModel.printXStatus.value = null
|
||||
|
||||
updateTitle(sharedViewModel)
|
||||
observePrintStatus(sharedViewModel)
|
||||
|
||||
if (sharedViewModel.isEcr.value == true) {
|
||||
ecrAction(sharedViewModel)
|
||||
}
|
||||
|
||||
startResultTimeout(sharedViewModel)
|
||||
}
|
||||
|
||||
private fun updateTitle(sharedViewModel: SharedViewModel) {
|
||||
val payDetail = sharedViewModel.payDetail.value
|
||||
val resultCode = payDetail?.tradeAnswerCode.orEmpty()
|
||||
val qrStatus = payDetail?.qrTransStatus ?: -100
|
||||
|
||||
val isDemoMode = SystemParamsOperation.getInstance().demoStatus
|
||||
|
||||
val isSuccess = isDemoMode ||
|
||||
resultCode == Constant.ANSWER_CODE_ACCEPT ||
|
||||
resultCode == Constant.ANSWER_CODE_APPROVED
|
||||
|
||||
val title = when {
|
||||
isSuccess -> "Transaction Success"
|
||||
qrStatus == 1 || qrStatus == -1 || qrStatus == 2 || qrStatus == 3 -> "QR Pay"
|
||||
else -> "Error"
|
||||
}
|
||||
|
||||
val message = when {
|
||||
isSuccess -> "Transaction approved"
|
||||
payDetail?.tradeAnswerCode?.isNotBlank() == true -> payDetail.tradeAnswerCode
|
||||
else -> "Transaction failed"
|
||||
}
|
||||
|
||||
_state.value = _state.value.copy(
|
||||
title = title,
|
||||
message = message
|
||||
)
|
||||
}
|
||||
|
||||
private fun startResultTimeout(sharedViewModel: SharedViewModel) {
|
||||
viewModelScope.launch {
|
||||
delay(RESULT_TIMEOUT)
|
||||
|
||||
val payDetail = sharedViewModel.payDetail.value
|
||||
|
||||
if (payDetail == null) {
|
||||
navigateMain()
|
||||
return@launch
|
||||
}
|
||||
|
||||
val transactionType = sharedViewModel.transactionsType.value
|
||||
|
||||
when {
|
||||
isNonApprovedTrade(payDetail) &&
|
||||
isNonWavepayTransaction(transactionType) -> {
|
||||
startPrintProcess(sharedViewModel, false)
|
||||
isCardInside()
|
||||
}
|
||||
|
||||
transactionType == TransactionsType.SETTLEMENT -> {
|
||||
startPrintProcess(sharedViewModel, true)
|
||||
sendUiEvent(
|
||||
TransactionResultUiEvent.ShowSuccess(
|
||||
"Configs are updated"
|
||||
)
|
||||
)
|
||||
navigateMain()
|
||||
}
|
||||
|
||||
isWavePayNonSuccessTransaction(transactionType, payDetail) -> {
|
||||
startPrintProcess(sharedViewModel, false)
|
||||
navigateMain()
|
||||
}
|
||||
|
||||
else -> {
|
||||
SystemParamsOperation.getInstance()
|
||||
.setLastSuccessTrnx(payDetail.voucherNo)
|
||||
|
||||
emvParamOperation.loadEmvTerminalParam()
|
||||
navigatePrint()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun isNonApprovedTrade(payDetail: PayDetail): Boolean {
|
||||
return payDetail.tradeAnswerCode != Constant.ANSWER_CODE_APPROVED &&
|
||||
payDetail.tradeAnswerCode != Constant.ANSWER_CODE_ACCEPT
|
||||
}
|
||||
|
||||
private fun isNonWavepayTransaction(type: TransactionsType?): Boolean {
|
||||
return type != TransactionsType.WAVEPAY &&
|
||||
type != TransactionsType.WAVE_INQUIRY_STATUS &&
|
||||
type != TransactionsType.WAVEPAY_REFUND
|
||||
}
|
||||
|
||||
private fun isWavePayNonSuccessTransaction(
|
||||
type: TransactionsType?,
|
||||
payDetail: PayDetail
|
||||
): Boolean {
|
||||
return (type == TransactionsType.WAVEPAY && payDetail.qrTransStatus != 1) ||
|
||||
(type == TransactionsType.WAVE_INQUIRY_STATUS && payDetail.qrTransStatus != 1) ||
|
||||
(type == TransactionsType.WAVEPAY_REFUND && payDetail.qrTransStatus != 1)
|
||||
}
|
||||
|
||||
private fun observePrintStatus(sharedViewModel: SharedViewModel) {
|
||||
sharedViewModel.printXStatus.observeForever { status ->
|
||||
when (status) {
|
||||
PrintStatus.EMPTY_PAPER_ROLL -> {
|
||||
startPrintProcess(sharedViewModel, false)
|
||||
}
|
||||
|
||||
PrintStatus.DONE_PRINT -> {
|
||||
isCardInside()
|
||||
}
|
||||
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun startPrintProcess(
|
||||
sharedViewModel: SharedViewModel,
|
||||
isSettlement: Boolean
|
||||
) {
|
||||
PrintHelper.getInstance().checkPaperRollStatus(
|
||||
object : PaperRollStatusCallback {
|
||||
|
||||
override fun paperRollIsReady() {
|
||||
if (isSettlement) {
|
||||
sharedViewModel.startPrintProcessSettlement()
|
||||
} else {
|
||||
sharedViewModel.startPrintProcess()
|
||||
}
|
||||
}
|
||||
|
||||
override fun paperRollIsEmpty() {
|
||||
sendUiEvent(
|
||||
TransactionResultUiEvent.ShowPrinterDialog(
|
||||
"Paper roll not ready"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun paperRollLipIsOpened() {
|
||||
sendUiEvent(
|
||||
TransactionResultUiEvent.ShowPrinterDialog(
|
||||
"Printer lip is opened. Please close lip."
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun unknownStatusOccur(code: Int) {
|
||||
sendUiEvent(
|
||||
TransactionResultUiEvent.ShowError(
|
||||
"Check printer status: $code"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun getECRResponseMessage(
|
||||
sharedViewModel: SharedViewModel
|
||||
): String {
|
||||
val resp: TransactionsResp =
|
||||
CoreUtils.getInstance(sharedViewModel).generateResponseMsg()
|
||||
|
||||
return ECRProcess.generateECRResponse(resp)
|
||||
}
|
||||
|
||||
private fun getECRResponseCMHL(
|
||||
sharedViewModel: SharedViewModel
|
||||
): ByteArray {
|
||||
return CoreUtils.getInstance(sharedViewModel)
|
||||
.generateCMHLResponse(ECRResultStatus.RESPONSE_RECEIVED)
|
||||
}
|
||||
|
||||
private fun ecrAction(sharedViewModel: SharedViewModel) {
|
||||
if (SystemParamsOperation.getInstance().isCMHLEnabled) {
|
||||
val response = getECRResponseCMHL(sharedViewModel)
|
||||
|
||||
LogUtil.d(TAG, "ECR Response: ${ByteUtil.bytes2HexStr(response)}")
|
||||
|
||||
ECRHelper.send(response)
|
||||
CoreUtils.getInstance(sharedViewModel).responseACKCMHL()
|
||||
} else {
|
||||
val response = getECRResponseMessage(sharedViewModel)
|
||||
|
||||
LogUtil.d(TAG, "ECR Response: $response")
|
||||
|
||||
ECRHelper.send(response.toByteArray())
|
||||
}
|
||||
}
|
||||
|
||||
private fun isCardInside() {
|
||||
navigateMain()
|
||||
}
|
||||
|
||||
private fun navigateMain() {
|
||||
sendUiEvent(TransactionResultUiEvent.NavigateMain)
|
||||
}
|
||||
|
||||
private fun navigatePrint() {
|
||||
sendUiEvent(TransactionResultUiEvent.NavigatePrintReceipt)
|
||||
}
|
||||
|
||||
private fun sendUiEvent(event: TransactionResultUiEvent) {
|
||||
viewModelScope.launch {
|
||||
_uiEvent.send(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
package com.mob.utsmyanmar.utils
|
||||
|
||||
import android.content.Context
|
||||
|
||||
object AppContextHolder {
|
||||
private lateinit var appContext: Context
|
||||
|
||||
fun init(context: Context) {
|
||||
appContext = context.applicationContext
|
||||
}
|
||||
|
||||
fun get(): Context {
|
||||
return appContext
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
package com.mob.utsmyanmar.utils
|
||||
|
||||
import com.utsmyanmar.ecr.data.model.Transactions
|
||||
|
||||
interface ECRSetups {
|
||||
fun setUpECREchoTest()
|
||||
fun setUpECRSale(trans: Transactions): Boolean
|
||||
fun setUpECRQR(trans: Transactions): Boolean
|
||||
fun setUpECRVoid(trans: Transactions): Boolean
|
||||
fun setUpECRCashAdvance(trans: Transactions): Boolean
|
||||
fun setUpECRPreAuth(trans: Transactions): Boolean
|
||||
fun setUpECRPreAuthVoid(trans: Transactions): Boolean
|
||||
fun setUpECRPreAuthComplete(trans: Transactions): Boolean
|
||||
fun setUpECRPreAuthCompleteVoid(trans: Transactions): Boolean
|
||||
fun setUpECRSettlement()
|
||||
fun setUpECRRefund(trans: Transactions): Boolean
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
package com.mob.utsmyanmar.utils
|
||||
|
||||
import com.kizzy.cmhl.models.PingRequest
|
||||
import com.kizzy.cmhl.models.PreAuthCancellationRequest
|
||||
import com.kizzy.cmhl.models.PreAuthCompletionRequest
|
||||
import com.kizzy.cmhl.models.PreAuthRequest
|
||||
import com.kizzy.cmhl.models.QrPaymentRequest
|
||||
import com.kizzy.cmhl.models.SaleRequest
|
||||
import com.kizzy.cmhl.models.SettlementRequest
|
||||
import com.kizzy.cmhl.models.VoidQrPaymentRequest
|
||||
import com.kizzy.cmhl.models.VoidRequest
|
||||
|
||||
interface ECRSetupsCMHL {
|
||||
fun setUpECREchoTest()
|
||||
fun setupPingRequest(trans: PingRequest)
|
||||
fun setUpECRSale(trans: SaleRequest): Boolean
|
||||
fun setUpECRQR(trans: QrPaymentRequest): Boolean
|
||||
fun setUpECRQRVoid(trans: VoidQrPaymentRequest): Boolean
|
||||
fun setUpECRVoid(trans: VoidRequest): Boolean
|
||||
fun setUpECRPreAuth(trans: PreAuthRequest): Boolean
|
||||
fun setUpECRPreAuthVoid(trans: PreAuthCancellationRequest): Boolean
|
||||
fun setUpECRPreAuthComplete(trans: PreAuthCompletionRequest): Boolean
|
||||
fun setUpECRSettlement(trans: SettlementRequest)
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
package com.mob.utsmyanmar.utils
|
||||
|
||||
interface OldECRSetups {
|
||||
fun setUpECRTest()
|
||||
fun setUpECRSale(msg: String): Boolean
|
||||
fun setUpECRVoid(msg: String): Boolean
|
||||
fun setUpECRCashAdvance(msg: String): Boolean
|
||||
fun setUpECRPreAuth(msg: String): Boolean
|
||||
fun setUpECRPreAuthVoid(msg: String): Boolean
|
||||
fun setUpECRPreAuthComplete(msg: String): Boolean
|
||||
fun setUpECRPreAuthCompleteVoid(msg: String): Boolean
|
||||
fun setUpECRSettlement()
|
||||
fun setUpECRRefund(msg: String): Boolean
|
||||
}
|
||||
@ -1,120 +0,0 @@
|
||||
package com.mob.utsmyanmar.utils
|
||||
|
||||
import com.mob.utsmyanmar.config.Constants
|
||||
import com.utsmyanmar.checkxread.model.CardDataX
|
||||
import com.utsmyanmar.checkxread.util.CardTypeX
|
||||
import com.utsmyanmar.paylibs.model.CardInfo
|
||||
import com.utsmyanmar.paylibs.model.MAGCardInfo
|
||||
import com.utsmyanmar.paylibs.model.PayDetail
|
||||
import com.utsmyanmar.paylibs.model.TradeData
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||
import com.utsmyanmar.paylibs.utils.params.Params
|
||||
import sunmi.sunmiui.utils.LogUtil
|
||||
|
||||
object TransactionUtil {
|
||||
private const val TAG = "TransactionUtil"
|
||||
private const val MPU_CARD_SCHEME = "MPU"
|
||||
private const val VISA_CARD_SCHEME = "VISA"
|
||||
private const val MASTER_CARD_SCHEME = "MASTER"
|
||||
private const val UPI_CARD_SCHEME = "UPI"
|
||||
private val qrTerminalId: String
|
||||
get() = SystemParamsOperation.getInstance().secHostTerminalId
|
||||
|
||||
private val qrMerchantId: String
|
||||
get() = SystemParamsOperation.getInstance().secHostMerchantId
|
||||
|
||||
fun getQRMerchantId(): String {
|
||||
return qrMerchantId
|
||||
}
|
||||
|
||||
fun getQRTerminalId(): String {
|
||||
return qrTerminalId
|
||||
}
|
||||
|
||||
fun initMPUTransaction(
|
||||
cardDataX: CardDataX,
|
||||
cardTypeX: CardTypeX
|
||||
): TradeData {
|
||||
|
||||
LogUtil.d(TAG, "CardDataX : $cardDataX")
|
||||
|
||||
val tradeData = Params.newTrade(false)
|
||||
val payDetail = tradeData.payDetail
|
||||
|
||||
payDetail.cardNo = cardDataX.pan
|
||||
payDetail.expDate = cardDataX.exp
|
||||
payDetail.cardType = cardTypeX.value
|
||||
payDetail.accountType = MPU_CARD_SCHEME
|
||||
payDetail.cardHolderName = cardDataX.cardHolderName
|
||||
|
||||
val cardInfo = CardInfo()
|
||||
|
||||
val magCardInfo = MAGCardInfo()
|
||||
magCardInfo.track2Cipher = cardDataX.track2
|
||||
|
||||
cardInfo.magCardInfo = magCardInfo
|
||||
|
||||
payDetail.cardInfo = cardInfo
|
||||
|
||||
return tradeData
|
||||
}
|
||||
|
||||
fun initMagStripeTransaction(
|
||||
cardDataX: CardDataX,
|
||||
isFallback: Boolean
|
||||
): TradeData {
|
||||
|
||||
LogUtil.d(TAG, "CardDataX : $cardDataX")
|
||||
|
||||
val tradeData = Params.newTrade(false)
|
||||
val payDetail = tradeData.payDetail
|
||||
|
||||
payDetail.cardNo = cardDataX.pan
|
||||
payDetail.expDate = cardDataX.exp
|
||||
|
||||
payDetail.accountType = when {
|
||||
cardDataX.pan.startsWith("4") -> VISA_CARD_SCHEME
|
||||
cardDataX.pan.startsWith("5") -> MASTER_CARD_SCHEME
|
||||
cardDataX.pan.startsWith("6") -> UPI_CARD_SCHEME
|
||||
else -> MPU_CARD_SCHEME
|
||||
}
|
||||
|
||||
payDetail.cardType = if (isFallback) {
|
||||
-9
|
||||
} else {
|
||||
CardTypeX.MAG.value
|
||||
}
|
||||
|
||||
payDetail.cardHolderName = cardDataX.cardHolderName
|
||||
|
||||
val cardInfo = CardInfo()
|
||||
|
||||
val magCardInfo = MAGCardInfo()
|
||||
magCardInfo.track2Cipher = cardDataX.track2
|
||||
|
||||
cardInfo.magCardInfo = magCardInfo
|
||||
|
||||
payDetail.cardInfo = cardInfo
|
||||
|
||||
return tradeData
|
||||
}
|
||||
|
||||
fun initWalletTransaction(
|
||||
transactionType: TransactionsType
|
||||
): PayDetail {
|
||||
|
||||
val tradeData = Params.newTrade(true)
|
||||
val payDetail = tradeData.payDetail
|
||||
|
||||
payDetail.accountType = Constants.WALLET
|
||||
payDetail.transType = transactionType.name
|
||||
payDetail.transactionType = transactionType.value
|
||||
payDetail.terminalNo = qrTerminalId
|
||||
payDetail.merchantNo = qrMerchantId
|
||||
payDetail.currencyCode = "104"
|
||||
payDetail.isCanceled = false
|
||||
|
||||
return payDetail
|
||||
}
|
||||
}
|
||||
@ -1,152 +0,0 @@
|
||||
package com.mob.utsmyanmar.viewmodel
|
||||
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.mob.utsmyanmar.model.CardTransactionType
|
||||
import com.utsmyanmar.checkxread.CheckXRead
|
||||
import com.utsmyanmar.checkxread.checkcard.CheckCardResultX
|
||||
import com.utsmyanmar.checkxread.model.CardDataX
|
||||
import com.utsmyanmar.checkxread.readcard.ReadCardResultX
|
||||
import com.utsmyanmar.checkxread.readcard.ReadCardX
|
||||
import com.utsmyanmar.checkxread.sdk.SunmiSDK
|
||||
import com.utsmyanmar.paylibs.model.PayDetail
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class CardReaderViewModel @Inject constructor() : ViewModel() {
|
||||
|
||||
companion object {
|
||||
private val TAG = CardReaderViewModel::class.java.simpleName
|
||||
}
|
||||
|
||||
private val mainThreadHandler = Handler(Looper.getMainLooper())
|
||||
|
||||
private var oneTimeFlag = false
|
||||
|
||||
private var cardTransactionType: CardTransactionType? = null
|
||||
|
||||
/*
|
||||
* UI States
|
||||
*/
|
||||
|
||||
private val _errorCode = MutableStateFlow("")
|
||||
val errorCode = _errorCode.asStateFlow()
|
||||
|
||||
private val _cardData = MutableStateFlow<CardDataX?>(null)
|
||||
val cardData = _cardData.asStateFlow()
|
||||
|
||||
private var _cardTypeData = MutableStateFlow<Int?>(null)
|
||||
val cardTypeData = _cardTypeData.asStateFlow()
|
||||
|
||||
private val _payDetail = MutableStateFlow<PayDetail?>(null)
|
||||
val payDetail = _payDetail.asStateFlow()
|
||||
|
||||
private val _checkCardAlertMsg =
|
||||
MutableStateFlow<String?>(null)
|
||||
val checkCardAlertMsg =
|
||||
_checkCardAlertMsg.asStateFlow()
|
||||
|
||||
/*
|
||||
* Transaction Type
|
||||
*/
|
||||
|
||||
fun setCardTransactionType(
|
||||
cardTransactionType: CardTransactionType
|
||||
) {
|
||||
this.cardTransactionType = cardTransactionType
|
||||
}
|
||||
|
||||
fun getCardTransactionType(): CardTransactionType? {
|
||||
return cardTransactionType
|
||||
}
|
||||
|
||||
/*
|
||||
* Check Card Process
|
||||
*/
|
||||
|
||||
fun startCheckXProcess(
|
||||
allType: Int,
|
||||
timeOut: Int,
|
||||
cardResultX: CheckCardResultX
|
||||
) {
|
||||
CheckXRead.getInstance()
|
||||
.startCheckXProcess(
|
||||
allType,
|
||||
timeOut,
|
||||
cardResultX
|
||||
)
|
||||
}
|
||||
|
||||
fun isReaderReady(): Boolean {
|
||||
return SunmiSDK.getInstance().readCardOptV2 != null
|
||||
}
|
||||
|
||||
fun cancelCheckXProcess() {
|
||||
CheckXRead.getInstance()
|
||||
.cancelCheckXProcess()
|
||||
}
|
||||
|
||||
/*
|
||||
* Read Card Process
|
||||
*/
|
||||
|
||||
fun startReadXProcess(
|
||||
readCardX: ReadCardX,
|
||||
readCardResultX: ReadCardResultX
|
||||
) {
|
||||
CheckXRead.getInstance()
|
||||
.startReadXProcess(
|
||||
readCardX,
|
||||
readCardResultX
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
* Alert Message
|
||||
*/
|
||||
|
||||
fun setCheckCardAlertMsg(
|
||||
msg: String,
|
||||
isAutoHide: Boolean
|
||||
) {
|
||||
_checkCardAlertMsg.value = msg
|
||||
|
||||
if (isAutoHide) {
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
_checkCardAlertMsg.value = null
|
||||
}, 5000)
|
||||
}
|
||||
}
|
||||
|
||||
fun resetUI() {
|
||||
_checkCardAlertMsg.value = null
|
||||
}
|
||||
|
||||
/*
|
||||
* One Time Flag
|
||||
*/
|
||||
|
||||
fun resetOneTimeFlag() {
|
||||
oneTimeFlag = false
|
||||
}
|
||||
|
||||
/*
|
||||
* Cancel Card Checking
|
||||
*/
|
||||
|
||||
fun cancelCheckCard() {
|
||||
if (isReaderReady()) {
|
||||
SunmiSDK.getInstance()
|
||||
.cancelCheckCard()
|
||||
}
|
||||
}
|
||||
|
||||
fun setCardData(value: Int){
|
||||
_cardTypeData.value = value
|
||||
}
|
||||
}
|
||||
@ -1,429 +0,0 @@
|
||||
package com.mob.utsmyanmar.viewmodel
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.Message
|
||||
import android.text.TextUtils
|
||||
import com.utsmyanmar.baselib.emv.EmvParamOperation
|
||||
import com.utsmyanmar.baselib.repo.Repository
|
||||
import com.utsmyanmar.baselib.util.enums.EmvResultStatus
|
||||
import com.utsmyanmar.baselib.viewModel.EmvBaseViewModel
|
||||
import com.utsmyanmar.checkxread.util.CardTypeX
|
||||
import com.utsmyanmar.paylibs.model.PayDetail
|
||||
import com.utsmyanmar.paylibs.model.TradeData
|
||||
import com.utsmyanmar.paylibs.model.enums.TransCVM
|
||||
import com.utsmyanmar.paylibs.network.ISOSocket
|
||||
import com.utsmyanmar.paylibs.reversal.ReversalAction
|
||||
import com.utsmyanmar.paylibs.reversal.ReversalListener
|
||||
import com.utsmyanmar.paylibs.system.SingleLiveEvent
|
||||
import com.utsmyanmar.paylibs.transactions.TransactionsOperation
|
||||
import com.utsmyanmar.paylibs.transactions.TransactionsOperationListener
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionType
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import sunmi.sunmiui.utils.LogUtil
|
||||
import javax.inject.Inject
|
||||
import com.mob.utsmyanmar.model.TransResultStatus
|
||||
|
||||
@HiltViewModel
|
||||
class EmvTransactionProcessViewModel @Inject constructor(
|
||||
private val repository: Repository,
|
||||
emvParamOperation: EmvParamOperation
|
||||
) : EmvBaseViewModel(repository, emvParamOperation), ProcessingTransaction {
|
||||
|
||||
private val transResult = SingleLiveEvent<TransResultStatus>()
|
||||
|
||||
override fun handleMsg(msg: Message) {
|
||||
when (msg.what) {
|
||||
|
||||
PIN_CLICK_NUMBER -> {
|
||||
showPasswordView(msg.arg1)
|
||||
}
|
||||
|
||||
PIN_CLICK_CONFIRM -> {
|
||||
if (!mPayDetail.PINCipher.isNullOrEmpty()) {
|
||||
importPinInputStatus(0)
|
||||
} else if (isOfflinePinEntered) {
|
||||
importPinInputStatus(0)
|
||||
} else {
|
||||
importPinInputStatus(2)
|
||||
}
|
||||
|
||||
if (
|
||||
transType.value == TransactionsType.PRE_AUTH_COMPLETE ||
|
||||
transType.value == TransactionsType.PRE_AUTH_VOID ||
|
||||
transType.value == TransactionsType.REFUND
|
||||
) {
|
||||
emvResultStatus.postValue(EmvResultStatus.ON_NEXT_SCREEN)
|
||||
}
|
||||
}
|
||||
|
||||
PIN_CLICK_CANCEL -> {
|
||||
importPinInputStatus(1)
|
||||
}
|
||||
|
||||
PIN_ERROR -> {
|
||||
increasedKSN()
|
||||
importPinInputStatus(3)
|
||||
handleTransactionFail(msg.arg1, PIN_PAD_FAILED)
|
||||
}
|
||||
|
||||
PIN_CLICK_EMPTY -> {
|
||||
emvResultStatus.postValue(EmvResultStatus.PIN_EMPTY)
|
||||
}
|
||||
|
||||
EMV_APP_SELECT -> {
|
||||
val candiNames = msg.obj as Array<String>
|
||||
LogUtil.d(TAG, "CandiNames size:${candiNames.size}")
|
||||
candiList.value = candiNames
|
||||
emvResultStatus.postValue(EmvResultStatus.SELECT_APP)
|
||||
}
|
||||
|
||||
EMV_FINAL_APP_SELECT -> {
|
||||
importFinalAppSelectStatus(0)
|
||||
}
|
||||
|
||||
EMV_CONFIRM_CARD_NO -> {
|
||||
importCardNoStatus(0)
|
||||
}
|
||||
|
||||
EMV_CERT_VERIFY -> {
|
||||
importCertStatus(0)
|
||||
}
|
||||
|
||||
EMV_SIGNATURE -> {
|
||||
mPayDetail.setIsFreeSign(false)
|
||||
mPayDetail.transCVM = TransCVM.SIGNATURE
|
||||
importSignatureStatus(0)
|
||||
}
|
||||
|
||||
EMV_SHOW_PIN_PAD -> {
|
||||
startPinProcess()
|
||||
}
|
||||
|
||||
EMV_ONLINE_PROCESS -> {
|
||||
handleTransactionProcess()
|
||||
}
|
||||
|
||||
EMV_ERROR -> {
|
||||
handleTransactionFail(msg.arg1, msg.obj.toString())
|
||||
}
|
||||
|
||||
EMV_TRY_AGAIN -> {
|
||||
emvResultStatus.postValue(EmvResultStatus.TRY_AGAIN)
|
||||
}
|
||||
|
||||
EMV_CONFIRM_CODE_VERIFY -> {
|
||||
emvResultStatus.postValue(EmvResultStatus.CONFIRM_CODE_VERIFY)
|
||||
}
|
||||
|
||||
EMV_SUCCESS_ONLINE -> {
|
||||
transResult.postValue(TransResultStatus.SUCCESS)
|
||||
}
|
||||
|
||||
EMV_FAILURE_ONLINE -> {
|
||||
transResult.postValue(TransResultStatus.FAIL)
|
||||
}
|
||||
|
||||
EMV_SUCCESS_OFFLINE -> {
|
||||
transResult.postValue(TransResultStatus.OFFLINE_SUCCESS)
|
||||
}
|
||||
|
||||
EMV_FAILURE_OFFLINE -> {
|
||||
transResult.postValue(TransResultStatus.OFFLINE_FAILURE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onCancelEmvTransaction() {
|
||||
LogUtil.e(TAG, "Terminate Transaction : $mProcessStep")
|
||||
|
||||
when (mProcessStep) {
|
||||
EMV_APP_SELECT -> importAppSelect(-1)
|
||||
EMV_FINAL_APP_SELECT -> importFinalAppSelectStatus(-1)
|
||||
EMV_CONFIRM_CARD_NO -> importCardNoStatus(1)
|
||||
EMV_CERT_VERIFY -> importCertStatus(1)
|
||||
PIN_ERROR -> importPinInputStatus(3)
|
||||
EMV_ONLINE_PROCESS -> importOnlineProcessStatus(1)
|
||||
EMV_SIGNATURE -> importSignatureStatus(1)
|
||||
EMV_SHOW_PIN_PAD -> importPinInputStatus(1)
|
||||
}
|
||||
}
|
||||
|
||||
fun setPayDetail(payDetail: PayDetail) {
|
||||
mPayDetail = payDetail
|
||||
mTradeData = TradeData().apply {
|
||||
setPayDetail(payDetail)
|
||||
}
|
||||
}
|
||||
|
||||
fun getPayDetail(): PayDetail {
|
||||
return mPayDetail
|
||||
}
|
||||
|
||||
fun resetProcessStepCount() {
|
||||
mProcessStep = 0
|
||||
}
|
||||
|
||||
override fun resetTransactionStatus() {
|
||||
emvResultStatus.clear()
|
||||
transResult.clear()
|
||||
}
|
||||
|
||||
override fun getTransStatus(): SingleLiveEvent<TransResultStatus> {
|
||||
return transResult
|
||||
}
|
||||
|
||||
private fun isCardLessTrans(): Boolean {
|
||||
return transType.value == TransactionsType.VOID ||
|
||||
transType.value == TransactionsType.PRE_AUTH_COMPLETE_VOID ||
|
||||
transType.value == TransactionsType.PRE_AUTH_VOID ||
|
||||
transType.value == TransactionsType.REFUND
|
||||
}
|
||||
|
||||
fun setPinPadCancel() {
|
||||
importPinInputStatus(1)
|
||||
}
|
||||
|
||||
override fun startOnlineProcess() {
|
||||
isReversal = false
|
||||
|
||||
TransactionsOperation.getInstance()
|
||||
.getStartOperation(mTradeData, transType.value)
|
||||
.checkOperation(object : TransactionsOperationListener {
|
||||
|
||||
override fun onSuccess(tradeData: TradeData) {
|
||||
val payDetailRes = tradeData.payDetail
|
||||
|
||||
payDetailRes.invoiceNo =
|
||||
SystemParamsOperation.getInstance().incrementInvoiceNum
|
||||
|
||||
LogUtil.d(TAG, "Transaction Operation Success: ${payDetailRes.tradeAnswerCode}")
|
||||
LogUtil.d(TAG, "Transaction Type: ${payDetailRes.transactionType}")
|
||||
|
||||
if (
|
||||
TextUtils.equals(payDetailRes.tradeAnswerCode, RC_APPROVED_V1) ||
|
||||
TextUtils.equals(payDetailRes.tradeAnswerCode, RC_APPROVED_V2)
|
||||
) {
|
||||
when (transType.value) {
|
||||
TransactionsType.VOID -> processVoidDB(payDetailRes)
|
||||
TransactionsType.REFUND -> processRefundDB(payDetailRes)
|
||||
TransactionsType.PRE_AUTH_VOID -> processPreVoidDb(payDetailRes)
|
||||
TransactionsType.PRE_AUTH_COMPLETE -> processPreCompDb(payDetailRes)
|
||||
TransactionsType.PRE_AUTH_COMPLETE_VOID -> processPreCompVoidDb(payDetailRes)
|
||||
else -> insertDB(payDetailRes)
|
||||
}
|
||||
|
||||
payDetailResult.value = payDetailRes
|
||||
|
||||
if (isCardLessTrans()) {
|
||||
transResult.value = TransResultStatus.SUCCESS
|
||||
} else if (payDetailRes.cardType == CardTypeX.MANUAL.value) {
|
||||
transResult.value = TransResultStatus.SUCCESS
|
||||
}
|
||||
|
||||
} else {
|
||||
payDetailResult.value = payDetailRes
|
||||
|
||||
if (isCardLessTrans()) {
|
||||
transResult.value = TransResultStatus.FAIL
|
||||
} else if (payDetailRes.cardType == CardTypeX.MANUAL.value) {
|
||||
transResult.value = TransResultStatus.FAIL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onReversal(tradeData: TradeData) {
|
||||
LogUtil.d(TAG, "<<<< On Reversal >>>>")
|
||||
|
||||
isReversal = true
|
||||
transResult.postValue(TransResultStatus.REVERSAL_PREPARE)
|
||||
|
||||
var reversalDelay = 15000
|
||||
|
||||
val delayValue = SystemParamsOperation.getInstance().reversalDelay
|
||||
if (!delayValue.isNullOrEmpty()) {
|
||||
reversalDelay = "${delayValue}000".toInt()
|
||||
}
|
||||
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
val payDetailReversal = tradeData.payDetail
|
||||
|
||||
if (
|
||||
payDetailReversal.transactionType == TransactionType.SALE ||
|
||||
payDetailReversal.transactionType == TransactionType.VOID ||
|
||||
payDetailReversal.transactionType == TransactionType.REFUND ||
|
||||
payDetailReversal.transactionType == TransactionType.PRE_SALE ||
|
||||
payDetailReversal.transactionType == TransactionType.CASH_ADVANCE ||
|
||||
payDetailReversal.transactionType == TransactionType.PRE_SALE_CANCEL ||
|
||||
payDetailReversal.transactionType == TransactionType.PRE_SALE_COMPLETE ||
|
||||
payDetailReversal.transactionType == TransactionType.PRE_SALE_COMPLETE_VOID
|
||||
) {
|
||||
emvResultStatus.postValue(EmvResultStatus.REVERSAL_PROCESS)
|
||||
transResult.postValue(TransResultStatus.REVERSAL_PROCESS)
|
||||
callReversal(tradeData)
|
||||
} else {
|
||||
emvResultStatus.postValue(EmvResultStatus.REVERSAL_FAIL)
|
||||
transResult.postValue(TransResultStatus.REVERSAL_FAIL)
|
||||
}
|
||||
}, reversalDelay.toLong())
|
||||
}
|
||||
|
||||
override fun onError(message: String) {
|
||||
LogUtil.e(TAG, "<<<< On Error >>>>")
|
||||
LogUtil.e(TAG, "error message:$message")
|
||||
|
||||
if (TextUtils.equals(message, TRY_SECONDARY)) {
|
||||
emvResultStatus.postValue(EmvResultStatus.SECONDARY)
|
||||
transResult.postValue(TransResultStatus.SECONDARY)
|
||||
startOnlineProcess()
|
||||
} else {
|
||||
importOnlineProcessStatus(1)
|
||||
setNetWorkErrorDesc(message)
|
||||
errorCodeMsg.value = message
|
||||
emvResultStatus.postValue(EmvResultStatus.NETWORK_ERROR)
|
||||
transResult.postValue(TransResultStatus.NETWORK_ERROR)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun insertDB(payResult: PayDetail) {
|
||||
payResult.PINCipher = ""
|
||||
repository.insertPayDetail(payResult)
|
||||
}
|
||||
|
||||
override fun processVoidDB(payResult: PayDetail) {
|
||||
mPayDetail.setIsCanceled(true)
|
||||
updatePayDetail(mPayDetail)
|
||||
repository.insertPayDetail(updateCurrentDateAndTime(payResult))
|
||||
}
|
||||
|
||||
override fun processPreVoidDb(payResult: PayDetail) {
|
||||
oldTransPayDetail.setIsCanceled(true)
|
||||
updatePayDetail(oldTransPayDetail)
|
||||
repository.insertPayDetail(updateCurrentDateAndTime(payResult))
|
||||
}
|
||||
|
||||
override fun processPreCompDb(payResult: PayDetail) {
|
||||
if (oldTransPayDetail.amount == payResult.amount) {
|
||||
oldTransPayDetail.setIsCanceled(true)
|
||||
updatePayDetail(oldTransPayDetail)
|
||||
} else {
|
||||
oldTransPayDetail.setIsCanceled(false)
|
||||
updatePayDetail(oldTransPayDetail)
|
||||
}
|
||||
|
||||
repository.insertPayDetail(updateCurrentDateAndTime(payResult))
|
||||
}
|
||||
|
||||
override fun processPreCompVoidDb(payResult: PayDetail) {
|
||||
mPayDetail.setIsCanceled(true)
|
||||
updatePayDetail(mPayDetail)
|
||||
repository.insertPayDetail(updateCurrentDateAndTime(payResult))
|
||||
}
|
||||
|
||||
override fun processRefundDB(payResult: PayDetail) {
|
||||
mPayDetail.setReturnGood(true)
|
||||
updatePayDetail(mPayDetail)
|
||||
repository.insertPayDetail(updateCurrentDateAndTime(payResult))
|
||||
}
|
||||
|
||||
private fun handleTransactionFail(code: Int, description: String) {
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
LogUtil.d(TAG, "On handleTransactionFail ::")
|
||||
|
||||
if (isReversal) {
|
||||
transResult.value = TransResultStatus.REVERSAL_PREPARE
|
||||
} else {
|
||||
emvResultStatus.postValue(EmvResultStatus.ERROR)
|
||||
transResult.value = TransResultStatus.FAIL
|
||||
errorCodeMsg.postValue("$code:$description")
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
|
||||
private fun handleTransactionProcess() {
|
||||
val cardNo = mPayDetail.cardNo
|
||||
|
||||
if (cardNo.isNullOrEmpty()) {
|
||||
getCardInfo()
|
||||
}
|
||||
|
||||
if (
|
||||
transType.value == TransactionsType.PRE_AUTH_COMPLETE ||
|
||||
transType.value == TransactionsType.PRE_AUTH_VOID ||
|
||||
transType.value == TransactionsType.REFUND
|
||||
) {
|
||||
emvResultStatus.postValue(EmvResultStatus.ON_NEXT_SCREEN)
|
||||
} else {
|
||||
emvResultStatus.postValue(EmvResultStatus.SUCCESS)
|
||||
}
|
||||
}
|
||||
|
||||
protected fun callReversal(tradeData: TradeData) {
|
||||
if (transType.value == TransactionsType.VOID) {
|
||||
tradeData.payDetail.icC55 = ""
|
||||
}
|
||||
|
||||
ReversalAction.getInstance()
|
||||
.setData(tradeData)
|
||||
.enqueue()
|
||||
.startReversal(object : ReversalListener {
|
||||
|
||||
override fun onSuccessReversal() {
|
||||
importOnlineProcessStatus(0)
|
||||
emvResultStatus.postValue(EmvResultStatus.REVERSAL_SUCCESS)
|
||||
transResult.postValue(TransResultStatus.REVERSAL_SUCCESS)
|
||||
}
|
||||
|
||||
override fun onNetworkFail(msg: String) {
|
||||
importOnlineProcessStatus(0)
|
||||
}
|
||||
|
||||
override fun onFailReversal(msg: String) {
|
||||
importOnlineProcessStatus(0)
|
||||
|
||||
if (!isSecondCall) {
|
||||
if (!TextUtils.equals(msg, REVERSAL)) {
|
||||
emvResultStatus.postValue(EmvResultStatus.REVERSAL_SECONDARY)
|
||||
transResult.postValue(TransResultStatus.REVERSAL_SECONDARY)
|
||||
|
||||
ISOSocket.getInstance().switchIp()
|
||||
isSecondCall = true
|
||||
|
||||
callReversal(tradeData)
|
||||
} else {
|
||||
saveNeedReversal()
|
||||
}
|
||||
} else {
|
||||
saveNeedReversal()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun saveNeedReversal() {
|
||||
mPayDetail.setNeedReversal(true)
|
||||
mPayDetail.transactionType = TransactionType.REVERSAL
|
||||
mPayDetail.transType = REVERSAL
|
||||
mPayDetail.pid = null
|
||||
|
||||
repository.insertPayDetail(mPayDetail)
|
||||
|
||||
emvResultStatus.postValue(EmvResultStatus.REVERSAL_FAIL)
|
||||
transResult.postValue(TransResultStatus.REVERSAL_FAIL)
|
||||
|
||||
isSecondCall = false
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = EmvTransactionProcessViewModel::class.java.simpleName
|
||||
private const val TRY_SECONDARY = "TRY_SECONDARY"
|
||||
private const val PIN_PAD_FAILED = "Pin pad failed"
|
||||
private const val RC_APPROVED_V1 = "00"
|
||||
private const val RC_APPROVED_V2 = "000"
|
||||
private const val REVERSAL = "REVERSAL"
|
||||
}
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
package com.mob.utsmyanmar.viewmodel
|
||||
|
||||
import com.mob.utsmyanmar.model.TransResultStatus
|
||||
import com.utsmyanmar.paylibs.model.PayDetail
|
||||
import com.utsmyanmar.paylibs.system.SingleLiveEvent
|
||||
|
||||
interface ProcessingTransaction {
|
||||
fun resetTransactionStatus()
|
||||
|
||||
fun getTransStatus(): SingleLiveEvent<TransResultStatus>
|
||||
|
||||
fun startOnlineProcess()
|
||||
|
||||
fun insertDB(payResult: PayDetail)
|
||||
|
||||
fun processVoidDB(payResult: PayDetail)
|
||||
|
||||
fun processPreVoidDb(payResult: PayDetail)
|
||||
|
||||
fun processPreCompDb(payResult: PayDetail)
|
||||
|
||||
fun processPreCompVoidDb(payResult: PayDetail)
|
||||
|
||||
fun processRefundDB(payResult: PayDetail)
|
||||
}
|
||||
@ -1,663 +0,0 @@
|
||||
package com.mob.utsmyanmar.viewmodel
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.mob.utsmyanmar.model.SettlementType
|
||||
import com.utsmyanmar.baselib.network.model.sirius.SiriusRequest
|
||||
import com.utsmyanmar.baselib.network.model.sirius.SiriusResponse
|
||||
import com.utsmyanmar.baselib.repo.Repository
|
||||
import com.utsmyanmar.ecr.data.TransType
|
||||
import com.utsmyanmar.ecr.data.model.Transactions
|
||||
import com.utsmyanmar.paylibs.model.PayDetail
|
||||
import com.utsmyanmar.paylibs.print.printx.PrintXReceipt
|
||||
import com.utsmyanmar.paylibs.print.printx.PrintXStatus
|
||||
import com.utsmyanmar.paylibs.system.SingleLiveEvent
|
||||
import com.utsmyanmar.paylibs.system.SystemDateTime
|
||||
import com.utsmyanmar.paylibs.utils.AccountType
|
||||
import com.utsmyanmar.paylibs.utils.PrintStatus
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation
|
||||
import com.utsmyanmar.paylibs.utils.enums.HostType
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionType
|
||||
import com.utsmyanmar.paylibs.utils.enums.TransMenu
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import io.reactivex.rxjava3.core.Observable
|
||||
import sunmi.sunmiui.utils.LogUtil
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class SharedViewModel @Inject constructor(
|
||||
private val repository: Repository
|
||||
) : ViewModel() {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "SharedViewModel"
|
||||
}
|
||||
|
||||
val transactionsType = SingleLiveEvent<TransactionsType>()
|
||||
|
||||
val settlementType = SingleLiveEvent<SettlementType>()
|
||||
|
||||
val accountType = SingleLiveEvent<AccountType>()
|
||||
|
||||
val amount = SingleLiveEvent<String>()
|
||||
|
||||
val totalAmount = SingleLiveEvent<Long>()
|
||||
|
||||
val cardNo = SingleLiveEvent<String>()
|
||||
|
||||
val processCode = SingleLiveEvent<String>()
|
||||
|
||||
val payDetail = SingleLiveEvent<PayDetail>()
|
||||
|
||||
val printStatus = SingleLiveEvent<PrintStatus>()
|
||||
|
||||
val merchantName = SingleLiveEvent<String>()
|
||||
|
||||
val transactionName = SingleLiveEvent<String>()
|
||||
|
||||
val payDetailList = SingleLiveEvent<List<PayDetail>>()
|
||||
|
||||
val isEcr = SingleLiveEvent<Boolean>()
|
||||
|
||||
val traceNo = SingleLiveEvent<String>()
|
||||
|
||||
val rrNNo = SingleLiveEvent<String>()
|
||||
|
||||
val approvalCode = SingleLiveEvent<String>()
|
||||
|
||||
val isEcrFinished = SingleLiveEvent<Boolean>()
|
||||
|
||||
val isEmv = SingleLiveEvent<Boolean>()
|
||||
|
||||
private val settlementStatus = MutableLiveData<Boolean>()
|
||||
|
||||
private val wavePayStatus = MutableLiveData<Boolean>()
|
||||
|
||||
val sendMsg = SingleLiveEvent<String>()
|
||||
|
||||
val qrData = SingleLiveEvent<String>()
|
||||
|
||||
val qrRefNum = SingleLiveEvent<String>()
|
||||
|
||||
val ecrCMD = SingleLiveEvent<TransType>()
|
||||
|
||||
val _transMenu = SingleLiveEvent<TransMenu?>()
|
||||
|
||||
val twoBtnLayout = MutableLiveData(0)
|
||||
|
||||
val oneBtnLayout = MutableLiveData(8)
|
||||
|
||||
private val reprintBtnLayout = MutableLiveData(8)
|
||||
|
||||
val isReprint = SingleLiveEvent<Boolean>()
|
||||
|
||||
var signBitmap: Bitmap? = null
|
||||
|
||||
val hostType = SingleLiveEvent<HostType>()
|
||||
|
||||
private val printReceiptButtons = MutableLiveData(0)
|
||||
|
||||
val printReceiptMsg = SingleLiveEvent<String>()
|
||||
|
||||
val reprintTransTypeMsg = SingleLiveEvent<String>()
|
||||
|
||||
val ecrTrans = SingleLiveEvent<Transactions>()
|
||||
|
||||
val _manualEntryStatus = MutableLiveData<Boolean>()
|
||||
|
||||
val fullVoidPreauthStatus = MutableLiveData<Boolean>()
|
||||
|
||||
val partialVoidPreauthStatus = MutableLiveData<Boolean>()
|
||||
|
||||
val printXStatus = SingleLiveEvent<PrintStatus>()
|
||||
|
||||
private val _errorFragmentMsg = SingleLiveEvent<String>()
|
||||
|
||||
private val _successFragmentMsg = SingleLiveEvent<String>()
|
||||
|
||||
private val _currencyText = SingleLiveEvent<String>()
|
||||
|
||||
val tapCardStatus = MutableLiveData(1)
|
||||
|
||||
val tapDeviceStatus = MutableLiveData(1)
|
||||
|
||||
val insertCardStatus = MutableLiveData(1)
|
||||
|
||||
val swipeCardStatus = MutableLiveData(0)
|
||||
|
||||
val countDownTxt = MutableLiveData<String>()
|
||||
|
||||
val mmqrLoading = MutableLiveData<Int>()
|
||||
|
||||
val isMMPay = MutableLiveData<Int>()
|
||||
|
||||
val isWavePay = MutableLiveData<Int>()
|
||||
|
||||
val mockData = SingleLiveEvent<String>()
|
||||
|
||||
val qrPayVisibility = MutableLiveData<Int>()
|
||||
|
||||
val loadingView = MutableLiveData(8)
|
||||
|
||||
val loadingMsg = SingleLiveEvent<String>()
|
||||
|
||||
private val isFallback = SingleLiveEvent<Boolean>()
|
||||
|
||||
private val _isCardDataExist = SingleLiveEvent<Boolean>()
|
||||
|
||||
private val _isAmountExist = SingleLiveEvent<Boolean>()
|
||||
|
||||
private var mPayDetail = PayDetail()
|
||||
|
||||
init {
|
||||
setPrintStatus(PrintStatus.FIRST_PRINT)
|
||||
isReprint.value = false
|
||||
cardNo.value = ""
|
||||
}
|
||||
|
||||
fun setSettlementStatus(status: Boolean) {
|
||||
settlementStatus.value = status
|
||||
}
|
||||
|
||||
fun getSettlementStatus(): MutableLiveData<Boolean> {
|
||||
return settlementStatus
|
||||
}
|
||||
|
||||
fun setWavePayStatus(status: Boolean) {
|
||||
wavePayStatus.value = status
|
||||
}
|
||||
|
||||
fun getWavePayStatus(): MutableLiveData<Boolean> {
|
||||
return wavePayStatus
|
||||
}
|
||||
|
||||
fun setEmvTrans(status: Boolean) {
|
||||
isEmv.value = status
|
||||
}
|
||||
|
||||
fun isEmvTrans(): SingleLiveEvent<Boolean> {
|
||||
return isEmv
|
||||
}
|
||||
|
||||
private fun getPayDetail(): PayDetail {
|
||||
return mPayDetail
|
||||
}
|
||||
|
||||
private fun cachePayDetail(payDetail: PayDetail) {
|
||||
mPayDetail = payDetail
|
||||
}
|
||||
|
||||
fun setPrintReceiptButtons(visible: Boolean) {
|
||||
printReceiptButtons.value = if (visible) 0 else 8
|
||||
}
|
||||
|
||||
fun postPrintReceiptButtons(visible: Boolean) {
|
||||
printReceiptButtons.postValue(if (visible) 0 else 8)
|
||||
}
|
||||
|
||||
fun getPrintReceiptButtons(): MutableLiveData<Int> {
|
||||
return printReceiptButtons
|
||||
}
|
||||
|
||||
fun getReprintBtnLayout(): MutableLiveData<Int> {
|
||||
return reprintBtnLayout
|
||||
}
|
||||
|
||||
fun setReprintBtnLayout(visible: Boolean) {
|
||||
reprintBtnLayout.value = if (visible) 0 else 8
|
||||
}
|
||||
|
||||
fun setPrintReceiptMsg(msg: String) {
|
||||
printReceiptMsg.value = msg
|
||||
}
|
||||
|
||||
fun postPrintReceiptMsg(msg: String) {
|
||||
printReceiptMsg.postValue(msg)
|
||||
}
|
||||
|
||||
fun setPrintStatus(printStatus: PrintStatus) {
|
||||
this.printStatus.value = printStatus
|
||||
}
|
||||
|
||||
fun postPrintStatus(printStatus: PrintStatus) {
|
||||
this.printStatus.postValue(printStatus)
|
||||
}
|
||||
|
||||
fun getPrintStatusEvent(): SingleLiveEvent<PrintStatus> {
|
||||
return printStatus
|
||||
}
|
||||
|
||||
fun setIsFallback(status: Boolean) {
|
||||
isFallback.value = status
|
||||
}
|
||||
|
||||
fun getIsFallback(): SingleLiveEvent<Boolean> {
|
||||
return isFallback
|
||||
}
|
||||
|
||||
fun setCardDataExist(exist: Boolean) {
|
||||
_isCardDataExist.value = exist
|
||||
}
|
||||
|
||||
fun getCardDataExist(): SingleLiveEvent<Boolean> {
|
||||
return _isCardDataExist
|
||||
}
|
||||
|
||||
fun setAmountExist(exist: Boolean) {
|
||||
_isAmountExist.value = exist
|
||||
}
|
||||
|
||||
fun getAmountExist(): SingleLiveEvent<Boolean> {
|
||||
return _isAmountExist
|
||||
}
|
||||
|
||||
fun getManualEntryStatus(): MutableLiveData<Boolean> {
|
||||
return _manualEntryStatus
|
||||
}
|
||||
|
||||
fun setManualEntryStatus(status: Boolean) {
|
||||
_manualEntryStatus.value = status
|
||||
}
|
||||
|
||||
fun getErrorFragmentMsg(): SingleLiveEvent<String> {
|
||||
return _errorFragmentMsg
|
||||
}
|
||||
|
||||
fun set_errorFragmentMsg(msg: String) {
|
||||
_errorFragmentMsg.value = msg
|
||||
}
|
||||
|
||||
fun getSuccessFragmentMsg(): SingleLiveEvent<String> {
|
||||
return _successFragmentMsg
|
||||
}
|
||||
|
||||
fun set_currencyText(msg: String) {
|
||||
_currencyText.value = msg
|
||||
}
|
||||
|
||||
fun get_currencyText(): SingleLiveEvent<String> {
|
||||
return _currencyText
|
||||
}
|
||||
|
||||
fun set_successFragmentMsg(msg: String) {
|
||||
_successFragmentMsg.value = msg
|
||||
}
|
||||
|
||||
fun getTransMenu(): SingleLiveEvent<TransMenu?> {
|
||||
return _transMenu
|
||||
}
|
||||
|
||||
fun setTransMenu(transMenu: TransMenu?) {
|
||||
_transMenu.value = transMenu
|
||||
}
|
||||
|
||||
fun loadingMsg(msg: String) {
|
||||
loadingView.value = 0
|
||||
loadingMsg.value = msg
|
||||
}
|
||||
|
||||
fun dismissLoadingMsg() {
|
||||
loadingView.value = 8
|
||||
loadingMsg.value = ""
|
||||
}
|
||||
|
||||
fun getParams(siriusRequest: SiriusRequest): Observable<SiriusResponse> {
|
||||
return repository.getParams(siriusRequest)
|
||||
}
|
||||
|
||||
private fun printReceipt(isMerchantCopy: Boolean) {
|
||||
PrintXReceipt.getInstance()
|
||||
.printSmileReceipt(payDetail.value, isMerchantCopy, object : PrintXStatus {
|
||||
|
||||
override fun onSuccess() {
|
||||
|
||||
if (isMerchantCopy) {
|
||||
|
||||
if (!SystemParamsOperation.getInstance().demoStatus) {
|
||||
if (SystemParamsOperation.getInstance().printISOStatus) {
|
||||
PrintXReceipt.getInstance()
|
||||
.printSmileISoReceipt(payDetail.value)
|
||||
}
|
||||
}
|
||||
|
||||
postPrintStatus(PrintStatus.FIRST_PRINT_DONE)
|
||||
|
||||
} else {
|
||||
setPrintStatus(PrintStatus.SECOND_PRINT_DONE)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure() {
|
||||
LogUtil.d(TAG, "Print Status Result Failure!")
|
||||
printXStatus.postValue(PrintStatus.EMPTY_PAPER_ROLL)
|
||||
postPrintReceiptButtons(true)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun startPrintReceipt(isFirstPrint: Boolean) {
|
||||
|
||||
payDetail.value?.let {
|
||||
cachePayDetail(it)
|
||||
}
|
||||
|
||||
PrintXReceipt.getInstance()
|
||||
.printSmileReceipt(getPayDetail(), isFirstPrint, object : PrintXStatus {
|
||||
|
||||
override fun onSuccess() {
|
||||
|
||||
if (isFirstPrint) {
|
||||
|
||||
if (!SystemParamsOperation.getInstance().demoStatus) {
|
||||
if (SystemParamsOperation.getInstance().printISOStatus) {
|
||||
PrintXReceipt.getInstance()
|
||||
.printSmileISoReceipt(getPayDetail())
|
||||
}
|
||||
}
|
||||
|
||||
postPrintStatus(PrintStatus.FIRST_PRINT_DONE)
|
||||
|
||||
if (isEcr.value == true &&
|
||||
SystemParamsOperation.getInstance()
|
||||
.isAutoPrintCustomerCopy
|
||||
) {
|
||||
printReceiptButtons.postValue(8)
|
||||
} else {
|
||||
printReceiptButtons.postValue(0)
|
||||
}
|
||||
|
||||
} else {
|
||||
postPrintStatus(PrintStatus.SECOND_PRINT_DONE)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure() {
|
||||
LogUtil.d(TAG, "Print Status Result Failure!")
|
||||
|
||||
if (isFirstPrint) {
|
||||
setPrintStatus(PrintStatus.EMPTY_PAPER_ROLL_FIRST)
|
||||
} else {
|
||||
setPrintStatus(PrintStatus.EMPTY_PAPER_ROLL_SECOND)
|
||||
}
|
||||
|
||||
postPrintReceiptButtons(true)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun startPrintProcess() {
|
||||
|
||||
LogUtil.d(TAG, "Print status : ${getPrintStatusEvent().value}")
|
||||
|
||||
when (getPrintStatusEvent().value) {
|
||||
|
||||
PrintStatus.FIRST_PRINT -> {
|
||||
printReceipt(true)
|
||||
postPrintReceiptMsg("Printing Receipt for Merchant")
|
||||
postPrintReceiptButtons(false)
|
||||
}
|
||||
|
||||
PrintStatus.SECOND_PRINT -> {
|
||||
printReceipt(false)
|
||||
postPrintReceiptMsg("Printing Receipt for Customer")
|
||||
}
|
||||
|
||||
PrintStatus.NOT_PRINT -> {
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
fun startPrintProcessSettlement() {
|
||||
|
||||
val detail = payDetail.value ?: return
|
||||
|
||||
PrintXReceipt.getInstance()
|
||||
.printSmileSettlementReport(detail, object : PrintXStatus {
|
||||
|
||||
override fun onSuccess() {
|
||||
}
|
||||
|
||||
override fun onFailure() {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun getLastThreeTransactions(): LiveData<List<PayDetail>> {
|
||||
return repository.getLastThreeTransactions()
|
||||
}
|
||||
|
||||
fun getSettlementRecords(): LiveData<List<PayDetail>> {
|
||||
return repository.getSettlementPOS()
|
||||
}
|
||||
|
||||
fun getReversalTransaction(voucherNo: String): LiveData<PayDetail> {
|
||||
return repository.getReversalTransaction(voucherNo)
|
||||
}
|
||||
|
||||
fun updatePayDetail(payDetail: PayDetail) {
|
||||
repository.updatePayDetail(payDetail)
|
||||
}
|
||||
|
||||
fun insertPayDetail(payDetail: PayDetail) {
|
||||
repository.insertPayDetail(payDetail)
|
||||
}
|
||||
|
||||
fun saveMockHostResultForTesting() {
|
||||
when (transactionsType.value) {
|
||||
TransactionsType.SETTLEMENT -> saveMockSettlementForTesting()
|
||||
TransactionsType.VOID -> saveMockApprovedVoidForTesting()
|
||||
TransactionsType.REFUND -> saveMockApprovedRefundForTesting()
|
||||
else -> saveMockApprovedSaleForVoidTesting()
|
||||
}
|
||||
}
|
||||
|
||||
fun saveMockApprovedSaleForVoidTesting() {
|
||||
val detail = payDetail.value ?: return
|
||||
|
||||
val systemParams = SystemParamsOperation.getInstance()
|
||||
val mockTraceNo = systemParams.incrementSerialNum
|
||||
val mockInvoiceNo = systemParams.incrementInvoiceNum
|
||||
val mockApprovalCode = mockTraceNo.takeLast(6).padStart(6, '0')
|
||||
val mockReferenceNo = buildString {
|
||||
append(SystemDateTime.getYYMMDD())
|
||||
append(SystemDateTime.getHHmmss())
|
||||
}.takeLast(12)
|
||||
|
||||
detail.voucherNo = mockTraceNo
|
||||
detail.invoiceNo = mockInvoiceNo
|
||||
detail.referNo = mockReferenceNo
|
||||
detail.approvalCode = mockApprovalCode
|
||||
detail.authNo = mockApprovalCode
|
||||
detail.tradeAnswerCode = "00"
|
||||
detail.tradeResultDes = "MOCK APPROVED"
|
||||
detail.transactionType = TransactionType.SALE
|
||||
detail.transType = TransactionsType.SALE.name
|
||||
detail.isCanceled = false
|
||||
detail.isSettle = false
|
||||
detail.isNeedReversal = false
|
||||
detail.isReturnGood = false
|
||||
detail.TradeDate = SystemDateTime.getMMDD()
|
||||
detail.TradeTime = SystemDateTime.getHHmmss()
|
||||
detail.tradeDateAndTime = SystemDateTime.getMMDDhhmmss()
|
||||
detail.tradeDateTime = SystemDateTime.getYYMMDDhhmmss()
|
||||
detail.transDate = SystemDateTime.getTodayDateFormat()
|
||||
detail.transTime = SystemDateTime.getTodayTimeFormat()
|
||||
|
||||
repository.insertPayDetail(detail)
|
||||
payDetail.value = detail
|
||||
traceNo.value = mockTraceNo
|
||||
rrNNo.value = mockReferenceNo
|
||||
approvalCode.value = mockApprovalCode
|
||||
}
|
||||
|
||||
fun saveMockApprovedVoidForTesting() {
|
||||
val originalSale = payDetail.value ?: return
|
||||
|
||||
originalSale.isCanceled = true
|
||||
repository.updatePayDetail(originalSale)
|
||||
|
||||
val systemParams = SystemParamsOperation.getInstance()
|
||||
val mockTraceNo = systemParams.incrementSerialNum
|
||||
val mockInvoiceNo = systemParams.incrementInvoiceNum
|
||||
val mockApprovalCode = mockTraceNo.takeLast(6).padStart(6, '0')
|
||||
val mockReferenceNo = buildString {
|
||||
append(SystemDateTime.getYYMMDD())
|
||||
append(SystemDateTime.getHHmmss())
|
||||
}.takeLast(12)
|
||||
|
||||
val voidDetail = PayDetail().apply {
|
||||
merchantName = originalSale.merchantName
|
||||
merchantNo = originalSale.merchantNo
|
||||
terminalNo = originalSale.terminalNo
|
||||
CardNo = originalSale.CardNo
|
||||
cardType = originalSale.cardType
|
||||
EXPDate = originalSale.EXPDate
|
||||
cardHolderName = originalSale.cardHolderName
|
||||
processCode = TransactionsType.VOID.processCode
|
||||
amount = originalSale.amount
|
||||
transPlatform = originalSale.transPlatform
|
||||
transactionType = TransactionType.VOID
|
||||
transType = TransactionsType.VOID.name
|
||||
currencyCode = originalSale.currencyCode
|
||||
currency = originalSale.currency
|
||||
batchNo = originalSale.batchNo
|
||||
voucherNo = mockTraceNo
|
||||
invoiceNo = mockInvoiceNo
|
||||
referNo = mockReferenceNo
|
||||
approvalCode = mockApprovalCode
|
||||
authNo = mockApprovalCode
|
||||
accountType = originalSale.accountType
|
||||
tradeAnswerCode = "00"
|
||||
tradeResultDes = "MOCK VOID APPROVED"
|
||||
TradeDate = SystemDateTime.getMMDD()
|
||||
TradeTime = SystemDateTime.getHHmmss()
|
||||
tradeDateAndTime = SystemDateTime.getMMDDhhmmss()
|
||||
tradeDateTime = SystemDateTime.getYYMMDDhhmmss()
|
||||
transDate = SystemDateTime.getTodayDateFormat()
|
||||
transTime = SystemDateTime.getTodayTimeFormat()
|
||||
originalPOSNum = originalSale.voucherNo
|
||||
originalReferNo = originalSale.referNo
|
||||
originalAuthNo = originalSale.approvalCode
|
||||
originalBathNo = originalSale.batchNo
|
||||
originalTransDate = originalSale.TradeDate
|
||||
originalAmount = originalSale.amount
|
||||
isCanceled = false
|
||||
isSettle = false
|
||||
isNeedReversal = false
|
||||
isReturnGood = false
|
||||
}
|
||||
|
||||
repository.insertPayDetail(voidDetail)
|
||||
payDetail.value = voidDetail
|
||||
traceNo.value = mockTraceNo
|
||||
rrNNo.value = mockReferenceNo
|
||||
approvalCode.value = mockApprovalCode
|
||||
}
|
||||
|
||||
fun saveMockApprovedRefundForTesting() {
|
||||
val refundDetail = payDetail.value ?: return
|
||||
|
||||
val systemParams = SystemParamsOperation.getInstance()
|
||||
val mockTraceNo = systemParams.incrementSerialNum
|
||||
val mockInvoiceNo = systemParams.incrementInvoiceNum
|
||||
val mockApprovalCode = mockTraceNo.takeLast(6).padStart(6, '0')
|
||||
val refundRrn = rrNNo.value?.trim().orEmpty()
|
||||
|
||||
refundDetail.voucherNo = mockTraceNo
|
||||
refundDetail.invoiceNo = mockInvoiceNo
|
||||
refundDetail.referNo = refundRrn
|
||||
refundDetail.approvalCode = mockApprovalCode
|
||||
refundDetail.authNo = mockApprovalCode
|
||||
refundDetail.tradeAnswerCode = "00"
|
||||
refundDetail.tradeResultDes = "MOCK REFUND APPROVED"
|
||||
refundDetail.transactionType = TransactionType.REFUND
|
||||
refundDetail.transType = TransactionsType.REFUND.name
|
||||
refundDetail.isCanceled = false
|
||||
refundDetail.isSettle = false
|
||||
refundDetail.isNeedReversal = false
|
||||
refundDetail.isReturnGood = false
|
||||
refundDetail.TradeDate = SystemDateTime.getMMDD()
|
||||
refundDetail.TradeTime = SystemDateTime.getHHmmss()
|
||||
refundDetail.tradeDateAndTime = SystemDateTime.getMMDDhhmmss()
|
||||
refundDetail.tradeDateTime = SystemDateTime.getYYMMDDhhmmss()
|
||||
refundDetail.transDate = SystemDateTime.getTodayDateFormat()
|
||||
refundDetail.transTime = SystemDateTime.getTodayTimeFormat()
|
||||
|
||||
repository.insertPayDetail(refundDetail)
|
||||
payDetail.value = refundDetail
|
||||
traceNo.value = mockTraceNo
|
||||
rrNNo.value = refundRrn
|
||||
approvalCode.value = mockApprovalCode
|
||||
}
|
||||
|
||||
fun saveMockSettlementForTesting() {
|
||||
val systemParams = SystemParamsOperation.getInstance()
|
||||
val mockTraceNo = systemParams.incrementSerialNum
|
||||
val mockInvoiceNo = systemParams.incrementInvoiceNum
|
||||
|
||||
val settlementDetail = PayDetail().apply {
|
||||
merchantNo = systemParams.merchantId
|
||||
merchantName = systemParams.merchantName
|
||||
terminalNo = systemParams.terminalId
|
||||
voucherNo = mockTraceNo
|
||||
invoiceNo = mockInvoiceNo
|
||||
batchNo = systemParams.systemParamsSettings.batchNumStart
|
||||
processCode = TransactionsType.SETTLEMENT.processCode
|
||||
transactionType = TransactionType.SETTLEMENT
|
||||
transType = TransactionsType.SETTLEMENT.name
|
||||
currencyCode = systemParams.currencyType.removed0CurrencyCode
|
||||
tradeAnswerCode = "00"
|
||||
tradeResultDes = "MOCK SETTLEMENT APPROVED"
|
||||
TradeDate = SystemDateTime.getMMDD()
|
||||
TradeTime = SystemDateTime.getHHmmss()
|
||||
tradeDateAndTime = SystemDateTime.getMMDDhhmmss()
|
||||
tradeDateTime = SystemDateTime.getYYMMDDhhmmss()
|
||||
transDate = SystemDateTime.getTodayDateFormat()
|
||||
transTime = SystemDateTime.getTodayTimeFormat()
|
||||
isSettle = false
|
||||
isNeedReversal = false
|
||||
isCanceled = false
|
||||
}
|
||||
|
||||
payDetail.value = settlementDetail
|
||||
traceNo.value = mockTraceNo
|
||||
}
|
||||
|
||||
fun enableCardStatusIcon(
|
||||
tapCard: Boolean,
|
||||
tapDevice: Boolean,
|
||||
insertCard: Boolean,
|
||||
swipeCard: Boolean
|
||||
) {
|
||||
|
||||
tapCardStatus.value = if (tapCard) 1 else 0
|
||||
tapDeviceStatus.value = if (tapDevice) 1 else 0
|
||||
insertCardStatus.value = if (insertCard) 1 else 0
|
||||
swipeCardStatus.value = if (swipeCard) 1 else 0
|
||||
}
|
||||
|
||||
fun resetParamsMain() {
|
||||
|
||||
isEcrFinished.postValue(true)
|
||||
isEcr.postValue(false)
|
||||
|
||||
setAmountExist(false)
|
||||
setCardDataExist(false)
|
||||
setTransMenu(null)
|
||||
}
|
||||
|
||||
fun updateButtonStatus() {
|
||||
setSettlementStatus(
|
||||
SystemParamsOperation.getInstance().settlementStatus
|
||||
)
|
||||
|
||||
setWavePayStatus(
|
||||
SystemParamsOperation.getInstance().wavePayStatus
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -1,348 +0,0 @@
|
||||
package com.mob.utsmyanmar.viewmodel
|
||||
|
||||
import android.text.TextUtils
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.mob.utsmyanmar.model.TransResultStatus
|
||||
import com.utsmyanmar.baselib.repo.Repository
|
||||
import com.utsmyanmar.paylibs.model.PayDetail
|
||||
import com.utsmyanmar.paylibs.model.TradeData
|
||||
import com.utsmyanmar.paylibs.network.ISOSocket
|
||||
import com.utsmyanmar.paylibs.reversal.ReversalAction
|
||||
import com.utsmyanmar.paylibs.reversal.ReversalListener
|
||||
import com.utsmyanmar.paylibs.system.SystemDateTime
|
||||
import com.utsmyanmar.paylibs.transactions.TransactionsOperation
|
||||
import com.utsmyanmar.paylibs.transactions.TransactionsOperationListener
|
||||
import com.utsmyanmar.paylibs.utils.PrintStatus
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class TransProcessViewModel @Inject constructor(
|
||||
private val repository: Repository
|
||||
) : ViewModel(), ProcessingTransaction {
|
||||
|
||||
companion object {
|
||||
private const val RC_APPROVED_V1 = "00"
|
||||
private const val RC_APPROVED_V2 = "000"
|
||||
private const val TRY_SECONDARY = "TRY_SECONDARY"
|
||||
}
|
||||
|
||||
private var pan: String = ""
|
||||
|
||||
private lateinit var tradeData: TradeData
|
||||
|
||||
var payDetail: PayDetail? = null
|
||||
|
||||
private var oldTransPayDetail: PayDetail? = null
|
||||
|
||||
private var isSecondCall = false
|
||||
private var isThirdCall = false
|
||||
|
||||
/*
|
||||
* States
|
||||
*/
|
||||
|
||||
private val _transResultStatus =
|
||||
MutableStateFlow<TransResultStatus?>(null)
|
||||
|
||||
val transResultStatus =
|
||||
_transResultStatus.asStateFlow()
|
||||
|
||||
private val _transType = MutableStateFlow<TransactionsType?>(null)
|
||||
|
||||
val transType =_transType.asStateFlow()
|
||||
|
||||
fun setTransType(type: TransactionsType?) {
|
||||
_transType.value = type
|
||||
}
|
||||
|
||||
private val _printStatus =
|
||||
MutableStateFlow(PrintStatus.FIRST_PRINT)
|
||||
|
||||
val printStatus =
|
||||
_printStatus.asStateFlow()
|
||||
|
||||
private val _payDetailResult =
|
||||
MutableStateFlow<PayDetail?>(null)
|
||||
|
||||
val payDetailResult =
|
||||
_payDetailResult.asStateFlow()
|
||||
|
||||
private val _errorMessage =
|
||||
MutableStateFlow<String?>(null)
|
||||
|
||||
val errorMessage =
|
||||
_errorMessage.asStateFlow()
|
||||
|
||||
/*
|
||||
* Setup
|
||||
*/
|
||||
|
||||
fun setTradeData(tradeData: TradeData) {
|
||||
this.tradeData = tradeData
|
||||
payDetail = tradeData.payDetail
|
||||
pan = payDetail?.cardNo ?: ""
|
||||
}
|
||||
|
||||
fun getTradeData(): TradeData {
|
||||
return tradeData
|
||||
}
|
||||
|
||||
fun updatePayDetail(payDetail: PayDetail) {
|
||||
this.payDetail = payDetail
|
||||
|
||||
tradeData = TradeData().apply {
|
||||
this.payDetail = payDetail
|
||||
}
|
||||
}
|
||||
|
||||
fun setOldTransPayDetail(payDetail: PayDetail) {
|
||||
oldTransPayDetail = payDetail
|
||||
}
|
||||
|
||||
/*
|
||||
* Transaction
|
||||
*/
|
||||
|
||||
override fun startOnlineProcess() {
|
||||
|
||||
TransactionsOperation.getInstance()
|
||||
.getStartOperation(
|
||||
tradeData,
|
||||
transType.value
|
||||
)
|
||||
.checkOperation(object : TransactionsOperationListener {
|
||||
|
||||
override fun onSuccess(tradeData: TradeData) {
|
||||
|
||||
val payDetailRes =
|
||||
tradeData.payDetail
|
||||
|
||||
if (
|
||||
TextUtils.equals(
|
||||
payDetailRes.tradeAnswerCode,
|
||||
RC_APPROVED_V1
|
||||
) ||
|
||||
TextUtils.equals(
|
||||
payDetailRes.tradeAnswerCode,
|
||||
RC_APPROVED_V2
|
||||
)
|
||||
) {
|
||||
|
||||
payDetailRes.invoiceNo =
|
||||
SystemParamsOperation
|
||||
.getInstance()
|
||||
.incrementInvoiceNum
|
||||
|
||||
when (transType.value) {
|
||||
|
||||
TransactionsType.VOID -> {
|
||||
processVoidDB(payDetailRes)
|
||||
}
|
||||
|
||||
TransactionsType.REFUND -> {
|
||||
processRefundDB(payDetailRes)
|
||||
}
|
||||
|
||||
TransactionsType.PRE_AUTH_VOID -> {
|
||||
processPreVoidDb(payDetailRes)
|
||||
}
|
||||
|
||||
TransactionsType.PRE_AUTH_COMPLETE -> {
|
||||
processPreCompDb(payDetailRes)
|
||||
}
|
||||
|
||||
TransactionsType.PRE_AUTH_COMPLETE_VOID -> {
|
||||
processPreCompVoidDb(payDetailRes)
|
||||
}
|
||||
|
||||
else -> {
|
||||
insertDB(payDetailRes)
|
||||
}
|
||||
}
|
||||
|
||||
_payDetailResult.value =
|
||||
payDetailRes
|
||||
|
||||
_transResultStatus.value =
|
||||
TransResultStatus.SUCCESS
|
||||
|
||||
} else {
|
||||
|
||||
_payDetailResult.value =
|
||||
payDetailRes
|
||||
|
||||
_transResultStatus.value =
|
||||
TransResultStatus.FAIL
|
||||
}
|
||||
}
|
||||
|
||||
override fun onReversal(
|
||||
tradeData: TradeData
|
||||
) {
|
||||
|
||||
_transResultStatus.value =
|
||||
TransResultStatus.REVERSAL_PREPARE
|
||||
|
||||
callReversal(tradeData)
|
||||
}
|
||||
|
||||
override fun onError(message: String) {
|
||||
|
||||
if (message == TRY_SECONDARY) {
|
||||
|
||||
_transResultStatus.value =
|
||||
TransResultStatus.SECONDARY
|
||||
|
||||
startOnlineProcess()
|
||||
|
||||
} else {
|
||||
|
||||
_errorMessage.value = message
|
||||
|
||||
_transResultStatus.value =
|
||||
TransResultStatus.ERROR
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
* Database
|
||||
*/
|
||||
|
||||
override fun insertDB(payResult: PayDetail) {
|
||||
|
||||
payDetail?.pinCipher = ""
|
||||
|
||||
repository.insertPayDetail(
|
||||
payDetail
|
||||
)
|
||||
}
|
||||
|
||||
override fun processVoidDB(payResult: PayDetail) {
|
||||
|
||||
payDetail?.isCanceled = true
|
||||
|
||||
payDetail?.let {
|
||||
repository.updatePayDetail(it)
|
||||
}
|
||||
|
||||
repository.insertPayDetail(
|
||||
updateCurrentDateAndTime(payResult)
|
||||
)
|
||||
}
|
||||
|
||||
override fun processRefundDB(payResult: PayDetail) {
|
||||
|
||||
oldTransPayDetail?.apply {
|
||||
isReturnGood = true
|
||||
isCanceled = true
|
||||
|
||||
repository.updatePayDetail(this)
|
||||
}
|
||||
|
||||
repository.insertPayDetail(
|
||||
updateCurrentDateAndTime(payResult)
|
||||
)
|
||||
}
|
||||
|
||||
override fun processPreVoidDb(payResult: PayDetail) {}
|
||||
override fun processPreCompDb(payResult: PayDetail) {}
|
||||
override fun processPreCompVoidDb(payResult: PayDetail) {}
|
||||
|
||||
/*
|
||||
* Reversal
|
||||
*/
|
||||
|
||||
private fun callReversal(tradeData: TradeData) {
|
||||
|
||||
payDetail = tradeData.payDetail
|
||||
|
||||
ReversalAction.getInstance()
|
||||
.setData(tradeData)
|
||||
.enqueue()
|
||||
.startReversal(object : ReversalListener {
|
||||
|
||||
override fun onSuccessReversal() {
|
||||
|
||||
_transResultStatus.value =
|
||||
TransResultStatus.REVERSAL_SUCCESS
|
||||
|
||||
payDetail?.let {
|
||||
repository.insertPayDetail(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNetworkFail(msg: String) {
|
||||
|
||||
SystemParamsOperation
|
||||
.getInstance()
|
||||
.setSecondHostEnable(true)
|
||||
|
||||
if (
|
||||
SystemParamsOperation
|
||||
.getInstance()
|
||||
.isSecondHostEnabled
|
||||
) {
|
||||
|
||||
if (!isSecondCall) {
|
||||
|
||||
_transResultStatus.value =
|
||||
TransResultStatus.REVERSAL_SECONDARY
|
||||
|
||||
ISOSocket.getInstance()
|
||||
.switchIp()
|
||||
|
||||
isSecondCall = true
|
||||
|
||||
callReversal(tradeData)
|
||||
|
||||
} else {
|
||||
|
||||
_transResultStatus.value =
|
||||
TransResultStatus.REVERSAL_FAIL
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
_transResultStatus.value =
|
||||
TransResultStatus.REVERSAL_FAIL
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailReversal(msg: String) {
|
||||
|
||||
_transResultStatus.value =
|
||||
TransResultStatus.REVERSAL_FAIL
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
* Utils
|
||||
*/
|
||||
|
||||
private fun updateCurrentDateAndTime(
|
||||
payDetail: PayDetail
|
||||
): PayDetail {
|
||||
|
||||
payDetail.tradeDate =
|
||||
SystemDateTime.getMMDD()
|
||||
|
||||
payDetail.tradeTime =
|
||||
SystemDateTime.getHHmmss()
|
||||
|
||||
return payDetail
|
||||
}
|
||||
|
||||
override fun resetTransactionStatus() {
|
||||
_transResultStatus.value = null
|
||||
}
|
||||
|
||||
override fun getTransStatus() = TODO()
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
<!--
|
||||
~ Copyright (C) 2026 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="800dp"
|
||||
android:height="800dp"
|
||||
android:viewportWidth="15.133"
|
||||
android:viewportHeight="15.133">
|
||||
<path
|
||||
android:pathData="M14.487,0H0.647C0.306,0 0.028,0.277 0.028,0.619v2.165c0,0.342 0.277,0.619 0.619,0.619h0.966h0.074h0.902l-0.726,10.54c0,0.654 0.532,1.186 1.186,1.188l9.033,0.002c0.653,0 1.188,-0.53 1.188,-1.187L12.552,3.402h0.891c0.005,0 0.008,-0.002 0.013,-0.002v0.002h1.031c0.341,0 0.618,-0.277 0.618,-0.619V0.619C15.105,0.277 14.828,0 14.487,0zM7.883,14.339L3.05,14.337c-0.218,0 -0.395,-0.178 -0.395,-0.396L3.441,2.518c0,-0.218 0.178,-0.395 0.396,-0.395l4.051,0.001L7.883,14.339zM12.084,14.339h-1.062L10.246,2.125h1.061c0.22,0 0.396,0.177 0.396,0.395l0.776,11.424C12.478,14.164 12.301,14.341 12.084,14.339zM12.524,2.963L12.524,2.963l-0.03,-0.442c0,-0.655 -0.531,-1.187 -1.188,-1.187L3.837,1.331c-0.654,0 -1.187,0.532 -1.187,1.186L2.62,2.965H2.619H1.717l0.006,-0.084c0.02,-1.148 0.96,-2.077 2.113,-2.077l7.47,0.003c0.564,0 1.096,0.22 1.496,0.62c0.391,0.392 0.609,0.908 0.617,1.459l0.006,0.077C13.425,2.963 12.524,2.963 12.524,2.963zM3.387,10.312l1.075,-0.009l0.025,3.125l-1.074,0.009L3.387,10.312z"
|
||||
android:fillColor="#030104"/>
|
||||
</vector>
|
||||
@ -1,24 +0,0 @@
|
||||
<!--
|
||||
~ Copyright (C) 2026 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="800dp"
|
||||
android:height="800dp"
|
||||
android:viewportWidth="52"
|
||||
android:viewportHeight="52">
|
||||
<path
|
||||
android:pathData="M26,2C12.7,2 2,12.7 2,26s10.7,24 24,24s24,-10.7 24,-24S39.3,2 26,2zM39.4,20L24.1,35.5c-0.6,0.6 -1.6,0.6 -2.2,0L13.5,27c-0.6,-0.6 -0.6,-1.6 0,-2.2l2.2,-2.2c0.6,-0.6 1.6,-0.6 2.2,0l4.4,4.5c0.4,0.4 1.1,0.4 1.5,0L35,15.5c0.6,-0.6 1.6,-0.6 2.2,0l2.2,2.2C40.1,18.3 40.1,19.3 39.4,20z"
|
||||
android:fillColor="#000000"/>
|
||||
</vector>
|
||||
@ -1,49 +0,0 @@
|
||||
<!--
|
||||
~ Copyright (C) 2026 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="800dp"
|
||||
android:height="800dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M4.91,11.84C9.21,8.52 14.8,8.52 19.1,11.84"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="1.5"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#292D32"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M2,8.36C8.06,3.68 15.94,3.68 22,8.36"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="1.5"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#292D32"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M6.79,15.49C9.94,13.05 14.05,13.05 17.2,15.49"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="1.5"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#292D32"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M9.4,19.15C10.98,17.93 13.03,17.93 14.61,19.15"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="1.5"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#292D32"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
||||
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 46 KiB |
@ -1,4 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
@ -1,4 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
|
Before Width: | Height: | Size: 4.4 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 8.2 KiB |
|
Before Width: | Height: | Size: 6.0 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 982 B |
|
Before Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 5.3 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 8.0 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 9.8 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 14 KiB |