Initialise

Prerequisites

  1. Should be registered as a Yoco merchant via the Yoco website
  2. Received a Yoco card terminal [Go]
  3. Integrators: Requested a SDK Integration Key via SDK Integration Application form to obtain a secret key
  4. minSDKVersion: API
  5. targetSdkVersion: API
  6. Requires Java 11

Project Configuration

You will need to add the following permissions, which are required by the Yoco SDK and should be aded to your Manifest.xml

PermissionDescription
android.permission.BLUETOOTH_ADMINRequired for Terminal state changes
android.permission.BLUETOOTHRequired for connecting to terminals
android.permission.BLUETOOTH_CONNECTRequired for connecting to terminals
android.permission.BLUETOOTH_SCANRequired for scanning for terminals
android.permission.ACCESS_FINE_LOCATIONRequired for security of transactions
android.permission.ACCESS_COARSE_LOCATIONRequired for security of transactions
android.permission.ACCESS_WIFI_STATERequired for sending/receiving data from Yoco servers
android.permission.ACCESS_NETWORK_STATERequired for sending/receiving data from Yoco servers
android.permission.INTERNETRequired for sending/receiving data from Yoco servers
android.permission.ACCESS_WAKE_LOCKRequired for processing of Transactions
android.permission.READ_PHONE_STATE(optional)Required for network diagnostics

Initialising the YocoSDK

You will first need to request permissions, once these are granted you will need to initialise the YocoSDK in your app. This allows the SDK to setup everything it needs to perform its tasks.

import com.yoco.payments.sdk.YocoSDK
class SampleApplication : Application() {
override fun onCreate() {
super.onCreate()
requestPermissions()
}
private fun requestPermissions() {
val permissions = when (Build.VERSION.SDK_INT >= 12) {
true -> arrayOf(
android.Manifest.permission.ACCESS_COARSE_LOCATION,
android.Manifest.permission.ACCESS_FINE_LOCATION,
android.Manifest.permission.ACCESS_NETWORK_STATE,
android.Manifest.permission.BLUETOOTH_SCAN,
android.Manifest.permission.BLUETOOTH_CONNECT)
else -> arrayOf(
android.Manifest.permission.ACCESS_COARSE_LOCATION,
android.Manifest.permission.ACCESS_FINE_LOCATION,
android.Manifest.permission.ACCESS_NETWORK_STATE)
}
ActivityCompat.requestPermissions(this, permissions, 0)
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (grantResults.filter { it == PackageManager.PERMISSION_DENIED }.isNotEmpty()) {
requestPermissions()
} else {
initialiseSdk()
}
}
fun initialiseSdk() {
if (Build.VERSION.SDK_INT < 12 || (
ActivityCompat.checkSelfPermission(this, android.Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, android.Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED
)) {
// Initialises Yoco Payment UI SDK
YocoSDK.initialise(
context = applicationContext
)
}
}
}
danger

The YocoSDK should ONLY be initialised once per application lifecycle.