Initialise
Prerequisites
- Should be registered as a Yoco merchant via the Yoco website
- Received a Yoco card terminal [Go]
- Integrators: Requested a SDK Integration Key via SDK Integration Application form to obtain a
secret
key - minSDKVersion:
- targetSdkVersion:
- 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
Permission | Description |
---|---|
android.permission.BLUETOOTH_ADMIN | Required for Terminal state changes |
android.permission.BLUETOOTH | Required for connecting to terminals |
android.permission.BLUETOOTH_CONNECT | Required for connecting to terminals |
android.permission.BLUETOOTH_SCAN | Required for scanning for terminals |
android.permission.ACCESS_FINE_LOCATION | Required for security of transactions |
android.permission.ACCESS_COARSE_LOCATION | Required for security of transactions |
android.permission.ACCESS_WIFI_STATE | Required for sending/receiving data from Yoco servers |
android.permission.ACCESS_NETWORK_STATE | Required for sending/receiving data from Yoco servers |
android.permission.INTERNET | Required for sending/receiving data from Yoco servers |
android.permission.ACCESS_WAKE_LOCK | Required 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.