forked from thijooree/android
added support for BML loans
This commit is contained in:
@@ -49,6 +49,30 @@ class BmlAccountClient {
|
||||
} catch (_: Exception) { null }
|
||||
}
|
||||
|
||||
fun fetchLoanDetail(session: BmlSession, internalId: String): BmlLoanDetail? {
|
||||
val resp = client.newCall(bmlApiRequest(session, "$BML_BASE_URL/api/mobile/account/$internalId")).execute()
|
||||
val code = resp.code
|
||||
val json = resp.body?.string() ?: return null
|
||||
resp.close()
|
||||
if (code == 401 || code == 419) throw AuthExpiredException()
|
||||
return try {
|
||||
val root = JSONObject(json)
|
||||
if (!root.optBoolean("success")) return null
|
||||
val p = root.optJSONObject("payload") ?: return null
|
||||
BmlLoanDetail(
|
||||
loanAmount = p.optDouble("loanAmount", 0.0),
|
||||
outstandingAmt = p.optDouble("outstandingAmt", 0.0),
|
||||
repayAmount = p.optDouble("repayAmount", 0.0),
|
||||
intRate = p.optDouble("intRate", 0.0),
|
||||
loanStatus = p.optString("loanStatus"),
|
||||
startDate = p.optString("startDate"),
|
||||
endDate = p.optString("endDate"),
|
||||
noOfRepayOverdue = p.optInt("noOfRepayOverdue", 0),
|
||||
overdueAmount = p.optDouble("overdueAmount", 0.0)
|
||||
)
|
||||
} catch (_: Exception) { null }
|
||||
}
|
||||
|
||||
private fun parseDashboard(
|
||||
json: String,
|
||||
loginTag: String,
|
||||
@@ -61,6 +85,7 @@ class BmlAccountClient {
|
||||
|
||||
val casaAccounts = mutableListOf<BankAccount>()
|
||||
val prepaidCards = mutableListOf<BankAccount>()
|
||||
val loanAccounts = mutableListOf<BankAccount>()
|
||||
|
||||
for (i in 0 until dashboard.length()) {
|
||||
val item = dashboard.getJSONObject(i)
|
||||
@@ -91,6 +116,26 @@ class BmlAccountClient {
|
||||
profileId = profileId,
|
||||
internalId = internalId
|
||||
))
|
||||
} else if (accountType == "Loan") {
|
||||
val outstanding = Math.abs(item.optDouble("availableBalance", 0.0))
|
||||
loanAccounts.add(BankAccount(
|
||||
bank = "BML",
|
||||
profileName = profileName,
|
||||
profileType = "BML_LOAN",
|
||||
accountNumber = accountNumber,
|
||||
accountBriefName = item.optString("alias"),
|
||||
currencyName = currency,
|
||||
accountTypeName = product,
|
||||
availableBalance = "%.2f".format(outstanding),
|
||||
currentBalance = "%.2f".format(outstanding),
|
||||
blockedAmount = "0.00",
|
||||
mvrBalance = "0.00",
|
||||
statusDesc = status,
|
||||
profileImageHash = null,
|
||||
loginTag = loginTag,
|
||||
profileId = profileId,
|
||||
internalId = internalId
|
||||
))
|
||||
} else if (accountType == "Card") {
|
||||
val isVisible = item.optBoolean("account_visible", false)
|
||||
if (!isVisible) continue
|
||||
@@ -119,6 +164,6 @@ class BmlAccountClient {
|
||||
}
|
||||
}
|
||||
|
||||
return casaAccounts + prepaidCards
|
||||
return casaAccounts + prepaidCards + loanAccounts
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,18 @@ data class BmlTransferResult(
|
||||
val errorMessage: String = ""
|
||||
)
|
||||
|
||||
data class BmlLoanDetail(
|
||||
val loanAmount: Double,
|
||||
val outstandingAmt: Double, // negative as returned by API
|
||||
val repayAmount: Double,
|
||||
val intRate: Double,
|
||||
val loanStatus: String,
|
||||
val startDate: String, // ISO8601 e.g. "2023-10-26T00:00:00+05:00"
|
||||
val endDate: String,
|
||||
val noOfRepayOverdue: Int,
|
||||
val overdueAmount: Double
|
||||
)
|
||||
|
||||
data class BmlForeignLimit(
|
||||
val type: String,
|
||||
val used: Double,
|
||||
|
||||
Reference in New Issue
Block a user