Android Integration

    Our Android libraries let you easily accept mobile payments and manage customer information inside any Android app.

    Stripe has created a Java library for Android, allowing you to easily submit payments from an Android app. With our mobile library, we shoulder the burden of PCI compliance by eliminating the need to send card data directly to your server. Instead, our libraries send the card data directly to our servers, where we can convert them to tokens.

    Your app will receive the token back, and can then send the token to an endpoint on your server, where it can be used to process a payment, establish recurring billing, or merely saved for later use.

    We support Android back to version 14, and the library has no external dependencies other than Google’s support libraries.


    Installing the Stripe Android library is simple using Android Studio and IntelliJ. You don’t need to clone a repo or download any files. Just add the following to your project’s build.gradle file, inside the dependencies section.

    implementation 'com.stripe:stripe-android:6.1.2'

    Collecting credit card information

    At some point in the flow of your app, you’ll want to obtain payment details from the user. There are a couple ways to do this:

    Instructions for each route follows, although you may want to write your app to offer support for both.

    Using the card input widget

    To collect card data from your customers directly, you can use Stripe’s CardInputWidget in your application.

    Android Card Input Widget

    The different states of the CardInputWidget

    You can include it in any view’s layout file. Note that it has a minimum width of 320px.


    This will allow your customers to input all of the required data for their card: the number, the expiration date, and the CVC code.

    To access the card reader in your application code, first import the class.


    Next, find the CardInputWidget in your layout as you would any other view.

    CardInputWidget mCardInputWidget = (CardInputWidget) findViewById(;

    You can then directly access the widget and ask for a card object. Note that if the data in the widget is either incomplete or fails client-side validity checks, the Card object will be null.

    Card cardToSave = mCardInputWidget.getCard();
    if (cardToSave == null) {
        mErrorDialogHandler.showError("Invalid Card Data");

    If you have any other data that you would like to associate with the card, such as name, address, or ZIP code, you can put additional input controls on your layout and add them directly to the Card object.

    cardToSave.setName("Customer Name");

    Styling the card widget

    The CardInputWidget is a custom view which contains several customized Android EditText elements. If you set values for EditText attributes in your Theme, they will be picked up by the CardInputWidget.

    There are also two special parameters that you can set: the card tint and the error text color. To set these values, make sure to add the res/auto namespace in the layout file where you have created the CardInputWidget. You can use any legal value for the namespace, such as stripe.


    You can then apply your preferred values for the color of the empty card hint item (before a brand has been detected) and as a text error color. By default, the card tint is identical to the hint text color of your theme, and the Stripe library selects a text error color from two different shades of red, depending on how dark the background of your theme is.

    To apply your custom colors, simply add them to the CardInputWidget’s XML declaration.


    Changing the text and background colors

    To change the text colors, create a theme with the colors you would like and apply it to the CardInputWidget. The background color can be set using the android:background property, either directly on the widget, or as part of a theme. The following example sets both the background and text colors in the theme so that they can be easily applied wherever you use CardInputWidget in your app.

    <style name="CardWidgetStyle" parent="@android:style/Theme.DeviceDefault">
        <item name="android:background">#0000FF</item>
        <item name="editTextStyle">@style/EditTextOverride</item>
        <item name="android:editTextStyle">@style/EditTextOverride</item>
    <style name="EditTextOverride" parent="@android:style/Widget.EditText">
        <item name="android:textColor">#FF0000</item>
        <item name="android:textColorHint">#00FF00</item>

    Then, apply the style to the CardInputWidget to change its text, text hint, and background colors.


    The above example creates a CardInputWidget with a blue background, red text, and green text hints.

    Building your own form

    If you build your own payment form, you’ll need to collect at least your customers’ card numbers and expiration dates. Stripe strongly recommends collecting the CVC. You can optionally collect the user’s name and billing address for additional fraud protection.

    Once you’ve collected a customer’s information, you will need to exchange the information for a Stripe token.

    Creating & validating cards from a custom form

    To create a Card object from data you’ve collected from other forms, you can create the object with its constructor.

    public void onClickSomething(String cardNumber, String cardExpMonth, String cardExpYear, String cardCVC) {
      Card card = new Card(

    As you can see in the example above, the Card instance contains some helpers to validate that the card number passes the Luhn check, that the expiration date is the future, and that the CVC looks valid. You’ll probably want to validate these three things at once, so we’ve included a validateCard function that does so.

    Card card = new Card("4242-4242-4242-4242", 12, 2019, "123");
    if (!card.validateCard()) {
      // Show errors

    Creating tokens

    The next step is to pass off that sensitive payment information securely to Stripe, where you’ll exchange it for a token. You can create tokens using the Stripe instance method createToken, passing in a Card instance, and completion callbacks. An asynchronous network request will be executed, and the appropriate callback invoked when it completes.

    Note that you will need access to a Context object, which can be the Activity or Fragment in which you are operating, or can be retrieved from any View via the View#getContext() method.

    First, import the Stripe object and the Token object.


    Then, get your Card object, which can be done from a custom form.

    Card card = new Card("4242424242424242", 12, 2019, "123");
    // Remember to validate the card object before you use it to save time.
    if (!card.validateCard()) {
      // Do not continue token creation.

    You can also simply take the data from a CardInputWidget.

    // Remember that the card object will be null if the user inputs invalid data.
    Card card = mCardInputWidget.getCard();
    if (card == null) {
      // Do not continue token creation.

    However you create your Card object, you can now move on and convert it into a token. You should not store the object locally.

    Stripe stripe = new Stripe(mContext, "pk_test_TYooMQauvdEDq54NiTphI7jx");
      new TokenCallback() {
        public void onSuccess(Token token) {
          // Send token to your server
        public void onError(Exception error) {
          // Show localized error message

    We’ve placed your test publishable API key as the second argument to Stripe. You’ll need to swap it out with your live publishable key in production. You can see all your keys in your dashboard.

    Using tokens

    Using the payment token, however it was obtained, requires an API call from your server using your secret API key. (For security purposes, you should never embed your secret API key in your app.)

    Set up an endpoint on your server that can receive an HTTP POST call for the token. In the onActivityResult method (for Android Pay) or the onSuccess callback (when using your own form), you’ll need to POST the supplied token to your server. Make sure any communication with your server is SSL secured to prevent eavesdropping.

    Take a look at the full example application to see everything put together.

    Next Up

    Once you’ve retrieved a token from Stripe on your server, you’re going to want to do something with the payment details you just collected. This is usually one of three things:


    We're always happy to help with code or other questions you might have! Search our documentation, contact support, or connect with our sales team. You can also chat live with other developers in #stripe on freenode.

    Was this page helpful? Yes No


    Thank you for helping improve Stripe's documentation. If you need help or have any questions, please consider contacting support.