Stripe - Android SDK

Devices Supported: Stripe M2 Reader & Android Tap To Pay (on Compatible Devices)

πŸ“˜

Current SDK Version: 2.1.0

To get a copy of our SDK, please contact our partner team at [email protected] or directly reach out to your Integrated Partner Manager.

For links to setup documentation of the previous version of the SDK, see below:
2.0.0 Setup Documentation Reference

🚧

Minimum Supported Android Version

Android 8.0 API 26

🚧

AndroidX Notice

The SDK will not be compatible with apps using support libraries. Make sure you have migrated your app to AndroidX.

❗️

When utilizing the Android Stripe SDK, do not manually delete locations in the Stripe dashboard. Manual deletion of locations in the Stripe dashboard will interfere with functionality of the SDK.

Import Libraries

  • Create folder named libs in base project directory
  • Copy provided aar into libs folder.
  • In your app level gradle file add all required dependencies.

To install the SDK, ensure the following dependencies are added to the dependencies block of your app's build.gradle file:

apply plugin: 'com.android.application'

android { ... }

dependencies {
    implementation 'com.stripe:stripeterminal-localmobile:3.2.1'
    implementation 'com.stripe:stripeterminal-core:3.2.1'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.android.volley:volley:1.2.1'
    implementation 'com.google.code.gson:gson:2.8.9'
  
  implementation files('../libs/EverCommercePaymentsAndroidSdk-release.aar')
}

Ensure you have been distributed the latest version of the EverCommercePaymentsAndroidSdk for your reference of EverCommercePaymentsAndroidSdk-release.aar. You can check which version of the SDK you are using by utilizing Get ECP SDK Version .

Additionally, our Android Stripe SDK currently relies on Java 8. Ensure the proper target version is also set in your app's build.gradle file:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

Below is a full gradle example:

apply plugin: 'com.android.application'
apply plugin: 'realm-android'

buildscript {
    repositories {
        jcenter()
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.2'
        classpath "io.realm:realm-gradle-plugin:4.2.0"
    }
}

android {
    compileSdk 34
    defaultConfig {
        applicationId "com.paysimple.TestApp"
        minSdk 26
        targetSdk 34
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildToolsVersion '31.0.0'
}

dependencies {
  // Stripe Dependencies
    implementation "com.stripe:stripeterminal-localmobile:3.2.1"
    implementation "com.stripe:stripeterminal-core:3.2.1"
  // EverCommerce Dependency
    implementation files('../libs/EverCommercePaymentsAndroidSdk-release.aar')
  
  // Other dependencies:
    implementation 'androidx.appcompat:appcompat:1.4.1
    implementation 'com.android.volley:volley:1.2.1'
    implementation 'com.google.code.gson:gson:2.8.9'

    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
    implementation "com.squareup.okhttp3:okhttp:4.10.0"
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'

    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

 

}

task prepareKotlinBuildScriptModel {

}

task wrapper(type: Wrapper){
    gradleVersion = '7.4.2'
}

Permissions

Our Android Stripe SDK requires various permissions for use.

The following permissions should be declared in AndroidManifest.xml:

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

The following permissions should be requested in code to use alongside our Shared ECP SDK:

ACCESS_FINE_LOCATION
ACCESS_COARSE_LOCATION
BLUETOOTH_CONNECT
BLUETOOTH_SCAN

Before initializing and attempting to use our Shared ECPSdk, make sure the permissions listed below are requested in code.

Example below for requesting permissions in code.

 ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION,
 Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.BLUETOOTH_CONNECT,
 Manifest.permission.BLUETOOTH_SCAN}, 1);

You will also want to verify that your app user grants the permissions - the SDK will have issues functioning without the necessary permissions. One way to do this is to override the onRequestPermissionsResult method in your app and check the permission result. See sample code below (note: you will want to customize for your own individual app's needs):

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        for (int i : grantResults) {
            if (i != 0) {
                Toast.makeText(MainActivity.this, "Not all permissions granted.  You may need to check your permissions", Toast.LENGTH_LONG).show();
            }
        }
    // more code if needed here
    }

🚧

The SDK needs to know where payments occur. If we can't determine the location of a device, payments may become disabled until location access is functioning again. Please ensure users of your app are always allowing location access.

ECPApplicationSetupService (Required)

To ensure our SDK functions properly, your application needs to implement an Application subclass where ECPApplicationSetupService is utilized to inform the SDK of lifecycle events. In onCreate(), you will need to create a new ECPApplicationSetupService as shown below, then call performOnCreateSetup passing in this.

The subclass will help register activity lifecycle callbacks. See example below:

// Make sure your class name lines up with your application name. Make sure to keep the class name the same as your AndroidManifest.xml

public class MyApplicationName extends Application {

    // Instance of AppContainer that will be used by all the Activities of the app
    public AppContainer appContainer = new AppContainer();

    @Override
    public void onCreate() {
        super.onCreate();
        ECPApplicationSetupService setupService = new ECPApplicationSetupService();
        setupService.performOnCreateSetup(this);
    }

}

Example of Application name in AndroidManifest.xml:

    <application
        android:name=".MyApplicationName"
			<!--  more manifest code here... -->
    </application>

Debuggable Security Setup (Required for Tap To Pay)

Using Tap To Pay on Android does not support debuggable applications for security and compliance reasons. In order to have your Tap To Pay device work your application must not be debuggable. If you will use bluetooth functionality only, in development environments you can continue to have a debuggable application.

Here is a sample of one way to make your app not debuggable:

Sample build.gradle for app (see debuggable setting to false):

    buildTypes {

        debug {
            debuggable false
        }
        release {
            minifyEnabled false
            debuggable false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildToolsVersion '31.0.0'
}

Sample AndroidManifest.xml (see debuggable set to false and tools:ignore="HardcodedDebugMode")

    <application
        android:name=".MyApplication"
        android:debuggable="false"
        android:allowBackup="true"
        android:extractNativeLibs="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.TestApp"
        tools:ignore="HardcodedDebugMode">