Created
October 6, 2023 13:44
-
-
Save soham2008xyz/25474b0f42d7e541fd2b3dc9bfed0bb9 to your computer and use it in GitHub Desktop.
doOnlineProcess.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun doOnlineProcess(): String { | |
val onlineResult = StringBuffer() | |
val rEMVCardData: CardData = rEMV.uSDKprocessCardRecord(null) | |
cardDataBundle = Bundle() | |
cardDataBundle?.putParcelable(Flags.CARD_DATA_PARCEL, rEMVCardData) | |
// TODO: 5A33 to be set in case the transaction is not completed from the server end | |
// All the responses received from the server is to be converted to HEX | |
val flowtype = lastCardRecord?.flowType?.toInt() | |
if (flowtype == FlowType.EMV_FLOWTYPE_M_CHIP) { | |
Log.i(Flags.uSDK_FLAG, "doOnlineProcess: Flags.RF_CARD_READ_SUCCESS") | |
rEMVCallback.emvStatus(Flags.RF_CARD_READ_SUCCESS, cardDataBundle, object : TransactionResponse { | |
override fun responseParams(success: Boolean, responseData: String?, responseCode: String?) { | |
val hostRespCode = BytesUtil.asciiToHex(responseCode) | |
onlineResult.append(EMVTag.DEF_TAG_ONLINE_STATUS).append("01").append("00") | |
if (responseData != null) | |
onlineResult.append(responseData) | |
// TODO: Set three more tags here - 91, 71, 72. | |
if (responseCode != null && success) { | |
onlineResult.append(EMVTag.EMV_TAG_TM_ARC).append("02").append(hostRespCode) | |
Log.e("HostResponseCode", "$responseCode $hostRespCode") | |
rEMV.setTransactionSuccessStatus(true) | |
} else { | |
// @TODO: onlineResult.append(EMVTag.EMV_TAG_TM_ARC).append("02").append(hostRespCode) | |
onlineResult.append(EMVTag.EMV_TAG_TM_ARC).append("02").append(hostRespCode) | |
rEMV.respondEvent(onlineResult.toString()) | |
rEMVCallback.emvStatus(Flags.CARD_TRANSACTION_FAIL, null, null) | |
return | |
} | |
onlineResult.append(EMVTag.DEF_TAG_AUTHORIZE_FLAG).append("01").append(if (success) "01" else "00") | |
val terminalResponse = rEMV.respondEvent(onlineResult.toString()) | |
if (terminalResponse != 0) rEMVCallback.emvStatus(Flags.CARD_TRANSACTION_FAIL, null, null) | |
else rEMVCallback.emvStatus(Flags.CARD_TRANSACTION_SUCCESS, null, null) | |
} | |
}) | |
} else { | |
Log.i(Flags.uSDK_FLAG, "doOnlineProcess: CardStatus.READ_CARD_RECORD_SUCCESS") | |
rEMVCallback.emvStatus(CardStatus.READ_CARD_RECORD_SUCCESS, cardDataBundle, object : TransactionResponse { | |
override fun responseParams(success: Boolean, responseData: String?, responseCode: String?) { | |
onlineResult.append(EMVTag.DEF_TAG_ONLINE_STATUS).append("01").append("00") | |
if (responseData != null) | |
onlineResult.append(responseData) | |
if (responseCode != null && success) { | |
val hostRespCode = BytesUtil.asciiToHex(responseCode) | |
onlineResult.append(EMVTag.EMV_TAG_TM_ARC).append("02").append(hostRespCode) | |
Log.e("HostResponseCode", "$responseCode $hostRespCode") | |
rEMV.setTransactionSuccessStatus(true) | |
} else { | |
rEMVCallback.emvStatus(Flags.CARD_TRANSACTION_FAIL, null, null) | |
return | |
} | |
onlineResult.append(EMVTag.DEF_TAG_AUTHORIZE_FLAG).append("01").append(if (success) "01" else "00") | |
val terminalResponse = rEMV.respondEvent(onlineResult.toString()) | |
Log.e("TerminalResponse", terminalResponse.toString()) | |
// auto reverse the transaction if response from the terminal is non zero | |
if (terminalResponse != 0) rEMVCallback.emvStatus(Flags.CARD_TRANSACTION_FAIL, null, null) | |
else rEMVCallback.emvStatus(Flags.CARD_TRANSACTION_SUCCESS, null, null) | |
} | |
}) | |
} | |
return onlineResult.toString() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment