forked from shihaam/thijooree
BML account lookup and add new contacts
This commit is contained in:
@@ -203,6 +203,107 @@ class BmlLoginFlow {
|
||||
} catch (_: Exception) { "" }
|
||||
}
|
||||
|
||||
fun validateAccount(session: BmlSession, input: String): BmlAccountValidation? {
|
||||
val resp = apiClient.newCall(
|
||||
Request.Builder().url("$BASE_URL/api/mobile/validate/account/$input")
|
||||
.header("Authorization", "Bearer ${session.accessToken}")
|
||||
.header("User-Agent", APP_USER_AGENT)
|
||||
.header("x-app-version", APP_VERSION)
|
||||
.header("Accept", "application/json")
|
||||
.build()
|
||||
).execute()
|
||||
val json = resp.body?.string() ?: return null
|
||||
resp.close()
|
||||
return try {
|
||||
val root = JSONObject(json)
|
||||
if (!root.optBoolean("success")) return null
|
||||
val payload = root.optJSONObject("payload") ?: return null
|
||||
val trnType = payload.optString("trnType", "")
|
||||
val validationType = payload.optString("validationType", "")
|
||||
if (validationType == "alias") {
|
||||
val cdtrAcct = payload.optJSONObject("CdtrAcct") ?: return null
|
||||
BmlAccountValidation(
|
||||
trnType = trnType,
|
||||
validationType = validationType,
|
||||
account = cdtrAcct.optString("Acct"),
|
||||
originalInput = input,
|
||||
name = payload.optString("contact_name").trim(),
|
||||
alias = null,
|
||||
currency = payload.optString("currency", "MVR"),
|
||||
agnt = cdtrAcct.optString("FinInstnId").takeIf { it.isNotBlank() }
|
||||
)
|
||||
} else {
|
||||
BmlAccountValidation(
|
||||
trnType = trnType,
|
||||
validationType = validationType,
|
||||
account = payload.optString("account"),
|
||||
originalInput = input,
|
||||
name = payload.optString("name"),
|
||||
alias = payload.optString("alias").takeIf { it.isNotBlank() && it != "null" },
|
||||
currency = payload.optString("currency", "MVR")
|
||||
)
|
||||
}
|
||||
} catch (_: Exception) { null }
|
||||
}
|
||||
|
||||
fun verifyMibAccount(session: BmlSession, account: String): BmlAccountValidation? {
|
||||
val resp = apiClient.newCall(
|
||||
Request.Builder().url("$BASE_URL/api/mobile/favara/account-verification/$account/MIB")
|
||||
.header("Authorization", "Bearer ${session.accessToken}")
|
||||
.header("User-Agent", APP_USER_AGENT)
|
||||
.header("x-app-version", APP_VERSION)
|
||||
.header("Accept", "application/json")
|
||||
.build()
|
||||
).execute()
|
||||
val json = resp.body?.string() ?: return null
|
||||
resp.close()
|
||||
return try {
|
||||
val root = JSONObject(json)
|
||||
if (!root.optBoolean("success")) return null
|
||||
BmlAccountValidation(
|
||||
trnType = "DOT",
|
||||
validationType = "MIB",
|
||||
account = root.optString("account"),
|
||||
originalInput = account,
|
||||
name = root.optString("name"),
|
||||
alias = null,
|
||||
currency = "MVR",
|
||||
agnt = root.optString("agnt").takeIf { it.isNotBlank() }
|
||||
)
|
||||
} catch (_: Exception) { null }
|
||||
}
|
||||
|
||||
fun saveContact(
|
||||
session: BmlSession,
|
||||
contactType: String,
|
||||
account: String,
|
||||
alias: String,
|
||||
currency: String? = null,
|
||||
name: String? = null,
|
||||
swift: String? = null
|
||||
): Boolean {
|
||||
val bodyObj = JSONObject().apply {
|
||||
put("contact_type", contactType)
|
||||
put("account", account)
|
||||
put("alias", alias)
|
||||
if (currency != null) put("currency", currency)
|
||||
if (name != null) put("name", name)
|
||||
if (swift != null) put("swift", swift)
|
||||
}
|
||||
val resp = apiClient.newCall(
|
||||
Request.Builder().url("$BASE_URL/api/mobile/contacts")
|
||||
.post(bodyObj.toString().toRequestBody("application/json".toMediaType()))
|
||||
.header("Authorization", "Bearer ${session.accessToken}")
|
||||
.header("User-Agent", APP_USER_AGENT)
|
||||
.header("x-app-version", APP_VERSION)
|
||||
.header("Accept", "application/json")
|
||||
.build()
|
||||
).execute()
|
||||
val json = resp.body?.string() ?: return false
|
||||
resp.close()
|
||||
return try { JSONObject(json).optBoolean("success") } catch (_: Exception) { false }
|
||||
}
|
||||
|
||||
fun fetchContacts(session: BmlSession): List<MibBeneficiary> {
|
||||
val resp = apiClient.newCall(apiRequest(session, "$BASE_URL/api/mobile/contacts")).execute()
|
||||
val json = resp.body?.string() ?: return emptyList()
|
||||
|
||||
@@ -5,6 +5,17 @@ data class BmlSession(
|
||||
val deviceId: String
|
||||
)
|
||||
|
||||
data class BmlAccountValidation(
|
||||
val trnType: String, // IAT, QTR, DOT
|
||||
val validationType: String, // BML, alias, MIB
|
||||
val account: String, // resolved account number
|
||||
val originalInput: String, // original user input (alias/Favara for QTR)
|
||||
val name: String,
|
||||
val alias: String?,
|
||||
val currency: String,
|
||||
val agnt: String? = null // BIC for DOT (MIB account on BML)
|
||||
)
|
||||
|
||||
data class BmlForeignLimit(
|
||||
val type: String,
|
||||
val used: Double,
|
||||
|
||||
@@ -126,6 +126,62 @@ class MibContactsClient {
|
||||
}
|
||||
}
|
||||
|
||||
fun createContact(
|
||||
session: MibSession,
|
||||
benefType: String, // "I" = MIB internal, "L" = local/BML
|
||||
bankNo: Int, // 2 = MIB, 3 = BML
|
||||
benefAccount: String,
|
||||
benefName: String,
|
||||
nickName: String,
|
||||
transferCy: String = "462",
|
||||
categoryId: String = "0",
|
||||
imageBase64: String = ""
|
||||
): Boolean {
|
||||
val body = FormBody.Builder()
|
||||
.add("benefType", benefType)
|
||||
.add("imageSet", if (imageBase64.isNotBlank()) "1" else "0")
|
||||
.add("benefAccount", benefAccount)
|
||||
.add("benefIban", "")
|
||||
.add("benefName", benefName)
|
||||
.add("nickName", nickName)
|
||||
.add("transferCy", transferCy)
|
||||
.add("transferCySwift", "840")
|
||||
.add("benefAddress", "")
|
||||
.add("benefCity", "")
|
||||
.add("benefCountry", "4")
|
||||
.add("benefBankSwift", "")
|
||||
.add("bankNo", bankNo.toString())
|
||||
.add("benefBankName", "")
|
||||
.add("benefBankBranch", "")
|
||||
.add("benefBankAddress", "")
|
||||
.add("benefBankCity", "")
|
||||
.add("benefBankCountry", "4")
|
||||
.add("intBankSwift", "")
|
||||
.add("intBankName", "")
|
||||
.add("intBankAddress", "")
|
||||
.add("intBankBranch", "")
|
||||
.add("intBankCity", "")
|
||||
.add("intBankCountry", "4")
|
||||
.add("categoryId", categoryId)
|
||||
.add("email", "")
|
||||
.add("contactNumber", "")
|
||||
.add("website", "")
|
||||
.add("image", imageBase64)
|
||||
.build()
|
||||
|
||||
val request = Request.Builder()
|
||||
.url("$BASE_WV_URL/ajaxBeneficiary/createLocalBeneficiary")
|
||||
.post(body)
|
||||
.withSessionHeaders(session)
|
||||
.header("Referer", "$BASE_WV_URL/beneficiary/createNew")
|
||||
.build()
|
||||
|
||||
return client.newCall(request).execute().use { response ->
|
||||
val bodyStr = response.body?.string() ?: return@use false
|
||||
try { JSONObject(bodyStr).optBoolean("success") } catch (_: Exception) { false }
|
||||
}
|
||||
}
|
||||
|
||||
fun fetchProfileImageBase64(session: MibSession, imageHash: String): String? {
|
||||
val body = FormBody.Builder()
|
||||
.add("imageHash", imageHash)
|
||||
|
||||
@@ -232,7 +232,8 @@ class MibLoginFlow(private val prefs: android.content.SharedPreferences) {
|
||||
mvrBalance = a.optString("mvrBalance"),
|
||||
statusDesc = a.optString("statusDesc"),
|
||||
profileImageHash = profile.customerImage,
|
||||
loginTag = loginTag
|
||||
loginTag = loginTag,
|
||||
profileId = profile.profileId
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@ data class MibAccount(
|
||||
val mvrBalance: String,
|
||||
val statusDesc: String,
|
||||
val profileImageHash: String?,
|
||||
val loginTag: String = ""
|
||||
val loginTag: String = "",
|
||||
val profileId: String = "" // MIB profile ID; empty for BML accounts
|
||||
)
|
||||
|
||||
data class MibBeneficiaryCategory(
|
||||
@@ -53,7 +54,8 @@ data class MibBeneficiary(
|
||||
val benefStatus: String,
|
||||
val transferCyDesc: String,
|
||||
val customerImgHash: String?,
|
||||
val benefCategoryId: String // "0" = uncategorized
|
||||
val benefCategoryId: String, // "0" = uncategorized
|
||||
val profileId: String = "" // MIB profile ID; empty for BML contacts
|
||||
)
|
||||
|
||||
data class MibIpsAccountInfo(
|
||||
|
||||
Reference in New Issue
Block a user