SDK Functions Code Samples

This guide will provide you with guidance on various code samples that you can use to enable various functions that we have in our Android SDK.

📘

Note:

The code samples shown here are the backend of the program and not including the interface. You can modify the interface as needed when you build your own app.

1. Authentication

You should start with the authentication first when you use our Android SDK. There are log in and log out functions within authentication.

1.1 Log in

To enable the login function, simply follow the code below:

Code sample:

RmsClient.signIn(this, object : RmsAuthCallback {
                override fun success(accessToken: String, refreshToken: String) {
                    ApplicationGlobal.accessToken = accessToken
                    ApplicationGlobal.refreshToken = refreshToken
                    startActivity(Intent([email protected], HomeActivity::class.java))
                    finishAffinity()
                }

                override fun error(exception: RmsAuthException) {
                }

                override fun signOut() {

                }
            })

2. Select the terminal

To enable the terminal selection function, please refer to the code sample below.

Code sample:

RmsClient.getTerminalsList(object : RmsApiCallback<ModelTerminal> {
            override fun success(data: ModelTerminal?) {
                isShowLoader.value = false
                data?.let {
                    terminalList.value = data
                }
            }

            override fun error(exception: RmsApiException) {
                isShowLoader.value = false
                snackbarMessage.value = exception.apiError.message
            }
        })

3. Initiate a sale

To enable the sale, refund, and cashback initiation function, please refer to the code sample below.

Code sample:

RmsClient.createTransaction(
            amount,
            CurrencyCode.POUND,
            saleType,
            cashBackAmount,
            object : RmsApiCallback<Transaction> {
                override fun success(data: Transaction?) {
                    transactionOngoing.value = false
                    data?.let {
                        val list = arrayListOf<Transaction>()
                        list.addAll(transactionListInfo.value ?: emptyList())
                        list.add(data)
                        transactionListInfo.value = list
                        scrollListToBottom.value = true
                    }

                }

                override fun error(exception: RmsApiException) {
                    transactionOngoing.value = false
                    snackbarMessage.value = exception.apiError.message
                }
            })

4. Cancel transaction

To enable the transaction cancellation function, please refer to the code sample below.

Code sample:

RmsClient.cancelTransaction(transaction.getTransactionId(),
            object : RmsApiCallback<Void> {
                override fun error(exception: RmsApiException) {
                    isShowLoader.value = false
                    snackbarMessage.value = exception.apiError.message
                }

                override fun success(data: Void?) {
                    isShowLoader.value = false
                    onCancelTransactionSuccess.value = true
                }
            })

5. List/filter transactions

You can list/filter the transactions by status, type, and, transaction ID. To do that, please refer to the code sample below.

Code sample:

RmsClient.searchTransactions(terminalId = terminalId,
            transactionStatus = transactionStatus,
            transactionType = transactionType,
            callback = object : RmsApiCallback<ModelTransaction> {
                override fun error(exception: RmsApiException) {
                    isShowLoader.value = false
                    snackbarMessage.value = exception.apiError.message
                }

                override fun success(data: ModelTransaction?) {
                    isShowLoader.value = false
                    data?.let {
                        transactionList.value = data
                    }
                }
            })

6. Retrieve the status of the transactions

To retrieve the status of the transactions, please refer to the code sample below.

Code sample:

RmsClient.checkStatus(transaction.getTransactionId(),
            object : RmsApiCallback<Transaction> {
                override fun success(data: Transaction?) {
                    isShowLoader.value = false
                    data?.let {
                        val list = arrayListOf<Transaction>()
                        transactionListInfo.value?.forEach { item ->
                            if (item.getTransactionId() == data.getTransactionId()) {
                                list.add(data)
                            } else {
                                list.add(item)
                            }
                        }
                        transactionListInfo.value = list
                    }
                }

                override fun error(exception: RmsApiException) {
                    isShowLoader.value = false
                    snackbarMessage.value = exception.apiError.message
                }
            })

7. View all transactions

To enable view all transactions function, please refer to the code sample below.

Code sample:

RmsClient.getTransactionsList(object : RmsApiCallback<ModelTransaction> {
            override fun error(exception: RmsApiException) {
                isShowLoader.value = false
                snackbarMessage.value = exception.apiError.message
            }

            override fun success(data: ModelTransaction?) {
                isShowLoader.value = false
                data?.let {
                    transactionList.value = data
                }
            }
        })

8. Start an XBAL and ZBAL Report

To enable the XBAL and ZBAL report generator function, please refer to the code sample below.

Code sample:

RmsClient.requestReportByType(reportType, object : RmsApiCallback<Void> {
            override fun error(exception: RmsApiException) {
                isShowLoader.value = false
                snackbarMessage.value = exception.apiError.message
            }

            override fun success(data: Void?) {
                isShowLoader.value = false
                onReportSuccess.value = true
            }

        })

💬 We're here to help!

If you're looking for help, shoot us an email. Please include a description of the issues that you are running into.


Did this page help you?