Save to Android Pay

This part of the Android Pay API focuses on the ability to provide a central location for customer loyalty, coupons and gift cards within the Android Pay app.

This helps to remove a lot of friction around loyalty because it removes the need to send an offer or gift card via the post, email or any other form of advertising. This also helps if a customer has forgotten to bring a loyalty or membership card into the store. How many times have you gone to your local coffee shop to find out you’ve left your loyalty card at home? That’s where Android Pay comes in to help digitize the loyalty experience, making it easier for your users to save and more likely to shop with you because of a simpler, more pleasurable experience.

Adding the Save to Android Pay Button

So before we get started on how all the different Save to Android Pay functions work, let’s start by looking at how we can add a button for our users to interact with.

We have two options when it comes to display of the Save to Android Pay button, there are a number of different ways we may wish to distribute it to our users.

Deep Linking

We can embed the deep link into an email, as shown on the left. But that’s not all, we can also distribute this link to our users anywhere where links can be used by the user, for example this could be through:

SMS

Your Website

Your Android App

Social Media

And it’s as simple as that! The link looks something like this:

We haven’t yet got to how to define the information stated here, we’ll get onto that in the next sections! In this link we are simply passing:

The generated JWT object for our loyalty class

The JSON web token

The ClassId for our loyalty class

Now this has been created, we simply just have to link our desired button using this link. When the user clicks this button they’ll be navigated to a page in their browser to confirm the save. Once confirmed the loyalty instance will be added to their Android Pay account.

Native Buttons

We can also use native button solutions for our apps or webpages. To begin with we can add a Save to Android Pay button to our webpage with two simple bits of code. To begin with we need to include the script on the page where we wish to use the button:

<script src="https://apis.google.com/js/plusone.js" type="text/javascript"></script>

Followed by adding the actual button itself to the place where we wish for it to be displayed:

<g:savetowallet jwt="{generated JWT}" onsuccess="successHandler" onfailure="failureHandler"

size="small" theme="light" ></g:savetowallet>

Again here we pass the generated JWT object when defining the button on our webpage.

However, if we want to add a native button to our android application then we must define the code in our activity. Using the assets provided in the Android Pay Toolkit, we can add a button to our layout using the Save to Android Pay image resource like so:

Followed by initialisation of the GoogleApiClient:

And then saving the desired object to the Android Pay API like so:

We’ll look at how to define these objects in the next section, but once the request is carried out we can handle the result in our activity onActivityResult() method.

When the user presses a native button, one of two things will occur (unless there’s an error!):

If the user is logged into their Google account, then a rollover image will appear to confirm that the offer /gift card / loyalty card has been saved

If the user is not logged in, then an authentication window will appear asking the user to authenticate their google account before saving to Android Pay

Now we know how to add the button for our users, we need to look a little more into each of the Loyalty, Offer and Gift Card objects. The next three sections take a deeper look at each of these, there will be some repetition in each of these sections to ensure every detail is covered (just in case you only wish to read up on a specific object section!).