Skip to content

stripe/stripe-terminal-android

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

* 3.2.0 release

* Update 3.2.0 release date in CHANGELOG.md

Co-authored-by: chr-stripe <108023228+chr-stripe@users.noreply.github.com>

---------

Co-authored-by: chr-stripe <108023228+chr-stripe@users.noreply.github.com>
1cb7ad4

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
November 15, 2023 13:03
November 15, 2023 13:03
March 5, 2019 19:08
November 15, 2023 13:03
September 24, 2019 14:02
November 15, 2023 13:03

Stripe Terminal Android

For information on migrating from earlier versions of the Android SDK, see the migration guide.

Requirements

The Stripe Terminal Android SDK is compatible with apps supporting Android API level 26* and above. Apps can be written using Kotlin or Java 8.

* Note that attempting to override minSdkVersion to decrease the minimum supported API level will not work due to internal runtime API level validation. Furthermore, Stripe is updating the Terminal Android SDK to support Google’s recently released Android 14 (SDK 34). Please continue to target SDK 33 in the meantime as there are known issues with mPOS devices and TTP when targeting SDK 34. Please track the following ticket for updates on progress.

Try the example app

The Stripe Terminal Android SDK includes two open-source example apps (one in Java and the other in Kotlin), which you can use to familiarize yourself with the SDK before starting your own integration. To build the example app:

  1. Clone this repo.
  2. Import the Example project into Android Studio.
  3. Navigate to our example backend and deploy it following the instructions in the README.
  4. In gradle.properties, set the URL of the backend you just deployed.
  5. Build and run the app. The app includes a reader simulator, so you have no need for a physical reader to start your integration. Note that while the example app will work in an Android emulator, you will only be able to connect to a simulated reader due to lack of Bluetooth capabilities.

Installation

To use the Android SDK, add the SDK to the dependencies block of your build.gradle file:

dependencies {
    implementation "com.stripe:stripeterminal:3.2.0"
}

Next, since the SDK relies on Java 8, you’ll need to specify that as your target Java version (also in build.gradle):

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

Then, ensure that your kotlin version is >= 1.5.0 (in your application-level build.gradle):

buildscript {
    repositories {
        ...
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0"
        ...
    }
}

And in your module-specific build.gradle

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.0"
}

Configure your app

Location access must be enabled in order to use the SDK. You’ll need to make sure that the ACCESS_FINE_LOCATION permission is enabled in your app. To do this, add the following check before you initialize the Terminal object:

if (ContextCompat.checkSelfPermission(getActivity(), 
  Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION};
        
    // REQUEST_CODE should be defined on your app level
    ActivityCompat.requestPermissions(getActivity(), permissions, REQUEST_CODE_LOCATION);
}

You should also verify that the user allowed the location permission, since the SDK won’t function without it. To do this, override the onRequestPermissionsResult method in your app and check the permission result.

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    if (requestCode == REQUEST_CODE_LOCATION && grantResults.length > 0
            && grantResults[0] != PackageManager.PERMISSION_GRANTED) {
        throw new RuntimeException("Location services are required in order to " +
                "connect to a reader.");
    }
}

Note: Stripe needs to know where payments occur to reduce risks associated with those charges and to minimize disputes. If the SDK can’t determine the Android device’s location, payments are disabled until location access is restored.

Have an Application Class

The Android SDK is lifecycle aware. To prevent memory leaks and ensure proper cleanup of long-running Terminal SDK processes, your application must have the Application subclass where TerminalApplicationDelegate is used to inform the SDK of lifecycle events.

This subclass should call TerminalApplicationDelegate.onCreate from your application's onCreate method. For example:

// Substitute with your application name, and remember to keep it the same as your AndroidManifest.xml
class StripeTerminalApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        TerminalApplicationDelegate.onCreate(this)
    }
}

Lastly, don't forget to set your Application class in your AndroidManifest.xml accordingly. See the following taken from the example app:

<application
    android:name=".StripeTerminalApplication" // Or whatever your application class name is
    android:allowBackup="false"
    android:icon="@mipmap/launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/Theme.Example"
    tools:ignore="GoogleAppIndexingWarning">
    <activity android:name="com.stripe.example.MainActivity"
        android:screenOrientation="fullSensor">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Tap to Pay on Android (TTPA)

To use the Tap to Pay SDK, replace your existing stripeterminal dependencies in the dependencies block of your build.gradle file with the following:

dependencies {
  implementation "com.stripe:stripeterminal-localmobile:3.2.0"
  implementation "com.stripe:stripeterminal-core:3.2.0"
}

Please note that:

  • You must use an SDK version greater than the minimum SDK version documented in our user docs
  • The stripeterminal-localmobile SDK version must match the version you're using for other stripeterminal libraries.
  • There are no public APIs provided by this SDK. Please reference Stripe Terminal's public API references for more information on how to use the SDK.

Documentation