forked from thijooree/android
bml to fahipay and MIB to fahipay support
This commit is contained in:
@@ -50,9 +50,23 @@ class BmlValidateClient {
|
||||
} catch (_: Exception) { null }
|
||||
}
|
||||
|
||||
fun verifyMibAccount(session: BmlSession, account: String): BmlAccountValidation? {
|
||||
// BML's MIB verify endpoint doesn't return the MIB account's currency.
|
||||
fun verifyMibAccount(session: BmlSession, account: String): BmlAccountValidation? =
|
||||
verifyFavaraAccount(session, account, bankCode = "MIB", currency = "")
|
||||
|
||||
// Fahipay wallets are MVR only; the endpoint doesn't return a currency.
|
||||
fun verifyFahipayAccount(session: BmlSession, account: String): BmlAccountValidation? =
|
||||
verifyFavaraAccount(session, account, bankCode = "FHP", currency = "MVR")
|
||||
|
||||
/** Favara account verification of a non-BML account; [bankCode] is BML's code for the bank. */
|
||||
private fun verifyFavaraAccount(
|
||||
session: BmlSession,
|
||||
account: String,
|
||||
bankCode: String,
|
||||
currency: String
|
||||
): BmlAccountValidation? {
|
||||
val resp = client.newCall(
|
||||
Request.Builder().url("$BML_BASE_URL/api/mobile/favara/account-verification/$account/MIB")
|
||||
Request.Builder().url("$BML_BASE_URL/api/mobile/favara/account-verification/$account/$bankCode")
|
||||
.header("Authorization", "Bearer ${session.accessToken}")
|
||||
.header("User-Agent", BML_USER_AGENT)
|
||||
.header("x-app-version", BML_APP_VERSION)
|
||||
@@ -66,13 +80,12 @@ class BmlValidateClient {
|
||||
if (!root.optBoolean("success")) return null
|
||||
BmlAccountValidation(
|
||||
trnType = "DOT",
|
||||
validationType = "MIB",
|
||||
validationType = bankCode,
|
||||
account = root.optString("account"),
|
||||
originalInput = account,
|
||||
name = root.optString("name"),
|
||||
alias = null,
|
||||
// BML's MIB verify endpoint doesn't return the MIB account's currency.
|
||||
currency = "",
|
||||
currency = currency,
|
||||
agnt = root.optString("agnt").takeIf { it.isNotBlank() }
|
||||
)
|
||||
} catch (_: Exception) { null }
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
package sh.sar.basedbank.api.mib
|
||||
|
||||
import android.os.Build
|
||||
import okhttp3.FormBody
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import org.json.JSONObject
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* IPS (Favara) lookup and transfer through the WebView "Quick Transfer" page
|
||||
* (`/transferIps/quick`), which picks the destination bank explicitly by BIC and its bank list
|
||||
* ID. The MIB app pays Fahipay this way rather than through the encrypted API's B40/T51.
|
||||
* See docs/mibapi/08-transfer.md.
|
||||
*/
|
||||
class MibIpsWebClient {
|
||||
|
||||
private val client = OkHttpClient.Builder()
|
||||
.connectTimeout(20, TimeUnit.SECONDS)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
.build()
|
||||
|
||||
private fun cookieHeader(session: MibSession) =
|
||||
"mbmodel=AND-1.0; xxid=${session.xxid}; IBSID=${session.xxid}; " +
|
||||
"mbnonce=${session.nonceGenerator}; time-tracker=597"
|
||||
|
||||
private fun post(session: MibSession, path: String, body: FormBody): JSONObject {
|
||||
val request = Request.Builder()
|
||||
.url("$BASE_WV_URL/$path")
|
||||
.post(body)
|
||||
.header("Cookie", cookieHeader(session))
|
||||
.header("User-Agent", USER_AGENT)
|
||||
.header("X-Requested-With", "XMLHttpRequest")
|
||||
.header("Accept", "*/*")
|
||||
.header("Origin", BASE_WV_URL)
|
||||
.header("Referer", "$BASE_WV_URL/transferIps/quick?dashurl=1")
|
||||
.build()
|
||||
return client.newCall(request).execute().use { response ->
|
||||
if (response.code == 419) throw SessionExpiredException()
|
||||
// Errors come back as non-2xx with the same JSON shape, so parse either way
|
||||
val bodyStr = response.body?.string().orEmpty()
|
||||
try { JSONObject(bodyStr) } catch (_: Exception) {
|
||||
JSONObject().put("success", false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves [account] at the bank with [bankBic]. Throws [MibLookupException] with the
|
||||
* server's reason when it isn't found. The page doesn't return a currency: IPS accounts
|
||||
* reached this way are MVR only.
|
||||
*/
|
||||
fun lookupAccount(session: MibSession, bankBic: String, account: String): MibIpsAccountInfo {
|
||||
val json = post(session, "AjaxAlias/getIPSAccount", FormBody.Builder()
|
||||
.add("benefBank", bankBic)
|
||||
.add("benefAccount", account)
|
||||
.build())
|
||||
val name = json.optString("accountName").trim()
|
||||
if (!json.optBoolean("success") || name.isBlank()) {
|
||||
throw MibLookupException(json.optString("reasonText").trim().ifBlank { "Account not found" })
|
||||
}
|
||||
return MibIpsAccountInfo(
|
||||
accountName = name,
|
||||
accountNumber = account,
|
||||
bankId = json.optString("bankBic").ifBlank { bankBic },
|
||||
currency = "MVR"
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an MVR IPS transfer to [toAccount] at the bank with [bankBic] / [bankNo] (the
|
||||
* page's bank list ID — unrelated to the encrypted API's T50/T51 `bankNo`).
|
||||
*/
|
||||
fun transfer(
|
||||
session: MibSession,
|
||||
fromAccount: String,
|
||||
fromAccountName: String,
|
||||
toAccount: String,
|
||||
benefName: String,
|
||||
bankBic: String,
|
||||
bankNo: Int,
|
||||
amount: String,
|
||||
purpose: String,
|
||||
otp: String
|
||||
): MibTransferResult {
|
||||
val json = post(session, "ajaxIPSTransfer/transferIPSLocal", FormBody.Builder()
|
||||
.add("benefName", benefName)
|
||||
.add("benefNo", "0")
|
||||
.add("fromAccountNo", fromAccount)
|
||||
.add("fromAccountName", fromAccountName)
|
||||
.add("benefAccountNo", toAccount)
|
||||
.add("transferCy", MVR_CODE)
|
||||
.add("benefCurrencyCode", "")
|
||||
.add("amount", amount)
|
||||
.add("bankNo", bankNo.toString())
|
||||
.add("purpose", purpose.ifBlank { "-" })
|
||||
.add("otp", otp)
|
||||
.add("otpType", "3")
|
||||
.add("bankBic", bankBic)
|
||||
.build())
|
||||
val reasonCode = json.optString("reasonCode")
|
||||
if (!json.optBoolean("success")) {
|
||||
return MibTransferResult(
|
||||
success = false,
|
||||
errorMessage = json.optString("reasonText").ifBlank { "Transfer failed" },
|
||||
reasonCode = reasonCode
|
||||
)
|
||||
}
|
||||
// Success covers completed (2011/2012), still processing (2091, or trxId 0 / no date)
|
||||
// and awaiting approval (any other code): all were accepted, so never report a failure
|
||||
// that would invite the user to send it again
|
||||
val data = json.optJSONArray("data")?.optJSONObject(0)
|
||||
return MibTransferResult(
|
||||
success = true,
|
||||
trxId = data?.optString("trxId")?.takeUnless { it == "0" }.orEmpty(),
|
||||
date = data?.optString("date")?.takeUnless { it == "null" }.orEmpty()
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val BASE_WV_URL = "https://faisamobilex-wv-v2.mib.com.mv"
|
||||
private val USER_AGENT = "Mozilla/5.0 (Linux; Android ${Build.VERSION.RELEASE}; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/129.0.6668.70 Mobile Safari/537.36"
|
||||
private const val MVR_CODE = "462"
|
||||
|
||||
const val FAHIPAY_BIC = "FAHIMVMV"
|
||||
/** Fahipay's ID in the Quick Transfer page's bank list. */
|
||||
const val FAHIPAY_BANK_NO = 13
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package sh.sar.basedbank.api.mib
|
||||
|
||||
import sh.sar.basedbank.util.AccountInputParser
|
||||
|
||||
class MibLookupException(message: String) : Exception(message)
|
||||
|
||||
class MibTransferClient(private val flow: MibLoginFlow) {
|
||||
@@ -61,11 +63,13 @@ class MibTransferClient(private val flow: MibLoginFlow) {
|
||||
fun lookup(session: MibSession, input: String): MibIpsAccountInfo {
|
||||
// B40 only resolves Favara IDs with an uppercase "A" ("a239225" fails, "A239225" works)
|
||||
val trimmed = input.trim().let { if (it.matches(Regex("^a\\d{6}$"))) it.uppercase() else it }
|
||||
val supported = trimmed.matches(Regex("^7\\d{12}$")) ||
|
||||
trimmed.matches(Regex("^9\\d{16}$")) ||
|
||||
trimmed.matches(Regex("^[79]\\d{6}$")) ||
|
||||
trimmed.matches(Regex("^[Aa]\\d{6}$")) ||
|
||||
trimmed.contains("@")
|
||||
val supported = AccountInputParser.detect(trimmed) in setOf(
|
||||
AccountInputParser.InputType.BML_ACCOUNT,
|
||||
AccountInputParser.InputType.MIB_ACCOUNT,
|
||||
AccountInputParser.InputType.PHONE,
|
||||
AccountInputParser.InputType.NATIONAL_ID,
|
||||
AccountInputParser.InputType.EMAIL
|
||||
)
|
||||
if (!supported) throw MibLookupException("Unrecognized account number format")
|
||||
|
||||
val json = flow.request(session, "B40") { put("search", trimmed) }
|
||||
|
||||
@@ -23,6 +23,7 @@ import androidx.fragment.app.activityViewModels
|
||||
import androidx.swiperefreshlayout.widget.CircularProgressDrawable
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import sh.sar.basedbank.util.AccountInputParser
|
||||
import sh.sar.basedbank.util.ContactDisplay
|
||||
import sh.sar.basedbank.util.ContactImageCache
|
||||
import sh.sar.basedbank.util.CredentialStore
|
||||
@@ -166,11 +167,12 @@ class AddContactSheetFragment : BottomSheetDialogFragment() {
|
||||
!recipientName.isNullOrBlank() && !currency.isNullOrBlank()
|
||||
) {
|
||||
val bankBic = when {
|
||||
accountNumber.matches(Regex("^9\\d{16}$")) -> "MADVMVMV"
|
||||
accountNumber.matches(Regex("^7\\d{12}$")) -> "MALBMVMV"
|
||||
AccountInputParser.isMibAccount(accountNumber) -> "MADVMVMV"
|
||||
AccountInputParser.isBmlAccount(accountNumber) -> "MALBMVMV"
|
||||
AccountInputParser.isFahipayAccount(accountNumber) -> "FAHIMVMV"
|
||||
else -> ""
|
||||
}
|
||||
val trnType = if (accountNumber.matches(Regex("^9\\d{16}$"))) "DOT" else "IAT"
|
||||
val trnType = if (AccountInputParser.isBmlAccount(accountNumber)) "IAT" else "DOT"
|
||||
val validation = BmlAccountValidation(
|
||||
trnType = trnType,
|
||||
validationType = "prefilled",
|
||||
@@ -357,6 +359,10 @@ class AddContactSheetFragment : BottomSheetDialogFragment() {
|
||||
private fun lookupForBml(input: String): BmlAccountValidation? {
|
||||
val loginId = selectedDest?.bmlLoginId ?: return null
|
||||
val bmlSess = app.bmlSessions[loginId] ?: return null
|
||||
// Fahipay: only BML's Fahipay verify can resolve it
|
||||
if (AccountInputParser.isFahipayAccount(input)) {
|
||||
return try { BmlValidateClient().verifyFahipayAccount(bmlSess, input) } catch (_: Exception) { null }
|
||||
}
|
||||
// 1) Try BML validate
|
||||
val validated = try { BmlValidateClient().validateAccount(bmlSess, input) } catch (_: Exception) { null }
|
||||
if (validated != null) return validated
|
||||
@@ -440,8 +446,9 @@ class AddContactSheetFragment : BottomSheetDialogFragment() {
|
||||
|
||||
val displayName = validation.name.ifBlank { input }
|
||||
val bankName = when {
|
||||
validation.account.matches(Regex("^9\\d{16}$")) -> "MIB"
|
||||
validation.account.matches(Regex("^7\\d{12}$")) -> "BML"
|
||||
AccountInputParser.isMibAccount(validation.account) -> "MIB"
|
||||
AccountInputParser.isBmlAccount(validation.account) -> "BML"
|
||||
AccountInputParser.isFahipayAccount(validation.account) -> "Fahipay"
|
||||
else -> validation.account
|
||||
}
|
||||
val bankLabel = "$bankName · ${validation.account}"
|
||||
@@ -546,13 +553,17 @@ class AddContactSheetFragment : BottomSheetDialogFragment() {
|
||||
val lookup = bmlLookup ?: return false
|
||||
val account = lookup.account
|
||||
return when {
|
||||
account.matches(Regex("^7\\d{12}$")) ->
|
||||
AccountInputParser.isBmlAccount(account) ->
|
||||
// BML account → IAT
|
||||
BmlContactsClient().saveContact(bmlSess, "IAT", account, alias)
|
||||
account.matches(Regex("^9\\d{16}$")) ->
|
||||
AccountInputParser.isMibAccount(account) ->
|
||||
// MIB internal → DOT; swift is BML's internal UUID for MIB bank
|
||||
BmlContactsClient().saveContact(bmlSess, "DOT", account, alias,
|
||||
currency = lookup.currency, name = lookup.name, swift = MIB_SWIFT_ON_BML)
|
||||
AccountInputParser.isFahipayAccount(account) ->
|
||||
// Fahipay → DOT; swift is BML's internal UUID for Fahipay
|
||||
BmlContactsClient().saveContact(bmlSess, "DOT", account, alias,
|
||||
currency = lookup.currency.ifBlank { "MVR" }, name = lookup.name, swift = FAHIPAY_SWIFT_ON_BML)
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
@@ -566,7 +577,7 @@ class AddContactSheetFragment : BottomSheetDialogFragment() {
|
||||
val currency = binding.etCurrency.text?.toString()?.trim() ?: "MVR"
|
||||
val transferCy = if (currency.equals("USD", ignoreCase = true)) "840" else "462"
|
||||
|
||||
val isMibInternal = account.matches(Regex("^9\\d{16}$"))
|
||||
val isMibInternal = AccountInputParser.isMibAccount(account)
|
||||
val bankNo = if (isMibInternal) 2 else 3
|
||||
val name = bmlLookup?.name ?: ""
|
||||
|
||||
@@ -593,7 +604,7 @@ class AddContactSheetFragment : BottomSheetDialogFragment() {
|
||||
val profile = dest.mibProfile ?: return false
|
||||
val currency = binding.etCurrency.text?.toString()?.trim() ?: "MVR"
|
||||
val transferCy = if (currency.equals("USD", ignoreCase = true)) "840" else "462"
|
||||
val bankNo = if (contact.benefAccount.matches(Regex("^9\\d{16}$"))) 2 else 3
|
||||
val bankNo = if (AccountInputParser.isMibAccount(contact.benefAccount)) 2 else 3
|
||||
|
||||
return try {
|
||||
val flow = app.mibFlowFor(loginId)
|
||||
@@ -637,6 +648,7 @@ class AddContactSheetFragment : BottomSheetDialogFragment() {
|
||||
companion object {
|
||||
// BML's internal UUID for MIB bank — used as the "swift" field when saving DOT contacts
|
||||
private const val MIB_SWIFT_ON_BML = "F4E79935-3E73-E611-80DD-00155D020F0A"
|
||||
private const val FAHIPAY_SWIFT_ON_BML = "3941D32B-BBE1-F111-B828-00155D0C4810"
|
||||
|
||||
// MIB rejects longer nicknames with "invalid nick name"
|
||||
private const val MIB_MAX_ALIAS = 20
|
||||
|
||||
@@ -18,6 +18,7 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import sh.sar.basedbank.R
|
||||
import sh.sar.basedbank.databinding.SheetContactDetailsBinding
|
||||
import sh.sar.basedbank.util.AccountInputParser
|
||||
import sh.sar.basedbank.util.ContactDisplay
|
||||
import sh.sar.basedbank.util.ContactImageCache
|
||||
import sh.sar.basedbank.util.ContactListParser
|
||||
@@ -129,18 +130,20 @@ class ContactDetailsSheetFragment : BottomSheetDialogFragment() {
|
||||
}
|
||||
}
|
||||
|
||||
/** Which bank the contact's account is at ("BML" / "MIB"); null when we can't tell. */
|
||||
/** Which bank the contact's account is at ("BML" / "MIB" / "FAHIPAY"); null when we can't tell. */
|
||||
private fun contactBank(contact: ContactDisplay): String? = when {
|
||||
contact.network == TransferNetwork.MIB -> "MIB"
|
||||
contact.accountNumber.matches(Regex("^7\\d{12}$")) -> "BML"
|
||||
contact.accountNumber.matches(Regex("^9\\d{16}$")) -> "MIB"
|
||||
else -> null
|
||||
AccountInputParser.isBmlAccount(contact.accountNumber) -> "BML"
|
||||
AccountInputParser.isMibAccount(contact.accountNumber) -> "MIB"
|
||||
AccountInputParser.isFahipayAccount(contact.accountNumber) -> "FAHIPAY"
|
||||
else -> null
|
||||
}
|
||||
|
||||
/** Logo of the contact's bank; null when we have no logo for it (only MIB and BML for now). */
|
||||
/** Logo of the contact's bank; null when we have no logo for it. */
|
||||
private fun bankLogoRes(contact: ContactDisplay): Int? = when (contactBank(contact)) {
|
||||
"BML" -> R.drawable.bml_logo_vector
|
||||
"MIB" -> R.drawable.mib_logo
|
||||
"FAHIPAY" -> R.drawable.fahipay_logo
|
||||
else -> null
|
||||
}
|
||||
|
||||
|
||||
@@ -1302,7 +1302,11 @@ class TransferFragment : Fragment() {
|
||||
val mibSess = mibHandler.session
|
||||
val bmlSess = bmlSessionFor(selectedAccount)
|
||||
var errorMsg: String? = null
|
||||
val info = if (preferBml && bmlSess != null) {
|
||||
val info = if (preferBml && bmlSess != null && AccountInputParser.isFahipayAccount(accountNumber)) {
|
||||
// BML → Fahipay: only BML's Fahipay verify can resolve it, so no MIB fallback
|
||||
bmlHandler().validateDestination(bmlSess, accountNumber, verifyAsMib = false, verifyAsFahipay = true)
|
||||
.also { if (it == null) errorMsg = getString(R.string.transfer_account_not_found) }
|
||||
} else if (preferBml && bmlSess != null) {
|
||||
val isMibDest = AccountInputParser.detect(accountNumber) == AccountInputParser.InputType.MIB_ACCOUNT
|
||||
val bmlInfo = bmlHandler().validateDestination(bmlSess, accountNumber, verifyAsMib = isMibDest)
|
||||
if (bmlInfo != null) {
|
||||
@@ -1576,6 +1580,7 @@ class TransferFragment : Fragment() {
|
||||
val isBmlBusiness = isSrcBml && bmlHandler().isBusinessProfile(src) // to test on personal accounts: use `isSrcBml`
|
||||
val isSrcCard = src.profileType == "BML_PREPAID" || src.profileType == "BML_CREDIT" || src.profileType == "BML_DEBIT"
|
||||
val isDestMib = AccountInputParser.detect(resolvedAccountNumber) == AccountInputParser.InputType.MIB_ACCOUNT
|
||||
val isDestFahipay = AccountInputParser.isFahipayAccount(resolvedAccountNumber)
|
||||
val currency = src.currencyName.ifBlank { "MVR" }
|
||||
val allAccounts = viewModel.accounts.value ?: emptyList()
|
||||
val allContacts = viewModel.contacts.value ?: emptyList()
|
||||
@@ -1610,6 +1615,29 @@ class TransferFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
// BML → Fahipay requires a saved BML contact, whatever the currency
|
||||
if (isSrcBml && !isSrcCard && isDestFahipay) {
|
||||
val hasBmlContact = allContacts.any { it.benefCategoryId == "BML" && it.benefAccount == resolvedAccountNumber }
|
||||
if (!hasBmlContact) {
|
||||
val bmlProfileId = src.profileId.takeIf { it.isNotBlank() }
|
||||
?: src.loginTag.removePrefix("bml_").takeIf { it.isNotBlank() }
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.transfer_bml_contact_required_title)
|
||||
.setMessage(R.string.transfer_bml_contact_required_msg_fahipay)
|
||||
.setPositiveButton(R.string.contact_save) { _, _ ->
|
||||
AddContactSheetFragment.newInstance(
|
||||
bmlProfileId = bmlProfileId,
|
||||
accountNumber = resolvedAccountNumber,
|
||||
recipientName = resolvedRecipientName.takeIf { it.isNotBlank() },
|
||||
currency = "MVR"
|
||||
).show(parentFragmentManager, "add_contact")
|
||||
}
|
||||
.setNegativeButton(R.string.close, null)
|
||||
.show()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
val destDisplay = binding.tvToAccountName.text?.toString() ?: resolvedAccountNumber
|
||||
val bankNameCapture = resolvedBankName
|
||||
val capturedToAvatar = (binding.ivToPhoto.drawable as? android.graphics.drawable.BitmapDrawable)?.bitmap
|
||||
|
||||
@@ -32,6 +32,7 @@ import sh.sar.basedbank.ui.home.HomeActivity
|
||||
import sh.sar.basedbank.ui.home.HomeViewModel
|
||||
import sh.sar.basedbank.ui.home.TransferFragment
|
||||
import sh.sar.basedbank.ui.home.TransferReceiptData
|
||||
import sh.sar.basedbank.util.AccountInputParser
|
||||
import sh.sar.basedbank.util.CredentialStore
|
||||
import sh.sar.basedbank.util.PaymvQrParser
|
||||
import sh.sar.basedbank.util.RecentPick
|
||||
@@ -139,7 +140,8 @@ class BmlTransferHandler(
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a destination through BML — `verifyMibAccount` when [verifyAsMib], otherwise the
|
||||
* Resolves a destination through BML — `verifyMibAccount` when [verifyAsMib],
|
||||
* `verifyFahipayAccount` when [verifyAsFahipay], otherwise the
|
||||
* regular alias/account validation. Blocking; call from IO. Returns null when BML can't
|
||||
* resolve it, so the caller can fall back to the MIB IPS lookup.
|
||||
*
|
||||
@@ -151,11 +153,15 @@ class BmlTransferHandler(
|
||||
fun validateDestination(
|
||||
session: BmlSession,
|
||||
accountNumber: String,
|
||||
verifyAsMib: Boolean
|
||||
verifyAsMib: Boolean,
|
||||
verifyAsFahipay: Boolean = false
|
||||
): MibIpsAccountInfo? {
|
||||
val result = try {
|
||||
if (verifyAsMib) BmlValidateClient().verifyMibAccount(session, accountNumber)
|
||||
else BmlValidateClient().validateAccount(session, accountNumber)
|
||||
when {
|
||||
verifyAsMib -> BmlValidateClient().verifyMibAccount(session, accountNumber)
|
||||
verifyAsFahipay -> BmlValidateClient().verifyFahipayAccount(session, accountNumber)
|
||||
else -> BmlValidateClient().validateAccount(session, accountNumber)
|
||||
}
|
||||
} catch (_: Exception) { null } ?: return null
|
||||
val bankId = when (result.trnType) {
|
||||
"IAT" -> "MALBMVMV"
|
||||
@@ -620,7 +626,7 @@ class BmlTransferHandler(
|
||||
val routed = routeTransfer(destAccount, isSrcCard, isDestMib, currency, allAccounts, allContacts)
|
||||
?: return Triple(false, "BML contact not found for this account", null)
|
||||
val (transferType, creditAccount, bank) = routed
|
||||
val toBank = bank ?: if (isDestMib) "MIB" else "BML"
|
||||
val toBank = bank ?: destBankLabel(destAccount, isDestMib)
|
||||
|
||||
// Step 1: initiate
|
||||
val initiated = try {
|
||||
@@ -687,7 +693,7 @@ class BmlTransferHandler(
|
||||
return
|
||||
}
|
||||
val (transferType, creditAccount, bank) = routed
|
||||
val toBank = bank ?: if (isDestMib) "MIB" else "BML"
|
||||
val toBank = bank ?: destBankLabel(destAccount, isDestMib)
|
||||
|
||||
pendingTransfer = PendingTransfer(
|
||||
src = src,
|
||||
@@ -929,8 +935,8 @@ class BmlTransferHandler(
|
||||
|
||||
/**
|
||||
* Picks the BML transfer type and the credit-account identifier the API expects.
|
||||
* Returns null only for the USD → MIB case with no matching saved BML contact, which both
|
||||
* callers report as "BML contact not found".
|
||||
* Returns null only for the USD → MIB and Fahipay cases with no matching saved BML contact,
|
||||
* which both callers report as "BML contact not found".
|
||||
*/
|
||||
private fun routeTransfer(
|
||||
destAccount: String,
|
||||
@@ -952,6 +958,12 @@ class BmlTransferHandler(
|
||||
val card = allAccounts.first { isCard(it) && it.accountNumber == destAccount }
|
||||
Triple("CPA", card.internalId.ifBlank { destAccount }, null)
|
||||
}
|
||||
AccountInputParser.isFahipayAccount(destAccount) -> {
|
||||
// Fahipay DOT: like USD → MIB, BML only takes the saved contact's numeric ID
|
||||
val contact = allContacts.firstOrNull { it.benefCategoryId == "BML" && it.benefAccount == destAccount }
|
||||
?: return null
|
||||
Triple("DOT", contact.benefNo.removePrefix("bml_"), null)
|
||||
}
|
||||
isDestMib && currency == "MVR" -> Triple("DOT", destAccount, "MIB")
|
||||
isDestMib -> {
|
||||
// USD DOT: requires BML contact numeric ID
|
||||
@@ -965,6 +977,13 @@ class BmlTransferHandler(
|
||||
|
||||
private fun isCard(account: BankAccount) = BmlVerifiedCards.isCard(account)
|
||||
|
||||
/** The receipt's "to bank" for a transfer whose route didn't name one. */
|
||||
private fun destBankLabel(destAccount: String, isDestMib: Boolean) = when {
|
||||
AccountInputParser.isFahipayAccount(destAccount) -> "Fahipay"
|
||||
isDestMib -> "MIB"
|
||||
else -> "BML"
|
||||
}
|
||||
|
||||
private companion object {
|
||||
/** The BML token's TOTP window. */
|
||||
const val TOTP_WINDOW_MS = 30_000L
|
||||
|
||||
@@ -8,6 +8,7 @@ import sh.sar.basedbank.BasedBankApp
|
||||
import sh.sar.basedbank.R
|
||||
import sh.sar.basedbank.api.mib.MibContactsClient
|
||||
import sh.sar.basedbank.api.mib.MibIpsAccountInfo
|
||||
import sh.sar.basedbank.api.mib.MibIpsWebClient
|
||||
import sh.sar.basedbank.api.mib.MibLoginFlow
|
||||
import sh.sar.basedbank.api.mib.MibLookupException
|
||||
import sh.sar.basedbank.api.mib.MibSession
|
||||
@@ -61,7 +62,13 @@ class MibTransferHandler(
|
||||
val sess = session ?: return LookupOutcome(null, notFound())
|
||||
val flow = flow ?: return LookupOutcome(null, notFound())
|
||||
return try {
|
||||
LookupOutcome(MibTransferClient(flow).lookup(sess, accountNumber), null)
|
||||
val info = if (AccountInputParser.isFahipayAccount(accountNumber)) {
|
||||
// Like the MIB app: Fahipay is looked up on the WebView IPS page, not B40
|
||||
MibIpsWebClient().lookupAccount(sess, MibIpsWebClient.FAHIPAY_BIC, accountNumber)
|
||||
} else {
|
||||
MibTransferClient(flow).lookup(sess, accountNumber)
|
||||
}
|
||||
LookupOutcome(info, null)
|
||||
} catch (e: MibLookupException) {
|
||||
LookupOutcome(null, e.message)
|
||||
} catch (_: Exception) {
|
||||
@@ -127,9 +134,14 @@ class MibTransferHandler(
|
||||
val currencyCode = if (src.currencyName == "USD") "840" else "462"
|
||||
val currency = if (src.currencyName == "USD") "USD" else "MVR"
|
||||
val isDestMib = AccountInputParser.detect(destAccount) == AccountInputParser.InputType.MIB_ACCOUNT
|
||||
val isDestFahipay = AccountInputParser.isFahipayAccount(destAccount)
|
||||
if (isDestFahipay && currency != "MVR") {
|
||||
return Triple(false, ctx.getString(R.string.transfer_fahipay_mvr_only), null)
|
||||
}
|
||||
val bankNo = if (isDestMib) 2 else 3
|
||||
val toBank = when {
|
||||
isDestMib -> "MIB"
|
||||
isDestFahipay -> "Fahipay"
|
||||
else -> when (bankName.uppercase()) {
|
||||
"MALBMVMV" -> "BML"
|
||||
"MADVMVMV" -> "MIB"
|
||||
@@ -154,7 +166,21 @@ class MibTransferHandler(
|
||||
}
|
||||
val client = MibTransferClient(app.mibFlowFor(loginId))
|
||||
val send = { otp: String ->
|
||||
client.transfer(
|
||||
if (isDestFahipay) {
|
||||
// Like the MIB app: Fahipay is paid through the WebView IPS transfer, not T51
|
||||
MibIpsWebClient().transfer(
|
||||
session = sess,
|
||||
fromAccount = src.accountNumber,
|
||||
fromAccountName = src.profileName.ifBlank { src.accountBriefName },
|
||||
toAccount = destAccount,
|
||||
benefName = destName.ifBlank { "Recipient" },
|
||||
bankBic = MibIpsWebClient.FAHIPAY_BIC,
|
||||
bankNo = MibIpsWebClient.FAHIPAY_BANK_NO,
|
||||
amount = amount,
|
||||
purpose = remarks,
|
||||
otp = otp
|
||||
)
|
||||
} else client.transfer(
|
||||
session = sess,
|
||||
fromAccount = src.accountNumber,
|
||||
toAccount = destAccount,
|
||||
@@ -189,7 +215,9 @@ class MibTransferHandler(
|
||||
mibFromProfileName = src.profileName,
|
||||
mibTransactionType = transactionType
|
||||
)
|
||||
Triple(true, "BankTransaction ID: ${result.trxId}\n${result.date}", receipt)
|
||||
val msg = if (result.trxId.isBlank()) ctx.getString(R.string.transfer_processing)
|
||||
else "BankTransaction ID: ${result.trxId}\n${result.date}"
|
||||
Triple(true, msg, receipt)
|
||||
} else {
|
||||
Triple(false, result.errorMessage.ifBlank { "Transfer failed" }, null)
|
||||
}
|
||||
|
||||
@@ -286,6 +286,9 @@
|
||||
<string name="transfer_success">ފައިސާ ފޮނުވިއްޖެ</string>
|
||||
<string name="transfer_bml_contact_required_title">ކޮންޓެކްޓް ސޭވްކޮއްލާ</string>
|
||||
<string name="transfer_bml_contact_required_msg">ލިބޭ ފަރާތުގެ އެކައުންޓް ކަރަންސީ ކަށަވަރެއް ނުކުރެވުނެވެ.\n\nމި ފަރާތް ކޮންޓެކްޓެއްގެ ގޮތުގައި ސޭވްކޮށް، ރަނގަޅު ކަރަންސީ އިޚްތިޔާރުކުރުމަށްފަހު އަލުން މަސައްކަތްކޮއްލާ.</string>
|
||||
<string name="transfer_fahipay_mvr_only">ފަހިޕޭ އެކައުންޓަކަށް ފޮނުވޭނީ ރުފިޔާ އެކަންޏެވެ. ރުފިޔާ އެކައުންޓަކުން ފޮނުވާ.</string>
|
||||
<string name="transfer_processing">ޓްރާންސެކްޝަން ޕްރޮސެސްކުރަނީ</string>
|
||||
<string name="transfer_bml_contact_required_msg_fahipay">ފަހިޕޭ އެކައުންޓަކަށް ފައިސާ ފޮނުވޭނީ އެ ފަރާތެއް ކޮންޓެކްޓެއްގެ ގޮތުގައި ސޭވްކުރުމަށްފަހުގައެވެ.\n\nމި ފަރާތް ކޮންޓެކްޓެއްގެ ގޮތުގައި ސޭވްކުރުމަށްފަހު އަލުން މަސައްކަތްކޮއްލާ.</string>
|
||||
<string name="transfer_bml_contact_required_msg_bml_limit">ބީއެމްއެލް ނޫން އެކައުންޓަކަށް ޑޮލަރު ފޮނުވޭނީ އެ ފަރާތެއް ކޮންޓެކްޓެއްގެ ގޮތުގައި ސޭވްކުރުމަށްފަހުގައެވެ.\n\nމި ފަރާތް ކޮންޓެކްޓެއްގެ ގޮތުގައި ސޭވްކުރުމަށްފަހު އަލުން މަސައްކަތްކޮއްލާ.</string>
|
||||
<string name="transfer_missing_internal_id">އެކައުންޓް މަޢުލޫމާތު ފުރިހަމައެއް ނޫން - އަލުން ލޮގިންވެވަޑައިގަންނަވާ.</string>
|
||||
<string name="transfer_verify_payment">ފައިސާ ދެއްކުން ކަށަވަރުކޮއްލާ</string>
|
||||
|
||||
@@ -296,6 +296,9 @@
|
||||
<string name="transfer_success">Transfer Successful</string>
|
||||
<string name="transfer_bml_contact_required_title">Contact Required</string>
|
||||
<string name="transfer_bml_contact_required_msg">We couldn\'t verify the recipient\'s currency for this transfer.\n\nPlease save them as a contact, manually select the correct currency, then try again.</string>
|
||||
<string name="transfer_fahipay_mvr_only">Fahipay accounts can only receive MVR. Send from an MVR account.</string>
|
||||
<string name="transfer_processing">Transaction is being processed</string>
|
||||
<string name="transfer_bml_contact_required_msg_fahipay">BML\'s API requires Fahipay accounts to be saved as a contact before you can transfer to them.\n\nPlease save them as a contact, then try again.</string>
|
||||
<string name="transfer_bml_contact_required_msg_bml_limit">BML\'s API requires the recipient to be saved as a contact when sending USD to a non-BML account, even though we verified the account.\n\nPlease save them as a contact, then try again.</string>
|
||||
<string name="transfer_missing_internal_id">Account data is incomplete — please re-login to refresh.</string>
|
||||
<string name="transfer_verify_payment">Verify Payment</string>
|
||||
|
||||
@@ -265,9 +265,83 @@ Called by the official app when opening the transfer screen. Not consumed by thi
|
||||
|
||||
---
|
||||
|
||||
## WebView IPS Transfer (Fahipay)
|
||||
|
||||
The MIB app pays **Fahipay** accounts (12 digits starting with `5`) from its WebView "Quick Transfer" page, not through `B40`/`T51`. Both calls are plain form posts on the WebView host with the usual session cookies and AJAX headers (see [README](README.md)), plus `Referer: https://faisamobilex-wv-v2.mib.com.mv/transferIps/quick?dashurl=1`. Loading the page itself (`GET /transferIps/quick?dashurl=1`) isn't needed: the AJAX calls carry no token from it. HTTP `419` means the session has expired. Client: `MibIpsWebClient.kt`.
|
||||
|
||||
The page picks the destination bank explicitly from a dropdown. Each option has a BIC and a **bank list ID**, which is sent as `bankNo`. This is not the same `bankNo` as T50/T51, where `3` means "local bank":
|
||||
|
||||
| Bank | BIC | Bank list ID |
|
||||
|---|---|---|
|
||||
| Bank of Maldives (BML) | `MALBMVMV` | `1` |
|
||||
| State Bank of India (SBI) | `SBINMVMV` | `2` |
|
||||
| Maldives Islamic Bank (MIB) | `MADVMVMV` | `3` |
|
||||
| Bank of Ceylon (BOC) | `BCEYMVMV` | `4` |
|
||||
| The Mauritius Commercial Bank (MCB) | `MCBLMVMV` | `7` |
|
||||
| Dhiraagu Fintech (DHI) | `DHIRMVMV` | `8` |
|
||||
| Habib Bank Limited (HBL) | `HABBMVMV` | `9` |
|
||||
| Commercial Bank of Maldives (CBMV) | `CBMVMVMV` | `10` |
|
||||
| FahiPay (FHI) | `FAHIMVMV` | `13` |
|
||||
|
||||
Only Fahipay goes through this page in the app. Other banks still use `B40`/`T51`.
|
||||
|
||||
### Lookup
|
||||
|
||||
```
|
||||
POST https://faisamobilex-wv-v2.mib.com.mv/AjaxAlias/getIPSAccount
|
||||
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
|
||||
|
||||
benefBank=FAHIMVMV&benefAccount=500000000000
|
||||
```
|
||||
|
||||
```json
|
||||
{"success":true,"responseCode":"2","reasonCode":"201","reasonText":"Request Successful. Account Found","accountName":"Account Holder Name","bankBic":"FAHIMVMV"}
|
||||
```
|
||||
|
||||
No currency is returned: the page fixes the transfer currency to MVR (`462`). Errors come back as a non-2xx status with the same JSON shape; `reasonText` explains why. `reasonCode` `220` makes the page let the user type the name.
|
||||
|
||||
### Transfer
|
||||
|
||||
```
|
||||
POST https://faisamobilex-wv-v2.mib.com.mv/ajaxIPSTransfer/transferIPSLocal
|
||||
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
|
||||
|
||||
benefName=Account+Holder+Name&benefNo=0&fromAccountNo=90100000000001000&fromAccountName=Sender+Name
|
||||
&benefAccountNo=500000000000&transferCy=462&benefCurrencyCode=&amount=1&bankNo=13&purpose=-
|
||||
&otp=123456&otpType=3&bankBic=FAHIMVMV
|
||||
```
|
||||
|
||||
| Field | Value |
|
||||
|---|---|
|
||||
| `benefNo` | `0`: no saved contact needed |
|
||||
| `fromAccountName` | Sender's name |
|
||||
| `transferCy` | `462` (MVR) |
|
||||
| `benefCurrencyCode` | Empty |
|
||||
| `bankNo` | Bank list ID (`13`) |
|
||||
| `purpose` | `-` when empty |
|
||||
| `otpType` | `3` (TOTP) |
|
||||
| `bankBic` | `FAHIMVMV` |
|
||||
|
||||
```json
|
||||
{"success":true,"responseCode":"2","reasonText":"Favara request transfer completed","reasonCode":"2011","data":[{"date":"2026-01-01 12:00:00","trxId":"800000000"}]}
|
||||
```
|
||||
|
||||
How the page reads a `success: true` response:
|
||||
|
||||
| Condition | Meaning |
|
||||
|---|---|
|
||||
| `data[0].trxId == 0` or `data[0].date == null` | Being processed |
|
||||
| `reasonCode` `2011` / `2012` | Completed |
|
||||
| `reasonCode` `2091` | Submitted, not completed yet |
|
||||
| Any other `reasonCode` | Awaiting approval |
|
||||
|
||||
All of these mean the transfer was accepted, so the client reports success for every one of them. It never shows a failure that would invite the user to send again.
|
||||
|
||||
---
|
||||
|
||||
## `MibIpsAccountInfo` (client model)
|
||||
|
||||
`B40` lookups are mapped into this structure (`MibModels.kt`):
|
||||
`B40` and WebView IPS lookups are mapped into this structure (`MibModels.kt`):
|
||||
|
||||
| Field | Description |
|
||||
|---|---|
|
||||
|
||||
Reference in New Issue
Block a user