Contents
- Clone the
stripe-androidrepository. - Open the project in Android Studio.
- After forking the CodeSandbox project and configuring the app, build and run the project.
We provide an example backend hosted on CodeSandbox, allowing you to easily test an integration end-to-end.
- Open the CodeSandbox project.
- Click on "Fork", on the top right.
- In your newly created project, open the
.envfile in the left sidebar. - Set your Stripe testmode secret key as the
STRIPE_TEST_SECRET_KEYfield. - Your backend implementation should now be running. You can see the logs by clicking on "Logs" in the bottom bar.
We also provide same backend code pre-deployed at StripeDemos.com
- If it doesn't exist, create a
gradle.propertiesin 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.stripedemos.com/
# 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
PaymentMethodCreateParamsobject 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 } }) }