ready for prod
This commit is contained in:
@@ -1,24 +1,27 @@
|
||||
|
||||
package net.ipksindia
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import model.NeftTransaction
|
||||
import model.TransferTransaction
|
||||
import net.ipksindia.model.NeftTransaction
|
||||
import net.ipksindia.model.TransferTransaction
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
import response.TransactionFailureResponse
|
||||
import response.TransactionResponse
|
||||
import response.TransactionSuccessResponse
|
||||
import java.io.IOException
|
||||
import javax.net.ssl.HostnameVerifier
|
||||
|
||||
|
||||
class TransactionExecutor() {
|
||||
|
||||
private val protocol = "http"
|
||||
private val host = "localhost"
|
||||
private val port = "8080"
|
||||
private val rootRoute = "WESTBANGAL/api"
|
||||
private val protocol = "https"
|
||||
private val host = "180.179.119.227"
|
||||
private val port = "443"
|
||||
private val rootRoute = "IPKS_Queue_Generation"
|
||||
private val remoteUrl = "$protocol://$host:$port/$rootRoute"
|
||||
|
||||
fun executePair(transactionPair: Pair<TransferTransaction, NeftTransaction>): Pair<TransactionResponse, TransactionResponse> {
|
||||
@@ -31,13 +34,18 @@ class TransactionExecutor() {
|
||||
}
|
||||
|
||||
private fun execute(postBody: String): TransactionResponse {
|
||||
val transferRoute = "IPKSNeftRtgsApiTransfer"
|
||||
|
||||
val transferRoute = "Ipks"
|
||||
val transferURL = "$remoteUrl/$transferRoute"
|
||||
val jsonMediaType = "application/json; charset=utf-8".toMediaType()
|
||||
|
||||
val httpClient = OkHttpClient()
|
||||
val httpClient = OkHttpClient
|
||||
.Builder()
|
||||
.hostnameVerifier(HostnameVerifier { _, _ -> true })
|
||||
.build()
|
||||
|
||||
val request = Request.Builder()
|
||||
val request = Request
|
||||
.Builder()
|
||||
.url(transferURL)
|
||||
.post(postBody.toRequestBody(jsonMediaType))
|
||||
.build()
|
||||
@@ -49,10 +57,17 @@ class TransactionExecutor() {
|
||||
response.body!!.string()
|
||||
}
|
||||
|
||||
val responseObj = JSONObject(responseBody)
|
||||
val status = try {responseObj.getString("status") } catch(_: JSONException) { "" }
|
||||
val message = try { responseObj.getString("message") }catch(_: JSONException) { "" }
|
||||
val error = try { responseObj.getInt("error") } catch(_: JSONException) { 1 }
|
||||
|
||||
val response = if(responseBody.contains("SUCCESS")) {
|
||||
Json.decodeFromString<TransactionSuccessResponse>(responseBody)
|
||||
val queueNo = try { responseObj.getJSONObject("response").getString("QueueId") } catch(_: JSONException) { "" }
|
||||
return TransactionSuccessResponse(status, message, queueNo, error)
|
||||
} else {
|
||||
Json.decodeFromString<TransactionFailureResponse>(responseBody)
|
||||
val errorMsg = try { responseObj.getJSONObject("response").getString("errorMsg") } catch(_: JSONException) { "no error message provided" }
|
||||
return TransactionFailureResponse(status, message, errorMsg, error)
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user