minSdkVersion = 21
compileSdkVersion = 33
java 8
Add the snabble Repository to your gradle Repositories
repositories {
maven {
url 'https://raw.githubusercontent.com/snabble/maven-repository/releases'
}
}
Then add the library to your dependencies.
dependencies {
// core library
implementation 'io.snabble.pay:sdk:{currentVersion}'
}
To use and integrate Snabble Pay into an existing application an instance of SnabblePay
is needed.
To initialize SnabblePay
a configuration needs to be provided over the SnabblePay builder function.
val pay: SnabblePay = SnabblePay.getInstance(context = context) {
baseUrl = "https://payment.snabble-staging.io"
snabblePayKey = "shOnRkO4y5Gy..."
onNewAppCredentialsCallback =
SnabblePayAppCredentialsCallback { id: String, secret: String ->
sharedPreferences.saveAppCredentials(id, secret)
}
val (id, secret) = sharedPreferences.getAppCredentials() ?: return@snabblePay
appIdentifier = id
appSecret = secret
}
The app credentials generated by the API can be persisted over the SnabblePayAppCredentialsCallback
. Keep in mind
that these credentials need to be stored an provided in the configuration to hold an existing user. Otherwise the API generates new
app credentials with each call.
The following sequence displays the basic flow (happy path) from creating a new account up to starting a new session.
Use addNewAccount
to receive an AccountCheck
holding the validation link.
snabblePay.addNewAccount(
appUri = appUri,
city = city,
twoLetterIsoCountryCode = twoLetterIsoCountryCode
)
The given appUri
will be called by the backend after the account verification to navigate back to the application.
The given twoLetterIsoCountryCode
need to be provided in two-letter-format (also see: supported values )
After a succeeded validation the user will be redirected to the application over the given appUri, which contains the needed accountId as query parameter. The account can then be fetched with the given id.
snabblePay.getAccount(id)
If the mandate for the account is missing, a new one needs to be created for the given account id.
snabblePay.createMandate(accountId)
Accept the mandate to proceed with any further interaction. To accept a mandate the application needs to provide the account id for the mandate and the mandate id received other the mandate in the previous call.
snabblePay.acceptMandate(accountId, mandateId)
After the mandate has been accepted successfully, a session for any further interaction can be started. The application needs to provide an account id, which the session should be associated with.
snabblePay.createNewSession(accountId)