Skip to main content

WiseCashier-SDK for Android

info

This feature is currently under development and is expected to be available in an upcoming release. Thank you for your interest and patience!

WiseCashier-SDK Andorid provides a fast connection to WiseCashier via WLAN for POS Application, and provides interfaces for payment, refund, query, etc. for POS Application to call.

Get started with our example projects

Features

  • Quick Connect: Register-SDK uses mDNS, start the SDK, in the WiseCashier APP can quickly find all the POS Application devices, click on the pairing, realize the automatic connection.
  • Payment: This SDK provides a variety of payment methods, including code scanning bank cards, and also provides a lot of medium payment capabilities, such as consumption, revocation, refund, pre-authorization, pre-authorization completion and so on.
  • Client Manager: In LAN mode, WiseCashier acts as a Server, and the SDK is capable of connecting to multiple Servers, and the SDK provides methods to manage the Servers.

Installation

Requirements

  • Android Studio Giraffe | 2022.3.1 Patch 3
  • kotlin showLineNumbers1.3.41
  • gradle4.2.2
  • Java11
  • Android 8.0 (API level 26) and above

Configuration

  1. Add ecrhub-client-sdk-android to your build.gradle dependencies.
dependencies {
implementation 'com.github.paycloud-open:ecrhub-client-sdk-android:1.0.5'
}
  1. You can use the ecr_sdk module from GitHub as a library module for your app.

Function List

1 Device discovery and pairing

note

Only WLAN connection mode requires pairing first, USB connection mode does not require pairing.

1.1 Start/Stop Device Discovery Service

The terminal can only discover your POS application when the device discovery service is started

  • After completing a pairing operation, the terminal and POS application will record each other's network information
  • When pairing and connecting to the network are required, the device discovery service needs to be enabled
import com.wiseasy.ecr.sdk.EcrWifiDiscoveryService

val discoveryService = EcrWifiDiscoveryService(context)

//start device discover service
discoveryService.start(object : EcrPairListener {
override fun onDevicePair(data: EcrMessageData, ip: String) {
}

override fun onDeviceUnpair(data: EcrMessageData) {
}

})

//stop device discover service
discoveryService.stop()

1.2 Get a list of paired terminals

  • When using POS applications to push orders, you can select a device from the paired device list to push the order;
  • When POS applications need to display paired POS terminals, this function can be used to obtain a list of paired devices for display.
val mPairedList = discoveryService.pairedDeviceList

1.3 Remove paired terminals

When the POS terminal is no longer in use, it can be manually removed from the paired list of the POS application.

discoveryService.unPair(mPairedList[0])

2 Connect

Select a paired terminal to initiate a network connection, and once the connection is established, transaction instructions can be sent.

2.1 Call process

Register SDK for Android call flowchart

2.2 Create client instance

WLAN connection mode When a POS application connects to a POS terminal using WLAN, use the following method to create a client

import com.wiseasy.ecr.sdk.EcrClient

val mClient = EcrClient.getInstance()

mClient.init(context, object : EcrConnectListener{
override fun onConnect() {
}

override fun onDisconnect() {
}

override fun onError(errorCode: String, errorMsg: String) {
}

})

2.3 Connection

Establish a connection between the POS application and the POS terminal.

/// Connecting to the POS Terminal
mClient .connectWifi("ws://xxxxxx")

2.4 Disconnect

Disconnect the POS application from the POS terminal.

// This will try disconnect from POS Terminal
mClient.disConnect()

3 Transactions

3.1 Purchase/Sale

  1. Request/Response parameters
  2. Example:
val params = PaymentRequestParams()
params.app_id = "you payment app id"
params.topic = Constants.PAYMENT_TOPIC
params.timestamp = System.currentTimeMillis().toString()

params.biz_data = PaymentRequestParams.BizData()
params.biz_data.trans_type = Constants.TRANS_TYPE_SALE
params.biz_data.order_amount = "1.1"
params.biz_data.merchant_order_no = "1234567890"
params.biz_data.pay_scenario = "SWIPE_CARD"
params.biz_data.isConfirm_on_terminal = false

val json = JSON.toJSONString(params)

mClient.doTransaction(json, object : EcrResponseCallBack {
override fun onError(errorCode: String, errorMsg: String) {
}

override fun onSuccess(data: String) {
}
})

3.2 Cashback

  1. Request/Response parameters
  2. Example:
val params = PaymentRequestParams()
params.app_id = "you payment app id"
params.topic = Constants.PAYMENT_TOPIC
params.timestamp = System.currentTimeMillis().toString()

params.biz_data = PaymentRequestParams.BizData()
params.biz_data.trans_type = Constants.TRANS_TYPE_CASH_BACK
params.biz_data.order_amount = "1.1"
params.biz_data.cashback_amount = "1.1"
params.biz_data.merchant_order_no = "1234567890"
params.biz_data.pay_scenario = "SWIPE_CARD"
params.biz_data.isConfirm_on_terminal = false

