Added remitterAddress, beneficiaryName, beneficiaryAddress, senderAcctType, beneficiaryAcctType, beneficiaryBankName, beneficiaryBranchName, commissionAmount to transactions as told by C-Edge. Also removed errorMsg from TransactionFailureResponse class. Refactored code for more readability. Removed application logs from STDOUT.

This commit is contained in:
2024-10-24 12:39:07 +05:30
parent df7d0e8006
commit 6c5dab0a17
12 changed files with 100 additions and 51 deletions

View File

@@ -4,19 +4,19 @@ import kotlinx.serialization.json.Json
import net.ipksindia.config.AppConfig
import net.ipksindia.model.NeftTransaction
import net.ipksindia.model.TransferTransaction
import net.ipksindia.response.TransactionFailureResponse
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONObject
import org.slf4j.LoggerFactory
import response.TransactionFailureResponse
import response.TransactionResponse
import response.TransactionSuccessResponse
import java.io.IOException
class TransactionExecutor() {
class TransactionExecutor {
private val logger = LoggerFactory.getLogger(TransactionExecutor::class.java)
private val transactionUrl = AppConfig.remoteServerConfig.transactionUrl
@@ -24,17 +24,18 @@ class TransactionExecutor() {
val transferTransaction = transactionPair.first
val neftTransaction = transactionPair.second
logger.debug("TRF-RRN: {}, NEFT-RRN: {}", transferTransaction.rrn, neftTransaction.rrn)
val transferResponseString = execute(Json.encodeToString(transferTransaction))
logger.debug("TRANSFER-RRN: {} - CBS Response: {}", transferTransaction.rrn, transferResponseString)
val transferResponse = processResponse(transferResponseString)
val neftResponseString = execute(Json.encodeToString(neftTransaction))
logger.debug("NEFT-RRN: {}, CBS Response: {}", neftTransaction.rrn, neftResponseString)
val neftResponse = processResponse(neftResponseString)
return Pair(transferResponse, neftResponse)
}
private fun execute(postBody: String): String {
logger.debug("request: {}", postBody)
val jsonMediaType = "application/json; charset=utf-8".toMediaType()
val httpClient = OkHttpClient
@@ -52,7 +53,9 @@ class TransactionExecutor() {
if (!response.isSuccessful) {
throw IOException("Unexpected response: ${response.body}")
}
response.body?.string() ?: throw IOException("no response body")
val responseString = response.body?.string() ?: throw IOException("no response body")
logger.debug("response: {}", responseString)
responseString
}
}
@@ -63,14 +66,11 @@ class TransactionExecutor() {
val message = responseObj.getString("message")
val error = responseObj.getInt("error")
if(responseBody.contains("SUCCESS")) {
return if (responseBody.contains("SUCCESS")) {
val queueNo = responseObj.getJSONObject("response").getString("QueueId")
return TransactionSuccessResponse(status, message, queueNo, error)
TransactionSuccessResponse(status, message, queueNo, error)
} else {
val errorMsg = responseObj.getJSONObject("response").getString("errorMsg")
return TransactionFailureResponse(status, message, errorMsg, error)
TransactionFailureResponse(status, message, error)
}
}
}
}