Mobile SDK
Android
Setup
12 min
credentials to be able to add the toro sdk to your project, you will need access to our maven repository, which we will provide credentials for we recommend creating a toro properties file to store the credentials at the root directory of your project properties maven repo url=\<repository url> maven username=\<your username> maven password=\<your password> ensure you add toro properties to your gitignore (or equivalent) to avoid commiting the credentials to your project's version control you could also set these as environment variables on your system if you wanted add maven repository to project you will then need to add the repository in your project your repositories block could be in settings gradle or project level build gradle depending on how your project is setup our example shows the setup in settings gradle gradle kotlin dsl // if you are using a properties file, you can load it here val toroprops = java util properties() apply { val propsfile = file("toro properties") if (propsfile exists()) { propsfile inputstream() use { load(it) } } } dependencyresolutionmanagement { repositoriesmode set(repositoriesmode prefer settings) repositories { google() // keep your existing repositories mavencentral() // add the toro maven repository maven { name = "tororepo" url = uri(toroprops getproperty("maven repo url") ? system getenv("maven repo url") ? throw gradleexception("no url found for toro repository")) credentials { username = toroprops getproperty("maven username") ? system getenv("maven username") ? throw gradleexception("no username found for toro repository") password = toroprops getproperty("maven password") ? system getenv("maven password") ? throw gradleexception("no password found for toro repository") } } } } gradle groovy dsl // if you are using a properties file, you can load it here def toroprops = new properties() def propsfile = file("toro properties") if (propsfile exists()) { propsfile withinputstream { stream > toroprops load(stream) } } dependencyresolutionmanagement { repositoriesmode set(repositoriesmode prefer settings) repositories { google() // keep your existing repositories mavencentral() // add the toro maven repository maven { name 'tororepo' url = uri(toroprops getproperty('maven repo url') ? system getenv('maven repo url') ? { throw new gradleexception('no url found for toro repository') }()) credentials { username = toroprops getproperty('maven username') ? system getenv('maven username') ? { throw new gradleexception('no username found for toro repository') }() password = toroprops getproperty('maven password') ? system getenv('maven password') ? { throw new gradleexception('no password found for toro repository') }() } } } } in this snippet we support adding credentials from both environment variables and the toro properties file the reason being it tends to be easier to use a properties file locally, and environment variables are typically better suited for ci/cd pipelines declare the dependencies in your app level build gradle you can now add the toro sdk as a dependency kotlin dsl dependencies { releaseimplementation("services cabcard toro\ toro $toroversion") debugimplementation("services cabcard toro\ toro debug $toroversion") }dependencies { releaseimplementation "services cabcard toro\ toro ${toroversion}" debugimplementation "services cabcard toro\ toro debug ${toroversion}" } ensure you declare the dependencies like this the release variant is obfuscated with logging disabled by default for security reasons we do retain the mapping, so you can contact us to decode stack traces and help diagnose production issues if necessary manifest permissions ensure the following permissions are present in your androidmanifest xml \<! these are only required if you want to collection geolocation for transactions > \<uses permission android\ name="android permission access fine location" /> \<uses permission android\ name="android permission access coarse location" /> \<! these are always required to connect to miura devices over bluetooth > \<uses permission android\ name="android permission bluetooth connect" /> \<uses permission android\ name="android permission bluetooth scan" /> \<! this is for devices below android 12 (api 31) > \<uses permission android\ name="android permission bluetooth admin" /> initialisation in the sample application, we use https //dagger dev/hilt/ to handle dependency injection and initialisation, but you can feel free to use any other method you prefer dagger hilt @module @installin(singletoncomponent class) object appmodule { @provides @singleton fun providetoroclient(@applicationcontext context context) toroclient { return toroclient( applicationcontext = context, config = toroconfig( merchant = merchantconfig( categorycode = "5812" // your merchant category code ) ) ) } } then in your view model, you can inject the toroclient instance @hiltviewmodel class transactionviewmodel @inject constructor( private val toro toroclient ) alternative create a singleton object to manage the sdk instance object torosdk { private var instance toroclient? = null val instance toroclient get() = checknotnull( instance) { "torosdk not initialised call torosdk initialise() in your application class" } fun initialise(applicationcontext context) { if ( instance != null) { return // already initialised } instance = toroclient( applicationcontext = applicationcontext, config = toroconfig( merchant = merchantconfig( categorycode = "5812" // your merchant category code ) ) ) } } initialise the sdk in your application class class mainapplication application() { override fun oncreate() { super oncreate() torosdk initialise(applicationcontext) } } then use it in your viewmodels or other classes class transactionviewmodel viewmodel() { private val toro = torosdk instance }public class transactionviewmodel extends viewmodel { private final toroclient toro = torosdk getinstance(); } you must provide applicationcontext (not any other context) to the toroclient constructor the sdk should only be initialised once during the app's lifecycle