val json = JSON.toJSONString(params)

mClient.doTransaction(json, object : EcrResponseCallBack {
override fun onError(errorCode: String, errorMsg: String) {
}

override fun onSuccess(data: String) {
}
})

3.3 Pre-auth

  1. Request/Response parameters
  2. Example:
val params = PaymentRequestParams()
params.app_id = "you payment app id"
params.topic = Constants.PAYMENT_TOPIC
params.timestamp = System.currentTimeMillis().toString()

params.biz_data = PaymentRequestParams.BizData()
params.biz_data.trans_type = Constants.TRANS_TYPE_PRE_AUTH
params.biz_data.order_amount = "1.1"
params.biz_data.merchant_order_no = "1234567890"
params.biz_data.pay_scenario = "SWIPE_CARD"
params.biz_data.isConfirm_on_terminal = false

val json = JSON.toJSONString(params)

mClient.doTransaction(json, object : EcrResponseCallBack {
override fun onError(errorCode: String, errorMsg: String) {
}

override fun onSuccess(data: String) {
}
})

3.4 Pre-auth Completion

  1. Request/Response parameters
  2. Example:
val params = PaymentRequestParams()
params.app_id = "you payment app id"
params.topic = Constants.PAYMENT_TOPIC
params.timestamp = System.currentTimeMillis().toString()

params.biz_data = PaymentRequestParams.BizData()
params.biz_data.trans_type = Constants.TRANS_TYPE_PRE_AUTH_COMPLETE
params.biz_data.order_amount = "1.1"
params.biz_data.merchant_order_no = "1234567891"
params.biz_data.orig_merchant_order_no = "1234567890"
params.biz_data.pay_scenario = "SWIPE_CARD"
params.biz_data.isConfirm_on_terminal = false

val json = JSON.toJSONString(params)

mClient.doTransaction(json, object : EcrResponseCallBack {
override fun onError(errorCode: String, errorMsg: String) {
}

override fun onSuccess(data: String) {
}
})

3.5 Void/Cancellation

  1. Request/Response parameters
  2. Example:
val params = PaymentRequestParams()
params.app_id = "you payment app id"
params.topic = Constants.PAYMENT_TOPIC
params.timestamp = System.currentTimeMillis().toString()

params.biz_data = PaymentRequestParams.BizData()
params.biz_data.trans_type = Constants.TRANS_TYPE_VOID
params.biz_data.order_amount = "1.1"
params.biz_data.merchant_order_no = "1234567890"
params.biz_data.orig_merchant_order_no = "1234567891"
params.biz_data.pay_scenario = "SWIPE_CARD"
params.biz_data.isConfirm_on_terminal = false

val json = JSON.toJSONString(params)

mClient.doTransaction(json, object : EcrResponseCallBack {
override fun onError(errorCode: String, errorMsg: String) {
}

override fun onSuccess(data: String) {
}
})

3.6 Refund

  1. Request/Response parameters
  2. Example:
val params = PaymentRequestParams()
params.app_id = "you payment app id"
params.topic = Constants.PAYMENT_TOPIC
params.timestamp = System.currentTimeMillis().toString()

params.biz_data = PaymentRequestParams.BizData()
params.biz_data.trans_type = Constants.TRANS_TYPE_REFUND
params.biz_data.order_amount = "1.1"
params.biz_data.merchant_order_no = "1234567890"
params.biz_data.orig_merchant_order_no = "1234567891"
params.biz_data.pay_scenario = "SWIPE_CARD"
params.biz_data.isConfirm_on_terminal = false

val json = JSON.toJSONString(params)

mClient.doTransaction(json, object : EcrResponseCallBack {
override fun onError(errorCode: String, errorMsg: String) {
}

override fun onSuccess(data: String) {
}
})

3.7 Query

  1. Request/Response parameters
  2. Example:
val params = PaymentRequestParams()
params.app_id = "you payment app id"
params.topic = Constants.QUERY_TOPIC
params.biz_data = PaymentRequestParams.BizData()
params.biz_data.merchant_order_no = "1234567890"

val json = JSON.toJSONString(params)

mClient.queryTransaction(json, object : EcrResponseCallBack {
override fun onError(errorCode: String, errorMsg: String) {
}

override fun onSuccess(data: String) {
}

})

3.8 Close

  1. Request/Response parameters
  2. Example:
// Build close request
val params = PaymentRequestParams()
params.app_id = "you payment app id"
params.topic = Constants.CLOSE_TOPIC
params.biz_data = PaymentRequestParams.BizData()
params.biz_data.merchant_order_no = "1234567890"

val json = JSON.toJSONString(params)

mClient.cancelTransaction(json)