add support for fahipay login and view history
Auto Tag on Version Change / check-version (push) Successful in 2s
Auto Tag on Version Change / check-version (push) Successful in 2s
This commit is contained in:
@@ -10,6 +10,7 @@ object AccountCache {
|
||||
private const val PREFS = "account_cache"
|
||||
private const val KEY_MIB = "mib_accounts"
|
||||
private const val KEY_BML = "bml_accounts"
|
||||
private const val KEY_FAHIPAY = "fahipay_accounts"
|
||||
|
||||
fun save(context: Context, accounts: List<MibAccount>) {
|
||||
val arr = JSONArray()
|
||||
@@ -86,6 +87,56 @@ object AccountCache {
|
||||
} catch (e: Exception) { emptyList() }
|
||||
}
|
||||
|
||||
fun saveFahipay(context: Context, accounts: List<MibAccount>) {
|
||||
val arr = JSONArray()
|
||||
for (acc in accounts) {
|
||||
arr.put(JSONObject().apply {
|
||||
put("profileName", acc.profileName)
|
||||
put("profileType", acc.profileType)
|
||||
put("accountNumber", acc.accountNumber)
|
||||
put("accountBriefName", acc.accountBriefName)
|
||||
put("currencyName", acc.currencyName)
|
||||
put("accountTypeName", acc.accountTypeName)
|
||||
put("availableBalance", acc.availableBalance)
|
||||
put("currentBalance", acc.currentBalance)
|
||||
put("blockedAmount", acc.blockedAmount)
|
||||
put("mvrBalance", acc.mvrBalance)
|
||||
put("statusDesc", acc.statusDesc)
|
||||
put("loginTag", acc.loginTag)
|
||||
put("internalId", acc.internalId)
|
||||
})
|
||||
}
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
.edit().putString(KEY_FAHIPAY, CacheEncryption.encrypt(arr.toString())).apply()
|
||||
}
|
||||
|
||||
fun loadFahipay(context: Context): List<MibAccount> {
|
||||
val raw = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
.getString(KEY_FAHIPAY, null) ?: return emptyList()
|
||||
return try {
|
||||
val arr = JSONArray(CacheEncryption.decrypt(raw))
|
||||
(0 until arr.length()).map { i ->
|
||||
val o = arr.getJSONObject(i)
|
||||
MibAccount(
|
||||
profileName = o.optString("profileName"),
|
||||
profileType = o.optString("profileType"),
|
||||
accountNumber = o.optString("accountNumber"),
|
||||
accountBriefName = o.optString("accountBriefName"),
|
||||
currencyName = o.optString("currencyName"),
|
||||
accountTypeName = o.optString("accountTypeName"),
|
||||
availableBalance = o.optString("availableBalance"),
|
||||
currentBalance = o.optString("currentBalance"),
|
||||
blockedAmount = o.optString("blockedAmount"),
|
||||
mvrBalance = o.optString("mvrBalance"),
|
||||
statusDesc = o.optString("statusDesc"),
|
||||
profileImageHash = null,
|
||||
loginTag = o.optString("loginTag"),
|
||||
internalId = o.optString("internalId", "")
|
||||
)
|
||||
}
|
||||
} catch (_: Exception) { emptyList() }
|
||||
}
|
||||
|
||||
fun clear(context: Context) {
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().clear().apply()
|
||||
}
|
||||
|
||||
@@ -19,11 +19,13 @@ class CredentialStore(context: Context) {
|
||||
|
||||
data class MibCredentials(val username: String, val passwordHash: String, val otpSeed: String)
|
||||
data class BmlCredentials(val username: String, val password: String, val otpSeed: String)
|
||||
data class FahipayCredentials(val idCard: String, val password: String)
|
||||
|
||||
// ── MIB login credentials ─────────────────────────────────────────────────
|
||||
|
||||
fun hasMibCredentials(): Boolean = prefs.contains("mib_enc_username")
|
||||
fun hasBmlCredentials(): Boolean = prefs.contains("bml_enc_username")
|
||||
fun hasFahipayCredentials(): Boolean = prefs.contains("fahipay_enc_id_card")
|
||||
|
||||
fun saveMibCredentials(username: String, passwordHash: String, otpSeed: String) {
|
||||
val key = getOrCreateKey()
|
||||
@@ -144,6 +146,114 @@ class CredentialStore(context: Context) {
|
||||
.apply()
|
||||
}
|
||||
|
||||
// ── Fahipay login credentials ─────────────────────────────────────────────
|
||||
|
||||
fun saveFahipayCredentials(idCard: String, password: String) {
|
||||
val key = getOrCreateKey()
|
||||
prefs.edit()
|
||||
.putString("fahipay_enc_id_card", encrypt(idCard, key))
|
||||
.putString("fahipay_enc_password", encrypt(password, key))
|
||||
.apply()
|
||||
}
|
||||
|
||||
fun loadFahipayCredentials(): FahipayCredentials? {
|
||||
val key = getOrCreateKey()
|
||||
val encId = prefs.getString("fahipay_enc_id_card", null) ?: return null
|
||||
val encPw = prefs.getString("fahipay_enc_password", null) ?: return null
|
||||
return try {
|
||||
FahipayCredentials(decrypt(encId, key), decrypt(encPw, key))
|
||||
} catch (_: Exception) { null }
|
||||
}
|
||||
|
||||
fun clearFahipayCredentials() {
|
||||
prefs.edit()
|
||||
.remove("fahipay_enc_id_card")
|
||||
.remove("fahipay_enc_password")
|
||||
.apply()
|
||||
}
|
||||
|
||||
// ── Fahipay session (authId + __Secure-sess cookie) ───────────────────────
|
||||
|
||||
fun saveFahipaySession(authId: String, sessionCookie: String) {
|
||||
val key = getOrCreateKey()
|
||||
prefs.edit()
|
||||
.putString("fahipay_enc_auth_id", encrypt(authId, key))
|
||||
.putString("fahipay_enc_session_cookie", encrypt(sessionCookie, key))
|
||||
.apply()
|
||||
}
|
||||
|
||||
fun loadFahipaySession(): Pair<String, String>? {
|
||||
val key = getOrCreateKey()
|
||||
val encAuth = prefs.getString("fahipay_enc_auth_id", null) ?: return null
|
||||
val encCookie = prefs.getString("fahipay_enc_session_cookie", null) ?: return null
|
||||
return try {
|
||||
Pair(decrypt(encAuth, key), decrypt(encCookie, key))
|
||||
} catch (_: Exception) { null }
|
||||
}
|
||||
|
||||
fun clearFahipaySession() {
|
||||
prefs.edit()
|
||||
.remove("fahipay_enc_auth_id")
|
||||
.remove("fahipay_enc_session_cookie")
|
||||
.apply()
|
||||
}
|
||||
|
||||
// ── Fahipay device UUID (generated once, shared across all Fahipay accounts) ─
|
||||
|
||||
fun getOrCreateFahipayDeviceUuid(): String {
|
||||
val key = getOrCreateKey()
|
||||
val enc = prefs.getString("fahipay_enc_device_uuid", null)
|
||||
if (enc != null) {
|
||||
try { return decrypt(enc, key) } catch (_: Exception) {}
|
||||
}
|
||||
val uuid = sh.sar.basedbank.api.fahipay.FahipayLoginFlow.generateDeviceUuid()
|
||||
prefs.edit().putString("fahipay_enc_device_uuid", encrypt(uuid, key)).apply()
|
||||
return uuid
|
||||
}
|
||||
|
||||
// ── Fahipay user profile ──────────────────────────────────────────────────
|
||||
|
||||
data class FahipayUserProfile(
|
||||
val fullName: String,
|
||||
val email: String,
|
||||
val mobile: String,
|
||||
val nid: String,
|
||||
val profileId: String,
|
||||
val walletAccount: String,
|
||||
val linkedAccounts: String
|
||||
)
|
||||
|
||||
fun saveFahipayUserProfile(p: FahipayUserProfile) {
|
||||
val json = org.json.JSONObject().apply {
|
||||
put("fullName", p.fullName)
|
||||
put("email", p.email)
|
||||
put("mobile", p.mobile)
|
||||
put("nid", p.nid)
|
||||
put("profileId", p.profileId)
|
||||
put("walletAccount", p.walletAccount)
|
||||
put("linkedAccounts", p.linkedAccounts)
|
||||
}.toString()
|
||||
val key = getOrCreateKey()
|
||||
prefs.edit().putString("fahipay_enc_profile", encrypt(json, key)).apply()
|
||||
}
|
||||
|
||||
fun loadFahipayUserProfile(): FahipayUserProfile? {
|
||||
val key = getOrCreateKey()
|
||||
val enc = prefs.getString("fahipay_enc_profile", null) ?: return null
|
||||
return try {
|
||||
val o = org.json.JSONObject(decrypt(enc, key))
|
||||
FahipayUserProfile(
|
||||
fullName = o.optString("fullName"),
|
||||
email = o.optString("email"),
|
||||
mobile = o.optString("mobile"),
|
||||
nid = o.optString("nid"),
|
||||
profileId = o.optString("profileId"),
|
||||
walletAccount = o.optString("walletAccount"),
|
||||
linkedAccounts = o.optString("linkedAccounts", "{}")
|
||||
)
|
||||
} catch (_: Exception) { null }
|
||||
}
|
||||
|
||||
// ── Security credential (PIN / pattern hash) ──────────────────────────────
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user