ConnectionProvider
Implement the ConnectionProvider
and make a call to your server to generate a connectionSecret
.
// Kotlin Sample Code
interface ConnectionProvider {
suspend fun createConnection(): String
}
Example Implementation
import com.tyro.taptopay.sdk.api.ConnectionProvider
...
class SdkDemoConnectionProvider(engine: HttpClientEngine = CIO.create()) : ConnectionProvider {
private val client =
HttpClient(engine) {
install(ContentNegotiation) {
json(
Json {
ignoreUnknownKeys = true
isLenient = true
},
)
}
}
// update this to fetch your connection secret
override suspend fun createConnection(): String {
return client.post(UPDATE__THIS__CONNECTION_SECRET_ENDPOINT_URL) {
contentType(ContentType.Application.Json)
setBody(DemoConnectionRequestBody(UPDATE__THIS__DEMO_READER_ID))
}.body<DemoConnectionResponse>().connectionSecret
}
@Serializable
data class DemoConnectionRequestBody(val readerId: String)
@Serializable
data class DemoConnectionResponse(val connectionSecret: String)
companion object {
// TODO
// create an endpoint on your server to generate the connection secret
const val UPDATE__THIS__CONNECTION_SECRET_ENDPOINT_URL = "https://example.connection/endpoint"
// TODO
// create the reader id and set it here for demo
// only one reader can be used on one device any a time otherwise transactions will fail
// your app would usually retrieve the reader id from your server
const val UPDATE__THIS__DEMO_READER_ID = "e2b72601-9fb5-4341-b25b-6b64abb43ef3"
}
}