initConnection
The initConnection API is called by the POS to initialize the connection and check the communication between the POS and payment terminal. Ensure that you call the initConnection API first before creating a payment request.
Method signature
When calling this method, please use the following standard method signature format.
fun initConnect(
deviceKey: DeviceKey,
globalConfig: GlobalConfig? = null,
connectListener: ConnectListener
)Parameters
Parameter name | Type | Required | Description |
deviceKey | Yes | Indicates the object that contains the parameters that must be passed for the USB connection. | |
globalConfig | No | Indicates the global configuration of the payment terminal. | |
callback | Yes | The callback that is used to return the query result. See callback for details. |
callback
Parameter name | Type | Required | Description |
result | No | Indicates the communication status between the POS and payment terminal. |
Return values
This method does not return any value.
Samples
After calling the initConnection API, if the initialization is successful, a Connected successfully response will be returned:
class UsbDeviceKey(val context: Context, val usbDevice: UsbDevice) : DeviceKeyPaymentManager.initConnect(
UsbDeviceKey(applicationContext, usbDevice),
GlobalConfig(15000L, true),
object : ConnectListener {
override fun onConnectSuccess() {
runOnUiThread {
Toast.makeText(this@UsbHotScanActivity, "Connected successfully", Toast.LENGTH_SHORT).show()
tvStatus.text = "Status: Connected successfully"
}
}
override fun onConnectFailure(e: Exception) {
runOnUiThread {
Toast.makeText(this@UsbHotScanActivity, "Failed to connect. Check the USB connection.", Toast.LENGTH_SHORT).show()
tvStatus.text = "Status: Failed to connect"
}
}
}
)Error codes
The following table lists the possible result codes and error codes that can be returned by the initConnection API:
Result/error codes | Description | Further action |
| SDK initialization failed. | Confirm that both the POS and the terminal device are connected to the network. If the POS client initialization fails, provide the client-side message from the host system and check the SDK's input parameters. |
| The terminal device is not logged in. | Log in to the terminal device by entering the password. |
| Payment failed. | Confirm that both the POS and the terminal are connected to the network |
| Payment canceled. | After the payment is interrupted or canceled from the terminal device side, the result code will be synchronized to the host. |