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,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 }
}
}