Stripe - Android SDK

Devices Supported: Stripe M2 Reader

📘

UPDATE: As of February 14, 2024 a new version of the SDK is available. Documentation for the new version of the SDK (2.1.0) is available here.

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

🚧

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:2.23.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')
}

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.0.4'
        classpath "io.realm:realm-gradle-plugin:4.2.0"
    }
}

android {
    compileSdk 33
    defaultConfig {
        applicationId "com.paysimple.TestApp"
        minSdk 26
        targetSdk 33
        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 Dependency
    implementation "com.stripe:stripeterminal:2.23.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.0.4'
}

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" />

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

ACCESS_FINE_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.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>

What’s Next

Continue to Stripe - Android Framework