-
Notifications
You must be signed in to change notification settings - Fork 0
ATS Client
The ATS SDK includes a communication client for sending messages to/from an ATS server. This component handles connecting to ATS over a persistent socket connection and returns messages to your app thru a simple callback.
To configure the ATS client, you must provide the IP address and communication port of the ATS server.
import com.mastercard.gateway.ats.ATSClient
val atsClient = ATSClient()
val atsIpAddress = "1.1.1.1"
val atsPort = 20002
atsClient.connect(atsIpAddress, atsPort)
import com.mastercard.gateway.ats.domain.ATSMessage
import com.mastercard.gateway.ats.domain.CardServiceResponse
import com.mastercard.gateway.ats.domain.DeviceRequest
val callback = object : ATSClient.Callback() {
override fun onConnect() {}
override fun onDisconnect() {}
override fun onMessageReceived(message: ATSMessage?) {
// handle the message
if (message is CardServiceResponse) {
// handle card service response
} else if (message is DeviceRequest) {
// handle device request
}
}
override fun onError(throwable: Throwable) {}
}
atsClient.addCallback(callback)
You can also subsequently remove a callback during tear down routines
atsClient.removeCallback(callback)
When you are ready to run a transaction with ATS, you first connect to the server.
atsClient.connect(atsIpAddress, atsPort)
Once you have successfully connected to ATS, you may begin sending/receiving messages.
Important Note:
After the transaction is complete, it is an ATS requirement that you disconnect in order to complete the transaction. Once you receive your desired response, close the ATS client.
atsClient.close()
To send a message to ATS, you may construct a fully qualified message using the provided domain objects.
val posData = CardServiceRequest.POSData()
posData.posTimeStamp = Date()
posData.transactionNumber = transactionNumber
posData.reference = reference
val totalAmountType = TotalAmountType()
totalAmountType.value = BigDecimal(amount)
totalAmountType.paymentAmount = BigDecimal(amount)
// create the CardServiceRequest and populate the optional fields that we need for this transaction.
val request = CardServiceRequest()
request.requestType = CardRequestType.CardPayment
request.workstationID = "some workstation ID"
request.requestID = "1"
request.applicationSender = "ATSClient"
request.posData = posData
request.totalAmount = totalAmountType
// send the request
atsClient.sendMessage(request)
Or, you may also send plain XML string messages. The send
message on iOS supports sending xml as a string and sending of an XML object.
val xmlMessage = "<?xml version=\"1.0\"?>" +
"<CardServiceRequest RequestType=\"CardTokenise\" ApplicationSender=\"ATSClient\" WorkstationID=\"12341234\" RequestID=\"1\">" +
"<POSdata>" +
"<POSTimeStamp>2012-05-15T14:30:00</POSTimeStamp>" +
"<TransactionNumber>1</TransactionNumber>" +
"</POSdata>" +
"</CardServiceRequest>"
// send the request
atsClient.sendMessage(xmlMessage)