Google Wallet API enables your users to add an object to Google Wallet from the web. Users can add their cards directly from your website.
This reference provides details about the HTML element g:savetoandroidpay
that
renders a Google Wallet API button
as well as the JSON Web Token
that describes your web service to Google.
Google Wallet API JavaScript
To automatically parse g:savetoandroidpay
HTML tags on load include the standard
JavaScript
<script src="https://apis.google.com/js/platform.js" type="text/javascript"></script>
For AJAX applications and explicit rendering of Google Wallet API buttons, include the "parsetags": "explicit"
parameter.
<script src="https://apis.google.com/js/platform.js" type="text/javascript"> {"parsetags": "explicit"} </script>
g:savetoandroidpay
HTML tag
The g:savetoandroidpay
namespace tag defines the
placement and various attributes of the Save to
Google Wallet button. Use this tag if you're rendering HTML and JWTs
server side.
<g:savetoandroidpay jwt="JWT" onsuccess="successHandler" onfailure="failureHandler" />
Field | Type | Required | Description |
---|---|---|---|
height |
String | N | Height of button to display. Possible values are: small (30px high) and
standard (38px high). The height defaults to small .
Refer to Google Wallet API buttons
to see samples of buttons with different height settings. |
jwt |
String | Y | Google Wallet API JWT. |
onsuccess |
String | N | String name of the add success callback handler function. |
onfailure |
String | N | String name of the save failure callback handler function. This function is passed an error object containing an errorCode and errorMessage. |
onprovidejwt |
String | N | String name of the provide JWT handler function. The purpose of this function is to
intercept and potentially manipulate the JWT data before the object is saved to Google Wallet.
This function takes in no parameters and must return the JWT as String.
When implementing the event handler, the original JWT data can be retrieved
under field this.getOpenParams().renderData.userParams.jwt . |
size |
String | N | Width of button to display. You can set size to matchparent
to have the width match the width of the parent element. Or, leave size
undefined so that the width stretches to fit the width of the text setting.
Refer to Google Wallet API buttons
to see samples of buttons with different size settings. |
text |
String | N | Deprecated |
textsize |
String | N | When textsize=large is specified, displays
dramatically increased text size and
button size, for cases with special UI requirements. |
theme |
String | N | Theme of button to display. Possible values are: dark and
light . The default theme is dark . Refer to
Google Wallet API buttons
to see samples of buttons with different theme settings. |
gapi.savetoandroidpay.render
function
This function allows you to explicitly render the Google Wallet API button.
gapi.savetoandroidpay.render("dom-container",{ "jwt": "JWT", "onsuccess": "successHandler", "onfailure": "failureHandler" });
Field | Type | Required | Description |
---|---|---|---|
dom-container |
String | Y | ID of container to place Google Wallet API button. |
jwt |
String | Y | JWT defining content to save. |
onsuccess |
String | N | String name of the save success callback handler function. |
onfailure |
String | N | String name of the save failure callback handler function. This function is passed an error object containing an errorCode and errorMessage. |
onprovidejwt |
String | N | String name of the provide JWT handler function. The purpose of this function is to
intercept and potentially manipulate the JWT data before the object is saved into Google Wallet.
This function takes in no parameters and must return the JWT as String.
When implementing the event handler, the original JWT data can be retrieved
under field this.getOpenParams().renderData.userParams.jwt . |
Google Wallet API error codes and messages
The following tables list the error codes and default error messages passed in the error object to the failure callback function, when an object doesn't save successfully using the javascript button.
{ "errorCode": "errorCode", "errorMessage": "errorMessage" }
errorCode |
errorMessage |
---|---|
SERVICE_FAILURE |
An error occurred on the Google Wallet server. |
CLASS_NOT_FOUND |
Class referenced in object was not found. |
CLASS_MISMATCH |
Object must be present, of the same type, and must reference the enclosed class. |
ORIGIN_MISMATCH |
Origin of button does not match those specified in the origins list. |
INVALID_NUM_TYPES |
Exactly one type of object can be specified. |
INVALID_SIGNATURE |
Signature could not be verified. |
INVALID_DUPLICATE_IDS |
Duplicates objects or classes are not allowed. |
INVALID_JWT |
Invalid JWT. |
INVALID_EXP_IAT |
JWT expired or was issued in the future. |
INVALID_AUD |
Invalid value for AUD field. |
INVALID_TYP |
Invalid value for TYP field. |
INVALID_NUM_OBJECTS |
Exactly one object and at most one class can be specified for loyalty cards, gift cards, and offers. |
MALFORMED_ORIGIN_URL |
Malformed origin url. Url must contain a protocol and domain. |
MISSING_ORIGIN |
Origin must be specified. |
MISSING_FIELDS |
Enclosed object or class was missing required fields. |
Localization
The language in the JavaScript button changes based on the following criteria:
- If the user is logged into Google, the button renders in the preferred language given in the user's Google account profile. A user can read Change language to learn how to change their Google account's preferred language.
- If the user isn't logged into Google, the button uses the
ACCEPT-LANGUAGE
value in the HTTP header.
If you notice the button doesn't render in the correct language based on the logic above, or if the wording is unnatural, contact our support team.