mirror of
https://github.com/google-wallet/rest-samples.git
synced 2026-01-09 13:38:01 -05:00
Addition of batch pass creation examples
* Updated .NET and Java file names to be consistent * Corrected indentation in .NET files * Added missing quotes in HTTP request bodies * Updated gradle version for Java examples * Added missing JSON conversion for Java HTTP requests * Added code to generate batch statements
This commit is contained in:
@@ -20,6 +20,7 @@ async function main() {
|
||||
// [START imports]
|
||||
const { GoogleAuth } = require('google-auth-library');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
// [END imports]
|
||||
|
||||
/*
|
||||
@@ -44,14 +45,15 @@ async function main() {
|
||||
* userId - Developer-defined ID for the user, such as an email address
|
||||
* - Environment variable: WALLET_USER_ID
|
||||
*/
|
||||
const userId = process.env.WALLET_USER_ID || 'user-id';
|
||||
let userId = process.env.WALLET_USER_ID || 'user-id';
|
||||
|
||||
/*
|
||||
* objectId - ID for the wallet object
|
||||
* - Format: `issuerId.userId`
|
||||
* - Format: `issuerId.identifier`
|
||||
* - Should only include alphanumeric characters, '.', '_', or '-'
|
||||
* - `identifier` is developer-defined and unique to the user
|
||||
*/
|
||||
const objectId = `${issuerId}.${userId.replace(/[^\w.-]/g, '_')}-${classId}`;
|
||||
let objectId = `${issuerId}.${userId.replace(/[^\w.-]/g, '_')}-${classId}`;
|
||||
// [END setup]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -192,8 +194,8 @@ async function main() {
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
let objectResponse;
|
||||
|
||||
try {
|
||||
objectResponse = await httpClient.request({
|
||||
url: objectUrl + objectId,
|
||||
@@ -217,7 +219,7 @@ async function main() {
|
||||
// [END object]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Create a JWT for the object, and encode it to create a "Save" URL.
|
||||
// Create a JWT for the object, and encode it to create a 'Save' URL.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// [START jwt]
|
||||
@@ -245,13 +247,13 @@ async function main() {
|
||||
|
||||
// [START createIssuer]
|
||||
// New issuer name
|
||||
const issuerName = "name";
|
||||
const issuerName = 'name';
|
||||
|
||||
// New issuer email address
|
||||
const issuerEmail = "email-address";
|
||||
const issuerEmail = 'email-address';
|
||||
|
||||
// Issuer API endpoint
|
||||
const issuerUrl = "https://walletobjects.googleapis.com/walletobjects/v1/issuer";
|
||||
const issuerUrl = 'https://walletobjects.googleapis.com/walletobjects/v1/issuer';
|
||||
|
||||
// New issuer information
|
||||
let issuerPayload = {
|
||||
@@ -284,8 +286,8 @@ async function main() {
|
||||
permissions: [
|
||||
// Copy as needed for each email address that will need access
|
||||
{
|
||||
emailAddress: "email-address",
|
||||
role: "READER | WRITER | OWNER"
|
||||
emailAddress: 'email-address',
|
||||
role: 'READER | WRITER | OWNER'
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -298,4 +300,137 @@ async function main() {
|
||||
|
||||
console.log('permissions PUT response:', permissionsResponse);
|
||||
// [END updatePermissions]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Batch create Google Wallet objects from an existing class
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//[START batch]
|
||||
// The request body will be a multiline string
|
||||
// See below for more information
|
||||
// https://cloud.google.com/compute/docs/api/how-tos/batch#example
|
||||
let data = '';
|
||||
let batchObject;
|
||||
|
||||
// Example: Generate three new pass objects
|
||||
for (let i = 0; i < 3; i++) {
|
||||
// Generate a random user ID
|
||||
userId = uuidv4().replace('[^\\w.-]', '_');
|
||||
|
||||
// Generate an object ID with the user ID
|
||||
objectId = `${issuerId}.${userId}-${classId}`;
|
||||
batchObject = {
|
||||
"id": objectId,
|
||||
"classId": `${issuerId}.${classId}`,
|
||||
"heroImage": {
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg",
|
||||
"description": "Test heroImage description"
|
||||
}
|
||||
},
|
||||
"textModulesData": [
|
||||
{
|
||||
"header": "Test text module header",
|
||||
"body": "Test text module body"
|
||||
}
|
||||
],
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Test link module uri description"
|
||||
},
|
||||
{
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Test link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"mainImage": {
|
||||
"kind": "walletobjects#image",
|
||||
"sourceUri": {
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg",
|
||||
"description": "Test image module description"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"barcode": {
|
||||
"kind": "walletobjects#barcode",
|
||||
"type": "qrCode",
|
||||
"value": "Test QR Code"
|
||||
},
|
||||
"state": "active",
|
||||
"seatInfo": {
|
||||
"kind": "walletobjects#eventSeat",
|
||||
"seat": {
|
||||
"kind": "walletobjects#localizedString",
|
||||
"defaultValue": {
|
||||
"kind": "walletobjects#translatedString",
|
||||
"language": "en-us",
|
||||
"value": "42"
|
||||
}
|
||||
},
|
||||
"row": {
|
||||
"kind": "walletobjects#localizedString",
|
||||
"defaultValue": {
|
||||
"kind": "walletobjects#translatedString",
|
||||
"language": "en-us",
|
||||
"value": "G3"
|
||||
}
|
||||
},
|
||||
"section": {
|
||||
"kind": "walletobjects#localizedString",
|
||||
"defaultValue": {
|
||||
"kind": "walletobjects#translatedString",
|
||||
"language": "en-us",
|
||||
"value": "5"
|
||||
}
|
||||
},
|
||||
"gate": {
|
||||
"kind": "walletobjects#localizedString",
|
||||
"defaultValue": {
|
||||
"kind": "walletobjects#translatedString",
|
||||
"language": "en-us",
|
||||
"value": "A"
|
||||
}
|
||||
}
|
||||
},
|
||||
"ticketHolderName": "Test ticket holder name",
|
||||
"ticketNumber": "Test ticket number",
|
||||
"locations": [
|
||||
{
|
||||
"kind": "walletobjects#latLongPoint",
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
data += '--batch_createobjectbatch\n';
|
||||
data += 'Content-Type: application/json\n\n';
|
||||
data += 'POST /walletobjects/v1/eventTicketObject/\n\n';
|
||||
|
||||
data += JSON.stringify(batchObject) + '\n\n';
|
||||
}
|
||||
data += '--batch_createobjectbatch--';
|
||||
|
||||
// Invoke the batch API calls
|
||||
let batchResponse = await httpClient.request({
|
||||
url: 'https://walletobjects.googleapis.com/batch',
|
||||
method: 'POST',
|
||||
data: data,
|
||||
headers: {
|
||||
// `boundary` is the delimiter between API calls in the batch request
|
||||
'Content-Type': 'multipart/mixed; boundary=batch_createobjectbatch'
|
||||
}
|
||||
});
|
||||
|
||||
console.log('batch POST response:', batchResponse);
|
||||
// [END batch]
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ async function main() {
|
||||
// [START imports]
|
||||
const { GoogleAuth } = require('google-auth-library');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
// [END imports]
|
||||
|
||||
/*
|
||||
@@ -44,14 +45,15 @@ async function main() {
|
||||
* userId - Developer-defined ID for the user, such as an email address
|
||||
* - Environment variable: WALLET_USER_ID
|
||||
*/
|
||||
const userId = process.env.WALLET_USER_ID || 'user-id';
|
||||
let userId = process.env.WALLET_USER_ID || 'user-id';
|
||||
|
||||
/*
|
||||
* objectId - ID for the wallet object
|
||||
* - Format: `issuerId.userId`
|
||||
* - Format: `issuerId.identifier`
|
||||
* - Should only include alphanumeric characters, '.', '_', or '-'
|
||||
* - `identifier` is developer-defined and unique to the user
|
||||
*/
|
||||
const objectId = `${issuerId}.${userId.replace(/[^\w.-]/g, '_')}-${classId}`;
|
||||
let objectId = `${issuerId}.${userId.replace(/[^\w.-]/g, '_')}-${classId}`;
|
||||
// [END setup]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -174,8 +176,8 @@ async function main() {
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
let objectResponse;
|
||||
|
||||
try {
|
||||
objectResponse = await httpClient.request({
|
||||
url: objectUrl + objectId,
|
||||
@@ -199,7 +201,7 @@ async function main() {
|
||||
// [END object]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Create a JWT for the object, and encode it to create a "Save" URL.
|
||||
// Create a JWT for the object, and encode it to create a 'Save' URL.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// [START jwt]
|
||||
@@ -227,13 +229,13 @@ async function main() {
|
||||
|
||||
// [START createIssuer]
|
||||
// New issuer name
|
||||
const issuerName = "name";
|
||||
const issuerName = 'name';
|
||||
|
||||
// New issuer email address
|
||||
const issuerEmail = "email-address";
|
||||
const issuerEmail = 'email-address';
|
||||
|
||||
// Issuer API endpoint
|
||||
const issuerUrl = "https://walletobjects.googleapis.com/walletobjects/v1/issuer";
|
||||
const issuerUrl = 'https://walletobjects.googleapis.com/walletobjects/v1/issuer';
|
||||
|
||||
// New issuer information
|
||||
let issuerPayload = {
|
||||
@@ -266,8 +268,8 @@ async function main() {
|
||||
permissions: [
|
||||
// Copy as needed for each email address that will need access
|
||||
{
|
||||
emailAddress: "email-address",
|
||||
role: "READER | WRITER | OWNER"
|
||||
emailAddress: 'email-address',
|
||||
role: 'READER | WRITER | OWNER'
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -280,4 +282,108 @@ async function main() {
|
||||
|
||||
console.log('permissions PUT response:', permissionsResponse);
|
||||
// [END updatePermissions]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Batch create Google Wallet objects from an existing class
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//[START batch]
|
||||
// The request body will be a multiline string
|
||||
// See below for more information
|
||||
// https://cloud.google.com/compute/docs/api/how-tos/batch#example
|
||||
let data = '';
|
||||
let batchObject;
|
||||
|
||||
// Example: Generate three new pass objects
|
||||
for (let i = 0; i < 3; i++) {
|
||||
// Generate a random user ID
|
||||
userId = uuidv4().replace('[^\\w.-]', '_');
|
||||
|
||||
// Generate an object ID with the user ID
|
||||
objectId = `${issuerId}.${userId}-${classId}`;
|
||||
batchObject = {
|
||||
"id": objectId,
|
||||
"classId": `${issuerId}.${classId}`,
|
||||
"heroImage": {
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg",
|
||||
"description": "Test heroImage description"
|
||||
}
|
||||
},
|
||||
"textModulesData": [
|
||||
{
|
||||
"header": "Test text module header",
|
||||
"body": "Test text module body"
|
||||
}
|
||||
],
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Test link module uri description"
|
||||
},
|
||||
{
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Test link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"mainImage": {
|
||||
"kind": "walletobjects#image",
|
||||
"sourceUri": {
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg",
|
||||
"description": "Test image module description"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"barcode": {
|
||||
"kind": "walletobjects#barcode",
|
||||
"type": "qrCode",
|
||||
"value": "Test QR Code"
|
||||
},
|
||||
"state": "active",
|
||||
"passengerName": "Test passenger name",
|
||||
"reservationInfo": {
|
||||
"confirmationCode": "Test confirmation code"
|
||||
},
|
||||
"boardingAndSeatingInfo": {
|
||||
"seatNumber": "42",
|
||||
"boardingGroup": "B"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"kind": "walletobjects#latLongPoint",
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
data += '--batch_createobjectbatch\n';
|
||||
data += 'Content-Type: application/json\n\n';
|
||||
data += 'POST /walletobjects/v1/flightObject/\n\n';
|
||||
|
||||
data += JSON.stringify(batchObject) + '\n\n';
|
||||
}
|
||||
data += '--batch_createobjectbatch--';
|
||||
|
||||
// Invoke the batch API calls
|
||||
let batchResponse = await httpClient.request({
|
||||
url: 'https://walletobjects.googleapis.com/batch',
|
||||
method: 'POST',
|
||||
data: data,
|
||||
headers: {
|
||||
// `boundary` is the delimiter between API calls in the batch request
|
||||
'Content-Type': 'multipart/mixed; boundary=batch_createobjectbatch'
|
||||
}
|
||||
});
|
||||
|
||||
console.log('batch POST response:', batchResponse);
|
||||
// [END batch]
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ async function main() {
|
||||
// [START imports]
|
||||
const { GoogleAuth } = require('google-auth-library');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
// [END imports]
|
||||
|
||||
/*
|
||||
@@ -44,14 +45,15 @@ async function main() {
|
||||
* userId - Developer-defined ID for the user, such as an email address
|
||||
* - Environment variable: WALLET_USER_ID
|
||||
*/
|
||||
const userId = process.env.WALLET_USER_ID || 'user-id';
|
||||
let userId = process.env.WALLET_USER_ID || 'user-id';
|
||||
|
||||
/*
|
||||
* objectId - ID for the wallet object
|
||||
* - Format: `issuerId.userId`
|
||||
* - Format: `issuerId.identifier`
|
||||
* - Should only include alphanumeric characters, '.', '_', or '-'
|
||||
* - `identifier` is developer-defined and unique to the user
|
||||
*/
|
||||
const objectId = `${issuerId}.${userId.replace(/[^\w.-]/g, '_')}-${classId}`;
|
||||
let objectId = `${issuerId}.${userId.replace(/[^\w.-]/g, '_')}-${classId}`;
|
||||
// [END setup]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -165,8 +167,8 @@ async function main() {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let objectResponse;
|
||||
|
||||
try {
|
||||
objectResponse = await httpClient.request({
|
||||
url: objectUrl + objectId,
|
||||
@@ -190,7 +192,7 @@ async function main() {
|
||||
// [END object]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Create a JWT for the object, and encode it to create a "Save" URL.
|
||||
// Create a JWT for the object, and encode it to create a 'Save' URL.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// [START jwt]
|
||||
@@ -218,13 +220,13 @@ async function main() {
|
||||
|
||||
// [START createIssuer]
|
||||
// New issuer name
|
||||
const issuerName = "name";
|
||||
const issuerName = 'name';
|
||||
|
||||
// New issuer email address
|
||||
const issuerEmail = "email-address";
|
||||
const issuerEmail = 'email-address';
|
||||
|
||||
// Issuer API endpoint
|
||||
const issuerUrl = "https://walletobjects.googleapis.com/walletobjects/v1/issuer";
|
||||
const issuerUrl = 'https://walletobjects.googleapis.com/walletobjects/v1/issuer';
|
||||
|
||||
// New issuer information
|
||||
let issuerPayload = {
|
||||
@@ -257,8 +259,8 @@ async function main() {
|
||||
permissions: [
|
||||
// Copy as needed for each email address that will need access
|
||||
{
|
||||
emailAddress: "email-address",
|
||||
role: "READER | WRITER | OWNER"
|
||||
emailAddress: 'email-address',
|
||||
role: 'READER | WRITER | OWNER'
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -271,4 +273,117 @@ async function main() {
|
||||
|
||||
console.log('permissions PUT response:', permissionsResponse);
|
||||
// [END updatePermissions]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Batch create Google Wallet objects from an existing class
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//[START batch]
|
||||
// The request body will be a multiline string
|
||||
// See below for more information
|
||||
// https://cloud.google.com/compute/docs/api/how-tos/batch#example
|
||||
let data = '';
|
||||
let batchObject;
|
||||
|
||||
// Example: Generate three new pass objects
|
||||
for (let i = 0; i < 3; i++) {
|
||||
// Generate a random user ID
|
||||
userId = uuidv4().replace('[^\\w.-]', '_');
|
||||
|
||||
// Generate an object ID with the user ID
|
||||
objectId = `${issuerId}.${userId}-${classId}`;
|
||||
batchObject = {
|
||||
"id": objectId,
|
||||
"classId": `${issuerId}.${classId}`,
|
||||
"heroImage": {
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg",
|
||||
"description": "Test heroImage description"
|
||||
}
|
||||
},
|
||||
"textModulesData": [
|
||||
{
|
||||
"header": "Test text module header",
|
||||
"body": "Test text module body"
|
||||
}
|
||||
],
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Test link module uri description"
|
||||
},
|
||||
{
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Test link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"mainImage": {
|
||||
"kind": "walletobjects#image",
|
||||
"sourceUri": {
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg",
|
||||
"description": "Test image module description"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"barcode": {
|
||||
"kind": "walletobjects#barcode",
|
||||
"type": "qrCode",
|
||||
"value": "Test QR Code"
|
||||
},
|
||||
"genericType": "GENERIC_TYPE_UNSPECIFIED",
|
||||
"hexBackgroundColor": "#4285f4",
|
||||
"logo": {
|
||||
"sourceUri": {
|
||||
"uri": "https://storage.googleapis.com/wallet-lab-tools-codelab-artifacts-public/pass_google_logo.jpg"
|
||||
}
|
||||
},
|
||||
"cardTitle": {
|
||||
"defaultValue": {
|
||||
"language": "en-US",
|
||||
"value": "Testing Generic Title"
|
||||
}
|
||||
},
|
||||
"header": {
|
||||
"defaultValue": {
|
||||
"language": "en-US",
|
||||
"value": "Testing Generic Header"
|
||||
}
|
||||
},
|
||||
"subheader": {
|
||||
"defaultValue": {
|
||||
"language": "en",
|
||||
"value": "Testing Generic Sub Header"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
data += '--batch_createobjectbatch\n';
|
||||
data += 'Content-Type: application/json\n\n';
|
||||
data += 'POST /walletobjects/v1/genericObject/\n\n';
|
||||
|
||||
data += JSON.stringify(batchObject) + '\n\n';
|
||||
}
|
||||
data += '--batch_createobjectbatch--';
|
||||
|
||||
// Invoke the batch API calls
|
||||
let batchResponse = await httpClient.request({
|
||||
url: 'https://walletobjects.googleapis.com/batch',
|
||||
method: 'POST',
|
||||
data: data,
|
||||
headers: {
|
||||
// `boundary` is the delimiter between API calls in the batch request
|
||||
'Content-Type': 'multipart/mixed; boundary=batch_createobjectbatch'
|
||||
}
|
||||
});
|
||||
|
||||
console.log('batch POST response:', batchResponse);
|
||||
// [END batch]
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ async function main() {
|
||||
// [START imports]
|
||||
const { GoogleAuth } = require('google-auth-library');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
// [END imports]
|
||||
|
||||
/*
|
||||
@@ -44,14 +45,15 @@ async function main() {
|
||||
* userId - Developer-defined ID for the user, such as an email address
|
||||
* - Environment variable: WALLET_USER_ID
|
||||
*/
|
||||
const userId = process.env.WALLET_USER_ID || 'user-id';
|
||||
let userId = process.env.WALLET_USER_ID || 'user-id';
|
||||
|
||||
/*
|
||||
* objectId - ID for the wallet object
|
||||
* - Format: `issuerId.userId`
|
||||
* - Format: `issuerId.identifier`
|
||||
* - Should only include alphanumeric characters, '.', '_', or '-'
|
||||
* - `identifier` is developer-defined and unique to the user
|
||||
*/
|
||||
const objectId = `${issuerId}.${userId.replace(/[^\w.-]/g, '_')}-${classId}`;
|
||||
let objectId = `${issuerId}.${userId.replace(/[^\w.-]/g, '_')}-${classId}`;
|
||||
// [END setup]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -160,8 +162,8 @@ async function main() {
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
let objectResponse;
|
||||
|
||||
try {
|
||||
objectResponse = await httpClient.request({
|
||||
url: objectUrl + objectId,
|
||||
@@ -185,7 +187,7 @@ async function main() {
|
||||
// [END object]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Create a JWT for the object, and encode it to create a "Save" URL.
|
||||
// Create a JWT for the object, and encode it to create a 'Save' URL.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// [START jwt]
|
||||
@@ -213,13 +215,13 @@ async function main() {
|
||||
|
||||
// [START createIssuer]
|
||||
// New issuer name
|
||||
const issuerName = "name";
|
||||
const issuerName = 'name';
|
||||
|
||||
// New issuer email address
|
||||
const issuerEmail = "email-address";
|
||||
const issuerEmail = 'email-address';
|
||||
|
||||
// Issuer API endpoint
|
||||
const issuerUrl = "https://walletobjects.googleapis.com/walletobjects/v1/issuer";
|
||||
const issuerUrl = 'https://walletobjects.googleapis.com/walletobjects/v1/issuer';
|
||||
|
||||
// New issuer information
|
||||
let issuerPayload = {
|
||||
@@ -252,8 +254,8 @@ async function main() {
|
||||
permissions: [
|
||||
// Copy as needed for each email address that will need access
|
||||
{
|
||||
emailAddress: "email-address",
|
||||
role: "READER | WRITER | OWNER"
|
||||
emailAddress: 'email-address',
|
||||
role: 'READER | WRITER | OWNER'
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -266,4 +268,109 @@ async function main() {
|
||||
|
||||
console.log('permissions PUT response:', permissionsResponse);
|
||||
// [END updatePermissions]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Batch create Google Wallet objects from an existing class
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//[START batch]
|
||||
// The request body will be a multiline string
|
||||
// See below for more information
|
||||
// https://cloud.google.com/compute/docs/api/how-tos/batch#example
|
||||
let data = '';
|
||||
let batchObject;
|
||||
|
||||
// Example: Generate three new pass objects
|
||||
for (let i = 0; i < 3; i++) {
|
||||
// Generate a random user ID
|
||||
userId = uuidv4().replace('[^\\w.-]', '_');
|
||||
|
||||
// Generate an object ID with the user ID
|
||||
objectId = `${issuerId}.${userId}-${classId}`;
|
||||
batchObject = {
|
||||
"id": objectId,
|
||||
"classId": `${issuerId}.${classId}`,
|
||||
"heroImage": {
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg",
|
||||
"description": "Test heroImage description"
|
||||
}
|
||||
},
|
||||
"textModulesData": [
|
||||
{
|
||||
"header": "Test text module header",
|
||||
"body": "Test text module body"
|
||||
}
|
||||
],
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Test link module uri description"
|
||||
},
|
||||
{
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Test link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"mainImage": {
|
||||
"kind": "walletobjects#image",
|
||||
"sourceUri": {
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg",
|
||||
"description": "Test image module description"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"barcode": {
|
||||
"kind": "walletobjects#barcode",
|
||||
"type": "qrCode",
|
||||
"value": "Test QR Code"
|
||||
},
|
||||
"cardNumber": "Test card number",
|
||||
"cardPin": "Test card pin",
|
||||
"balance": {
|
||||
"kind": "walletobjects#money",
|
||||
"micros": 20000000,
|
||||
"currencyCode": "USD"
|
||||
},
|
||||
"balanceUpdateTime": {
|
||||
"date": "2020-04-12T16:20:50.52Z"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"kind": "walletobjects#latLongPoint",
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
data += '--batch_createobjectbatch\n';
|
||||
data += 'Content-Type: application/json\n\n';
|
||||
data += 'POST /walletobjects/v1/giftCardObject/\n\n';
|
||||
|
||||
data += JSON.stringify(batchObject) + '\n\n';
|
||||
}
|
||||
data += '--batch_createobjectbatch--';
|
||||
|
||||
// Invoke the batch API calls
|
||||
let batchResponse = await httpClient.request({
|
||||
url: 'https://walletobjects.googleapis.com/batch',
|
||||
method: 'POST',
|
||||
data: data,
|
||||
headers: {
|
||||
// `boundary` is the delimiter between API calls in the batch request
|
||||
'Content-Type': 'multipart/mixed; boundary=batch_createobjectbatch'
|
||||
}
|
||||
});
|
||||
|
||||
console.log('batch POST response:', batchResponse);
|
||||
// [END batch]
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ async function main() {
|
||||
// [START imports]
|
||||
const { GoogleAuth } = require('google-auth-library');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
// [END imports]
|
||||
|
||||
/*
|
||||
@@ -44,14 +45,15 @@ async function main() {
|
||||
* userId - Developer-defined ID for the user, such as an email address
|
||||
* - Environment variable: WALLET_USER_ID
|
||||
*/
|
||||
const userId = process.env.WALLET_USER_ID || 'user-id';
|
||||
let userId = process.env.WALLET_USER_ID || 'user-id';
|
||||
|
||||
/*
|
||||
* objectId - ID for the wallet object
|
||||
* - Format: `issuerId.userId`
|
||||
* - Format: `issuerId.identifier`
|
||||
* - Should only include alphanumeric characters, '.', '_', or '-'
|
||||
* - `identifier` is developer-defined and unique to the user
|
||||
*/
|
||||
const objectId = `${issuerId}.${userId.replace(/[^\w.-]/g, '_')}-${classId}`;
|
||||
let objectId = `${issuerId}.${userId.replace(/[^\w.-]/g, '_')}-${classId}`;
|
||||
// [END setup]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -165,8 +167,8 @@ async function main() {
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
let objectResponse;
|
||||
|
||||
try {
|
||||
objectResponse = await httpClient.request({
|
||||
url: objectUrl + objectId,
|
||||
@@ -190,7 +192,7 @@ async function main() {
|
||||
// [END object]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Create a JWT for the object, and encode it to create a "Save" URL.
|
||||
// Create a JWT for the object, and encode it to create a 'Save' URL.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// [START jwt]
|
||||
@@ -218,13 +220,13 @@ async function main() {
|
||||
|
||||
// [START createIssuer]
|
||||
// New issuer name
|
||||
const issuerName = "name";
|
||||
const issuerName = 'name';
|
||||
|
||||
// New issuer email address
|
||||
const issuerEmail = "email-address";
|
||||
const issuerEmail = 'email-address';
|
||||
|
||||
// Issuer API endpoint
|
||||
const issuerUrl = "https://walletobjects.googleapis.com/walletobjects/v1/issuer";
|
||||
const issuerUrl = 'https://walletobjects.googleapis.com/walletobjects/v1/issuer';
|
||||
|
||||
// New issuer information
|
||||
let issuerPayload = {
|
||||
@@ -257,8 +259,8 @@ async function main() {
|
||||
permissions: [
|
||||
// Copy as needed for each email address that will need access
|
||||
{
|
||||
emailAddress: "email-address",
|
||||
role: "READER | WRITER | OWNER"
|
||||
emailAddress: 'email-address',
|
||||
role: 'READER | WRITER | OWNER'
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -271,4 +273,108 @@ async function main() {
|
||||
|
||||
console.log('permissions PUT response:', permissionsResponse);
|
||||
// [END updatePermissions]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Batch create Google Wallet objects from an existing class
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//[START batch]
|
||||
// The request body will be a multiline string
|
||||
// See below for more information
|
||||
// https://cloud.google.com/compute/docs/api/how-tos/batch#example
|
||||
let data = '';
|
||||
let batchObject;
|
||||
|
||||
// Example: Generate three new pass objects
|
||||
for (let i = 0; i < 3; i++) {
|
||||
// Generate a random user ID
|
||||
userId = uuidv4().replace('[^\\w.-]', '_');
|
||||
|
||||
// Generate an object ID with the user ID
|
||||
objectId = `${issuerId}.${userId}-${classId}`;
|
||||
batchObject = {
|
||||
"id": objectId,
|
||||
"classId": `${issuerId}.${classId}`,
|
||||
"heroImage": {
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg",
|
||||
"description": "Test heroImage description"
|
||||
}
|
||||
},
|
||||
"textModulesData": [
|
||||
{
|
||||
"header": "Test text module header",
|
||||
"body": "Test text module body"
|
||||
}
|
||||
],
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Test link module uri description"
|
||||
},
|
||||
{
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Test link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"mainImage": {
|
||||
"kind": "walletobjects#image",
|
||||
"sourceUri": {
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg",
|
||||
"description": "Test image module description"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"barcode": {
|
||||
"kind": "walletobjects#barcode",
|
||||
"type": "qrCode",
|
||||
"value": "Test QR Code"
|
||||
},
|
||||
"state": "active",
|
||||
"accountId": "Test account id",
|
||||
"accountName": "Test account name",
|
||||
"loyaltyPoints": {
|
||||
"balance": {
|
||||
"string": "800"
|
||||
},
|
||||
"label": "Points"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"kind": "walletobjects#latLongPoint",
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
data += '--batch_createobjectbatch\n';
|
||||
data += 'Content-Type: application/json\n\n';
|
||||
data += 'POST /walletobjects/v1/loyaltyObject/\n\n';
|
||||
|
||||
data += JSON.stringify(batchObject) + '\n\n';
|
||||
}
|
||||
data += '--batch_createobjectbatch--';
|
||||
|
||||
// Invoke the batch API calls
|
||||
let batchResponse = await httpClient.request({
|
||||
url: 'https://walletobjects.googleapis.com/batch',
|
||||
method: 'POST',
|
||||
data: data,
|
||||
headers: {
|
||||
// `boundary` is the delimiter between API calls in the batch request
|
||||
'Content-Type': 'multipart/mixed; boundary=batch_createobjectbatch'
|
||||
}
|
||||
});
|
||||
|
||||
console.log('batch POST response:', batchResponse);
|
||||
// [END batch]
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ async function main() {
|
||||
// [START imports]
|
||||
const { GoogleAuth } = require('google-auth-library');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
// [END imports]
|
||||
|
||||
/*
|
||||
@@ -44,14 +45,15 @@ async function main() {
|
||||
* userId - Developer-defined ID for the user, such as an email address
|
||||
* - Environment variable: WALLET_USER_ID
|
||||
*/
|
||||
const userId = process.env.WALLET_USER_ID || 'user-id';
|
||||
let userId = process.env.WALLET_USER_ID || 'user-id';
|
||||
|
||||
/*
|
||||
* objectId - ID for the wallet object
|
||||
* - Format: `issuerId.userId`
|
||||
* - Format: `issuerId.identifier`
|
||||
* - Should only include alphanumeric characters, '.', '_', or '-'
|
||||
* - `identifier` is developer-defined and unique to the user
|
||||
*/
|
||||
const objectId = `${issuerId}.${userId.replace(/[^\w.-]/g, '_')}-${classId}`;
|
||||
let objectId = `${issuerId}.${userId.replace(/[^\w.-]/g, '_')}-${classId}`;
|
||||
// [END setup]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -160,8 +162,8 @@ async function main() {
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
let objectResponse;
|
||||
|
||||
try {
|
||||
objectResponse = await httpClient.request({
|
||||
url: objectUrl + objectId,
|
||||
@@ -185,7 +187,7 @@ async function main() {
|
||||
// [END object]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Create a JWT for the object, and encode it to create a "Save" URL.
|
||||
// Create a JWT for the object, and encode it to create a 'Save' URL.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// [START jwt]
|
||||
@@ -213,13 +215,13 @@ async function main() {
|
||||
|
||||
// [START createIssuer]
|
||||
// New issuer name
|
||||
const issuerName = "name";
|
||||
const issuerName = 'name';
|
||||
|
||||
// New issuer email address
|
||||
const issuerEmail = "email-address";
|
||||
const issuerEmail = 'email-address';
|
||||
|
||||
// Issuer API endpoint
|
||||
const issuerUrl = "https://walletobjects.googleapis.com/walletobjects/v1/issuer";
|
||||
const issuerUrl = 'https://walletobjects.googleapis.com/walletobjects/v1/issuer';
|
||||
|
||||
// New issuer information
|
||||
let issuerPayload = {
|
||||
@@ -252,8 +254,8 @@ async function main() {
|
||||
permissions: [
|
||||
// Copy as needed for each email address that will need access
|
||||
{
|
||||
emailAddress: "email-address",
|
||||
role: "READER | WRITER | OWNER"
|
||||
emailAddress: 'email-address',
|
||||
role: 'READER | WRITER | OWNER'
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -266,4 +268,108 @@ async function main() {
|
||||
|
||||
console.log('permissions PUT response:', permissionsResponse);
|
||||
// [END updatePermissions]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Batch create Google Wallet objects from an existing class
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//[START batch]
|
||||
// The request body will be a multiline string
|
||||
// See below for more information
|
||||
// https://cloud.google.com/compute/docs/api/how-tos/batch#example
|
||||
let data = '';
|
||||
let batchObject;
|
||||
|
||||
// Example: Generate three new pass objects
|
||||
for (let i = 0; i < 3; i++) {
|
||||
// Generate a random user ID
|
||||
userId = uuidv4().replace('[^\\w.-]', '_');
|
||||
|
||||
// Generate an object ID with the user ID
|
||||
objectId = `${issuerId}.${userId}-${classId}`;
|
||||
batchObject = {
|
||||
"id": objectId,
|
||||
"classId": `${issuerId}.${classId}`,
|
||||
"heroImage": {
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg",
|
||||
"description": "Test heroImage description"
|
||||
}
|
||||
},
|
||||
"textModulesData": [
|
||||
{
|
||||
"header": "Test text module header",
|
||||
"body": "Test text module body"
|
||||
}
|
||||
],
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Test link module uri description"
|
||||
},
|
||||
{
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Test link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"mainImage": {
|
||||
"kind": "walletobjects#image",
|
||||
"sourceUri": {
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg",
|
||||
"description": "Test image module description"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"barcode": {
|
||||
"type": "qrCode",
|
||||
"value": "Testing Offers QR Code"
|
||||
},
|
||||
"state": "active",
|
||||
"validTimeInterval": {
|
||||
"kind": "walletobjects#timeInterval",
|
||||
"start": {
|
||||
"date": "2023-06-12T23:20:50.52Z"
|
||||
},
|
||||
"end": {
|
||||
"date": "2023-12-12T23:20:50.52Z"
|
||||
}
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"kind": "walletobjects#latLongPoint",
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
data += '--batch_createobjectbatch\n';
|
||||
data += 'Content-Type: application/json\n\n';
|
||||
data += 'POST /walletobjects/v1/offerObject/\n\n';
|
||||
|
||||
data += JSON.stringify(batchObject) + '\n\n';
|
||||
}
|
||||
data += '--batch_createobjectbatch--';
|
||||
|
||||
// Invoke the batch API calls
|
||||
let batchResponse = await httpClient.request({
|
||||
url: 'https://walletobjects.googleapis.com/batch',
|
||||
method: 'POST',
|
||||
data: data,
|
||||
headers: {
|
||||
// `boundary` is the delimiter between API calls in the batch request
|
||||
'Content-Type': 'multipart/mixed; boundary=batch_createobjectbatch'
|
||||
}
|
||||
});
|
||||
|
||||
console.log('batch POST response:', batchResponse);
|
||||
// [END batch]
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ async function main() {
|
||||
// [START imports]
|
||||
const { GoogleAuth } = require('google-auth-library');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
// [END imports]
|
||||
|
||||
/*
|
||||
@@ -44,14 +45,15 @@ async function main() {
|
||||
* userId - Developer-defined ID for the user, such as an email address
|
||||
* - Environment variable: WALLET_USER_ID
|
||||
*/
|
||||
const userId = process.env.WALLET_USER_ID || 'user-id';
|
||||
let userId = process.env.WALLET_USER_ID || 'user-id';
|
||||
|
||||
/*
|
||||
* objectId - ID for the wallet object
|
||||
* - Format: `issuerId.userId`
|
||||
* - Format: `issuerId.identifier`
|
||||
* - Should only include alphanumeric characters, '.', '_', or '-'
|
||||
* - `identifier` is developer-defined and unique to the user
|
||||
*/
|
||||
const objectId = `${issuerId}.${userId.replace(/[^\w.-]/g, '_')}-${classId}`;
|
||||
let objectId = `${issuerId}.${userId.replace(/[^\w.-]/g, '_')}-${classId}`;
|
||||
// [END setup]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -210,8 +212,8 @@ async function main() {
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
let objectResponse;
|
||||
|
||||
try {
|
||||
objectResponse = await httpClient.request({
|
||||
url: objectUrl + objectId,
|
||||
@@ -235,7 +237,7 @@ async function main() {
|
||||
// [END object]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Create a JWT for the object, and encode it to create a "Save" URL.
|
||||
// Create a JWT for the object, and encode it to create a 'Save' URL.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// [START jwt]
|
||||
@@ -263,13 +265,13 @@ async function main() {
|
||||
|
||||
// [START createIssuer]
|
||||
// New issuer name
|
||||
const issuerName = "name";
|
||||
const issuerName = 'name';
|
||||
|
||||
// New issuer email address
|
||||
const issuerEmail = "email-address";
|
||||
const issuerEmail = 'email-address';
|
||||
|
||||
// Issuer API endpoint
|
||||
const issuerUrl = "https://walletobjects.googleapis.com/walletobjects/v1/issuer";
|
||||
const issuerUrl = 'https://walletobjects.googleapis.com/walletobjects/v1/issuer';
|
||||
|
||||
// New issuer information
|
||||
let issuerPayload = {
|
||||
@@ -302,8 +304,8 @@ async function main() {
|
||||
permissions: [
|
||||
// Copy as needed for each email address that will need access
|
||||
{
|
||||
emailAddress: "email-address",
|
||||
role: "READER | WRITER | OWNER"
|
||||
emailAddress: 'email-address',
|
||||
role: 'READER | WRITER | OWNER'
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -316,4 +318,152 @@ async function main() {
|
||||
|
||||
console.log('permissions PUT response:', permissionsResponse);
|
||||
// [END updatePermissions]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Batch create Google Wallet objects from an existing class
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//[START batch]
|
||||
// The request body will be a multiline string
|
||||
// See below for more information
|
||||
// https://cloud.google.com/compute/docs/api/how-tos/batch#example
|
||||
let data = '';
|
||||
let batchObject;
|
||||
|
||||
// Example: Generate three new pass objects
|
||||
for (let i = 0; i < 3; i++) {
|
||||
// Generate a random user ID
|
||||
userId = uuidv4().replace('[^\\w.-]', '_');
|
||||
|
||||
// Generate an object ID with the user ID
|
||||
objectId = `${issuerId}.${userId}-${classId}`;
|
||||
batchObject = {
|
||||
"id": objectId,
|
||||
"classId": `${issuerId}.${classId}`,
|
||||
"heroImage": {
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg",
|
||||
"description": "Test heroImage description"
|
||||
}
|
||||
},
|
||||
"textModulesData": [
|
||||
{
|
||||
"header": "Test text module header",
|
||||
"body": "Test text module body"
|
||||
}
|
||||
],
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Test link module uri description"
|
||||
},
|
||||
{
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Test link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"mainImage": {
|
||||
"kind": "walletobjects#image",
|
||||
"sourceUri": {
|
||||
"kind": "walletobjects#uri",
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg",
|
||||
"description": "Test image module description"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"barcode": {
|
||||
"kind": "walletobjects#barcode",
|
||||
"type": "qrCode",
|
||||
"value": "Test QR Code"
|
||||
},
|
||||
"passengerType": "singlePassenger",
|
||||
"passengerNames": "Test passenger names",
|
||||
"ticketLeg": {
|
||||
"originStationCode": "LA",
|
||||
"originName": {
|
||||
"kind": "walletobjects#localizedString",
|
||||
"translatedValues": [
|
||||
{
|
||||
"kind": "walletobjects#translatedString",
|
||||
"language": "en-us",
|
||||
"value": "Test translated origin name"
|
||||
}
|
||||
],
|
||||
"defaultValue": {
|
||||
"kind": "walletobjects#translatedString",
|
||||
"language": "en-us",
|
||||
"value": "Test default origin name"
|
||||
}
|
||||
},
|
||||
"destinationStationCode": "SFO",
|
||||
"destinationName": {
|
||||
"kind": "walletobjects#localizedString",
|
||||
"translatedValues": [
|
||||
{
|
||||
"kind": "walletobjects#translatedString",
|
||||
"language": "en-us",
|
||||
"value": "Test translated destination name"
|
||||
}
|
||||
],
|
||||
"defaultValue": {
|
||||
"kind": "walletobjects#translatedString",
|
||||
"language": "en-us",
|
||||
"value": "Test default destination name"
|
||||
}
|
||||
},
|
||||
"departureDateTime": "2020-04-12T16:20:50.52Z",
|
||||
"arrivalDateTime": "2020-04-12T20:20:50.52Z",
|
||||
"fareName": {
|
||||
"kind": "walletobjects#localizedString",
|
||||
"translatedValues": [
|
||||
{
|
||||
"kind": "walletobjects#translatedString",
|
||||
"language": "en-us",
|
||||
"value": "Test translated fare name"
|
||||
}
|
||||
],
|
||||
"defaultValue": {
|
||||
"kind": "walletobjects#translatedString",
|
||||
"language": "en-us",
|
||||
"value": "Test default fare name"
|
||||
}
|
||||
}
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"kind": "walletobjects#latLongPoint",
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
data += '--batch_createobjectbatch\n';
|
||||
data += 'Content-Type: application/json\n\n';
|
||||
data += 'POST /walletobjects/v1/transitObject/\n\n';
|
||||
|
||||
data += JSON.stringify(batchObject) + '\n\n';
|
||||
}
|
||||
data += '--batch_createobjectbatch--';
|
||||
|
||||
// Invoke the batch API calls
|
||||
let batchResponse = await httpClient.request({
|
||||
url: 'https://walletobjects.googleapis.com/batch',
|
||||
method: 'POST',
|
||||
data: data,
|
||||
headers: {
|
||||
// `boundary` is the delimiter between API calls in the batch request
|
||||
'Content-Type': 'multipart/mixed; boundary=batch_createobjectbatch'
|
||||
}
|
||||
});
|
||||
|
||||
console.log('batch POST response:', batchResponse);
|
||||
// [END batch]
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user