- Clone the
stripe-android
repository. - Open the project in Android Studio.
- After configuring, build and run the project.
- Create a Heroku account if you don't have one.
- Navigate to the example mobile backend repo and click "Deploy to Heroku".
- Set an App Name of your choice (e.g. Stripe Example Mobile Backend).
- Under Config Vars, set your Stripe testmode secret key for the
STRIPE_TEST_SECRET_KEY
field. - Click "Deploy for Free".
-
Set Settings.PUBLISHABLE_KEY to your test publishable key.
For example,
const val PUBLISHABLE_KEY = "pk_test_12345"
-
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"
-
Check that Google Pay is available and ready in
isReadyToPay()
. -
Create a Google Pay
PaymentDataRequest
increateGooglePayRequest()
.- Optionally, require Billing Address (
isBillingAddressRequired
), Phone Number (isPhoneNumberRequired
), and Email (isEmailRequired
)
- Optionally, require Billing Address (
-
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 PayPaymentData
object usingPaymentMethodCreateParams.createFromGooglePay()
.val paymentData = PaymentData.getFromIntent(data) ?: return val paymentMethodParams = PaymentMethodCreateParams.createFromGooglePay( JSONObject(paymentData.toJson()) )
-
Create a Stripe Payment Method object with the
PaymentMethodCreateParams
object usingStripe#createPaymentMethod()
.stripe.createPaymentMethod(paymentMethodCreateParams, object : ApiResultCallback<PaymentMethod> { override fun onSuccess(paymentMethod: PaymentMethod) { // do something with paymentMethod } override fun onError(e: Exception) { // handle error } }) }