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.

copy
fun initConnect(
    deviceKey: DeviceKey,
    globalConfig: GlobalConfig? = null,
    connectListener: ConnectListener
)

Parameters

Parameter name

Type

Required

Description

deviceKey

UsbDeviceKey

Yes

Indicates the object that contains the parameters that must be passed for the USB connection.

globalConfig

GlobalConfig

No

Indicates the global configuration of the payment terminal.

callback

ConnectListener

Yes

The callback that is used to return the query result. See callback for details.

callback

Parameter name

Type

Required

Description

result

ConnectListener

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:

copy
class UsbDeviceKey(val context: Context, val usbDevice: UsbDevice) : DeviceKey
copy
PaymentManager.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

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.

TERMINAL_NOT_LOGIN

The terminal device is not logged in.Log in to the terminal device by entering the password.

PAYMENT_FAILED

Payment failed.Confirm that both the POS and the terminal are connected to the network

PAYMENT_CANCELLED

Payment canceled.After the payment is interrupted or canceled from the terminal device side, the result code will be synchronized to the host.