add support to detect dhiraagu and ooredoo packages

This commit is contained in:
2026-05-17 00:25:48 +05:00
parent 93405aade2
commit ccc9e11d55
9 changed files with 781 additions and 3 deletions
@@ -0,0 +1,71 @@
package sh.sar.basedbank.api.dhiraagu
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONObject
import java.util.concurrent.TimeUnit
class DhiraaguClient {
private val client = OkHttpClient.Builder()
.connectTimeout(15, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.build()
enum class CustType { RELOAD, BILL_PAY, UNSUPPORTED }
companion object {
private const val UA = "Mozilla/5.0 (X11; Linux x86_64; rv:150.0) Gecko/20100101 Firefox/150.0"
}
data class Result(val type: CustType, val ownerName: String = "")
fun validateNumber(number: String): Result {
// Step 1: fetch Easy Pay page to extract the nonce
val pageResp = client.newCall(
Request.Builder()
.url("https://www.dhiraagu.com.mv/services/easy-pay")
.header("User-Agent", UA)
.get()
.build()
).execute()
val html = pageResp.body?.string() ?: return Result(CustType.UNSUPPORTED)
pageResp.close()
val nonce = Regex("""var nonce = "([^"]+)"""").find(html)
?.groupValues?.getOrNull(1) ?: return Result(CustType.UNSUPPORTED)
// Step 2: look up number
val body = """{"number":"$number"}"""
.toRequestBody("application/json".toMediaType())
val resp = client.newCall(
Request.Builder()
.url("https://www.dhiraagu.com.mv/api/sdk-dhr-webapi.ashx?website_id=CA2BB809-3A22-485B-A518-DA6B6DE653A5&sub=dhiraaguIO&act=infoUnlisted")
.post(body)
.header("User-Agent", UA)
.header("nonce", nonce)
.header("Origin", "https://dhiraagu.com.mv")
.build()
).execute()
val json = resp.body?.string() ?: return Result(CustType.UNSUPPORTED)
resp.close()
return try {
val obj = JSONObject(json)
if (obj.optString("respStatus") != "OK") return Result(CustType.UNSUPPORTED)
val prepaid = obj.optJSONArray("serviceDetails")
?.optJSONObject(0)
?.optString("prepaidIndicator")
val ownerName = obj.optJSONObject("accountOwnerInfo")
?.optString("name") ?: ""
val type = when (prepaid) {
"Y" -> CustType.RELOAD
"N" -> CustType.BILL_PAY
else -> CustType.UNSUPPORTED
}
Result(type, ownerName)
} catch (_: Exception) { Result(CustType.UNSUPPORTED) }
}
}
@@ -0,0 +1,43 @@
package sh.sar.basedbank.api.fahipay
import okhttp3.OkHttpClient
import okhttp3.Request
import org.json.JSONObject
import java.util.concurrent.TimeUnit
class OoredooClient {
private val client = OkHttpClient.Builder()
.connectTimeout(15, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.build()
enum class CustType { PRE, POST, HYBRID, UNSUPPORTED }
/**
* Validates an Ooredoo number and returns which services are supported.
* @param number 7-digit Maldivian phone number (without country code)
*/
fun validateNumber(number: String): CustType {
val resp = client.newCall(
Request.Builder()
.url("https://www.ooredoo.mv/ooredoo-prod/QuickPayPackage/v1/numberTypeValidation?action=cust_details&msisdn=960$number")
.get()
.build()
).execute()
val json = resp.body?.string() ?: return CustType.UNSUPPORTED
resp.close()
return try {
val custType = JSONObject(json)
.optJSONObject("data")
?.optString("custType")
?.takeIf { it.isNotBlank() && it != "null" }
when (custType) {
"PRE" -> CustType.PRE
"POST" -> CustType.POST
"HYBRID" -> CustType.HYBRID
else -> CustType.UNSUPPORTED
}
} catch (_: Exception) { CustType.UNSUPPORTED }
}
}