Contents
- Clone the
stripe-android
repository. - Open the project in Android Studio.
- After remixing the Glitch project and configuring the app, build and run the project.
We provide an example backend hosted on Glitch, allowing you to easily test an integration end-to-end.
- Open the Glitch project.
- Click on "Remix", on the top right.
- In your newly created project, open the
.env
file in the left sidebar. - Set your Stripe testmode secret key as the
STRIPE_TEST_SECRET_KEY
field. - Your backend implementation should now be running. You can see the logs by clicking on "Logs" in the bottom bar.
- 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
. - 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=
-
Check that Google Pay is available and ready in
isReadyToPay()
. -
Create a Google Pay PaymentDataRequest in
createGooglePayRequest()
.- Optionally, require Billing Address with
isBillingAddressRequired
, Phone Number withisPhoneNumberRequired
, and Email withisEmailRequired
.
- Optionally, require Billing Address with
-
Display Google Pay sheet in
payWithGoogle()
. -
After user selects a payment method,
Activity#onActivityResult()
is called. Handle result inhandleGooglePayResult()
. -
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()) )
-
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 } }) }