The Android API for Google Pay API for Passes lets users save Valuable Objects to Google Pay with the click of a button. This sample quickstart provides easy setup for saving loyalty, gift card, and offer objects.
Follow the Native Android SDK guide and then the following steps to run the sample android app:
Step 1: Set up the Android App
The quickstart is an open source project that you can download from GitHub. To download this project:
- Visit the GitHub repo
- Either download the zip or clone the repository by running
git clone https://github.com/google-pay/s2gp-quickstart-android
.
The sample app can then be opened with Android Studio as an existing project. The project may need to be synced to compile correctly. Once the sample app is built on Android Studio, it can be run an Android device or an emulator.
Step 2: Create a class
A class can be created from the Google Pay API for Passes Merchant. From the 'Classes' page in the Merchant Center, select 'Create Class' to create the class. Input fields with a red outline are required, while the remaining are optional. For any fields with a URL, make sure the link is publicly accessible. The created class will be referenced when creating the valuable object.
Step 3: Configure the Android App
To configure the sample app so it works properly, certain values must be
adjusted. Within strings.xml
found in
app/res/values/
:
- Replace the
ISSUER_ID
value with the your Google Pay API for Passes Issuer Id. - Replace
LOYALTY_CLASS_ID
,GIFTCARD_CLASS_ID
, orOFFER_CLASS_ID
with the name of the class of interest already created in your Google Pay API for Passes Merchant Center.
Within MainActivity.java
certain values for each object type
must be configured so that they match the class the object references in the
Merchant Center:
- For a
GiftCardWalletObject
in thegenerateGiftCardWalletObject
method,setIssuerName
andsetTitle
must match the values in the class. - For a
LoyaltyWalletObject
in thegenerateLoyaltyWalletObject
method,setIssuerName
andsetProgramName
must match the values in the class. - For a
OfferWalletObject
in thegenerateLoyaltyWalletObject
method,setIssuerName
andsetTitle
must match the values in the class.
Step 4: Test the Android App
The application can be run either through an emulator or a physical Android device. Once the gradle is synced properly, run the app through Android Studio and select desired deployment target. Once the deployment finishes, the sample app should automatically launch.