Skip to content
Branch: master
Find file History
mshafrir-stripe Make PaymentSessionActivity save instance data (#1823)
Also make `PaymentSessionActivity` use a `ScrollView`
Latest commit d27d075 Nov 14, 2019

README.md

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 deploying the example backend to Heroku and configuring the app, build and run the project.

Deploy the example backend to Heroku

  1. Create a Heroku account if you don't have one.
  2. Navigate to the example mobile backend repo and click "Deploy to Heroku".
  3. Set an App Name of your choice (e.g. Stripe Example Mobile Backend).
  4. Under Config Vars, set your Stripe testmode secret key for the STRIPE_TEST_SECRET_KEY field.
  5. Click "Deploy for Free".

Configure the app

  1. Set Settings.PUBLISHABLE_KEY to your test publishable key.

    For example,

    const val PUBLISHABLE_KEY = "pk_test_12345"
    
  2. Set Settings.BASE_URL to the URL of the example backend deployed to Heroku.

    For example,

    const val BASE_URL = "https://my-example-app.herokuapp.com"
    

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
            }
         })
     }
    
You can’t perform that action at this time.