How to create a Google digital pass template
A Google digital pass template is required to format a CWT or Semantic CWT credential as a Google digital pass.
Overview
Creating a Google digital pass template comprises the following steps:
Prerequisites
- Credentials associated with your organisation’s Google account.
Sample templates: You can download the following sample templates to better understand how to structure your own templates as you follow along this guide:
- CWT credential sample Google digital pass template.
- Semantic CWT credential sample Google digital pass template. Note that our provided template offers greater flexibility in designing the digital pass, while the suggested template in the code snippets below would be easier to get started with. Either way. it is highly recommended to use Google’s Generic Pass template.
Design a template
Create your template in a JSON file and then bundle it into a .zip
file. The JSON file contains
the digital pass information, identifiers and value mappings. It is structured as follows:
.zip
file cannot be larger than 1mb.{
"genericClass": {
"textModulesData": [
{
"header": "Name",
"body": "{{ decoded.name }}"
},
{
"header": "Certification",
"body": "{{ decoded.certificationName }}"
},
{
"header": "Code",
"body": "{{ decoded.code }}"
},
{
"header": "Certified for",
"body": "{{ decoded.certificationLevel }}"
},
{
"header": "Expires on",
"body": "{{ date decoded.expiry 'dd MMM yyyy' }}"
},
{
"header": "Issued by",
"body": "{{ decoded.issuerName }}"
}
]
},
"genericObject": {
"genericType": "GENERIC_TYPE_UNSPECIFIED",
"cardTitle": {
"defaultValue": {
"language": "en-US",
"value": "Working at Heights Certification"
}
},
"header": {
"defaultValue": {
"language": "en-US",
"value": "{{ decoded.certificationName }}"
}
},
"subHeader": {
"defaultValue": {
"language": "en-US",
"value": "Advanced Safety Training"
}
},
"logo": {
"sourceUri": {
"uri": "https://YOUR_WEB_DOMAIN/LINK_TO_LOGO_IMAGE.png",
"description": ""
}
},
"hexBackgroundColor": "#CACACA",
"heroImage": {
"sourceUri": {
"uri": "https://YOUR_WEB_DOMAIN/LINK_TO_HERO_IMAGE.png",
"description": ""
}
},
"barcode": {
"type": "QR_CODE",
"value": "{{encoded}}",
"alternateText": "QR code"
}
}
}
genericClass
: Contains common data across objects. Text fields on the pass face are defined here. Each text module contains a header and a body for each row. To add text to the pass details, set the values in thetextModulesData
. Refer to Google Wallet GenericClass documentation for more options.genericObject
: Represents each Generic Pass a user has in their Google Wallet app. It contains a number of configurable attributes such as card title, header, sub header, logo, background color, hero image and barcode. The image assets should be uploaded and publicly accessible. Refer to Google Wallet GenericObject documentation for more options.
Create a MATTR VII template
Request
Make a multipart/form-data
request with the template .zip
file included as a binary file to
create a CWT credential Google digital pass template:
POST /v2/credentials/compact/digital-pass/google/templates
You can make a similar request to a different endpoint to create a Semantic CWT credential Apple digital pass template:
POST /v2/credentials/compact-semantic/digital-pass/google/templates
Request keys
Key | Type | Description |
---|---|---|
template | File | Include your template .zip file. |
name | Text | Insert a name to identify this Google digital pass template. |
issuerId | Text | Google Wallet Pass signer issuer ID. |
serviceAccountClientEmail | Text | Email address of the Google Cloud Platform service account for accessing the Google Pay Passes API. |
serviceAccountPrivateKey | Text | Private key PEM of the Google Cloud Platform service account. |
Learn how to grant access to your service account to call the Google Wallet API.
Response
{
"id": "0793fade-bd27-46a8-8dfe-67c4d3e9cf09",
"name": "example",
"passType": "google",
"metadata": {
"issuerId": "xxxxx",
"serviceAccountClientEmail": "xxxxx",
"payPassId": "xxxxx"
}
}
id
: This is a unique identifier for this Apple digital pass template. You will use it as thetemplateId
when formatting a CWT credential as a Google digital pass.- All other fields in the response include information retrieved from your Google digital pass template.
Troubleshooting
Errors may occur in the following scenarios:
- Unable to decompress the template
.zip
file. template.json
is missing from the bundle or it is malformed.- The template
.zip
file exceeds the maximum size allowed (1mb).
To avoid potential impact on previously generated Google digital passes, updating an existing template will always create a new template in the Google Pay Business Console.