Google Pay API Implementation Demo (Android)
Articles Blog

Google Pay API Implementation Demo (Android)

(narrator) With the Google Pay API
for Android, you can facilitate
payment transactions for your users, making the checkout experience
in your application more convenient. Join other businesses like yours
who are using Google Pay today to drive user growth,
increase conversions, and reduce data exposure
and transaction vulnerabilities. Here is how you can integrate Google Pay on your Android application
in four simple steps: configure your project; determine readiness to pay; show the Google Pay button; create aPaymentDataRequestobject. First, add the Google Pay library
to the list ofdependenciesin your application module. Make sure to review our documentation
to check the latest version available. You also need to enable
the Google Pay API in yourmanifest. You can do that by adding
the following tag inside of your application node. As soon as you are ready, open the activity where you plan
to show the Google Pay button and obtain a new instance
of thepaymentsClientinside of youronCreatemethod. Note that thegetPaymentsClientmethod
takes awalletOptionsparameter. Use the definitions in this class
to specify the environment in which you want to operate,TESTorPRODUCTION. For theTESTenvironment,
you don’t need to register with Google. You can play with the API yourself
and integrate into your application. In this case, you can use
real payment information. However, whenever a selection is made,
we return you a non-chargeable token. Remember, your real card details
are never used when inEnvironmenttest, but you must add at least one
chargeable card to your Google account before you proceed. Once you complete the integration
and you are ready to handle real payments, come and register with us
through our self-service portal and then flip the environment
toPRODUCTION. You can apply for production access that you have
yourpaymentsClientconstructed, the first API you need to call
isIsReadyToPay. WithIsReadyToPayyou can determine whether the user
has a valid payment method on file and is capable of completing
a transaction on a supported device. This request takes parameters
that specify the API version targeted in your call, as well as the payment methods
allowed for this transaction. At Google, we focus
on optimizing for conversions, so ifIsReadyToPayreturns false, we highly recommend that you do not show
the Google Pay button. Now that you know that the user is ready
to make a payment using Google Pay, you can make the button
visible to the user. We recommend that you use the graphic
shared in the developer documentation to ensure the Google Pay branding
is used correctly per our latest guidelines. In this bundle, you will find drawable
and layout resources that adapt to different screen sizes
and resolutions, as well as translations
into multiple languages for the text in the button. Once the user taps on the button, you call theloadPaymentData(request)to open up the payment sheet. You can construct
thePaymentDataRequestobject which is a set of payments configurations
used for this particular transaction. You can request additional information, like a shipping address and email address, in addition to the payment credentials. We recommend that you collect
as little information as necessary to prevent users
from typing additional information which might not be stored
in their accounts. One more point to call out in this object is thePaymentRequest
tokenization parameters. Google encrypts information
about a user’s selected card for secure processing
by a merchant’s gateway or directly on
a merchant’s secured servers. Be sure to check
your processor’s integration guidelines to find out what they need
to finalize the payment. Now that you’ve constructed
therequestobject, you can pass it toloadPaymentData— an asynchronous task
which opens the payments sheet. Once the user makes a selection, we return to you aPaymentDataobject
as an activity result, which consists of metadata
about the user’s selection. It also includes the payment token which you can use
to complete the transaction. Now you can send the final
production-ready application to Google for a final test. Google tests the app with real cards and informs you if everything is correct. The app is then cleared to launch. You can find additional information
in our developer documentation’t miss any future videos
about Google Pay and Android, and subscribe
to the Android Developers channel. If you are watching on a mobile, tap the little bell
to receive new upload notifications. See you soon!

18 thoughts on “Google Pay API Implementation Demo (Android)

  1. All of this is useless when you realize that Google Pay is still not available in your country 😕

  2. Sir i build a application and many people are use this application and Google pay money me plz inform

  3. I'm a professional Android engineer working on implementing Google Pay into our application's sign-up funnel. Our business model is subscription-based, and our internal subscription API currently requires the expiration month of the user's payment method so that we can warn them about expiring payment methods to avoid failed charges. Is there currently any way to retrieve the expiration date from the user's payment method in the PaymentData object?

  4. What is the difference between this API and Google Play Billing API in terms of functionality?

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top