Android SDK
Integration options
Activity mode
The SmartPay Activity Mode provides you with a complete checkout screen. The user can navigate back to the previous activity by just pressing the back
button.
Fragment mode
The SmartPay Fragment Mode allows you to integrate the SmartPay fragments directly into your app experience and gives you maximum control over the various checkout elements.
Add the SmartPay SDK to your app
To integrate the SmartPay libraries into your project, there is a necessity to perform a few basic tasks to prepare the project. This tutorial assumes your IDE for application development is Android Studio.
First, copy SDK files (listed below) to the module “libs” folder (usually the app/libs/):
- smartpay.arr
- kontocloud-sdk.aar
- kontocloud-apiclient.aar
- kontocloud-uicomponents.aar
Then, in your module Gradle file (usually the app/build.gradle), add the dependencies for the SmartPay libraries:
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
// …
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "androidx.fragment:fragment:1.2.5"
implementation "androidx.fragment:fragment-ktx:1.2.5"
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'net.danlew:android.joda:2.10.6'
implementation 'com.samskivert:jmustache:1.15'
implementation(name: 'smartpay', ext: 'aar')
implementation(name: 'kontocloud-apiclient', ext: 'aar')
implementation(name: 'kontocloud-uicomponents', ext: 'aar')
implementation(name: 'kontocloud-sdk', ext: 'aar')
}
Add the INTERNET permission to the AndroidManifest file (usually the app\src\main\AndroidManifest.xml):
// ...
<uses-permission android:name="android.permission.INTERNET" />
//...
To initialize the SmartPay:
class App : Application() {
override fun onCreate() {
super.onCreate()
SmartPay.init(this)
Make sure to set the correct environment / smartPayMode
in the smartPayOptions
:
Environment | SmartPayMode |
---|---|
Sandbox | CONS |
Live | PROD |
class App : Application() {
override fun onCreate() {
super.onCreate()
val smartPayOptions: SmartPayOptions = SmartPayOptions()
smartPayOptions.smartPayMode = SmartPayMode.Live
SmartPay.init(this, smartPayOptions)
Complete payment in activity mode
Initialize SmartPay
To initialize SmartPay SDK forward transaction-ID to the startActivityForResult
method.
SmartPayCheckoutActivity.startActivityForResult(Context, TRANSACTION_ID)
Process Payment Results
To receive the transaction results, please override the method in Activity.onActivityResult
. In the response requestCode == SmartPayConst.SMART_PAY_PAYMENT_REQUEST_CODE
you can recieve the following results codes:
Result Code | Description |
---|---|
SmartPayConst.SMART_PAY_RESULT_CODE_CANCEL | The end-customer has canceled the transaction (i.e. closed the payment form window). |
SmartPayConst.SMART_PAY_RESULT_CODE_ERROR | Transaction has failed. |
SmartPayConst.SMART_PAY_RESULT_CODE_SUCCESS | Successful transaction execution |
To get the transaction-ID related to the processed payment extract the key SmartPayConst.SMART_PAY_TRANSACTION_ID
.
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == SmartPayConst.SMART_PAY_PAYMENT_REQUEST_CODE) {
val transactionId = data?.getStringExtra(SmartPayConst.SMART_PAY_TRANSACTION_ID) ?: ""
when (resultCode) {
SmartPayConst.SMART_PAY_RESULT_CODE_SUCCESS -> {
...
}
SmartPayConst.SMART_PAY_RESULT_CODE_CANCEL -> {
...
}
SmartPayConst.SMART_PAY_RESULT_CODE_ERROR -> {
...
}
}
}
}
The SmartPay Activity Mode can inherit the main application's theme by adding the following attribute (for more details see the Styling
section):
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="smartPayStyle">@style/MySmartPayStyle</item>
</style>
SmartPayCheckoutActivity.startActivityForResult(Context, TRANSACTION_ID, R.style.AppTheme)
Complete payment in fragment mode
Initialize SmartPay
To initialize SmartPay widget forward transaction-ID to the getInstance
method.
SmartPayCheckoutFragment.getInstance(TRANSACTION_ID)