all the application configurations has been defined in application.conf, application-dev.conf and application-prod.conf. Also made the ktor server configuration in external file.

This commit is contained in:
2024-09-28 01:26:57 +05:30
parent 48877ddcec
commit 0516c2c964
9 changed files with 178 additions and 138 deletions

View File

@@ -1,6 +1,7 @@
package net.ipksindia
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import net.ipksindia.config.AppConfig
import net.ipksindia.model.NeftTransaction
import net.ipksindia.model.TransferTransaction
import okhttp3.MediaType.Companion.toMediaType
@@ -18,11 +19,7 @@ import javax.net.ssl.HostnameVerifier
class TransactionExecutor() {
private val protocol = "https"
private val host = "180.179.110.185"
private val port = "443"
private val rootRoute = "IPKS_Queue_Generation"
private val remoteUrl = "$protocol://$host:$port/$rootRoute"
private val transactionUrl = AppConfig.remoteServerConfig.transactionUrl
fun executePair(transactionPair: Pair<TransferTransaction, NeftTransaction>): Pair<TransactionResponse, TransactionResponse> {
@@ -36,8 +33,6 @@ class TransactionExecutor() {
private fun execute(postBody: String): TransactionResponse {
// println(postBody)
val transferRoute = "IpksApi"
val transferURL = "$remoteUrl/$transferRoute"
val jsonMediaType = "application/json; charset=utf-8".toMediaType()
val httpClient = OkHttpClient
@@ -47,7 +42,7 @@ class TransactionExecutor() {
val request = Request
.Builder()
.url(transferURL)
.url(transactionUrl)
.post(postBody.toRequestBody(jsonMediaType))
.build()
@@ -63,14 +58,14 @@ class TransactionExecutor() {
val message = try { responseObj.getString("message") }catch(_: JSONException) { "" }
val error = try { responseObj.getInt("error") } catch(_: JSONException) { 1 }
val response = if(responseBody.contains("SUCCESS")) {
if(responseBody.contains("SUCCESS")) {
val queueNo = try { responseObj.getJSONObject("response").getString("QueueId") } catch(_: JSONException) { "" }
return TransactionSuccessResponse(status, message, queueNo, error)
} else {
val errorMsg = try { responseObj.getJSONObject("response").getString("errorMsg") } catch(_: JSONException) { responseBody }
return TransactionFailureResponse(status, message, errorMsg, error)
}
return response
}
}