Skip to content

Latest commit

 

History

History
 
 

example

Stripe Examples App

Contents

  1. Setup
  2. Examples

Setup

Install

  1. Clone the stripe-android repository.
  2. Open the project in Android Studio.
  3. After remixing the Glitch project and configuring the app, build and run the project.

Remix the example project on Glitch

We provide an example backend hosted on Glitch, allowing you to easily test an integration end-to-end.

  1. Open the Glitch project.
  2. Click on "Remix", on the top right.
  3. In your newly created project, open the .env file in the left sidebar.
  4. Set your Stripe testmode secret key as the STRIPE_TEST_SECRET_KEY field.
  5. Your backend implementation should now be running. You can see the logs by clicking on "Logs" in the bottom bar.

Configure the app

  1. If it doesn't exist, create a gradle.properties in a location defined in the Gradle Build Environment docs. For example, the default location on macOS is ~/.gradle/gradle.properties.
  2. Append the following entries to gradle.properties.
# Set to example backend project in Glitch
STRIPE_EXAMPLE_BACKEND_URL=https://stripe-example-mobile-backend.glitch.me/

# Set to a test publishable key from https://dashboard.stripe.com/test/apikeys
STRIPE_EXAMPLE_PUBLISHABLE_KEY=pk_test_mykey

# Optionally, set to a Connect Account id to test Connect
STRIPE_ACCOUNT_ID=

Examples

Google Pay

Source

PayWithGoogleActivity.kt

Overview

  1. Check that Google Pay is available and ready in isReadyToPay().

  2. Create a Google Pay PaymentDataRequest in createGooglePayRequest().

    • Optionally, require Billing Address with isBillingAddressRequired, Phone Number with isPhoneNumberRequired, and Email with isEmailRequired.
  3. Display Google Pay sheet in payWithGoogle().

  4. After user selects a payment method, Activity#onActivityResult() is called. Handle result in handleGooglePayResult().

  5. Create a PaymentMethodCreateParams object from the Google Pay PaymentData object using PaymentMethodCreateParams.createFromGooglePay().

    val paymentData = PaymentData.getFromIntent(data) ?: return
    
    val paymentMethodCreateParams = PaymentMethodCreateParams.createFromGooglePay(
        JSONObject(paymentData.toJson())
    )
    
  6. Create a Stripe Payment Method object with the PaymentMethodCreateParams object using Stripe#createPaymentMethod().

    stripe.createPaymentMethod(paymentMethodCreateParams,
        object : ApiResultCallback<PaymentMethod> {
            override fun onSuccess(paymentMethod: PaymentMethod) {
                // do something with paymentMethod
            }
    
            override fun onError(e: Exception) {
                // handle error
            }
         })
     }