mirror of
https://github.com/google-wallet/rest-samples.git
synced 2026-01-09 13:38:01 -05:00
Merge pull request #111 from google-wallet/cloudlibs
Use official client libraries for all samples
This commit is contained in:
@@ -69,7 +69,7 @@ class DemoEventTicket
|
||||
.FromFile(keyFilePath)
|
||||
.CreateScoped(new List<string>
|
||||
{
|
||||
"https://www.googleapis.com/auth/wallet_object.issuer"
|
||||
WalletobjectsService.ScopeConstants.WalletObjectIssuer
|
||||
})
|
||||
.UnderlyingCredential;
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class DemoFlight
|
||||
.FromFile(keyFilePath)
|
||||
.CreateScoped(new List<string>
|
||||
{
|
||||
"https://www.googleapis.com/auth/wallet_object.issuer"
|
||||
WalletobjectsService.ScopeConstants.WalletObjectIssuer
|
||||
})
|
||||
.UnderlyingCredential;
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class DemoGeneric
|
||||
.FromFile(keyFilePath)
|
||||
.CreateScoped(new List<string>
|
||||
{
|
||||
"https://www.googleapis.com/auth/wallet_object.issuer"
|
||||
WalletobjectsService.ScopeConstants.WalletObjectIssuer
|
||||
})
|
||||
.UnderlyingCredential;
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class DemoGiftCard
|
||||
.FromFile(keyFilePath)
|
||||
.CreateScoped(new List<string>
|
||||
{
|
||||
"https://www.googleapis.com/auth/wallet_object.issuer"
|
||||
WalletobjectsService.ScopeConstants.WalletObjectIssuer
|
||||
})
|
||||
.UnderlyingCredential;
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class DemoLoyalty
|
||||
.FromFile(keyFilePath)
|
||||
.CreateScoped(new List<string>
|
||||
{
|
||||
"https://www.googleapis.com/auth/wallet_object.issuer"
|
||||
WalletobjectsService.ScopeConstants.WalletObjectIssuer
|
||||
})
|
||||
.UnderlyingCredential;
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class DemoOffer
|
||||
.FromFile(keyFilePath)
|
||||
.CreateScoped(new List<string>
|
||||
{
|
||||
"https://www.googleapis.com/auth/wallet_object.issuer"
|
||||
WalletobjectsService.ScopeConstants.WalletObjectIssuer
|
||||
})
|
||||
.UnderlyingCredential;
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class DemoTransit
|
||||
.FromFile(keyFilePath)
|
||||
.CreateScoped(new List<string>
|
||||
{
|
||||
"https://www.googleapis.com/auth/wallet_object.issuer"
|
||||
WalletobjectsService.ScopeConstants.WalletObjectIssuer
|
||||
})
|
||||
.UnderlyingCredential;
|
||||
|
||||
|
||||
@@ -22,8 +22,6 @@ creating a pass class, updating issuer permissions, and more.
|
||||
* Follow the steps outlined in the
|
||||
[Google Wallet prerequisites](https://developers.google.com/wallet/generic/web/prerequisites)
|
||||
to create the Google Wallet issuer account and Google Cloud service account
|
||||
* Download the C#
|
||||
[Google Wallet API Client library](https://developers.google.com/wallet/generic/resources/libraries#c)
|
||||
|
||||
## Environment variables
|
||||
|
||||
|
||||
@@ -2,17 +2,17 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>wallet_rest_samples</RootNamespace>
|
||||
<Nullable>disable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Google.Apis.Auth" Version="1.57.0" />
|
||||
<PackageReference Include="Google.Apis.IAMCredentials.v1" Version="1.57.0.2528" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.15.0" />
|
||||
<PackageReference Include="Google.Apis.Auth" Version="1.66.0" />
|
||||
<PackageReference Include="Google.Apis.Walletobjects.v1" Version="1.66.0.3324" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.34.0" />
|
||||
<!--
|
||||
Set the Include path to the path where you saved the library locally.
|
||||
-->
|
||||
@@ -27,4 +27,4 @@
|
||||
<CodeFiles Include="DemoTransit.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -20,6 +20,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/golang-jwt/jwt"
|
||||
@@ -27,35 +28,34 @@ import (
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/google"
|
||||
oauthJwt "golang.org/x/oauth2/jwt"
|
||||
"google.golang.org/api/option"
|
||||
"google.golang.org/api/walletobjects/v1"
|
||||
"io"
|
||||
"net/http"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// [END imports]
|
||||
|
||||
const (
|
||||
batchUrl = "https://walletobjects.googleapis.com/batch"
|
||||
classUrl = "https://walletobjects.googleapis.com/walletobjects/v1/eventTicketClass"
|
||||
objectUrl = "https://walletobjects.googleapis.com/walletobjects/v1/eventTicketObject"
|
||||
)
|
||||
|
||||
// [END setup]
|
||||
|
||||
type demoEventticket struct {
|
||||
credentials *oauthJwt.Config
|
||||
httpClient *http.Client
|
||||
batchUrl, classUrl, objectUrl string
|
||||
credentials *oauthJwt.Config
|
||||
service *walletobjects.Service
|
||||
}
|
||||
|
||||
// [START auth]
|
||||
// Create authenticated HTTP client using a service account file.
|
||||
func (d *demoEventticket) auth() {
|
||||
b, _ := os.ReadFile(os.Getenv("GOOGLE_APPLICATION_CREDENTIALS"))
|
||||
credentials, _ := google.JWTConfigFromJSON(b, "https://www.googleapis.com/auth/wallet_object.issuer")
|
||||
credentialsFile := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
||||
b, _ := os.ReadFile(credentialsFile)
|
||||
credentials, err := google.JWTConfigFromJSON(b, walletobjects.WalletObjectIssuerScope)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to load credentials: %v", err)
|
||||
}
|
||||
d.credentials = credentials
|
||||
d.httpClient = d.credentials.Client(oauth2.NoContext)
|
||||
d.service, _ = walletobjects.NewService(context.Background(), option.WithCredentialsFile(credentialsFile))
|
||||
}
|
||||
|
||||
// [END auth]
|
||||
@@ -63,28 +63,21 @@ func (d *demoEventticket) auth() {
|
||||
// [START createClass]
|
||||
// Create a class.
|
||||
func (d *demoEventticket) createClass(issuerId, classSuffix string) {
|
||||
newClass := fmt.Sprintf(`
|
||||
{
|
||||
"eventId": "EVENT_ID",
|
||||
"eventName": {
|
||||
"defaultValue": {
|
||||
"value": "Event name",
|
||||
"language": "en-US"
|
||||
}
|
||||
eventticketClass := new(walletobjects.EventTicketClass)
|
||||
eventticketClass.Id = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
eventticketClass.EventName = &walletobjects.LocalizedString{
|
||||
DefaultValue: &walletobjects.TranslatedString{
|
||||
Language: "en-us",
|
||||
Value: "Event name",
|
||||
},
|
||||
"issuerName": "Issuer name",
|
||||
"id": "%s.%s",
|
||||
"reviewStatus": "UNDER_REVIEW"
|
||||
}
|
||||
`, issuerId, classSuffix)
|
||||
|
||||
res, err := d.httpClient.Post(classUrl, "application/json", bytes.NewBuffer([]byte(newClass)))
|
||||
|
||||
eventticketClass.IssuerName = "Issuer name"
|
||||
eventticketClass.ReviewStatus = "UNDER_REVIEW"
|
||||
res, err := d.service.Eventticketclass.Insert(eventticketClass).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to insert class: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Class insert response:\n%s\n", b)
|
||||
fmt.Printf("Class insert id:\n%v\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,107 +86,90 @@ func (d *demoEventticket) createClass(issuerId, classSuffix string) {
|
||||
// [START createObject]
|
||||
// Create an object.
|
||||
func (d *demoEventticket) createObject(issuerId, classSuffix, objectSuffix string) {
|
||||
newObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"ticketHolderName": "Ticket holder name",
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
eventticketObject := new(walletobjects.EventTicketObject)
|
||||
eventticketObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
eventticketObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
eventticketObject.TicketHolderName = "Ticket holder name"
|
||||
eventticketObject.TicketNumber = "Ticket number"
|
||||
eventticketObject.State = "ACTIVE"
|
||||
eventticketObject.HeroImage = &walletobjects.Image{
|
||||
SourceUri: &walletobjects.ImageUri{
|
||||
Uri: "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg",
|
||||
},
|
||||
}
|
||||
eventticketObject.Barcode = &walletobjects.Barcode{
|
||||
Type: "QR_CODE",
|
||||
Value: "QR code",
|
||||
}
|
||||
eventticketObject.Locations = []*walletobjects.LatLongPoint{
|
||||
&walletobjects.LatLongPoint{
|
||||
Latitude: 37.424015499999996,
|
||||
Longitude: -122.09259560000001,
|
||||
},
|
||||
}
|
||||
eventticketObject.LinksModuleData = &walletobjects.LinksModuleData{
|
||||
Uris: []*walletobjects.Uri{
|
||||
&walletobjects.Uri{
|
||||
Id: "LINK_MODULE_URI_ID",
|
||||
Uri: "http://maps.google.com/",
|
||||
Description: "Link module URI description",
|
||||
},
|
||||
&walletobjects.Uri{
|
||||
Id: "LINK_MODULE_TEL_ID",
|
||||
Uri: "tel:6505555555",
|
||||
Description: "Link module tel description",
|
||||
},
|
||||
},
|
||||
}
|
||||
eventticketObject.ImageModulesData = []*walletobjects.ImageModuleData{
|
||||
&walletobjects.ImageModuleData{
|
||||
Id: "IMAGE_MODULE_ID",
|
||||
MainImage: &walletobjects.Image{
|
||||
SourceUri: &walletobjects.ImageUri{
|
||||
Uri: "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
eventticketObject.TextModulesData = []*walletobjects.TextModuleData{
|
||||
&walletobjects.TextModuleData{
|
||||
Body: "Text module body",
|
||||
Header: "Text module header",
|
||||
Id: "TEXT_MODULE_ID",
|
||||
},
|
||||
}
|
||||
eventticketObject.SeatInfo = &walletobjects.EventSeat{
|
||||
Gate: &walletobjects.LocalizedString{
|
||||
DefaultValue: &walletobjects.TranslatedString{
|
||||
Language: "en-us",
|
||||
Value: "A",
|
||||
},
|
||||
},
|
||||
Section: &walletobjects.LocalizedString{
|
||||
DefaultValue: &walletobjects.TranslatedString{
|
||||
Language: "en-us",
|
||||
Value: "5",
|
||||
},
|
||||
},
|
||||
Row: &walletobjects.LocalizedString{
|
||||
DefaultValue: &walletobjects.TranslatedString{
|
||||
Language: "en-us",
|
||||
Value: "G3",
|
||||
},
|
||||
},
|
||||
Seat: &walletobjects.LocalizedString{
|
||||
DefaultValue: &walletobjects.TranslatedString{
|
||||
Language: "en-us",
|
||||
Value: "42",
|
||||
},
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
],
|
||||
"state": "ACTIVE",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"ticketNumber": "Ticket number",
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"seatInfo": {
|
||||
"gate": {
|
||||
"defaultValue": {
|
||||
"value": "A",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"section": {
|
||||
"defaultValue": {
|
||||
"value": "5",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"row": {
|
||||
"defaultValue": {
|
||||
"value": "G3",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"seat": {
|
||||
"defaultValue": {
|
||||
"value": "42",
|
||||
"language": "en-US"
|
||||
}
|
||||
}
|
||||
},
|
||||
"id": "%s.%s"
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
|
||||
res, err := d.httpClient.Post(objectUrl, "application/json", bytes.NewBuffer([]byte(newObject)))
|
||||
|
||||
res, err := d.service.Eventticketobject.Insert(eventticketObject).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to insert object: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Object insert response:\n%s\n", b)
|
||||
fmt.Printf("Object insert id:\n%s\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,16 +181,14 @@ func (d *demoEventticket) createObject(issuerId, classSuffix, objectSuffix strin
|
||||
// Sets the object's state to Expired. If the valid time interval is
|
||||
// already set, the pass will expire automatically up to 24 hours after.
|
||||
func (d *demoEventticket) expireObject(issuerId, objectSuffix string) {
|
||||
patchBody := `{"state": "EXPIRED"}`
|
||||
url := fmt.Sprintf("%s/%s.%s", objectUrl, issuerId, objectSuffix)
|
||||
req, _ := http.NewRequest(http.MethodPatch, url, bytes.NewBuffer([]byte(patchBody)))
|
||||
res, err := d.httpClient.Do(req)
|
||||
|
||||
eventticketObject := &walletobjects.EventTicketObject{
|
||||
State: "EXPIRED",
|
||||
}
|
||||
res, err := d.service.Eventticketobject.Patch(fmt.Sprintf("%s.%s", issuerId, objectSuffix), eventticketObject).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to patch object: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Object expiration response:\n%s\n", b)
|
||||
fmt.Printf("Object expiration id:\n%s\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,123 +202,20 @@ func (d *demoEventticket) expireObject(issuerId, objectSuffix string) {
|
||||
// created. This allows you to create multiple pass classes and objects in
|
||||
// one API call when the user saves the pass to their wallet.
|
||||
func (d *demoEventticket) createJwtNewObjects(issuerId, classSuffix, objectSuffix string) {
|
||||
newClass := fmt.Sprintf(`
|
||||
{
|
||||
"eventId": "EVENT_ID",
|
||||
"eventName": {
|
||||
"defaultValue": {
|
||||
"value": "Event name",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"issuerName": "Issuer name",
|
||||
"id": "%s.%s",
|
||||
"reviewStatus": "UNDER_REVIEW"
|
||||
}
|
||||
`, issuerId, classSuffix)
|
||||
eventticketObject := new(walletobjects.EventTicketObject)
|
||||
eventticketObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
eventticketObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
eventticketObject.TicketHolderName = "Ticket holder name"
|
||||
eventticketObject.TicketNumber = "Ticket number"
|
||||
eventticketObject.State = "ACTIVE"
|
||||
|
||||
newObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"ticketHolderName": "Ticket holder name",
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
],
|
||||
"state": "ACTIVE",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"ticketNumber": "Ticket number",
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"seatInfo": {
|
||||
"gate": {
|
||||
"defaultValue": {
|
||||
"value": "A",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"section": {
|
||||
"defaultValue": {
|
||||
"value": "5",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"row": {
|
||||
"defaultValue": {
|
||||
"value": "G3",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"seat": {
|
||||
"defaultValue": {
|
||||
"value": "42",
|
||||
"language": "en-US"
|
||||
}
|
||||
}
|
||||
},
|
||||
"id": "%s.%s"
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
|
||||
var payload map[string]interface{}
|
||||
eventticketJson, _ := json.Marshal(eventticketObject)
|
||||
var payload map[string]any
|
||||
json.Unmarshal([]byte(fmt.Sprintf(`
|
||||
{
|
||||
"genericClasses": [%s],
|
||||
"genericObjects": [%s]
|
||||
"eventticketObjects": [%s]
|
||||
}
|
||||
`, newClass, newObject)), &payload)
|
||||
|
||||
`, eventticketJson)), &payload)
|
||||
claims := jwt.MapClaims{
|
||||
"iss": d.credentials.Email,
|
||||
"aud": "google",
|
||||
@@ -370,7 +241,7 @@ func (d *demoEventticket) createJwtNewObjects(issuerId, classSuffix, objectSuffi
|
||||
// their wallet, the pass objects defined in the JWT are added to the
|
||||
// user's Google Wallet app. This allows the user to save multiple pass
|
||||
// objects in one API call.
|
||||
func (d *demoEventticket) createJwtExistingObjects(issuerId string) {
|
||||
func (d *demoEventticket) createJwtExistingObjects(issuerId string, classSuffix string, objectSuffix string) {
|
||||
var payload map[string]interface{}
|
||||
json.Unmarshal([]byte(fmt.Sprintf(`
|
||||
{
|
||||
@@ -394,7 +265,7 @@ func (d *demoEventticket) createJwtExistingObjects(issuerId string) {
|
||||
"classId": "%s.GIFT_CARD_CLASS_SUFFIX"
|
||||
}],
|
||||
|
||||
"loyaltyObjects": [{
|
||||
"eventticketObjects": [{
|
||||
"id": "%s.LOYALTY_OBJECT_SUFFIX",
|
||||
"classId": "%s.LOYALTY_CLASS_SUFFIX"
|
||||
}],
|
||||
@@ -436,99 +307,15 @@ func (d *demoEventticket) batchCreateObjects(issuerId, classSuffix string) {
|
||||
for i := 0; i < 3; i++ {
|
||||
objectSuffix := strings.ReplaceAll(uuid.New().String(), "-", "_")
|
||||
|
||||
batchObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"ticketHolderName": "Ticket holder name",
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
],
|
||||
"state": "ACTIVE",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"ticketNumber": "Ticket number",
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"seatInfo": {
|
||||
"gate": {
|
||||
"defaultValue": {
|
||||
"value": "A",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"section": {
|
||||
"defaultValue": {
|
||||
"value": "5",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"row": {
|
||||
"defaultValue": {
|
||||
"value": "G3",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"seat": {
|
||||
"defaultValue": {
|
||||
"value": "42",
|
||||
"language": "en-US"
|
||||
}
|
||||
}
|
||||
},
|
||||
"id": "%s.%s"
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
eventticketObject := new(walletobjects.EventTicketObject)
|
||||
eventticketObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
eventticketObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
eventticketObject.TicketHolderName = "Ticket holder name"
|
||||
eventticketObject.TicketNumber = "Ticket number"
|
||||
eventticketObject.State = "ACTIVE"
|
||||
|
||||
eventticketJson, _ := json.Marshal(eventticketObject)
|
||||
batchObject := fmt.Sprintf("%s", eventticketJson)
|
||||
|
||||
data += "--batch_createobjectbatch\n"
|
||||
data += "Content-Type: application/json\n\n"
|
||||
@@ -537,9 +324,7 @@ func (d *demoEventticket) batchCreateObjects(issuerId, classSuffix string) {
|
||||
}
|
||||
data += "--batch_createobjectbatch--"
|
||||
|
||||
|
||||
// batchUrl = 'https://walletobjects.googleapis.com/batch';
|
||||
res, err := d.httpClient.Post(batchUrl, "multipart/mixed; boundary=batch_createobjectbatch", bytes.NewBuffer([]byte(data)))
|
||||
res, err := d.credentials.Client(oauth2.NoContext).Post("https://walletobjects.googleapis.com/batch", "multipart/mixed; boundary=batch_createobjectbatch", bytes.NewBuffer([]byte(data)))
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
@@ -552,11 +337,6 @@ func (d *demoEventticket) batchCreateObjects(issuerId, classSuffix string) {
|
||||
// [END batch]
|
||||
|
||||
func main() {
|
||||
if len(os.Args) == 0 {
|
||||
fmt.Println("Usage: go run demo_eventticket.go <issuer-id>")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
issuerId := os.Getenv("WALLET_ISSUER_ID")
|
||||
classSuffix := strings.ReplaceAll(uuid.New().String(), "-", "_")
|
||||
objectSuffix := fmt.Sprintf("%s-%s", strings.ReplaceAll(uuid.New().String(), "-", "_"), classSuffix)
|
||||
@@ -568,6 +348,6 @@ func main() {
|
||||
d.createObject(issuerId, classSuffix, objectSuffix)
|
||||
d.expireObject(issuerId, objectSuffix)
|
||||
d.createJwtNewObjects(issuerId, classSuffix, objectSuffix)
|
||||
d.createJwtExistingObjects(issuerId)
|
||||
d.createJwtExistingObjects(issuerId, classSuffix, objectSuffix)
|
||||
d.batchCreateObjects(issuerId, classSuffix)
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/golang-jwt/jwt"
|
||||
@@ -27,35 +28,34 @@ import (
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/google"
|
||||
oauthJwt "golang.org/x/oauth2/jwt"
|
||||
"google.golang.org/api/option"
|
||||
"google.golang.org/api/walletobjects/v1"
|
||||
"io"
|
||||
"net/http"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// [END imports]
|
||||
|
||||
const (
|
||||
batchUrl = "https://walletobjects.googleapis.com/batch"
|
||||
classUrl = "https://walletobjects.googleapis.com/walletobjects/v1/flightClass"
|
||||
objectUrl = "https://walletobjects.googleapis.com/walletobjects/v1/flightObject"
|
||||
)
|
||||
|
||||
// [END setup]
|
||||
|
||||
type demoFlight struct {
|
||||
credentials *oauthJwt.Config
|
||||
httpClient *http.Client
|
||||
batchUrl, classUrl, objectUrl string
|
||||
credentials *oauthJwt.Config
|
||||
service *walletobjects.Service
|
||||
}
|
||||
|
||||
// [START auth]
|
||||
// Create authenticated HTTP client using a service account file.
|
||||
func (d *demoFlight) auth() {
|
||||
b, _ := os.ReadFile(os.Getenv("GOOGLE_APPLICATION_CREDENTIALS"))
|
||||
credentials, _ := google.JWTConfigFromJSON(b, "https://www.googleapis.com/auth/wallet_object.issuer")
|
||||
credentialsFile := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
||||
b, _ := os.ReadFile(credentialsFile)
|
||||
credentials, err := google.JWTConfigFromJSON(b, walletobjects.WalletObjectIssuerScope)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to load credentials: %v", err)
|
||||
}
|
||||
d.credentials = credentials
|
||||
d.httpClient = d.credentials.Client(oauth2.NoContext)
|
||||
d.service, _ = walletobjects.NewService(context.Background(), option.WithCredentialsFile(credentialsFile))
|
||||
}
|
||||
|
||||
// [END auth]
|
||||
@@ -63,38 +63,33 @@ func (d *demoFlight) auth() {
|
||||
// [START createClass]
|
||||
// Create a class.
|
||||
func (d *demoFlight) createClass(issuerId, classSuffix string) {
|
||||
newClass := fmt.Sprintf(`
|
||||
{
|
||||
"origin": {
|
||||
"terminal": "1",
|
||||
"gate": "A2",
|
||||
"airportIataCode": "LAX"
|
||||
},
|
||||
"flightHeader": {
|
||||
"carrier": {
|
||||
"carrierIataCode": "LX"
|
||||
},
|
||||
"flightNumber": "123"
|
||||
},
|
||||
"localScheduledDepartureDateTime": "2023-07-02T15:30:00",
|
||||
"reviewStatus": "UNDER_REVIEW",
|
||||
"issuerName": "Issuer name",
|
||||
"destination": {
|
||||
"terminal": "2",
|
||||
"gate": "C3",
|
||||
"airportIataCode": "SFO"
|
||||
},
|
||||
"id": "%s.%s"
|
||||
flightClass := new(walletobjects.FlightClass)
|
||||
flightClass.Id = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
flightClass.ReviewStatus = "UNDER_REVIEW"
|
||||
flightClass.IssuerName = "Issuer name"
|
||||
flightClass.Origin = &walletobjects.AirportInfo{
|
||||
Terminal: "1",
|
||||
Gate: "A2",
|
||||
AirportIataCode: "LAX",
|
||||
}
|
||||
`, issuerId, classSuffix)
|
||||
|
||||
res, err := d.httpClient.Post(classUrl, "application/json", bytes.NewBuffer([]byte(newClass)))
|
||||
flightClass.Destination = &walletobjects.AirportInfo{
|
||||
Terminal: "2",
|
||||
Gate: "C3",
|
||||
AirportIataCode: "SFO",
|
||||
}
|
||||
flightClass.FlightHeader = &walletobjects.FlightHeader{
|
||||
Carrier: &walletobjects.FlightCarrier{
|
||||
CarrierIataCode: "LX",
|
||||
},
|
||||
FlightNumber: "123",
|
||||
}
|
||||
flightClass.LocalScheduledDepartureDateTime = "2023-06-12T23:20:50"
|
||||
|
||||
res, err := d.service.Flightclass.Insert(flightClass).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to insert class: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Class insert response:\n%s\n", b)
|
||||
fmt.Printf("Class insert id:\n%v\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,87 +98,70 @@ func (d *demoFlight) createClass(issuerId, classSuffix string) {
|
||||
// [START createObject]
|
||||
// Create an object.
|
||||
func (d *demoFlight) createObject(issuerId, classSuffix, objectSuffix string) {
|
||||
newObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"passengerName": "Passenger name",
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
],
|
||||
"boardingAndSeatingInfo": {
|
||||
"boardingGroup": "B",
|
||||
"seatNumber": "42"
|
||||
},
|
||||
"reservationInfo": {
|
||||
"confirmationCode": "Confirmation code"
|
||||
},
|
||||
"state": "ACTIVE",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"id": "%s.%s"
|
||||
flightObject := new(walletobjects.FlightObject)
|
||||
flightObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
flightObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
flightObject.State = "ACTIVE"
|
||||
flightObject.PassengerName = "Passenger name"
|
||||
flightObject.ReservationInfo = &walletobjects.ReservationInfo{
|
||||
ConfirmationCode: "Confirmation code",
|
||||
}
|
||||
flightObject.BoardingAndSeatingInfo = &walletobjects.BoardingAndSeatingInfo{
|
||||
BoardingGroup: "B",
|
||||
SeatNumber: "42",
|
||||
}
|
||||
flightObject.HeroImage = &walletobjects.Image{
|
||||
SourceUri: &walletobjects.ImageUri{
|
||||
Uri: "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg",
|
||||
},
|
||||
}
|
||||
flightObject.Barcode = &walletobjects.Barcode{
|
||||
Type: "QR_CODE",
|
||||
Value: "QR code",
|
||||
}
|
||||
flightObject.Locations = []*walletobjects.LatLongPoint{
|
||||
&walletobjects.LatLongPoint{
|
||||
Latitude: 37.424015499999996,
|
||||
Longitude: -122.09259560000001,
|
||||
},
|
||||
}
|
||||
flightObject.LinksModuleData = &walletobjects.LinksModuleData{
|
||||
Uris: []*walletobjects.Uri{
|
||||
&walletobjects.Uri{
|
||||
Id: "LINK_MODULE_URI_ID",
|
||||
Uri: "http://maps.google.com/",
|
||||
Description: "Link module URI description",
|
||||
},
|
||||
&walletobjects.Uri{
|
||||
Id: "LINK_MODULE_TEL_ID",
|
||||
Uri: "tel:6505555555",
|
||||
Description: "Link module tel description",
|
||||
},
|
||||
},
|
||||
}
|
||||
flightObject.ImageModulesData = []*walletobjects.ImageModuleData{
|
||||
&walletobjects.ImageModuleData{
|
||||
Id: "IMAGE_MODULE_ID",
|
||||
MainImage: &walletobjects.Image{
|
||||
SourceUri: &walletobjects.ImageUri{
|
||||
Uri: "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
flightObject.TextModulesData = []*walletobjects.TextModuleData{
|
||||
&walletobjects.TextModuleData{
|
||||
Body: "Text module body",
|
||||
Header: "Text module header",
|
||||
Id: "TEXT_MODULE_ID",
|
||||
},
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
|
||||
res, err := d.httpClient.Post(objectUrl, "application/json", bytes.NewBuffer([]byte(newObject)))
|
||||
|
||||
res, err := d.service.Flightobject.Insert(flightObject).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to insert object: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Object insert response:\n%s\n", b)
|
||||
fmt.Printf("Object insert id:\n%s\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,16 +173,14 @@ func (d *demoFlight) createObject(issuerId, classSuffix, objectSuffix string) {
|
||||
// Sets the object's state to Expired. If the valid time interval is
|
||||
// already set, the pass will expire automatically up to 24 hours after.
|
||||
func (d *demoFlight) expireObject(issuerId, objectSuffix string) {
|
||||
patchBody := `{"state": "EXPIRED"}`
|
||||
url := fmt.Sprintf("%s/%s.%s", objectUrl, issuerId, objectSuffix)
|
||||
req, _ := http.NewRequest(http.MethodPatch, url, bytes.NewBuffer([]byte(patchBody)))
|
||||
res, err := d.httpClient.Do(req)
|
||||
|
||||
flightObject := &walletobjects.FlightObject{
|
||||
State: "EXPIRED",
|
||||
}
|
||||
res, err := d.service.Flightobject.Patch(fmt.Sprintf("%s.%s", issuerId, objectSuffix), flightObject).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to patch object: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Object expiration response:\n%s\n", b)
|
||||
fmt.Printf("Object expiration id:\n%s\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,113 +194,22 @@ func (d *demoFlight) expireObject(issuerId, objectSuffix string) {
|
||||
// created. This allows you to create multiple pass classes and objects in
|
||||
// one API call when the user saves the pass to their wallet.
|
||||
func (d *demoFlight) createJwtNewObjects(issuerId, classSuffix, objectSuffix string) {
|
||||
newClass := fmt.Sprintf(`
|
||||
{
|
||||
"origin": {
|
||||
"terminal": "1",
|
||||
"gate": "A2",
|
||||
"airportIataCode": "LAX"
|
||||
},
|
||||
"flightHeader": {
|
||||
"carrier": {
|
||||
"carrierIataCode": "LX"
|
||||
},
|
||||
"flightNumber": "123"
|
||||
},
|
||||
"localScheduledDepartureDateTime": "2023-07-02T15:30:00",
|
||||
"reviewStatus": "UNDER_REVIEW",
|
||||
"issuerName": "Issuer name",
|
||||
"destination": {
|
||||
"terminal": "2",
|
||||
"gate": "C3",
|
||||
"airportIataCode": "SFO"
|
||||
},
|
||||
"id": "%s.%s"
|
||||
flightObject := new(walletobjects.FlightObject)
|
||||
flightObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
flightObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
flightObject.State = "ACTIVE"
|
||||
flightObject.PassengerName = "Passenger name"
|
||||
flightObject.ReservationInfo = &walletobjects.ReservationInfo{
|
||||
ConfirmationCode: "Confirmation code",
|
||||
}
|
||||
`, issuerId, classSuffix)
|
||||
|
||||
newObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"passengerName": "Passenger name",
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
],
|
||||
"boardingAndSeatingInfo": {
|
||||
"boardingGroup": "B",
|
||||
"seatNumber": "42"
|
||||
},
|
||||
"reservationInfo": {
|
||||
"confirmationCode": "Confirmation code"
|
||||
},
|
||||
"state": "ACTIVE",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"id": "%s.%s"
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
|
||||
var payload map[string]interface{}
|
||||
flightJson, _ := json.Marshal(flightObject)
|
||||
var payload map[string]any
|
||||
json.Unmarshal([]byte(fmt.Sprintf(`
|
||||
{
|
||||
"genericClasses": [%s],
|
||||
"genericObjects": [%s]
|
||||
"flightObjects": [%s]
|
||||
}
|
||||
`, newClass, newObject)), &payload)
|
||||
|
||||
`, flightJson)), &payload)
|
||||
claims := jwt.MapClaims{
|
||||
"iss": d.credentials.Email,
|
||||
"aud": "google",
|
||||
@@ -350,7 +235,7 @@ func (d *demoFlight) createJwtNewObjects(issuerId, classSuffix, objectSuffix str
|
||||
// their wallet, the pass objects defined in the JWT are added to the
|
||||
// user's Google Wallet app. This allows the user to save multiple pass
|
||||
// objects in one API call.
|
||||
func (d *demoFlight) createJwtExistingObjects(issuerId string) {
|
||||
func (d *demoFlight) createJwtExistingObjects(issuerId string, classSuffix string, objectSuffix string) {
|
||||
var payload map[string]interface{}
|
||||
json.Unmarshal([]byte(fmt.Sprintf(`
|
||||
{
|
||||
@@ -379,7 +264,7 @@ func (d *demoFlight) createJwtExistingObjects(issuerId string) {
|
||||
"classId": "%s.LOYALTY_CLASS_SUFFIX"
|
||||
}],
|
||||
|
||||
"offerObjects": [{
|
||||
"flightObjects": [{
|
||||
"id": "%s.OFFER_OBJECT_SUFFIX",
|
||||
"classId": "%s.OFFER_CLASS_SUFFIX"
|
||||
}],
|
||||
@@ -416,79 +301,17 @@ func (d *demoFlight) batchCreateObjects(issuerId, classSuffix string) {
|
||||
for i := 0; i < 3; i++ {
|
||||
objectSuffix := strings.ReplaceAll(uuid.New().String(), "-", "_")
|
||||
|
||||
batchObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"passengerName": "Passenger name",
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
],
|
||||
"boardingAndSeatingInfo": {
|
||||
"boardingGroup": "B",
|
||||
"seatNumber": "42"
|
||||
},
|
||||
"reservationInfo": {
|
||||
"confirmationCode": "Confirmation code"
|
||||
},
|
||||
"state": "ACTIVE",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"id": "%s.%s"
|
||||
flightObject := new(walletobjects.FlightObject)
|
||||
flightObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
flightObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
flightObject.State = "ACTIVE"
|
||||
flightObject.PassengerName = "Passenger name"
|
||||
flightObject.ReservationInfo = &walletobjects.ReservationInfo{
|
||||
ConfirmationCode: "Confirmation code",
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
|
||||
flightJson, _ := json.Marshal(flightObject)
|
||||
batchObject := fmt.Sprintf("%s", flightJson)
|
||||
|
||||
data += "--batch_createobjectbatch\n"
|
||||
data += "Content-Type: application/json\n\n"
|
||||
@@ -497,8 +320,7 @@ func (d *demoFlight) batchCreateObjects(issuerId, classSuffix string) {
|
||||
}
|
||||
data += "--batch_createobjectbatch--"
|
||||
|
||||
// batchUrl = 'https://walletobjects.googleapis.com/batch';
|
||||
res, err := d.httpClient.Post(batchUrl, "multipart/mixed; boundary=batch_createobjectbatch", bytes.NewBuffer([]byte(data)))
|
||||
res, err := d.credentials.Client(oauth2.NoContext).Post("https://walletobjects.googleapis.com/batch", "multipart/mixed; boundary=batch_createobjectbatch", bytes.NewBuffer([]byte(data)))
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
@@ -511,11 +333,6 @@ func (d *demoFlight) batchCreateObjects(issuerId, classSuffix string) {
|
||||
// [END batch]
|
||||
|
||||
func main() {
|
||||
if len(os.Args) == 0 {
|
||||
fmt.Println("Usage: go run demo_flight.go <issuer-id>")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
issuerId := os.Getenv("WALLET_ISSUER_ID")
|
||||
classSuffix := strings.ReplaceAll(uuid.New().String(), "-", "_")
|
||||
objectSuffix := fmt.Sprintf("%s-%s", strings.ReplaceAll(uuid.New().String(), "-", "_"), classSuffix)
|
||||
@@ -527,6 +344,6 @@ func main() {
|
||||
d.createObject(issuerId, classSuffix, objectSuffix)
|
||||
d.expireObject(issuerId, objectSuffix)
|
||||
d.createJwtNewObjects(issuerId, classSuffix, objectSuffix)
|
||||
d.createJwtExistingObjects(issuerId)
|
||||
d.createJwtExistingObjects(issuerId, classSuffix, objectSuffix)
|
||||
d.batchCreateObjects(issuerId, classSuffix)
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/golang-jwt/jwt"
|
||||
@@ -27,35 +28,34 @@ import (
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/google"
|
||||
oauthJwt "golang.org/x/oauth2/jwt"
|
||||
"google.golang.org/api/option"
|
||||
"google.golang.org/api/walletobjects/v1"
|
||||
"io"
|
||||
"net/http"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// [END imports]
|
||||
|
||||
const (
|
||||
batchUrl = "https://walletobjects.googleapis.com/batch"
|
||||
classUrl = "https://walletobjects.googleapis.com/walletobjects/v1/genericClass"
|
||||
objectUrl = "https://walletobjects.googleapis.com/walletobjects/v1/genericObject"
|
||||
)
|
||||
|
||||
// [END setup]
|
||||
|
||||
type demoGeneric struct {
|
||||
credentials *oauthJwt.Config
|
||||
httpClient *http.Client
|
||||
batchUrl, classUrl, objectUrl string
|
||||
credentials *oauthJwt.Config
|
||||
service *walletobjects.Service
|
||||
}
|
||||
|
||||
// [START auth]
|
||||
// Create authenticated HTTP client using a service account file.
|
||||
func (d *demoGeneric) auth() {
|
||||
b, _ := os.ReadFile(os.Getenv("GOOGLE_APPLICATION_CREDENTIALS"))
|
||||
credentials, _ := google.JWTConfigFromJSON(b, "https://www.googleapis.com/auth/wallet_object.issuer")
|
||||
credentialsFile := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
||||
b, _ := os.ReadFile(credentialsFile)
|
||||
credentials, err := google.JWTConfigFromJSON(b, walletobjects.WalletObjectIssuerScope)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to load credentials: %v", err)
|
||||
}
|
||||
d.credentials = credentials
|
||||
d.httpClient = d.credentials.Client(oauth2.NoContext)
|
||||
d.service, _ = walletobjects.NewService(context.Background(), option.WithCredentialsFile(credentialsFile))
|
||||
}
|
||||
|
||||
// [END auth]
|
||||
@@ -63,19 +63,13 @@ func (d *demoGeneric) auth() {
|
||||
// [START createClass]
|
||||
// Create a class.
|
||||
func (d *demoGeneric) createClass(issuerId, classSuffix string) {
|
||||
newClass := fmt.Sprintf(`
|
||||
{
|
||||
"id": "%s.%s"
|
||||
}
|
||||
`, issuerId, classSuffix)
|
||||
|
||||
res, err := d.httpClient.Post(classUrl, "application/json", bytes.NewBuffer([]byte(newClass)))
|
||||
|
||||
genericClass := new(walletobjects.GenericClass)
|
||||
genericClass.Id = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
res, err := d.service.Genericclass.Insert(genericClass).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to insert class: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Class insert response:\n%s\n", b)
|
||||
fmt.Printf("Class insert id:\n%v\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,97 +78,68 @@ func (d *demoGeneric) createClass(issuerId, classSuffix string) {
|
||||
// [START createObject]
|
||||
// Create an object.
|
||||
func (d *demoGeneric) createObject(issuerId, classSuffix, objectSuffix string) {
|
||||
newObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"cardTitle": {
|
||||
"defaultValue": {
|
||||
"value": "Generic card title",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"header": {
|
||||
"defaultValue": {
|
||||
"value": "Generic header",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"state": "ACTIVE",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"logo": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Generic card logo",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://storage.googleapis.com/wallet-lab-tools-codelab-artifacts-public/pass_google_logo.jpg"
|
||||
}
|
||||
},
|
||||
"hexBackgroundColor": "#4285f4",
|
||||
"id": "%s.%s"
|
||||
genericObject := new(walletobjects.GenericObject)
|
||||
genericObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
genericObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
genericObject.State = "ACTIVE"
|
||||
genericObject.Barcode = &walletobjects.Barcode{
|
||||
Type: "QR_CODE",
|
||||
Value: "QR code",
|
||||
}
|
||||
genericObject.CardTitle = &walletobjects.LocalizedString{
|
||||
DefaultValue: &walletobjects.TranslatedString{
|
||||
Language: "en-us",
|
||||
Value: "Card title",
|
||||
},
|
||||
}
|
||||
genericObject.Header = &walletobjects.LocalizedString{
|
||||
DefaultValue: &walletobjects.TranslatedString{
|
||||
Language: "en-us",
|
||||
Value: "Header",
|
||||
},
|
||||
}
|
||||
genericObject.HeroImage = &walletobjects.Image{
|
||||
SourceUri: &walletobjects.ImageUri{
|
||||
Uri: "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg",
|
||||
},
|
||||
}
|
||||
genericObject.LinksModuleData = &walletobjects.LinksModuleData{
|
||||
Uris: []*walletobjects.Uri{
|
||||
&walletobjects.Uri{
|
||||
Id: "LINK_MODULE_URI_ID",
|
||||
Uri: "http://maps.google.com/",
|
||||
Description: "Link module URI description",
|
||||
},
|
||||
&walletobjects.Uri{
|
||||
Id: "LINK_MODULE_TEL_ID",
|
||||
Uri: "tel:6505555555",
|
||||
Description: "Link module tel description",
|
||||
},
|
||||
},
|
||||
}
|
||||
genericObject.ImageModulesData = []*walletobjects.ImageModuleData{
|
||||
&walletobjects.ImageModuleData{
|
||||
Id: "IMAGE_MODULE_ID",
|
||||
MainImage: &walletobjects.Image{
|
||||
SourceUri: &walletobjects.ImageUri{
|
||||
Uri: "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
genericObject.TextModulesData = []*walletobjects.TextModuleData{
|
||||
&walletobjects.TextModuleData{
|
||||
Body: "Text module body",
|
||||
Header: "Text module header",
|
||||
Id: "TEXT_MODULE_ID",
|
||||
},
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
|
||||
res, err := d.httpClient.Post(objectUrl, "application/json", bytes.NewBuffer([]byte(newObject)))
|
||||
|
||||
res, err := d.service.Genericobject.Insert(genericObject).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to insert object: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Object insert response:\n%s\n", b)
|
||||
fmt.Printf("Object insert id:\n%s\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,16 +151,14 @@ func (d *demoGeneric) createObject(issuerId, classSuffix, objectSuffix string) {
|
||||
// Sets the object's state to Expired. If the valid time interval is
|
||||
// already set, the pass will expire automatically up to 24 hours after.
|
||||
func (d *demoGeneric) expireObject(issuerId, objectSuffix string) {
|
||||
patchBody := `{"state": "EXPIRED"}`
|
||||
url := fmt.Sprintf("%s/%s.%s", objectUrl, issuerId, objectSuffix)
|
||||
req, _ := http.NewRequest(http.MethodPatch, url, bytes.NewBuffer([]byte(patchBody)))
|
||||
res, err := d.httpClient.Do(req)
|
||||
|
||||
genericObject := &walletobjects.GenericObject{
|
||||
State: "EXPIRED",
|
||||
}
|
||||
res, err := d.service.Genericobject.Patch(fmt.Sprintf("%s.%s", issuerId, objectSuffix), genericObject).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to patch object: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Object expiration response:\n%s\n", b)
|
||||
fmt.Printf("Object expiration id:\n%s\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,104 +172,34 @@ func (d *demoGeneric) expireObject(issuerId, objectSuffix string) {
|
||||
// created. This allows you to create multiple pass classes and objects in
|
||||
// one API call when the user saves the pass to their wallet.
|
||||
func (d *demoGeneric) createJwtNewObjects(issuerId, classSuffix, objectSuffix string) {
|
||||
newClass := fmt.Sprintf(`
|
||||
{
|
||||
"id": "%s.%s"
|
||||
genericObject := new(walletobjects.GenericObject)
|
||||
genericObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
genericObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
genericObject.State = "ACTIVE"
|
||||
genericObject.Barcode = &walletobjects.Barcode{
|
||||
Type: "QR_CODE",
|
||||
Value: "QR code",
|
||||
}
|
||||
`, issuerId, classSuffix)
|
||||
|
||||
newObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"cardTitle": {
|
||||
"defaultValue": {
|
||||
"value": "Generic card title",
|
||||
"language": "en-US"
|
||||
}
|
||||
genericObject.CardTitle = &walletobjects.LocalizedString{
|
||||
DefaultValue: &walletobjects.TranslatedString{
|
||||
Language: "en-us",
|
||||
Value: "Card title",
|
||||
},
|
||||
}
|
||||
genericObject.Header = &walletobjects.LocalizedString{
|
||||
DefaultValue: &walletobjects.TranslatedString{
|
||||
Language: "en-us",
|
||||
Value: "Header",
|
||||
},
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"header": {
|
||||
"defaultValue": {
|
||||
"value": "Generic header",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"state": "ACTIVE",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"logo": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Generic card logo",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://storage.googleapis.com/wallet-lab-tools-codelab-artifacts-public/pass_google_logo.jpg"
|
||||
}
|
||||
},
|
||||
"hexBackgroundColor": "#4285f4",
|
||||
"id": "%s.%s"
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
|
||||
var payload map[string]interface{}
|
||||
genericJson, _ := json.Marshal(genericObject)
|
||||
var payload map[string]any
|
||||
json.Unmarshal([]byte(fmt.Sprintf(`
|
||||
{
|
||||
"genericClasses": [%s],
|
||||
"genericObjects": [%s]
|
||||
}
|
||||
`, newClass, newObject)), &payload)
|
||||
|
||||
`, genericJson)), &payload)
|
||||
claims := jwt.MapClaims{
|
||||
"iss": d.credentials.Email,
|
||||
"aud": "google",
|
||||
@@ -332,7 +225,7 @@ func (d *demoGeneric) createJwtNewObjects(issuerId, classSuffix, objectSuffix st
|
||||
// their wallet, the pass objects defined in the JWT are added to the
|
||||
// user's Google Wallet app. This allows the user to save multiple pass
|
||||
// objects in one API call.
|
||||
func (d *demoGeneric) createJwtExistingObjects(issuerId string) {
|
||||
func (d *demoGeneric) createJwtExistingObjects(issuerId string, classSuffix string, objectSuffix string) {
|
||||
var payload map[string]interface{}
|
||||
json.Unmarshal([]byte(fmt.Sprintf(`
|
||||
{
|
||||
@@ -398,89 +291,29 @@ func (d *demoGeneric) batchCreateObjects(issuerId, classSuffix string) {
|
||||
for i := 0; i < 3; i++ {
|
||||
objectSuffix := strings.ReplaceAll(uuid.New().String(), "-", "_")
|
||||
|
||||
batchObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"cardTitle": {
|
||||
"defaultValue": {
|
||||
"value": "Generic card title",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"header": {
|
||||
"defaultValue": {
|
||||
"value": "Generic header",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"state": "ACTIVE",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"logo": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Generic card logo",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://storage.googleapis.com/wallet-lab-tools-codelab-artifacts-public/pass_google_logo.jpg"
|
||||
}
|
||||
},
|
||||
"hexBackgroundColor": "#4285f4",
|
||||
"id": "%s.%s"
|
||||
genericObject := new(walletobjects.GenericObject)
|
||||
genericObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
genericObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
genericObject.State = "ACTIVE"
|
||||
genericObject.Barcode = &walletobjects.Barcode{
|
||||
Type: "QR_CODE",
|
||||
Value: "QR code",
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
genericObject.CardTitle = &walletobjects.LocalizedString{
|
||||
DefaultValue: &walletobjects.TranslatedString{
|
||||
Language: "en-us",
|
||||
Value: "Card title",
|
||||
},
|
||||
}
|
||||
genericObject.Header = &walletobjects.LocalizedString{
|
||||
DefaultValue: &walletobjects.TranslatedString{
|
||||
Language: "en-us",
|
||||
Value: "Header",
|
||||
},
|
||||
}
|
||||
|
||||
genericJson, _ := json.Marshal(genericObject)
|
||||
batchObject := fmt.Sprintf("%s", genericJson)
|
||||
|
||||
data += "--batch_createobjectbatch\n"
|
||||
data += "Content-Type: application/json\n\n"
|
||||
@@ -489,8 +322,7 @@ func (d *demoGeneric) batchCreateObjects(issuerId, classSuffix string) {
|
||||
}
|
||||
data += "--batch_createobjectbatch--"
|
||||
|
||||
// batchUrl = 'https://walletobjects.googleapis.com/batch';
|
||||
res, err := d.httpClient.Post(batchUrl, "multipart/mixed; boundary=batch_createobjectbatch", bytes.NewBuffer([]byte(data)))
|
||||
res, err := d.credentials.Client(oauth2.NoContext).Post("https://walletobjects.googleapis.com/batch", "multipart/mixed; boundary=batch_createobjectbatch", bytes.NewBuffer([]byte(data)))
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
@@ -503,11 +335,6 @@ func (d *demoGeneric) batchCreateObjects(issuerId, classSuffix string) {
|
||||
// [END batch]
|
||||
|
||||
func main() {
|
||||
if len(os.Args) == 0 {
|
||||
fmt.Println("Usage: go run demo_generic.go <issuer-id>")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
issuerId := os.Getenv("WALLET_ISSUER_ID")
|
||||
classSuffix := strings.ReplaceAll(uuid.New().String(), "-", "_")
|
||||
objectSuffix := fmt.Sprintf("%s-%s", strings.ReplaceAll(uuid.New().String(), "-", "_"), classSuffix)
|
||||
@@ -519,6 +346,6 @@ func main() {
|
||||
d.createObject(issuerId, classSuffix, objectSuffix)
|
||||
d.expireObject(issuerId, objectSuffix)
|
||||
d.createJwtNewObjects(issuerId, classSuffix, objectSuffix)
|
||||
d.createJwtExistingObjects(issuerId)
|
||||
d.createJwtExistingObjects(issuerId, classSuffix, objectSuffix)
|
||||
d.batchCreateObjects(issuerId, classSuffix)
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/golang-jwt/jwt"
|
||||
@@ -27,35 +28,34 @@ import (
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/google"
|
||||
oauthJwt "golang.org/x/oauth2/jwt"
|
||||
"google.golang.org/api/option"
|
||||
"google.golang.org/api/walletobjects/v1"
|
||||
"io"
|
||||
"net/http"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// [END imports]
|
||||
|
||||
const (
|
||||
batchUrl = "https://walletobjects.googleapis.com/batch"
|
||||
classUrl = "https://walletobjects.googleapis.com/walletobjects/v1/giftCardClass"
|
||||
objectUrl = "https://walletobjects.googleapis.com/walletobjects/v1/giftCardObject"
|
||||
)
|
||||
|
||||
// [END setup]
|
||||
|
||||
type demoGiftcard struct {
|
||||
credentials *oauthJwt.Config
|
||||
httpClient *http.Client
|
||||
batchUrl, classUrl, objectUrl string
|
||||
credentials *oauthJwt.Config
|
||||
service *walletobjects.Service
|
||||
}
|
||||
|
||||
// [START auth]
|
||||
// Create authenticated HTTP client using a service account file.
|
||||
func (d *demoGiftcard) auth() {
|
||||
b, _ := os.ReadFile(os.Getenv("GOOGLE_APPLICATION_CREDENTIALS"))
|
||||
credentials, _ := google.JWTConfigFromJSON(b, "https://www.googleapis.com/auth/wallet_object.issuer")
|
||||
credentialsFile := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
||||
b, _ := os.ReadFile(credentialsFile)
|
||||
credentials, err := google.JWTConfigFromJSON(b, walletobjects.WalletObjectIssuerScope)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to load credentials: %v", err)
|
||||
}
|
||||
d.credentials = credentials
|
||||
d.httpClient = d.credentials.Client(oauth2.NoContext)
|
||||
d.service, _ = walletobjects.NewService(context.Background(), option.WithCredentialsFile(credentialsFile))
|
||||
}
|
||||
|
||||
// [END auth]
|
||||
@@ -63,21 +63,15 @@ func (d *demoGiftcard) auth() {
|
||||
// [START createClass]
|
||||
// Create a class.
|
||||
func (d *demoGiftcard) createClass(issuerId, classSuffix string) {
|
||||
newClass := fmt.Sprintf(`
|
||||
{
|
||||
"issuerName": "Issuer name",
|
||||
"id": "%s.%s",
|
||||
"reviewStatus": "UNDER_REVIEW"
|
||||
}
|
||||
`, issuerId, classSuffix)
|
||||
|
||||
res, err := d.httpClient.Post(classUrl, "application/json", bytes.NewBuffer([]byte(newClass)))
|
||||
|
||||
giftcardClass := new(walletobjects.GiftCardClass)
|
||||
giftcardClass.Id = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
giftcardClass.IssuerName = "Issuer name"
|
||||
giftcardClass.ReviewStatus = "UNDER_REVIEW"
|
||||
res, err := d.service.Giftcardclass.Insert(giftcardClass).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to insert class: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Class insert response:\n%s\n", b)
|
||||
fmt.Printf("Class insert id:\n%v\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,88 +80,71 @@ func (d *demoGiftcard) createClass(issuerId, classSuffix string) {
|
||||
// [START createObject]
|
||||
// Create an object.
|
||||
func (d *demoGiftcard) createObject(issuerId, classSuffix, objectSuffix string) {
|
||||
newObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"pin": "1234",
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
],
|
||||
"balanceUpdateTime": {
|
||||
"date": "2020-04-12T16:20:50.52-04:00"
|
||||
},
|
||||
"state": "ACTIVE",
|
||||
"cardNumber": "Card number",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"balance": {
|
||||
"micros": 20000000,
|
||||
"currencyCode": "USD"
|
||||
},
|
||||
"id": "%s.%s"
|
||||
giftcardObject := new(walletobjects.GiftCardObject)
|
||||
giftcardObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
giftcardObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
giftcardObject.State = "ACTIVE"
|
||||
giftcardObject.CardNumber = "Card number"
|
||||
giftcardObject.Pin = "1234"
|
||||
giftcardObject.Balance = &walletobjects.Money{
|
||||
Micros: 20000000,
|
||||
CurrencyCode: "USD",
|
||||
}
|
||||
giftcardObject.BalanceUpdateTime = &walletobjects.DateTime{
|
||||
Date: "2023-12-12T23:20:50.52Z",
|
||||
}
|
||||
giftcardObject.HeroImage = &walletobjects.Image{
|
||||
SourceUri: &walletobjects.ImageUri{
|
||||
Uri: "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg",
|
||||
},
|
||||
}
|
||||
giftcardObject.Barcode = &walletobjects.Barcode{
|
||||
Type: "QR_CODE",
|
||||
Value: "QR code",
|
||||
}
|
||||
giftcardObject.Locations = []*walletobjects.LatLongPoint{
|
||||
&walletobjects.LatLongPoint{
|
||||
Latitude: 37.424015499999996,
|
||||
Longitude: -122.09259560000001,
|
||||
},
|
||||
}
|
||||
giftcardObject.LinksModuleData = &walletobjects.LinksModuleData{
|
||||
Uris: []*walletobjects.Uri{
|
||||
&walletobjects.Uri{
|
||||
Id: "LINK_MODULE_URI_ID",
|
||||
Uri: "http://maps.google.com/",
|
||||
Description: "Link module URI description",
|
||||
},
|
||||
&walletobjects.Uri{
|
||||
Id: "LINK_MODULE_TEL_ID",
|
||||
Uri: "tel:6505555555",
|
||||
Description: "Link module tel description",
|
||||
},
|
||||
},
|
||||
}
|
||||
giftcardObject.ImageModulesData = []*walletobjects.ImageModuleData{
|
||||
&walletobjects.ImageModuleData{
|
||||
Id: "IMAGE_MODULE_ID",
|
||||
MainImage: &walletobjects.Image{
|
||||
SourceUri: &walletobjects.ImageUri{
|
||||
Uri: "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
giftcardObject.TextModulesData = []*walletobjects.TextModuleData{
|
||||
&walletobjects.TextModuleData{
|
||||
Body: "Text module body",
|
||||
Header: "Text module header",
|
||||
Id: "TEXT_MODULE_ID",
|
||||
},
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
|
||||
res, err := d.httpClient.Post(objectUrl, "application/json", bytes.NewBuffer([]byte(newObject)))
|
||||
|
||||
res, err := d.service.Giftcardobject.Insert(giftcardObject).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to insert object: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Object insert response:\n%s\n", b)
|
||||
fmt.Printf("Object insert id:\n%s\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,16 +156,14 @@ func (d *demoGiftcard) createObject(issuerId, classSuffix, objectSuffix string)
|
||||
// Sets the object's state to Expired. If the valid time interval is
|
||||
// already set, the pass will expire automatically up to 24 hours after.
|
||||
func (d *demoGiftcard) expireObject(issuerId, objectSuffix string) {
|
||||
patchBody := `{"state": "EXPIRED"}`
|
||||
url := fmt.Sprintf("%s/%s.%s", objectUrl, issuerId, objectSuffix)
|
||||
req, _ := http.NewRequest(http.MethodPatch, url, bytes.NewBuffer([]byte(patchBody)))
|
||||
res, err := d.httpClient.Do(req)
|
||||
|
||||
giftcardObject := &walletobjects.GiftCardObject{
|
||||
State: "EXPIRED",
|
||||
}
|
||||
res, err := d.service.Giftcardobject.Patch(fmt.Sprintf("%s.%s", issuerId, objectSuffix), giftcardObject).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to patch object: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Object expiration response:\n%s\n", b)
|
||||
fmt.Printf("Object expiration id:\n%s\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,97 +177,19 @@ func (d *demoGiftcard) expireObject(issuerId, objectSuffix string) {
|
||||
// created. This allows you to create multiple pass classes and objects in
|
||||
// one API call when the user saves the pass to their wallet.
|
||||
func (d *demoGiftcard) createJwtNewObjects(issuerId, classSuffix, objectSuffix string) {
|
||||
newClass := fmt.Sprintf(`
|
||||
{
|
||||
"issuerName": "Issuer name",
|
||||
"id": "%s.%s",
|
||||
"reviewStatus": "UNDER_REVIEW"
|
||||
}
|
||||
`, issuerId, classSuffix)
|
||||
giftcardObject := new(walletobjects.GiftCardObject)
|
||||
giftcardObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
giftcardObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
giftcardObject.State = "ACTIVE"
|
||||
giftcardObject.CardNumber = "Card number"
|
||||
|
||||
newObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"pin": "1234",
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
],
|
||||
"balanceUpdateTime": {
|
||||
"date": "2020-04-12T16:20:50.52-04:00"
|
||||
},
|
||||
"state": "ACTIVE",
|
||||
"cardNumber": "Card number",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"balance": {
|
||||
"micros": 20000000,
|
||||
"currencyCode": "USD"
|
||||
},
|
||||
"id": "%s.%s"
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
|
||||
var payload map[string]interface{}
|
||||
giftcardJson, _ := json.Marshal(giftcardObject)
|
||||
var payload map[string]any
|
||||
json.Unmarshal([]byte(fmt.Sprintf(`
|
||||
{
|
||||
"genericClasses": [%s],
|
||||
"genericObjects": [%s]
|
||||
"giftcardObjects": [%s]
|
||||
}
|
||||
`, newClass, newObject)), &payload)
|
||||
|
||||
`, giftcardJson)), &payload)
|
||||
claims := jwt.MapClaims{
|
||||
"iss": d.credentials.Email,
|
||||
"aud": "google",
|
||||
@@ -318,7 +215,7 @@ func (d *demoGiftcard) createJwtNewObjects(issuerId, classSuffix, objectSuffix s
|
||||
// their wallet, the pass objects defined in the JWT are added to the
|
||||
// user's Google Wallet app. This allows the user to save multiple pass
|
||||
// objects in one API call.
|
||||
func (d *demoGiftcard) createJwtExistingObjects(issuerId string) {
|
||||
func (d *demoGiftcard) createJwtExistingObjects(issuerId string, classSuffix string, objectSuffix string) {
|
||||
var payload map[string]interface{}
|
||||
json.Unmarshal([]byte(fmt.Sprintf(`
|
||||
{
|
||||
@@ -347,7 +244,7 @@ func (d *demoGiftcard) createJwtExistingObjects(issuerId string) {
|
||||
"classId": "%s.LOYALTY_CLASS_SUFFIX"
|
||||
}],
|
||||
|
||||
"offerObjects": [{
|
||||
"giftcardObjects": [{
|
||||
"id": "%s.OFFER_OBJECT_SUFFIX",
|
||||
"classId": "%s.OFFER_CLASS_SUFFIX"
|
||||
}],
|
||||
@@ -384,80 +281,14 @@ func (d *demoGiftcard) batchCreateObjects(issuerId, classSuffix string) {
|
||||
for i := 0; i < 3; i++ {
|
||||
objectSuffix := strings.ReplaceAll(uuid.New().String(), "-", "_")
|
||||
|
||||
batchObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"pin": "1234",
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
],
|
||||
"balanceUpdateTime": {
|
||||
"date": "2020-04-12T16:20:50.52-04:00"
|
||||
},
|
||||
"state": "ACTIVE",
|
||||
"cardNumber": "Card number",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"balance": {
|
||||
"micros": 20000000,
|
||||
"currencyCode": "USD"
|
||||
},
|
||||
"id": "%s.%s"
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
giftcardObject := new(walletobjects.GiftCardObject)
|
||||
giftcardObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
giftcardObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
giftcardObject.State = "ACTIVE"
|
||||
giftcardObject.CardNumber = "Card number"
|
||||
|
||||
giftcardJson, _ := json.Marshal(giftcardObject)
|
||||
batchObject := fmt.Sprintf("%s", giftcardJson)
|
||||
|
||||
data += "--batch_createobjectbatch\n"
|
||||
data += "Content-Type: application/json\n\n"
|
||||
@@ -466,8 +297,7 @@ func (d *demoGiftcard) batchCreateObjects(issuerId, classSuffix string) {
|
||||
}
|
||||
data += "--batch_createobjectbatch--"
|
||||
|
||||
// batchUrl = 'https://walletobjects.googleapis.com/batch';
|
||||
res, err := d.httpClient.Post(batchUrl, "multipart/mixed; boundary=batch_createobjectbatch", bytes.NewBuffer([]byte(data)))
|
||||
res, err := d.credentials.Client(oauth2.NoContext).Post("https://walletobjects.googleapis.com/batch", "multipart/mixed; boundary=batch_createobjectbatch", bytes.NewBuffer([]byte(data)))
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
@@ -480,11 +310,6 @@ func (d *demoGiftcard) batchCreateObjects(issuerId, classSuffix string) {
|
||||
// [END batch]
|
||||
|
||||
func main() {
|
||||
if len(os.Args) == 0 {
|
||||
fmt.Println("Usage: go run demo_giftcard.go <issuer-id>")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
issuerId := os.Getenv("WALLET_ISSUER_ID")
|
||||
classSuffix := strings.ReplaceAll(uuid.New().String(), "-", "_")
|
||||
objectSuffix := fmt.Sprintf("%s-%s", strings.ReplaceAll(uuid.New().String(), "-", "_"), classSuffix)
|
||||
@@ -496,6 +321,6 @@ func main() {
|
||||
d.createObject(issuerId, classSuffix, objectSuffix)
|
||||
d.expireObject(issuerId, objectSuffix)
|
||||
d.createJwtNewObjects(issuerId, classSuffix, objectSuffix)
|
||||
d.createJwtExistingObjects(issuerId)
|
||||
d.createJwtExistingObjects(issuerId, classSuffix, objectSuffix)
|
||||
d.batchCreateObjects(issuerId, classSuffix)
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/golang-jwt/jwt"
|
||||
@@ -27,35 +28,34 @@ import (
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/google"
|
||||
oauthJwt "golang.org/x/oauth2/jwt"
|
||||
"google.golang.org/api/option"
|
||||
"google.golang.org/api/walletobjects/v1"
|
||||
"io"
|
||||
"net/http"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// [END imports]
|
||||
|
||||
const (
|
||||
batchUrl = "https://walletobjects.googleapis.com/batch"
|
||||
classUrl = "https://walletobjects.googleapis.com/walletobjects/v1/loyaltyClass"
|
||||
objectUrl = "https://walletobjects.googleapis.com/walletobjects/v1/loyaltyObject"
|
||||
)
|
||||
|
||||
// [END setup]
|
||||
|
||||
type demoLoyalty struct {
|
||||
credentials *oauthJwt.Config
|
||||
httpClient *http.Client
|
||||
batchUrl, classUrl, objectUrl string
|
||||
credentials *oauthJwt.Config
|
||||
service *walletobjects.Service
|
||||
}
|
||||
|
||||
// [START auth]
|
||||
// Create authenticated HTTP client using a service account file.
|
||||
func (d *demoLoyalty) auth() {
|
||||
b, _ := os.ReadFile(os.Getenv("GOOGLE_APPLICATION_CREDENTIALS"))
|
||||
credentials, _ := google.JWTConfigFromJSON(b, "https://www.googleapis.com/auth/wallet_object.issuer")
|
||||
credentialsFile := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
||||
b, _ := os.ReadFile(credentialsFile)
|
||||
credentials, err := google.JWTConfigFromJSON(b, walletobjects.WalletObjectIssuerScope)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to load credentials: %v", err)
|
||||
}
|
||||
d.credentials = credentials
|
||||
d.httpClient = d.credentials.Client(oauth2.NoContext)
|
||||
d.service, _ = walletobjects.NewService(context.Background(), option.WithCredentialsFile(credentialsFile))
|
||||
}
|
||||
|
||||
// [END auth]
|
||||
@@ -63,33 +63,22 @@ func (d *demoLoyalty) auth() {
|
||||
// [START createClass]
|
||||
// Create a class.
|
||||
func (d *demoLoyalty) createClass(issuerId, classSuffix string) {
|
||||
newClass := fmt.Sprintf(`
|
||||
{
|
||||
"programName": "Program name",
|
||||
"issuerName": "Issuer name",
|
||||
"reviewStatus": "UNDER_REVIEW",
|
||||
"id": "%s.%s",
|
||||
"programLogo": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Logo description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm8.staticflickr.com/7340/11177041185_a61a7f2139_o.jpg"
|
||||
}
|
||||
}
|
||||
logo := walletobjects.Image{
|
||||
SourceUri: &walletobjects.ImageUri{
|
||||
Uri: "http://farm8.staticflickr.com/7340/11177041185_a61a7f2139_o.jpg",
|
||||
},
|
||||
}
|
||||
`, issuerId, classSuffix)
|
||||
|
||||
res, err := d.httpClient.Post(classUrl, "application/json", bytes.NewBuffer([]byte(newClass)))
|
||||
|
||||
loyaltyClass := new(walletobjects.LoyaltyClass)
|
||||
loyaltyClass.Id = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
loyaltyClass.ProgramName = "Program name"
|
||||
loyaltyClass.IssuerName = "Issuer name"
|
||||
loyaltyClass.ReviewStatus = "UNDER_REVIEW"
|
||||
loyaltyClass.ProgramLogo = &logo
|
||||
res, err := d.service.Loyaltyclass.Insert(loyaltyClass).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to insert class: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Class insert response:\n%s\n", b)
|
||||
fmt.Printf("Class insert id:\n%v\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,87 +87,68 @@ func (d *demoLoyalty) createClass(issuerId, classSuffix string) {
|
||||
// [START createObject]
|
||||
// Create an object.
|
||||
func (d *demoLoyalty) createObject(issuerId, classSuffix, objectSuffix string) {
|
||||
newObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
],
|
||||
"accountName": "Account name",
|
||||
"state": "ACTIVE",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"id": "%s.%s",
|
||||
"loyaltyPoints": {
|
||||
"balance": {
|
||||
"int": 800
|
||||
},
|
||||
"label": "Points"
|
||||
},
|
||||
"accountId": "Account id"
|
||||
loyaltyObject := new(walletobjects.LoyaltyObject)
|
||||
loyaltyObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
loyaltyObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
loyaltyObject.AccountName = "Account name"
|
||||
loyaltyObject.AccountId = "Account id"
|
||||
loyaltyObject.State = "ACTIVE"
|
||||
loyaltyObject.LoyaltyPoints = &walletobjects.LoyaltyPoints{
|
||||
Balance: &walletobjects.LoyaltyPointsBalance{Int: 800},
|
||||
Label: "Points",
|
||||
}
|
||||
loyaltyObject.HeroImage = &walletobjects.Image{
|
||||
SourceUri: &walletobjects.ImageUri{
|
||||
Uri: "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg",
|
||||
},
|
||||
}
|
||||
loyaltyObject.Barcode = &walletobjects.Barcode{
|
||||
Type: "QR_CODE",
|
||||
Value: "QR code",
|
||||
}
|
||||
loyaltyObject.Locations = []*walletobjects.LatLongPoint{
|
||||
&walletobjects.LatLongPoint{
|
||||
Latitude: 37.424015499999996,
|
||||
Longitude: -122.09259560000001,
|
||||
},
|
||||
}
|
||||
loyaltyObject.LinksModuleData = &walletobjects.LinksModuleData{
|
||||
Uris: []*walletobjects.Uri{
|
||||
&walletobjects.Uri{
|
||||
Id: "LINK_MODULE_URI_ID",
|
||||
Uri: "http://maps.google.com/",
|
||||
Description: "Link module URI description",
|
||||
},
|
||||
&walletobjects.Uri{
|
||||
Id: "LINK_MODULE_TEL_ID",
|
||||
Uri: "tel:6505555555",
|
||||
Description: "Link module tel description",
|
||||
},
|
||||
},
|
||||
}
|
||||
loyaltyObject.ImageModulesData = []*walletobjects.ImageModuleData{
|
||||
&walletobjects.ImageModuleData{
|
||||
Id: "IMAGE_MODULE_ID",
|
||||
MainImage: &walletobjects.Image{
|
||||
SourceUri: &walletobjects.ImageUri{
|
||||
Uri: "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
loyaltyObject.TextModulesData = []*walletobjects.TextModuleData{
|
||||
&walletobjects.TextModuleData{
|
||||
Body: "Text module body",
|
||||
Header: "Text module header",
|
||||
Id: "TEXT_MODULE_ID",
|
||||
},
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
|
||||
res, err := d.httpClient.Post(objectUrl, "application/json", bytes.NewBuffer([]byte(newObject)))
|
||||
|
||||
res, err := d.service.Loyaltyobject.Insert(loyaltyObject).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to insert object: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Object insert response:\n%s\n", b)
|
||||
fmt.Printf("Object insert id:\n%s\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,16 +160,14 @@ func (d *demoLoyalty) createObject(issuerId, classSuffix, objectSuffix string) {
|
||||
// Sets the object's state to Expired. If the valid time interval is
|
||||
// already set, the pass will expire automatically up to 24 hours after.
|
||||
func (d *demoLoyalty) expireObject(issuerId, objectSuffix string) {
|
||||
patchBody := `{"state": "EXPIRED"}`
|
||||
url := fmt.Sprintf("%s/%s.%s", objectUrl, issuerId, objectSuffix)
|
||||
req, _ := http.NewRequest(http.MethodPatch, url, bytes.NewBuffer([]byte(patchBody)))
|
||||
res, err := d.httpClient.Do(req)
|
||||
|
||||
loyaltyObject := &walletobjects.LoyaltyObject{
|
||||
State: "EXPIRED",
|
||||
}
|
||||
res, err := d.service.Loyaltyobject.Patch(fmt.Sprintf("%s.%s", issuerId, objectSuffix), loyaltyObject).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to patch object: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Object expiration response:\n%s\n", b)
|
||||
fmt.Printf("Object expiration id:\n%s\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,108 +181,20 @@ func (d *demoLoyalty) expireObject(issuerId, objectSuffix string) {
|
||||
// created. This allows you to create multiple pass classes and objects in
|
||||
// one API call when the user saves the pass to their wallet.
|
||||
func (d *demoLoyalty) createJwtNewObjects(issuerId, classSuffix, objectSuffix string) {
|
||||
newClass := fmt.Sprintf(`
|
||||
{
|
||||
"programName": "Program name",
|
||||
"issuerName": "Issuer name",
|
||||
"reviewStatus": "UNDER_REVIEW",
|
||||
"id": "%s.%s",
|
||||
"programLogo": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Logo description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm8.staticflickr.com/7340/11177041185_a61a7f2139_o.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
`, issuerId, classSuffix)
|
||||
loyaltyObject := new(walletobjects.LoyaltyObject)
|
||||
loyaltyObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix+"_")
|
||||
loyaltyObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
loyaltyObject.AccountName = "Account name"
|
||||
loyaltyObject.AccountId = "Account id"
|
||||
loyaltyObject.State = "ACTIVE"
|
||||
|
||||
newObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
],
|
||||
"accountName": "Account name",
|
||||
"state": "ACTIVE",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"id": "%s.%s",
|
||||
"loyaltyPoints": {
|
||||
"balance": {
|
||||
"int": 800
|
||||
},
|
||||
"label": "Points"
|
||||
},
|
||||
"accountId": "Account id"
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
|
||||
var payload map[string]interface{}
|
||||
loyaltyJson, _ := json.Marshal(loyaltyObject)
|
||||
var payload map[string]any
|
||||
json.Unmarshal([]byte(fmt.Sprintf(`
|
||||
{
|
||||
"genericClasses": [%s],
|
||||
"genericObjects": [%s]
|
||||
"loyaltyObjects": [%s]
|
||||
}
|
||||
`, newClass, newObject)), &payload)
|
||||
|
||||
`, loyaltyJson)), &payload)
|
||||
claims := jwt.MapClaims{
|
||||
"iss": d.credentials.Email,
|
||||
"aud": "google",
|
||||
@@ -327,7 +207,7 @@ func (d *demoLoyalty) createJwtNewObjects(issuerId, classSuffix, objectSuffix st
|
||||
key, _ := jwt.ParseRSAPrivateKeyFromPEM(d.credentials.PrivateKey)
|
||||
token, _ := jwt.NewWithClaims(jwt.SigningMethodRS256, claims).SignedString(key)
|
||||
|
||||
fmt.Println("Add to Google Wallet link")
|
||||
fmt.Println("Add to Google Wallet link for new objects")
|
||||
fmt.Println("https://pay.google.com/gp/v/save/" + token)
|
||||
}
|
||||
|
||||
@@ -340,7 +220,7 @@ func (d *demoLoyalty) createJwtNewObjects(issuerId, classSuffix, objectSuffix st
|
||||
// their wallet, the pass objects defined in the JWT are added to the
|
||||
// user's Google Wallet app. This allows the user to save multiple pass
|
||||
// objects in one API call.
|
||||
func (d *demoLoyalty) createJwtExistingObjects(issuerId string) {
|
||||
func (d *demoLoyalty) createJwtExistingObjects(issuerId string, classSuffix string, objectSuffix string) {
|
||||
var payload map[string]interface{}
|
||||
json.Unmarshal([]byte(fmt.Sprintf(`
|
||||
{
|
||||
@@ -406,79 +286,15 @@ func (d *demoLoyalty) batchCreateObjects(issuerId, classSuffix string) {
|
||||
for i := 0; i < 3; i++ {
|
||||
objectSuffix := strings.ReplaceAll(uuid.New().String(), "-", "_")
|
||||
|
||||
batchObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
],
|
||||
"accountName": "Account name",
|
||||
"state": "ACTIVE",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"id": "%s.%s",
|
||||
"loyaltyPoints": {
|
||||
"balance": {
|
||||
"int": 800
|
||||
},
|
||||
"label": "Points"
|
||||
},
|
||||
"accountId": "Account id"
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
loyaltyObject := new(walletobjects.LoyaltyObject)
|
||||
loyaltyObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
loyaltyObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
loyaltyObject.AccountName = "Account name"
|
||||
loyaltyObject.AccountId = "Account id"
|
||||
loyaltyObject.State = "ACTIVE"
|
||||
|
||||
loyaltyJson, _ := json.Marshal(loyaltyObject)
|
||||
batchObject := fmt.Sprintf("%s", loyaltyJson)
|
||||
|
||||
data += "--batch_createobjectbatch\n"
|
||||
data += "Content-Type: application/json\n\n"
|
||||
@@ -487,8 +303,7 @@ func (d *demoLoyalty) batchCreateObjects(issuerId, classSuffix string) {
|
||||
}
|
||||
data += "--batch_createobjectbatch--"
|
||||
|
||||
// batchUrl = 'https://walletobjects.googleapis.com/batch';
|
||||
res, err := d.httpClient.Post(batchUrl, "multipart/mixed; boundary=batch_createobjectbatch", bytes.NewBuffer([]byte(data)))
|
||||
res, err := d.credentials.Client(oauth2.NoContext).Post("https://walletobjects.googleapis.com/batch", "multipart/mixed; boundary=batch_createobjectbatch", bytes.NewBuffer([]byte(data)))
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
@@ -501,11 +316,6 @@ func (d *demoLoyalty) batchCreateObjects(issuerId, classSuffix string) {
|
||||
// [END batch]
|
||||
|
||||
func main() {
|
||||
if len(os.Args) == 0 {
|
||||
fmt.Println("Usage: go run demo_loyalty.go <issuer-id>")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
issuerId := os.Getenv("WALLET_ISSUER_ID")
|
||||
classSuffix := strings.ReplaceAll(uuid.New().String(), "-", "_")
|
||||
objectSuffix := fmt.Sprintf("%s-%s", strings.ReplaceAll(uuid.New().String(), "-", "_"), classSuffix)
|
||||
@@ -517,6 +327,6 @@ func main() {
|
||||
d.createObject(issuerId, classSuffix, objectSuffix)
|
||||
d.expireObject(issuerId, objectSuffix)
|
||||
d.createJwtNewObjects(issuerId, classSuffix, objectSuffix)
|
||||
d.createJwtExistingObjects(issuerId)
|
||||
d.createJwtExistingObjects(issuerId, classSuffix, objectSuffix)
|
||||
d.batchCreateObjects(issuerId, classSuffix)
|
||||
}
|
||||
|
||||
390
go/demo_offer.go
390
go/demo_offer.go
@@ -20,6 +20,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/golang-jwt/jwt"
|
||||
@@ -27,35 +28,34 @@ import (
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/google"
|
||||
oauthJwt "golang.org/x/oauth2/jwt"
|
||||
"google.golang.org/api/option"
|
||||
"google.golang.org/api/walletobjects/v1"
|
||||
"io"
|
||||
"net/http"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// [END imports]
|
||||
|
||||
const (
|
||||
batchUrl = "https://walletobjects.googleapis.com/batch"
|
||||
classUrl = "https://walletobjects.googleapis.com/walletobjects/v1/offerClass"
|
||||
objectUrl = "https://walletobjects.googleapis.com/walletobjects/v1/offerObject"
|
||||
)
|
||||
|
||||
// [END setup]
|
||||
|
||||
type demoOffer struct {
|
||||
credentials *oauthJwt.Config
|
||||
httpClient *http.Client
|
||||
batchUrl, classUrl, objectUrl string
|
||||
credentials *oauthJwt.Config
|
||||
service *walletobjects.Service
|
||||
}
|
||||
|
||||
// [START auth]
|
||||
// Create authenticated HTTP client using a service account file.
|
||||
func (d *demoOffer) auth() {
|
||||
b, _ := os.ReadFile(os.Getenv("GOOGLE_APPLICATION_CREDENTIALS"))
|
||||
credentials, _ := google.JWTConfigFromJSON(b, "https://www.googleapis.com/auth/wallet_object.issuer")
|
||||
credentialsFile := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
||||
b, _ := os.ReadFile(credentialsFile)
|
||||
credentials, err := google.JWTConfigFromJSON(b, walletobjects.WalletObjectIssuerScope)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to load credentials: %v", err)
|
||||
}
|
||||
d.credentials = credentials
|
||||
d.httpClient = d.credentials.Client(oauth2.NoContext)
|
||||
d.service, _ = walletobjects.NewService(context.Background(), option.WithCredentialsFile(credentialsFile))
|
||||
}
|
||||
|
||||
// [END auth]
|
||||
@@ -63,24 +63,18 @@ func (d *demoOffer) auth() {
|
||||
// [START createClass]
|
||||
// Create a class.
|
||||
func (d *demoOffer) createClass(issuerId, classSuffix string) {
|
||||
newClass := fmt.Sprintf(`
|
||||
{
|
||||
"redemptionChannel": "ONLINE",
|
||||
"reviewStatus": "UNDER_REVIEW",
|
||||
"title": "Offer title",
|
||||
"issuerName": "Issuer name",
|
||||
"provider": "Provider name",
|
||||
"id": "%s.%s"
|
||||
}
|
||||
`, issuerId, classSuffix)
|
||||
|
||||
res, err := d.httpClient.Post(classUrl, "application/json", bytes.NewBuffer([]byte(newClass)))
|
||||
|
||||
offerClass := new(walletobjects.OfferClass)
|
||||
offerClass.Id = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
offerClass.RedemptionChannel = "ONLINE"
|
||||
offerClass.ReviewStatus = "UNDER_REVIEW"
|
||||
offerClass.Title = "Offer title"
|
||||
offerClass.IssuerName = "Issuer name"
|
||||
offerClass.Provider = "Provider name"
|
||||
res, err := d.service.Offerclass.Insert(offerClass).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to insert class: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Class insert response:\n%s\n", b)
|
||||
fmt.Printf("Class insert id:\n%v\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,87 +83,70 @@ func (d *demoOffer) createClass(issuerId, classSuffix string) {
|
||||
// [START createObject]
|
||||
// Create an object.
|
||||
func (d *demoOffer) createObject(issuerId, classSuffix, objectSuffix string) {
|
||||
newObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
offerObject := new(walletobjects.OfferObject)
|
||||
offerObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
offerObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
offerObject.State = "ACTIVE"
|
||||
offerObject.ValidTimeInterval = &walletobjects.TimeInterval{
|
||||
Start: &walletobjects.DateTime{
|
||||
Date: "2023-06-12T23:20:50.52Z",
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
End: &walletobjects.DateTime{
|
||||
Date: "2023-12-12T23:20:50.52Z",
|
||||
},
|
||||
}
|
||||
offerObject.HeroImage = &walletobjects.Image{
|
||||
SourceUri: &walletobjects.ImageUri{
|
||||
Uri: "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg",
|
||||
},
|
||||
}
|
||||
offerObject.Barcode = &walletobjects.Barcode{
|
||||
Type: "QR_CODE",
|
||||
Value: "QR code",
|
||||
}
|
||||
offerObject.Locations = []*walletobjects.LatLongPoint{
|
||||
&walletobjects.LatLongPoint{
|
||||
Latitude: 37.424015499999996,
|
||||
Longitude: -122.09259560000001,
|
||||
},
|
||||
}
|
||||
offerObject.LinksModuleData = &walletobjects.LinksModuleData{
|
||||
Uris: []*walletobjects.Uri{
|
||||
&walletobjects.Uri{
|
||||
Id: "LINK_MODULE_URI_ID",
|
||||
Uri: "http://maps.google.com/",
|
||||
Description: "Link module URI description",
|
||||
},
|
||||
&walletobjects.Uri{
|
||||
Id: "LINK_MODULE_TEL_ID",
|
||||
Uri: "tel:6505555555",
|
||||
Description: "Link module tel description",
|
||||
},
|
||||
},
|
||||
}
|
||||
offerObject.ImageModulesData = []*walletobjects.ImageModuleData{
|
||||
&walletobjects.ImageModuleData{
|
||||
Id: "IMAGE_MODULE_ID",
|
||||
MainImage: &walletobjects.Image{
|
||||
SourceUri: &walletobjects.ImageUri{
|
||||
Uri: "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
offerObject.TextModulesData = []*walletobjects.TextModuleData{
|
||||
&walletobjects.TextModuleData{
|
||||
Body: "Text module body",
|
||||
Header: "Text module header",
|
||||
Id: "TEXT_MODULE_ID",
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
],
|
||||
"validTimeInterval": {
|
||||
"start": {
|
||||
"date": "2023-06-12T23:20:50.52Z"
|
||||
},
|
||||
"end": {
|
||||
"date": "2023-12-12T23:20:50.52Z"
|
||||
}
|
||||
},
|
||||
"state": "ACTIVE",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"id": "%s.%s"
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
|
||||
res, err := d.httpClient.Post(objectUrl, "application/json", bytes.NewBuffer([]byte(newObject)))
|
||||
|
||||
res, err := d.service.Offerobject.Insert(offerObject).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to insert object: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Object insert response:\n%s\n", b)
|
||||
fmt.Printf("Object insert id:\n%s\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,16 +158,14 @@ func (d *demoOffer) createObject(issuerId, classSuffix, objectSuffix string) {
|
||||
// Sets the object's state to Expired. If the valid time interval is
|
||||
// already set, the pass will expire automatically up to 24 hours after.
|
||||
func (d *demoOffer) expireObject(issuerId, objectSuffix string) {
|
||||
patchBody := `{"state": "EXPIRED"}`
|
||||
url := fmt.Sprintf("%s/%s.%s", objectUrl, issuerId, objectSuffix)
|
||||
req, _ := http.NewRequest(http.MethodPatch, url, bytes.NewBuffer([]byte(patchBody)))
|
||||
res, err := d.httpClient.Do(req)
|
||||
|
||||
offerObject := &walletobjects.OfferObject{
|
||||
State: "EXPIRED",
|
||||
}
|
||||
res, err := d.service.Offerobject.Patch(fmt.Sprintf("%s.%s", issuerId, objectSuffix), offerObject).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to patch object: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Object expiration response:\n%s\n", b)
|
||||
fmt.Printf("Object expiration id:\n%s\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,99 +179,18 @@ func (d *demoOffer) expireObject(issuerId, objectSuffix string) {
|
||||
// created. This allows you to create multiple pass classes and objects in
|
||||
// one API call when the user saves the pass to their wallet.
|
||||
func (d *demoOffer) createJwtNewObjects(issuerId, classSuffix, objectSuffix string) {
|
||||
newClass := fmt.Sprintf(`
|
||||
{
|
||||
"redemptionChannel": "ONLINE",
|
||||
"reviewStatus": "UNDER_REVIEW",
|
||||
"title": "Offer title",
|
||||
"issuerName": "Issuer name",
|
||||
"provider": "Provider name",
|
||||
"id": "%s.%s"
|
||||
}
|
||||
`, issuerId, classSuffix)
|
||||
offerObject := new(walletobjects.OfferObject)
|
||||
offerObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
offerObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
offerObject.State = "ACTIVE"
|
||||
|
||||
newObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
],
|
||||
"validTimeInterval": {
|
||||
"start": {
|
||||
"date": "2023-06-12T23:20:50.52Z"
|
||||
},
|
||||
"end": {
|
||||
"date": "2023-12-12T23:20:50.52Z"
|
||||
}
|
||||
},
|
||||
"state": "ACTIVE",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"id": "%s.%s"
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
|
||||
var payload map[string]interface{}
|
||||
offerJson, _ := json.Marshal(offerObject)
|
||||
var payload map[string]any
|
||||
json.Unmarshal([]byte(fmt.Sprintf(`
|
||||
{
|
||||
"genericClasses": [%s],
|
||||
"genericObjects": [%s]
|
||||
"offerObjects": [%s]
|
||||
}
|
||||
`, newClass, newObject)), &payload)
|
||||
|
||||
`, offerJson)), &payload)
|
||||
claims := jwt.MapClaims{
|
||||
"iss": d.credentials.Email,
|
||||
"aud": "google",
|
||||
@@ -322,7 +216,7 @@ func (d *demoOffer) createJwtNewObjects(issuerId, classSuffix, objectSuffix stri
|
||||
// their wallet, the pass objects defined in the JWT are added to the
|
||||
// user's Google Wallet app. This allows the user to save multiple pass
|
||||
// objects in one API call.
|
||||
func (d *demoOffer) createJwtExistingObjects(issuerId string) {
|
||||
func (d *demoOffer) createJwtExistingObjects(issuerId string, classSuffix string, objectSuffix string) {
|
||||
var payload map[string]interface{}
|
||||
json.Unmarshal([]byte(fmt.Sprintf(`
|
||||
{
|
||||
@@ -388,79 +282,13 @@ func (d *demoOffer) batchCreateObjects(issuerId, classSuffix string) {
|
||||
for i := 0; i < 3; i++ {
|
||||
objectSuffix := strings.ReplaceAll(uuid.New().String(), "-", "_")
|
||||
|
||||
batchObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
],
|
||||
"validTimeInterval": {
|
||||
"start": {
|
||||
"date": "2023-06-12T23:20:50.52Z"
|
||||
},
|
||||
"end": {
|
||||
"date": "2023-12-12T23:20:50.52Z"
|
||||
}
|
||||
},
|
||||
"state": "ACTIVE",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"id": "%s.%s"
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
offerObject := new(walletobjects.OfferObject)
|
||||
offerObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
offerObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
offerObject.State = "ACTIVE"
|
||||
|
||||
offerJson, _ := json.Marshal(offerObject)
|
||||
batchObject := fmt.Sprintf("%s", offerJson)
|
||||
|
||||
data += "--batch_createobjectbatch\n"
|
||||
data += "Content-Type: application/json\n\n"
|
||||
@@ -469,8 +297,7 @@ func (d *demoOffer) batchCreateObjects(issuerId, classSuffix string) {
|
||||
}
|
||||
data += "--batch_createobjectbatch--"
|
||||
|
||||
// batchUrl = 'https://walletobjects.googleapis.com/batch';
|
||||
res, err := d.httpClient.Post(batchUrl, "multipart/mixed; boundary=batch_createobjectbatch", bytes.NewBuffer([]byte(data)))
|
||||
res, err := d.credentials.Client(oauth2.NoContext).Post("https://walletobjects.googleapis.com/batch", "multipart/mixed; boundary=batch_createobjectbatch", bytes.NewBuffer([]byte(data)))
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
@@ -483,11 +310,6 @@ func (d *demoOffer) batchCreateObjects(issuerId, classSuffix string) {
|
||||
// [END batch]
|
||||
|
||||
func main() {
|
||||
if len(os.Args) == 0 {
|
||||
fmt.Println("Usage: go run demo_offer.go <issuer-id>")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
issuerId := os.Getenv("WALLET_ISSUER_ID")
|
||||
classSuffix := strings.ReplaceAll(uuid.New().String(), "-", "_")
|
||||
objectSuffix := fmt.Sprintf("%s-%s", strings.ReplaceAll(uuid.New().String(), "-", "_"), classSuffix)
|
||||
@@ -499,6 +321,6 @@ func main() {
|
||||
d.createObject(issuerId, classSuffix, objectSuffix)
|
||||
d.expireObject(issuerId, objectSuffix)
|
||||
d.createJwtNewObjects(issuerId, classSuffix, objectSuffix)
|
||||
d.createJwtExistingObjects(issuerId)
|
||||
d.createJwtExistingObjects(issuerId, classSuffix, objectSuffix)
|
||||
d.batchCreateObjects(issuerId, classSuffix)
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/golang-jwt/jwt"
|
||||
@@ -27,35 +28,34 @@ import (
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/google"
|
||||
oauthJwt "golang.org/x/oauth2/jwt"
|
||||
"google.golang.org/api/option"
|
||||
"google.golang.org/api/walletobjects/v1"
|
||||
"io"
|
||||
"net/http"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// [END imports]
|
||||
|
||||
const (
|
||||
batchUrl = "https://walletobjects.googleapis.com/batch"
|
||||
classUrl = "https://walletobjects.googleapis.com/walletobjects/v1/transitClass"
|
||||
objectUrl = "https://walletobjects.googleapis.com/walletobjects/v1/transitObject"
|
||||
)
|
||||
|
||||
// [END setup]
|
||||
|
||||
type demoTransit struct {
|
||||
credentials *oauthJwt.Config
|
||||
httpClient *http.Client
|
||||
batchUrl, classUrl, objectUrl string
|
||||
credentials *oauthJwt.Config
|
||||
service *walletobjects.Service
|
||||
}
|
||||
|
||||
// [START auth]
|
||||
// Create authenticated HTTP client using a service account file.
|
||||
func (d *demoTransit) auth() {
|
||||
b, _ := os.ReadFile(os.Getenv("GOOGLE_APPLICATION_CREDENTIALS"))
|
||||
credentials, _ := google.JWTConfigFromJSON(b, "https://www.googleapis.com/auth/wallet_object.issuer")
|
||||
credentialsFile := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
||||
b, _ := os.ReadFile(credentialsFile)
|
||||
credentials, err := google.JWTConfigFromJSON(b, walletobjects.WalletObjectIssuerScope)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to load credentials: %v", err)
|
||||
}
|
||||
d.credentials = credentials
|
||||
d.httpClient = d.credentials.Client(oauth2.NoContext)
|
||||
d.service, _ = walletobjects.NewService(context.Background(), option.WithCredentialsFile(credentialsFile))
|
||||
}
|
||||
|
||||
// [END auth]
|
||||
@@ -63,33 +63,22 @@ func (d *demoTransit) auth() {
|
||||
// [START createClass]
|
||||
// Create a class.
|
||||
func (d *demoTransit) createClass(issuerId, classSuffix string) {
|
||||
newClass := fmt.Sprintf(`
|
||||
{
|
||||
"logo": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Logo description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://live.staticflickr.com/65535/48690277162_cd05f03f4d_o.png"
|
||||
}
|
||||
logo := walletobjects.Image{
|
||||
SourceUri: &walletobjects.ImageUri{
|
||||
Uri: "http://farm8.staticflickr.com/7340/11177041185_a61a7f2139_o.jpg",
|
||||
},
|
||||
"issuerName": "Issuer name",
|
||||
"reviewStatus": "UNDER_REVIEW",
|
||||
"id": "%s.%s",
|
||||
"transitType": "BUS"
|
||||
}
|
||||
`, issuerId, classSuffix)
|
||||
|
||||
res, err := d.httpClient.Post(classUrl, "application/json", bytes.NewBuffer([]byte(newClass)))
|
||||
|
||||
transitClass := new(walletobjects.TransitClass)
|
||||
transitClass.Id = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
transitClass.IssuerName = "Issuer name"
|
||||
transitClass.ReviewStatus = "UNDER_REVIEW"
|
||||
transitClass.Logo = &logo
|
||||
transitClass.TransitType = "BUS"
|
||||
res, err := d.service.Transitclass.Insert(transitClass).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to insert class: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Class insert response:\n%s\n", b)
|
||||
fmt.Printf("Class insert id:\n%v\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,106 +87,68 @@ func (d *demoTransit) createClass(issuerId, classSuffix string) {
|
||||
// [START createObject]
|
||||
// Create an object.
|
||||
func (d *demoTransit) createObject(issuerId, classSuffix, objectSuffix string) {
|
||||
newObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"passengerNames": "Passenger names",
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
},
|
||||
"ticketLeg": {
|
||||
"destinationStationCode": "SFO",
|
||||
"destinationName": {
|
||||
"defaultValue": {
|
||||
"value": "Destination name",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"arrivalDateTime": "2020-04-12T20:20:50.52Z",
|
||||
"originStationCode": "LA",
|
||||
"originName": {
|
||||
"defaultValue": {
|
||||
"value": "Origin name",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"departureDateTime": "2020-04-12T16:20:50.52Z",
|
||||
"fareName": {
|
||||
"defaultValue": {
|
||||
"value": "Fare name",
|
||||
"language": "en-US"
|
||||
}
|
||||
}
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
],
|
||||
"passengerType": "SINGLE_PASSENGER",
|
||||
"state": "ACTIVE",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"tripType": "ONE_WAY",
|
||||
"id": "%s.%s"
|
||||
transitObject := new(walletobjects.TransitObject)
|
||||
transitObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
transitObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
transitObject.State = "ACTIVE"
|
||||
transitObject.PassengerNames = "Passenger names"
|
||||
transitObject.TripType = "ONE_WAY"
|
||||
transitObject.PassengerType = "SINGLE_PASSENGER"
|
||||
transitObject.TicketLeg = &walletobjects.TicketLeg{
|
||||
DestinationStationCode: "SFO",
|
||||
OriginStationCode: "LA",
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
|
||||
res, err := d.httpClient.Post(objectUrl, "application/json", bytes.NewBuffer([]byte(newObject)))
|
||||
|
||||
transitObject.HeroImage = &walletobjects.Image{
|
||||
SourceUri: &walletobjects.ImageUri{
|
||||
Uri: "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg",
|
||||
},
|
||||
}
|
||||
transitObject.Barcode = &walletobjects.Barcode{
|
||||
Type: "QR_CODE",
|
||||
Value: "QR code",
|
||||
}
|
||||
transitObject.Locations = []*walletobjects.LatLongPoint{
|
||||
&walletobjects.LatLongPoint{
|
||||
Latitude: 37.424015499999996,
|
||||
Longitude: -122.09259560000001,
|
||||
},
|
||||
}
|
||||
transitObject.LinksModuleData = &walletobjects.LinksModuleData{
|
||||
Uris: []*walletobjects.Uri{
|
||||
&walletobjects.Uri{
|
||||
Id: "LINK_MODULE_URI_ID",
|
||||
Uri: "http://maps.google.com/",
|
||||
Description: "Link module URI description",
|
||||
},
|
||||
&walletobjects.Uri{
|
||||
Id: "LINK_MODULE_TEL_ID",
|
||||
Uri: "tel:6505555555",
|
||||
Description: "Link module tel description",
|
||||
},
|
||||
},
|
||||
}
|
||||
transitObject.ImageModulesData = []*walletobjects.ImageModuleData{
|
||||
&walletobjects.ImageModuleData{
|
||||
Id: "IMAGE_MODULE_ID",
|
||||
MainImage: &walletobjects.Image{
|
||||
SourceUri: &walletobjects.ImageUri{
|
||||
Uri: "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
transitObject.TextModulesData = []*walletobjects.TextModuleData{
|
||||
&walletobjects.TextModuleData{
|
||||
Body: "Text module body",
|
||||
Header: "Text module header",
|
||||
Id: "TEXT_MODULE_ID",
|
||||
},
|
||||
}
|
||||
res, err := d.service.Transitobject.Insert(transitObject).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to insert object: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Object insert response:\n%s\n", b)
|
||||
fmt.Printf("Object insert id:\n%s\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,16 +160,14 @@ func (d *demoTransit) createObject(issuerId, classSuffix, objectSuffix string) {
|
||||
// Sets the object's state to Expired. If the valid time interval is
|
||||
// already set, the pass will expire automatically up to 24 hours after.
|
||||
func (d *demoTransit) expireObject(issuerId, objectSuffix string) {
|
||||
patchBody := `{"state": "EXPIRED"}`
|
||||
url := fmt.Sprintf("%s/%s.%s", objectUrl, issuerId, objectSuffix)
|
||||
req, _ := http.NewRequest(http.MethodPatch, url, bytes.NewBuffer([]byte(patchBody)))
|
||||
res, err := d.httpClient.Do(req)
|
||||
|
||||
transitObject := &walletobjects.TransitObject{
|
||||
State: "EXPIRED",
|
||||
}
|
||||
res, err := d.service.Transitobject.Patch(fmt.Sprintf("%s.%s", issuerId, objectSuffix), transitObject).Do()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatalf("Unable to patch object: %v", err)
|
||||
} else {
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("Object expiration response:\n%s\n", b)
|
||||
fmt.Printf("Object expiration id:\n%s\n", res.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,127 +181,25 @@ func (d *demoTransit) expireObject(issuerId, objectSuffix string) {
|
||||
// created. This allows you to create multiple pass classes and objects in
|
||||
// one API call when the user saves the pass to their wallet.
|
||||
func (d *demoTransit) createJwtNewObjects(issuerId, classSuffix, objectSuffix string) {
|
||||
newClass := fmt.Sprintf(`
|
||||
{
|
||||
"logo": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Logo description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://live.staticflickr.com/65535/48690277162_cd05f03f4d_o.png"
|
||||
}
|
||||
},
|
||||
"issuerName": "Issuer name",
|
||||
"reviewStatus": "UNDER_REVIEW",
|
||||
"id": "%s.%s",
|
||||
"transitType": "BUS"
|
||||
transitObject := new(walletobjects.TransitObject)
|
||||
transitObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
transitObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
transitObject.State = "ACTIVE"
|
||||
transitObject.PassengerNames = "Passenger names"
|
||||
transitObject.TripType = "ONE_WAY"
|
||||
transitObject.PassengerType = "SINGLE_PASSENGER"
|
||||
transitObject.TicketLeg = &walletobjects.TicketLeg{
|
||||
DestinationStationCode: "SFO",
|
||||
OriginStationCode: "LA",
|
||||
}
|
||||
`, issuerId, classSuffix)
|
||||
|
||||
newObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"passengerNames": "Passenger names",
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
},
|
||||
"ticketLeg": {
|
||||
"destinationStationCode": "SFO",
|
||||
"destinationName": {
|
||||
"defaultValue": {
|
||||
"value": "Destination name",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"arrivalDateTime": "2020-04-12T20:20:50.52Z",
|
||||
"originStationCode": "LA",
|
||||
"originName": {
|
||||
"defaultValue": {
|
||||
"value": "Origin name",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"departureDateTime": "2020-04-12T16:20:50.52Z",
|
||||
"fareName": {
|
||||
"defaultValue": {
|
||||
"value": "Fare name",
|
||||
"language": "en-US"
|
||||
}
|
||||
}
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
],
|
||||
"passengerType": "SINGLE_PASSENGER",
|
||||
"state": "ACTIVE",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"tripType": "ONE_WAY",
|
||||
"id": "%s.%s"
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
|
||||
var payload map[string]interface{}
|
||||
transitJson, _ := json.Marshal(transitObject)
|
||||
var payload map[string]any
|
||||
json.Unmarshal([]byte(fmt.Sprintf(`
|
||||
{
|
||||
"genericClasses": [%s],
|
||||
"genericObjects": [%s]
|
||||
"transitObjects": [%s]
|
||||
}
|
||||
`, newClass, newObject)), &payload)
|
||||
|
||||
`, transitJson)), &payload)
|
||||
claims := jwt.MapClaims{
|
||||
"iss": d.credentials.Email,
|
||||
"aud": "google",
|
||||
@@ -365,7 +212,7 @@ func (d *demoTransit) createJwtNewObjects(issuerId, classSuffix, objectSuffix st
|
||||
key, _ := jwt.ParseRSAPrivateKeyFromPEM(d.credentials.PrivateKey)
|
||||
token, _ := jwt.NewWithClaims(jwt.SigningMethodRS256, claims).SignedString(key)
|
||||
|
||||
fmt.Println("Add to Google Wallet link")
|
||||
fmt.Println("Add to Google Wallet link for new objects")
|
||||
fmt.Println("https://pay.google.com/gp/v/save/" + token)
|
||||
}
|
||||
|
||||
@@ -378,7 +225,7 @@ func (d *demoTransit) createJwtNewObjects(issuerId, classSuffix, objectSuffix st
|
||||
// their wallet, the pass objects defined in the JWT are added to the
|
||||
// user's Google Wallet app. This allows the user to save multiple pass
|
||||
// objects in one API call.
|
||||
func (d *demoTransit) createJwtExistingObjects(issuerId string) {
|
||||
func (d *demoTransit) createJwtExistingObjects(issuerId string, classSuffix string, objectSuffix string) {
|
||||
var payload map[string]interface{}
|
||||
json.Unmarshal([]byte(fmt.Sprintf(`
|
||||
{
|
||||
@@ -444,98 +291,20 @@ func (d *demoTransit) batchCreateObjects(issuerId, classSuffix string) {
|
||||
for i := 0; i < 3; i++ {
|
||||
objectSuffix := strings.ReplaceAll(uuid.New().String(), "-", "_")
|
||||
|
||||
batchObject := fmt.Sprintf(`
|
||||
{
|
||||
"classId": "%s.%s",
|
||||
"passengerNames": "Passenger names",
|
||||
"heroImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Hero image description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
|
||||
}
|
||||
},
|
||||
"ticketLeg": {
|
||||
"destinationStationCode": "SFO",
|
||||
"destinationName": {
|
||||
"defaultValue": {
|
||||
"value": "Destination name",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"arrivalDateTime": "2020-04-12T20:20:50.52Z",
|
||||
"originStationCode": "LA",
|
||||
"originName": {
|
||||
"defaultValue": {
|
||||
"value": "Origin name",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"departureDateTime": "2020-04-12T16:20:50.52Z",
|
||||
"fareName": {
|
||||
"defaultValue": {
|
||||
"value": "Fare name",
|
||||
"language": "en-US"
|
||||
}
|
||||
}
|
||||
},
|
||||
"barcode": {
|
||||
"type": "QR_CODE",
|
||||
"value": "QR code"
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"latitude": 37.424015499999996,
|
||||
"longitude": -122.09259560000001
|
||||
}
|
||||
],
|
||||
"passengerType": "SINGLE_PASSENGER",
|
||||
"state": "ACTIVE",
|
||||
"linksModuleData": {
|
||||
"uris": [
|
||||
{
|
||||
"id": "LINK_MODULE_URI_ID",
|
||||
"uri": "http://maps.google.com/",
|
||||
"description": "Link module URI description"
|
||||
},
|
||||
{
|
||||
"id": "LINK_MODULE_TEL_ID",
|
||||
"uri": "tel:6505555555",
|
||||
"description": "Link module tel description"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imageModulesData": [
|
||||
{
|
||||
"id": "IMAGE_MODULE_ID",
|
||||
"mainImage": {
|
||||
"contentDescription": {
|
||||
"defaultValue": {
|
||||
"value": "Image module description",
|
||||
"language": "en-US"
|
||||
}
|
||||
},
|
||||
"sourceUri": {
|
||||
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"textModulesData": [
|
||||
{
|
||||
"body": "Text module body",
|
||||
"header": "Text module header",
|
||||
"id": "TEXT_MODULE_ID"
|
||||
}
|
||||
],
|
||||
"tripType": "ONE_WAY",
|
||||
"id": "%s.%s"
|
||||
transitObject := new(walletobjects.TransitObject)
|
||||
transitObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
|
||||
transitObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
|
||||
transitObject.State = "ACTIVE"
|
||||
transitObject.PassengerNames = "Passenger names"
|
||||
transitObject.TripType = "ONE_WAY"
|
||||
transitObject.PassengerType = "SINGLE_PASSENGER"
|
||||
transitObject.TicketLeg = &walletobjects.TicketLeg{
|
||||
DestinationStationCode: "SFO",
|
||||
OriginStationCode: "LA",
|
||||
}
|
||||
`, issuerId, classSuffix, issuerId, objectSuffix)
|
||||
|
||||
transitJson, _ := json.Marshal(transitObject)
|
||||
batchObject := fmt.Sprintf("%s", transitJson)
|
||||
|
||||
data += "--batch_createobjectbatch\n"
|
||||
data += "Content-Type: application/json\n\n"
|
||||
@@ -544,8 +313,7 @@ func (d *demoTransit) batchCreateObjects(issuerId, classSuffix string) {
|
||||
}
|
||||
data += "--batch_createobjectbatch--"
|
||||
|
||||
// batchUrl = 'https://walletobjects.googleapis.com/batch';
|
||||
res, err := d.httpClient.Post(batchUrl, "multipart/mixed; boundary=batch_createobjectbatch", bytes.NewBuffer([]byte(data)))
|
||||
res, err := d.credentials.Client(oauth2.NoContext).Post("https://walletobjects.googleapis.com/batch", "multipart/mixed; boundary=batch_createobjectbatch", bytes.NewBuffer([]byte(data)))
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
@@ -558,11 +326,6 @@ func (d *demoTransit) batchCreateObjects(issuerId, classSuffix string) {
|
||||
// [END batch]
|
||||
|
||||
func main() {
|
||||
if len(os.Args) == 0 {
|
||||
fmt.Println("Usage: go run demo_transit.go <issuer-id>")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
issuerId := os.Getenv("WALLET_ISSUER_ID")
|
||||
classSuffix := strings.ReplaceAll(uuid.New().String(), "-", "_")
|
||||
objectSuffix := fmt.Sprintf("%s-%s", strings.ReplaceAll(uuid.New().String(), "-", "_"), classSuffix)
|
||||
@@ -574,6 +337,6 @@ func main() {
|
||||
d.createObject(issuerId, classSuffix, objectSuffix)
|
||||
d.expireObject(issuerId, objectSuffix)
|
||||
d.createJwtNewObjects(issuerId, classSuffix, objectSuffix)
|
||||
d.createJwtExistingObjects(issuerId)
|
||||
d.createJwtExistingObjects(issuerId, classSuffix, objectSuffix)
|
||||
d.batchCreateObjects(issuerId, classSuffix)
|
||||
}
|
||||
|
||||
45
go/go.mod
45
go/go.mod
@@ -2,24 +2,35 @@ module example.com/wallet
|
||||
|
||||
go 1.20
|
||||
|
||||
require golang.org/x/oauth2 v0.8.0
|
||||
require (
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible
|
||||
github.com/google/uuid v1.4.0
|
||||
golang.org/x/oauth2 v0.15.0
|
||||
)
|
||||
|
||||
require (
|
||||
cloud.google.com/go/compute/metadata v0.2.0 // indirect
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/google/go-cmp v0.5.8 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/yuin/goldmark v1.4.13 // indirect
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
|
||||
golang.org/x/mod v0.8.0 // indirect
|
||||
golang.org/x/net v0.10.0 // indirect
|
||||
golang.org/x/sync v0.1.0 // indirect
|
||||
golang.org/x/sys v0.8.0 // indirect
|
||||
golang.org/x/term v0.8.0 // indirect
|
||||
golang.org/x/text v0.9.0 // indirect
|
||||
golang.org/x/tools v0.6.0 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
|
||||
cloud.google.com/go/compute v1.23.3 // indirect
|
||||
cloud.google.com/go/compute/metadata v0.2.3 // indirect
|
||||
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||
github.com/go-logr/logr v1.3.0 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/google/s2a-go v0.1.7 // indirect
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
|
||||
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
|
||||
go.opencensus.io v0.24.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect
|
||||
go.opentelemetry.io/otel v1.21.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.21.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.21.0 // indirect
|
||||
golang.org/x/crypto v0.16.0 // indirect
|
||||
golang.org/x/net v0.19.0 // indirect
|
||||
golang.org/x/sys v0.15.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
google.golang.org/api v0.154.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/protobuf v1.28.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4 // indirect
|
||||
google.golang.org/grpc v1.59.0 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
)
|
||||
|
||||
148
go/go.sum
148
go/go.sum
@@ -1,37 +1,167 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go/compute v1.23.3 h1:6sVlXXBmbd7jNX0Ipq0trII3e4n1/MsADLK6a+aiVlk=
|
||||
cloud.google.com/go/compute v1.23.3/go.mod h1:VCgBUoMnIVIR0CscqQiPJLAG25E3ZRZMzcFZeQ+h8CI=
|
||||
cloud.google.com/go/compute/metadata v0.2.0 h1:nBbNSZyDpkNlo3DepaaLKVuO7ClyifSAmNloSCZrHnQ=
|
||||
cloud.google.com/go/compute/metadata v0.2.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
|
||||
cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
|
||||
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
|
||||
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o=
|
||||
github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
|
||||
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfFxPRy3Bf7vr3h0cechB90XaQs=
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0=
|
||||
github.com/googleapis/gax-go/v2 v2.12.0 h1:A+gCJKdRfqXkr+BIRGtZLibNXf0m1f9E4HG56etFpas=
|
||||
github.com/googleapis/gax-go/v2 v2.12.0/go.mod h1:y+aIqrI5eb1YGMVJfuV3185Ts/D7qKpsEkdD5+I6QGU=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
|
||||
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 h1:aFJWCqJMNjENlcleuuOkGAPH82y0yULBScfXcIEdS24=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1/go.mod h1:sEGXWArGqc3tVa+ekntsN65DmVbVeW+7lTKTjZF3/Fo=
|
||||
go.opentelemetry.io/otel v1.21.0 h1:hzLeKBZEL7Okw2mGzZ0cc4k/A7Fta0uoPgaJCr8fsFc=
|
||||
go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znnUvNNEo=
|
||||
go.opentelemetry.io/otel/metric v1.21.0 h1:tlYWfeo+Bocx5kLEloTjbcDwBuELRrIFxwdQ36PlJu4=
|
||||
go.opentelemetry.io/otel/metric v1.21.0/go.mod h1:o1p3CA8nNHW8j5yuQLdc1eeqEaPfzug24uvsyIEJRWM=
|
||||
go.opentelemetry.io/otel/trace v1.21.0 h1:WD9i5gzvoUPuXIXH24ZNBudiarZDKuekPqi/E8fpfLc=
|
||||
go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
|
||||
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
|
||||
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.8.0 h1:6dkIjl3j3LtZ/O3sTgZTMsLKSftL/B8Zgq4huOIIUu8=
|
||||
golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/oauth2 v0.15.0 h1:s8pnnxNVzjWyrvYdFUQq5llS1PX2zhPXmccZv99h7uQ=
|
||||
golang.org/x/oauth2 v0.15.0/go.mod h1:q48ptWNTY5XWf+JNten23lcvHpLJ0ZSxF5ttTHKVCAM=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
||||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/api v0.154.0 h1:X7QkVKZBskztmpPKWQXgjJRPA2dJYrL6r+sYPRLj050=
|
||||
google.golang.org/api v0.154.0/go.mod h1:qhSMkM85hgqiokIYsrRyKxrjfBeIhgl4Z2JmeRkYylc=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
|
||||
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/genproto v0.0.0-20231120223509-83a465c0220f h1:Vn+VyHU5guc9KjB5KrjI2q0wCOWEOIh0OEsleqakHJg=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4 h1:DC7wcm+i+P1rN3Ff07vL+OndGg5OhNddHyTA+ocPqYE=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4/go.mod h1:eJVxU6o+4G1PSczBr85xmyvSNYAKvAYgkub40YGomFM=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
|
||||
google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk=
|
||||
google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
|
||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
||||
@@ -23,8 +23,6 @@ creating a pass class, updating issuer permissions, and more.
|
||||
* Follow the steps outlined in the
|
||||
[Google Wallet prerequisites](https://developers.google.com/wallet/generic/web/prerequisites)
|
||||
to create the Google Wallet issuer account and Google Cloud service account
|
||||
* Download the Java
|
||||
[Google Wallet API Client library](https://developers.google.com/wallet/generic/resources/libraries#java)
|
||||
|
||||
## Environment variables
|
||||
|
||||
@@ -39,16 +37,8 @@ for each class file.
|
||||
## How to use the code samples
|
||||
|
||||
1. Open the [`java`](./java/) project folder in your editor of choice.
|
||||
2. Copy the path to the Google Wallet API Client library (
|
||||
`libwalletobjects_public_java_lib_v1.jar` file) you downloaded. If needed,
|
||||
update the path in [`build.gradle`](./build.gradle) (line 14).
|
||||
|
||||
```plain
|
||||
implementation files('lib/libwalletobjects_public_java_lib_v1.jar')
|
||||
```
|
||||
|
||||
3. Build the project to install the dependencies.
|
||||
4. In your Java code, import a demo class and call its method(s). An example
|
||||
2. Build the project to install the dependencies.
|
||||
3. In your Java code, import a demo class and call its method(s). An example
|
||||
can be found below
|
||||
|
||||
```java
|
||||
|
||||
@@ -10,14 +10,12 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Replace with path to your local download of the Google Wallet library
|
||||
implementation files('lib/libwalletobjects_public_java_lib_v1.jar')
|
||||
|
||||
implementation 'com.auth0:java-jwt:3.19.1'
|
||||
implementation 'com.auth0:jwks-rsa:0.9.0'
|
||||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.4.2'
|
||||
implementation 'com.google.apis:google-api-services-oauth2:v2-rev20200213-2.0.0'
|
||||
implementation 'com.google.api-client:google-api-client:1.25.0'
|
||||
implementation 'com.google.api-client:google-api-client:2.2.0'
|
||||
implementation 'com.google.apis:google-api-services-walletobjects:v1-rev20240220-2.0.0'
|
||||
implementation 'com.google.auth:google-auth-library-oauth2-http:1.10.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.3.1'
|
||||
implementation 'javax.json:javax.json-api:1.1'
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.google.api.client.googleapis.json.GoogleJsonError;
|
||||
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
|
||||
import com.google.api.client.http.*;
|
||||
import com.google.api.client.json.gson.GsonFactory;
|
||||
import com.google.api.services.walletobjects.Walletobjects;
|
||||
import com.google.api.services.walletobjects.*;
|
||||
import com.google.api.services.walletobjects.model.*;
|
||||
import com.google.auth.http.HttpCredentialsAdapter;
|
||||
import com.google.auth.oauth2.GoogleCredentials;
|
||||
@@ -64,11 +64,9 @@ public class DemoEventTicket {
|
||||
*
|
||||
*/
|
||||
public void auth() throws Exception {
|
||||
String scope = "https://www.googleapis.com/auth/wallet_object.issuer";
|
||||
|
||||
credentials =
|
||||
GoogleCredentials.fromStream(new FileInputStream(keyFilePath))
|
||||
.createScoped(List.of(scope));
|
||||
.createScoped(List.of(WalletobjectsScopes.WALLET_OBJECT_ISSUER));
|
||||
credentials.refresh();
|
||||
|
||||
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.google.api.client.googleapis.json.GoogleJsonError;
|
||||
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
|
||||
import com.google.api.client.http.*;
|
||||
import com.google.api.client.json.gson.GsonFactory;
|
||||
import com.google.api.services.walletobjects.Walletobjects;
|
||||
import com.google.api.services.walletobjects.*;
|
||||
import com.google.api.services.walletobjects.model.*;
|
||||
import com.google.auth.http.HttpCredentialsAdapter;
|
||||
import com.google.auth.oauth2.GoogleCredentials;
|
||||
@@ -64,11 +64,9 @@ public class DemoFlight {
|
||||
*
|
||||
*/
|
||||
public void auth() throws Exception {
|
||||
String scope = "https://www.googleapis.com/auth/wallet_object.issuer";
|
||||
|
||||
credentials =
|
||||
GoogleCredentials.fromStream(new FileInputStream(keyFilePath))
|
||||
.createScoped(List.of(scope));
|
||||
.createScoped(List.of(WalletobjectsScopes.WALLET_OBJECT_ISSUER));
|
||||
credentials.refresh();
|
||||
|
||||
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.google.api.client.googleapis.json.GoogleJsonError;
|
||||
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
|
||||
import com.google.api.client.http.*;
|
||||
import com.google.api.client.json.gson.GsonFactory;
|
||||
import com.google.api.services.walletobjects.Walletobjects;
|
||||
import com.google.api.services.walletobjects.*;
|
||||
import com.google.api.services.walletobjects.model.*;
|
||||
import com.google.auth.http.HttpCredentialsAdapter;
|
||||
import com.google.auth.oauth2.GoogleCredentials;
|
||||
@@ -64,11 +64,9 @@ public class DemoGeneric {
|
||||
*
|
||||
*/
|
||||
public void auth() throws Exception {
|
||||
String scope = "https://www.googleapis.com/auth/wallet_object.issuer";
|
||||
|
||||
credentials =
|
||||
GoogleCredentials.fromStream(new FileInputStream(keyFilePath))
|
||||
.createScoped(List.of(scope));
|
||||
.createScoped(List.of(WalletobjectsScopes.WALLET_OBJECT_ISSUER));
|
||||
credentials.refresh();
|
||||
|
||||
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.google.api.client.googleapis.json.GoogleJsonError;
|
||||
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
|
||||
import com.google.api.client.http.*;
|
||||
import com.google.api.client.json.gson.GsonFactory;
|
||||
import com.google.api.services.walletobjects.Walletobjects;
|
||||
import com.google.api.services.walletobjects.*;
|
||||
import com.google.api.services.walletobjects.model.*;
|
||||
import com.google.auth.http.HttpCredentialsAdapter;
|
||||
import com.google.auth.oauth2.GoogleCredentials;
|
||||
@@ -64,11 +64,9 @@ public class DemoGiftCard {
|
||||
*
|
||||
*/
|
||||
public void auth() throws Exception {
|
||||
String scope = "https://www.googleapis.com/auth/wallet_object.issuer";
|
||||
|
||||
credentials =
|
||||
GoogleCredentials.fromStream(new FileInputStream(keyFilePath))
|
||||
.createScoped(List.of(scope));
|
||||
.createScoped(List.of(WalletobjectsScopes.WALLET_OBJECT_ISSUER));
|
||||
credentials.refresh();
|
||||
|
||||
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.google.api.client.googleapis.json.GoogleJsonError;
|
||||
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
|
||||
import com.google.api.client.http.*;
|
||||
import com.google.api.client.json.gson.GsonFactory;
|
||||
import com.google.api.services.walletobjects.Walletobjects;
|
||||
import com.google.api.services.walletobjects.*;
|
||||
import com.google.api.services.walletobjects.model.*;
|
||||
import com.google.auth.http.HttpCredentialsAdapter;
|
||||
import com.google.auth.oauth2.GoogleCredentials;
|
||||
@@ -64,11 +64,9 @@ public class DemoLoyalty {
|
||||
*
|
||||
*/
|
||||
public void auth() throws Exception {
|
||||
String scope = "https://www.googleapis.com/auth/wallet_object.issuer";
|
||||
|
||||
credentials =
|
||||
GoogleCredentials.fromStream(new FileInputStream(keyFilePath))
|
||||
.createScoped(List.of(scope));
|
||||
.createScoped(List.of(WalletobjectsScopes.WALLET_OBJECT_ISSUER));
|
||||
credentials.refresh();
|
||||
|
||||
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.google.api.client.googleapis.json.GoogleJsonError;
|
||||
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
|
||||
import com.google.api.client.http.*;
|
||||
import com.google.api.client.json.gson.GsonFactory;
|
||||
import com.google.api.services.walletobjects.Walletobjects;
|
||||
import com.google.api.services.walletobjects.*;
|
||||
import com.google.api.services.walletobjects.model.*;
|
||||
import com.google.auth.http.HttpCredentialsAdapter;
|
||||
import com.google.auth.oauth2.GoogleCredentials;
|
||||
@@ -64,11 +64,9 @@ public class DemoOffer {
|
||||
*
|
||||
*/
|
||||
public void auth() throws Exception {
|
||||
String scope = "https://www.googleapis.com/auth/wallet_object.issuer";
|
||||
|
||||
credentials =
|
||||
GoogleCredentials.fromStream(new FileInputStream(keyFilePath))
|
||||
.createScoped(List.of(scope));
|
||||
.createScoped(List.of(WalletobjectsScopes.WALLET_OBJECT_ISSUER));
|
||||
credentials.refresh();
|
||||
|
||||
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.google.api.client.googleapis.json.GoogleJsonError;
|
||||
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
|
||||
import com.google.api.client.http.*;
|
||||
import com.google.api.client.json.gson.GsonFactory;
|
||||
import com.google.api.services.walletobjects.Walletobjects;
|
||||
import com.google.api.services.walletobjects.*;
|
||||
import com.google.api.services.walletobjects.model.*;
|
||||
import com.google.auth.http.HttpCredentialsAdapter;
|
||||
import com.google.auth.oauth2.GoogleCredentials;
|
||||
@@ -63,11 +63,9 @@ public class DemoTransit {
|
||||
*
|
||||
*/
|
||||
public void auth() throws Exception {
|
||||
String scope = "https://www.googleapis.com/auth/wallet_object.issuer";
|
||||
|
||||
credentials =
|
||||
GoogleCredentials.fromStream(new FileInputStream(keyFilePath))
|
||||
.createScoped(List.of(scope));
|
||||
.createScoped(List.of(WalletobjectsScopes.WALLET_OBJECT_ISSUER));
|
||||
credentials.refresh();
|
||||
|
||||
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
// [START setup]
|
||||
// [START imports]
|
||||
const { GoogleAuth } = require('google-auth-library');
|
||||
const { google } = require('googleapis');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
// [END imports]
|
||||
@@ -31,12 +31,6 @@ class DemoEventTicket {
|
||||
* variable: GOOGLE_APPLICATION_CREDENTIALS.
|
||||
*/
|
||||
this.keyFilePath = process.env.GOOGLE_APPLICATION_CREDENTIALS || '/path/to/key.json';
|
||||
|
||||
this.baseUrl = 'https://walletobjects.googleapis.com/walletobjects/v1';
|
||||
this.batchUrl = 'https://walletobjects.googleapis.com/batch';
|
||||
this.classUrl = `${this.baseUrl}/eventTicketClass`;
|
||||
this.objectUrl = `${this.baseUrl}/eventTicketObject`;
|
||||
|
||||
this.auth();
|
||||
}
|
||||
// [END setup]
|
||||
@@ -46,11 +40,16 @@ class DemoEventTicket {
|
||||
* Create authenticated HTTP client using a service account file.
|
||||
*/
|
||||
auth() {
|
||||
const auth = new google.auth.GoogleAuth({
|
||||
keyFile: this.keyFilePath,
|
||||
scopes: ['https://www.googleapis.com/auth/wallet_object.issuer'],
|
||||
});
|
||||
|
||||
this.credentials = require(this.keyFilePath);
|
||||
|
||||
this.httpClient = new GoogleAuth({
|
||||
credentials: this.credentials,
|
||||
scopes: 'https://www.googleapis.com/auth/wallet_object.issuer'
|
||||
this.client = google.walletobjects({
|
||||
version: 'v1',
|
||||
auth: auth,
|
||||
});
|
||||
}
|
||||
// [END auth]
|
||||
@@ -69,9 +68,8 @@ class DemoEventTicket {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.eventticketclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
|
||||
console.log(`Class ${issuerId}.${classSuffix} already exists!`);
|
||||
@@ -100,10 +98,8 @@ class DemoEventTicket {
|
||||
'reviewStatus': 'UNDER_REVIEW'
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: this.classUrl,
|
||||
method: 'POST',
|
||||
data: newClass
|
||||
response = await this.client.eventticketclass.insert({
|
||||
requestBody: newClass
|
||||
});
|
||||
|
||||
console.log('Class insert response');
|
||||
@@ -129,9 +125,8 @@ class DemoEventTicket {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.eventticketclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -156,10 +151,9 @@ class DemoEventTicket {
|
||||
// Note: reviewStatus must be 'UNDER_REVIEW' or 'DRAFT' for updates
|
||||
updatedClass['reviewStatus'] = 'UNDER_REVIEW';
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'PUT',
|
||||
data: updatedClass
|
||||
response = await this.client.eventticketclass.update({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: updatedClass
|
||||
});
|
||||
|
||||
console.log('Class update response');
|
||||
@@ -185,9 +179,8 @@ class DemoEventTicket {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.eventticketclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -211,10 +204,9 @@ class DemoEventTicket {
|
||||
'reviewStatus': 'UNDER_REVIEW'
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.eventticketclass.patch({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Class patch response');
|
||||
@@ -240,9 +232,8 @@ class DemoEventTicket {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.eventticketclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -255,10 +246,9 @@ class DemoEventTicket {
|
||||
}
|
||||
}
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}/addMessage`,
|
||||
method: 'POST',
|
||||
data: {
|
||||
response = await this.client.eventticketclass.addmessage({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: {
|
||||
'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
@@ -288,9 +278,8 @@ class DemoEventTicket {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.eventticketobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
|
||||
console.log(`Object ${issuerId}.${objectSuffix} already exists!`);
|
||||
@@ -398,10 +387,8 @@ class DemoEventTicket {
|
||||
'ticketNumber': 'Ticket number'
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: this.objectUrl,
|
||||
method: 'POST',
|
||||
data: newObject
|
||||
response = await this.client.eventticketobject.insert({
|
||||
requestBody: newObject
|
||||
});
|
||||
|
||||
console.log('Object insert response');
|
||||
@@ -427,9 +414,8 @@ class DemoEventTicket {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.eventticketobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -458,10 +444,9 @@ class DemoEventTicket {
|
||||
updatedObject['linksModuleData']['uris'].push(newLink);
|
||||
}
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PUT',
|
||||
data: updatedObject
|
||||
response = await this.client.eventticketobject.update({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: updatedObject
|
||||
});
|
||||
|
||||
console.log('Object update response');
|
||||
@@ -485,9 +470,8 @@ class DemoEventTicket {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.eventticketobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -521,10 +505,9 @@ class DemoEventTicket {
|
||||
}
|
||||
patchBody['linksModuleData']['uris'].push(newLink);
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.eventticketobject.patch({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Object patch response');
|
||||
@@ -551,9 +534,8 @@ class DemoEventTicket {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.eventticketobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -571,10 +553,9 @@ class DemoEventTicket {
|
||||
'state': 'EXPIRED'
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.eventticketobject.patch({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Object expiration response');
|
||||
@@ -600,7 +581,7 @@ class DemoEventTicket {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
response = await this.client.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
});
|
||||
@@ -615,10 +596,9 @@ class DemoEventTicket {
|
||||
}
|
||||
}
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}/addMessage`,
|
||||
method: 'POST',
|
||||
data: {
|
||||
response = await this.client.eventticketclass.addmessage({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: {
|
||||
'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
@@ -989,8 +969,8 @@ class DemoEventTicket {
|
||||
data += '--batch_createobjectbatch--';
|
||||
|
||||
// Invoke the batch API calls
|
||||
let response = await this.httpClient.request({
|
||||
url: this.batchUrl, // https://walletobjects.googleapis.com/batch
|
||||
let response = await this.client.context._options.auth.request({
|
||||
url: 'https://walletobjects.googleapis.com/batch',
|
||||
method: 'POST',
|
||||
data: data,
|
||||
headers: {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
// [START setup]
|
||||
// [START imports]
|
||||
const { GoogleAuth } = require('google-auth-library');
|
||||
const { google } = require('googleapis');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
// [END imports]
|
||||
@@ -31,12 +31,6 @@ class DemoFlight {
|
||||
* variable: GOOGLE_APPLICATION_CREDENTIALS.
|
||||
*/
|
||||
this.keyFilePath = process.env.GOOGLE_APPLICATION_CREDENTIALS || '/path/to/key.json';
|
||||
|
||||
this.baseUrl = 'https://walletobjects.googleapis.com/walletobjects/v1';
|
||||
this.batchUrl = 'https://walletobjects.googleapis.com/batch';
|
||||
this.classUrl = `${this.baseUrl}/flightClass`;
|
||||
this.objectUrl = `${this.baseUrl}/flightObject`;
|
||||
|
||||
this.auth();
|
||||
}
|
||||
// [END setup]
|
||||
@@ -46,11 +40,16 @@ class DemoFlight {
|
||||
* Create authenticated HTTP client using a service account file.
|
||||
*/
|
||||
auth() {
|
||||
const auth = new google.auth.GoogleAuth({
|
||||
keyFile: this.keyFilePath,
|
||||
scopes: ['https://www.googleapis.com/auth/wallet_object.issuer'],
|
||||
});
|
||||
|
||||
this.credentials = require(this.keyFilePath);
|
||||
|
||||
this.httpClient = new GoogleAuth({
|
||||
credentials: this.credentials,
|
||||
scopes: 'https://www.googleapis.com/auth/wallet_object.issuer'
|
||||
this.client = google.walletobjects({
|
||||
version: 'v1',
|
||||
auth: auth,
|
||||
});
|
||||
}
|
||||
// [END auth]
|
||||
@@ -69,9 +68,8 @@ class DemoFlight {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.flightclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
|
||||
console.log(`Class ${issuerId}.${classSuffix} already exists!`);
|
||||
@@ -110,10 +108,8 @@ class DemoFlight {
|
||||
}
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: this.classUrl,
|
||||
method: 'POST',
|
||||
data: newClass
|
||||
response = await this.client.flightclass.insert({
|
||||
requestBody: newClass
|
||||
});
|
||||
|
||||
console.log('Class insert response');
|
||||
@@ -139,9 +135,8 @@ class DemoFlight {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.flightclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -166,10 +161,9 @@ class DemoFlight {
|
||||
// Note: reviewStatus must be 'UNDER_REVIEW' or 'DRAFT' for updates
|
||||
updatedClass['reviewStatus'] = 'UNDER_REVIEW';
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'PUT',
|
||||
data: updatedClass
|
||||
response = await this.client.flightclass.update({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: updatedClass
|
||||
});
|
||||
|
||||
console.log('Class update response');
|
||||
@@ -195,9 +189,8 @@ class DemoFlight {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.flightclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -221,10 +214,9 @@ class DemoFlight {
|
||||
'reviewStatus': 'UNDER_REVIEW'
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.flightclass.patch({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Class patch response');
|
||||
@@ -250,9 +242,8 @@ class DemoFlight {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.flightclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -265,10 +256,9 @@ class DemoFlight {
|
||||
}
|
||||
}
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}/addMessage`,
|
||||
method: 'POST',
|
||||
data: {
|
||||
response = await this.client.flightclass.addmessage({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: {
|
||||
'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
@@ -298,9 +288,8 @@ class DemoFlight {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.flightobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
|
||||
console.log(`Object ${issuerId}.${objectSuffix} already exists!`);
|
||||
@@ -388,10 +377,8 @@ class DemoFlight {
|
||||
}
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: this.objectUrl,
|
||||
method: 'POST',
|
||||
data: newObject
|
||||
response = await this.client.flightobject.insert({
|
||||
requestBody: newObject
|
||||
});
|
||||
|
||||
console.log('Object insert response');
|
||||
@@ -417,9 +404,8 @@ class DemoFlight {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.flightobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -448,10 +434,9 @@ class DemoFlight {
|
||||
updatedObject['linksModuleData']['uris'].push(newLink);
|
||||
}
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PUT',
|
||||
data: updatedObject
|
||||
response = await this.client.flightobject.update({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: updatedObject
|
||||
});
|
||||
|
||||
console.log('Object update response');
|
||||
@@ -475,9 +460,8 @@ class DemoFlight {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.flightobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -511,10 +495,9 @@ class DemoFlight {
|
||||
}
|
||||
patchBody['linksModuleData']['uris'].push(newLink);
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.flightobject.patch({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Object patch response');
|
||||
@@ -541,9 +524,8 @@ class DemoFlight {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.flightobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -561,10 +543,9 @@ class DemoFlight {
|
||||
'state': 'EXPIRED'
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.flightobject.patch({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Object expiration response');
|
||||
@@ -590,9 +571,8 @@ class DemoFlight {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.flightobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -605,10 +585,9 @@ class DemoFlight {
|
||||
}
|
||||
}
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}/addMessage`,
|
||||
method: 'POST',
|
||||
data: {
|
||||
response = await this.client.flightobject.addmessage({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: {
|
||||
'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
@@ -950,8 +929,8 @@ class DemoFlight {
|
||||
data += '--batch_createobjectbatch--';
|
||||
|
||||
// Invoke the batch API calls
|
||||
let response = await this.httpClient.request({
|
||||
url: this.batchUrl, // https://walletobjects.googleapis.com/batch
|
||||
let response = await this.client.context._options.auth.request({
|
||||
url: 'https://walletobjects.googleapis.com/batch',
|
||||
method: 'POST',
|
||||
data: data,
|
||||
headers: {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
// [START setup]
|
||||
// [START imports]
|
||||
const { GoogleAuth } = require('google-auth-library');
|
||||
const { google } = require('googleapis');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
// [END imports]
|
||||
@@ -31,12 +31,6 @@ class DemoGeneric {
|
||||
* variable: GOOGLE_APPLICATION_CREDENTIALS.
|
||||
*/
|
||||
this.keyFilePath = process.env.GOOGLE_APPLICATION_CREDENTIALS || '/path/to/key.json';
|
||||
|
||||
this.baseUrl = 'https://walletobjects.googleapis.com/walletobjects/v1';
|
||||
this.batchUrl = 'https://walletobjects.googleapis.com/batch';
|
||||
this.classUrl = `${this.baseUrl}/genericClass`;
|
||||
this.objectUrl = `${this.baseUrl}/genericObject`;
|
||||
|
||||
this.auth();
|
||||
}
|
||||
// [END setup]
|
||||
@@ -46,11 +40,16 @@ class DemoGeneric {
|
||||
* Create authenticated HTTP client using a service account file.
|
||||
*/
|
||||
auth() {
|
||||
const auth = new google.auth.GoogleAuth({
|
||||
keyFile: this.keyFilePath,
|
||||
scopes: ['https://www.googleapis.com/auth/wallet_object.issuer'],
|
||||
});
|
||||
|
||||
this.credentials = require(this.keyFilePath);
|
||||
|
||||
this.httpClient = new GoogleAuth({
|
||||
credentials: this.credentials,
|
||||
scopes: 'https://www.googleapis.com/auth/wallet_object.issuer'
|
||||
this.client = google.walletobjects({
|
||||
version: 'v1',
|
||||
auth: auth,
|
||||
});
|
||||
}
|
||||
// [END auth]
|
||||
@@ -69,9 +68,8 @@ class DemoGeneric {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.genericclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
|
||||
console.log(`Class ${issuerId}.${classSuffix} already exists!`);
|
||||
@@ -91,10 +89,8 @@ class DemoGeneric {
|
||||
'id': `${issuerId}.${classSuffix}`
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: this.classUrl,
|
||||
method: 'POST',
|
||||
data: newClass
|
||||
response = await this.client.genericclass.insert({
|
||||
requestBody: newClass
|
||||
});
|
||||
|
||||
console.log('Class insert response');
|
||||
@@ -120,9 +116,8 @@ class DemoGeneric {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.genericclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -150,10 +145,9 @@ class DemoGeneric {
|
||||
}
|
||||
updatedClass['linksModuleData']['uris'].push(newLink);
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'PUT',
|
||||
data: updatedClass
|
||||
response = await this.client.genericclass.update({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: updatedClass
|
||||
});
|
||||
|
||||
console.log('Class update response');
|
||||
@@ -179,9 +173,8 @@ class DemoGeneric {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.genericclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -216,10 +209,9 @@ class DemoGeneric {
|
||||
}
|
||||
patchBody['linksModuleData']['uris'].push(newLink);
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.genericclass.patch({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Class patch response');
|
||||
@@ -244,9 +236,8 @@ class DemoGeneric {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.genericobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
|
||||
console.log(`Object ${issuerId}.${objectSuffix} already exists!`);
|
||||
@@ -344,10 +335,8 @@ class DemoGeneric {
|
||||
}
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: this.objectUrl,
|
||||
method: 'POST',
|
||||
data: newObject
|
||||
response = await this.client.genericobject.insert({
|
||||
requestBody: newObject
|
||||
});
|
||||
|
||||
console.log('Object insert response');
|
||||
@@ -373,9 +362,8 @@ class DemoGeneric {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.genericobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -404,10 +392,9 @@ class DemoGeneric {
|
||||
updatedObject['linksModuleData']['uris'].push(newLink);
|
||||
}
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PUT',
|
||||
data: updatedObject
|
||||
response = await this.client.genericobject.update({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: updatedObject
|
||||
});
|
||||
|
||||
console.log('Object update response');
|
||||
@@ -431,9 +418,8 @@ class DemoGeneric {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.genericobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -467,10 +453,9 @@ class DemoGeneric {
|
||||
}
|
||||
patchBody['linksModuleData']['uris'].push(newLink);
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.genericobject.patch({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Object patch response');
|
||||
@@ -497,9 +482,8 @@ class DemoGeneric {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.genericobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -517,10 +501,9 @@ class DemoGeneric {
|
||||
'state': 'EXPIRED'
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.genericobject.patch({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Object expiration response');
|
||||
@@ -858,8 +841,8 @@ class DemoGeneric {
|
||||
data += '--batch_createobjectbatch--';
|
||||
|
||||
// Invoke the batch API calls
|
||||
let response = await this.httpClient.request({
|
||||
url: this.batchUrl, // https://walletobjects.googleapis.com/batch
|
||||
let response = await this.client.context._options.auth.request({
|
||||
url: 'https://walletobjects.googleapis.com/batch',
|
||||
method: 'POST',
|
||||
data: data,
|
||||
headers: {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
// [START setup]
|
||||
// [START imports]
|
||||
const { GoogleAuth } = require('google-auth-library');
|
||||
const { google } = require('googleapis');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
// [END imports]
|
||||
@@ -31,12 +31,6 @@ class DemoGiftCard {
|
||||
* variable: GOOGLE_APPLICATION_CREDENTIALS.
|
||||
*/
|
||||
this.keyFilePath = process.env.GOOGLE_APPLICATION_CREDENTIALS || '/path/to/key.json';
|
||||
|
||||
this.baseUrl = 'https://walletobjects.googleapis.com/walletobjects/v1';
|
||||
this.batchUrl = 'https://walletobjects.googleapis.com/batch';
|
||||
this.classUrl = `${this.baseUrl}/giftCardClass`;
|
||||
this.objectUrl = `${this.baseUrl}/giftCardObject`;
|
||||
|
||||
this.auth();
|
||||
}
|
||||
// [END setup]
|
||||
@@ -46,11 +40,16 @@ class DemoGiftCard {
|
||||
* Create authenticated HTTP client using a service account file.
|
||||
*/
|
||||
auth() {
|
||||
const auth = new google.auth.GoogleAuth({
|
||||
keyFile: this.keyFilePath,
|
||||
scopes: ['https://www.googleapis.com/auth/wallet_object.issuer'],
|
||||
});
|
||||
|
||||
this.credentials = require(this.keyFilePath);
|
||||
|
||||
this.httpClient = new GoogleAuth({
|
||||
credentials: this.credentials,
|
||||
scopes: 'https://www.googleapis.com/auth/wallet_object.issuer'
|
||||
this.client = google.walletobjects({
|
||||
version: 'v1',
|
||||
auth: auth,
|
||||
});
|
||||
}
|
||||
// [END auth]
|
||||
@@ -69,9 +68,8 @@ class DemoGiftCard {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.giftcardclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
|
||||
console.log(`Class ${issuerId}.${classSuffix} already exists!`);
|
||||
@@ -93,10 +91,8 @@ class DemoGiftCard {
|
||||
'reviewStatus': 'UNDER_REVIEW',
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: this.classUrl,
|
||||
method: 'POST',
|
||||
data: newClass
|
||||
response = await this.client.giftcardclass.insert({
|
||||
requestBody: newClass
|
||||
});
|
||||
|
||||
console.log('Class insert response');
|
||||
@@ -122,9 +118,8 @@ class DemoGiftCard {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.giftcardclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -149,10 +144,9 @@ class DemoGiftCard {
|
||||
// Note: reviewStatus must be 'UNDER_REVIEW' or 'DRAFT' for updates
|
||||
updatedClass['reviewStatus'] = 'UNDER_REVIEW';
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'PUT',
|
||||
data: updatedClass
|
||||
response = await this.client.giftcardclass.update({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: updatedClass
|
||||
});
|
||||
|
||||
console.log('Class update response');
|
||||
@@ -178,9 +172,8 @@ class DemoGiftCard {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.giftcardclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -204,10 +197,9 @@ class DemoGiftCard {
|
||||
'reviewStatus': 'UNDER_REVIEW'
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.giftcardclass.patch({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Class patch response');
|
||||
@@ -233,9 +225,8 @@ class DemoGiftCard {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.giftcardclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -248,10 +239,9 @@ class DemoGiftCard {
|
||||
}
|
||||
}
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}/addMessage`,
|
||||
method: 'POST',
|
||||
data: {
|
||||
response = await this.client.giftcardclass.addmessage({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: {
|
||||
'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
@@ -281,9 +271,8 @@ class DemoGiftCard {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.giftcardobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
|
||||
console.log(`Object ${issuerId}.${objectSuffix} already exists!`);
|
||||
@@ -372,10 +361,8 @@ class DemoGiftCard {
|
||||
}
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: this.objectUrl,
|
||||
method: 'POST',
|
||||
data: newObject
|
||||
response = await this.client.giftcardobject.insert({
|
||||
requestBody: newObject
|
||||
});
|
||||
|
||||
console.log('Object insert response');
|
||||
@@ -401,9 +388,8 @@ class DemoGiftCard {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.giftcardobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -432,10 +418,9 @@ class DemoGiftCard {
|
||||
updatedObject['linksModuleData']['uris'].push(newLink);
|
||||
}
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PUT',
|
||||
data: updatedObject
|
||||
response = await this.client.giftcardobject.update({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: updatedObject
|
||||
});
|
||||
|
||||
console.log('Object update response');
|
||||
@@ -459,9 +444,8 @@ class DemoGiftCard {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.giftcardobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -495,10 +479,9 @@ class DemoGiftCard {
|
||||
}
|
||||
patchBody['linksModuleData']['uris'].push(newLink);
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.giftcardobject.patch({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Object patch response');
|
||||
@@ -525,9 +508,8 @@ class DemoGiftCard {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.giftcardobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -545,10 +527,9 @@ class DemoGiftCard {
|
||||
'state': 'EXPIRED'
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.giftcardobject.patch({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Object expiration response');
|
||||
@@ -574,9 +555,8 @@ class DemoGiftCard {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.giftcardobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -589,10 +569,9 @@ class DemoGiftCard {
|
||||
}
|
||||
}
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}/addMessage`,
|
||||
method: 'POST',
|
||||
data: {
|
||||
response = await this.client.giftcardobject.addmessage({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: {
|
||||
'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
@@ -919,8 +898,8 @@ class DemoGiftCard {
|
||||
data += '--batch_createobjectbatch--';
|
||||
|
||||
// Invoke the batch API calls
|
||||
let response = await this.httpClient.request({
|
||||
url: this.batchUrl, // https://walletobjects.googleapis.com/batch
|
||||
let response = await this.client.context._options.auth.request({
|
||||
url: 'https://walletobjects.googleapis.com/batch',
|
||||
method: 'POST',
|
||||
data: data,
|
||||
headers: {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
// [START setup]
|
||||
// [START imports]
|
||||
const { GoogleAuth } = require('google-auth-library');
|
||||
const { google } = require('googleapis');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
// [END imports]
|
||||
@@ -31,12 +31,6 @@ class DemoLoyalty {
|
||||
* variable: GOOGLE_APPLICATION_CREDENTIALS.
|
||||
*/
|
||||
this.keyFilePath = process.env.GOOGLE_APPLICATION_CREDENTIALS || '/path/to/key.json';
|
||||
|
||||
this.baseUrl = 'https://walletobjects.googleapis.com/walletobjects/v1';
|
||||
this.batchUrl = 'https://walletobjects.googleapis.com/batch';
|
||||
this.classUrl = `${this.baseUrl}/loyaltyClass`;
|
||||
this.objectUrl = `${this.baseUrl}/loyaltyObject`;
|
||||
|
||||
this.auth();
|
||||
}
|
||||
// [END setup]
|
||||
@@ -46,11 +40,16 @@ class DemoLoyalty {
|
||||
* Create authenticated HTTP client using a service account file.
|
||||
*/
|
||||
auth() {
|
||||
const auth = new google.auth.GoogleAuth({
|
||||
keyFile: this.keyFilePath,
|
||||
scopes: ['https://www.googleapis.com/auth/wallet_object.issuer'],
|
||||
});
|
||||
|
||||
this.credentials = require(this.keyFilePath);
|
||||
|
||||
this.httpClient = new GoogleAuth({
|
||||
credentials: this.credentials,
|
||||
scopes: 'https://www.googleapis.com/auth/wallet_object.issuer'
|
||||
this.client = google.walletobjects({
|
||||
version: 'v1',
|
||||
auth: auth,
|
||||
});
|
||||
}
|
||||
// [END auth]
|
||||
@@ -69,9 +68,8 @@ class DemoLoyalty {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.loyaltyclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
|
||||
console.log(`Class ${issuerId}.${classSuffix} already exists!`);
|
||||
@@ -105,10 +103,8 @@ class DemoLoyalty {
|
||||
}
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: this.classUrl,
|
||||
method: 'POST',
|
||||
data: newClass
|
||||
response = await this.client.loyaltyclass.insert({
|
||||
requestBody: newClass
|
||||
});
|
||||
|
||||
console.log('Class insert response');
|
||||
@@ -134,9 +130,8 @@ class DemoLoyalty {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.loyaltyclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -161,10 +156,9 @@ class DemoLoyalty {
|
||||
// Note: reviewStatus must be 'UNDER_REVIEW' or 'DRAFT' for updates
|
||||
updatedClass['reviewStatus'] = 'UNDER_REVIEW';
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'PUT',
|
||||
data: updatedClass
|
||||
response = await this.client.loyaltyclass.update({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: updatedClass
|
||||
});
|
||||
|
||||
console.log('Class update response');
|
||||
@@ -190,9 +184,8 @@ class DemoLoyalty {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.loyaltyclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -216,10 +209,9 @@ class DemoLoyalty {
|
||||
'reviewStatus': 'UNDER_REVIEW'
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.loyaltyclass.patch({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Class patch response');
|
||||
@@ -245,9 +237,8 @@ class DemoLoyalty {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.loyaltyclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -260,10 +251,9 @@ class DemoLoyalty {
|
||||
}
|
||||
}
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}/addMessage`,
|
||||
method: 'POST',
|
||||
data: {
|
||||
response = await this.client.loyaltyclass.addmessage({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: {
|
||||
'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
@@ -293,9 +283,8 @@ class DemoLoyalty {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.loyaltyobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
|
||||
console.log(`Object ${issuerId}.${objectSuffix} already exists!`);
|
||||
@@ -383,10 +372,8 @@ class DemoLoyalty {
|
||||
}
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: this.objectUrl,
|
||||
method: 'POST',
|
||||
data: newObject
|
||||
response = await this.client.loyaltyobject.insert({
|
||||
requestBody: newObject
|
||||
});
|
||||
|
||||
console.log('Object insert response');
|
||||
@@ -412,9 +399,8 @@ class DemoLoyalty {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.loyaltyobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -443,10 +429,9 @@ class DemoLoyalty {
|
||||
updatedObject['linksModuleData']['uris'].push(newLink);
|
||||
}
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PUT',
|
||||
data: updatedObject
|
||||
response = await this.client.loyaltyobject.update({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: updatedObject
|
||||
});
|
||||
|
||||
console.log('Object update response');
|
||||
@@ -470,9 +455,8 @@ class DemoLoyalty {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.loyaltyobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -506,10 +490,9 @@ class DemoLoyalty {
|
||||
}
|
||||
patchBody['linksModuleData']['uris'].push(newLink);
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.loyaltyobject.patch({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Object patch response');
|
||||
@@ -536,9 +519,8 @@ class DemoLoyalty {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.loyaltyobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -556,10 +538,9 @@ class DemoLoyalty {
|
||||
'state': 'EXPIRED'
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.loyaltyobject.patch({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Object expiration response');
|
||||
@@ -585,9 +566,8 @@ class DemoLoyalty {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.loyaltyobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -600,10 +580,9 @@ class DemoLoyalty {
|
||||
}
|
||||
}
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}/addMessage`,
|
||||
method: 'POST',
|
||||
data: {
|
||||
response = await this.client.loyaltyobject.addmessage({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: {
|
||||
'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
@@ -940,8 +919,8 @@ class DemoLoyalty {
|
||||
data += '--batch_createobjectbatch--';
|
||||
|
||||
// Invoke the batch API calls
|
||||
let response = await this.httpClient.request({
|
||||
url: this.batchUrl, // https://walletobjects.googleapis.com/batch
|
||||
let response = await this.client.context._options.auth.request({
|
||||
url: 'https://walletobjects.googleapis.com/batch',
|
||||
method: 'POST',
|
||||
data: data,
|
||||
headers: {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
// [START setup]
|
||||
// [START imports]
|
||||
const { GoogleAuth } = require('google-auth-library');
|
||||
const { google } = require('googleapis');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
// [END imports]
|
||||
@@ -31,12 +31,6 @@ class DemoOffer {
|
||||
* variable: GOOGLE_APPLICATION_CREDENTIALS.
|
||||
*/
|
||||
this.keyFilePath = process.env.GOOGLE_APPLICATION_CREDENTIALS || '/path/to/key.json';
|
||||
|
||||
this.baseUrl = 'https://walletobjects.googleapis.com/walletobjects/v1';
|
||||
this.batchUrl = 'https://walletobjects.googleapis.com/batch';
|
||||
this.classUrl = `${this.baseUrl}/offerClass`;
|
||||
this.objectUrl = `${this.baseUrl}/offerObject`;
|
||||
|
||||
this.auth();
|
||||
}
|
||||
// [END setup]
|
||||
@@ -46,11 +40,16 @@ class DemoOffer {
|
||||
* Create authenticated HTTP client using a service account file.
|
||||
*/
|
||||
auth() {
|
||||
const auth = new google.auth.GoogleAuth({
|
||||
keyFile: this.keyFilePath,
|
||||
scopes: ['https://www.googleapis.com/auth/wallet_object.issuer'],
|
||||
});
|
||||
|
||||
this.credentials = require(this.keyFilePath);
|
||||
|
||||
this.httpClient = new GoogleAuth({
|
||||
credentials: this.credentials,
|
||||
scopes: 'https://www.googleapis.com/auth/wallet_object.issuer'
|
||||
this.client = google.walletobjects({
|
||||
version: 'v1',
|
||||
auth: auth,
|
||||
});
|
||||
}
|
||||
// [END auth]
|
||||
@@ -69,9 +68,8 @@ class DemoOffer {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.offerclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
|
||||
console.log(`Class ${issuerId}.${classSuffix} already exists!`);
|
||||
@@ -96,10 +94,8 @@ class DemoOffer {
|
||||
'redemptionChannel': 'ONLINE'
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: this.classUrl,
|
||||
method: 'POST',
|
||||
data: newClass
|
||||
response = await this.client.offerclass.insert({
|
||||
requestBody: newClass
|
||||
});
|
||||
|
||||
console.log('Class insert response');
|
||||
@@ -125,9 +121,8 @@ class DemoOffer {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.offerclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -152,10 +147,9 @@ class DemoOffer {
|
||||
// Note: reviewStatus must be 'UNDER_REVIEW' or 'DRAFT' for updates
|
||||
updatedClass['reviewStatus'] = 'UNDER_REVIEW';
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'PUT',
|
||||
data: updatedClass
|
||||
response = await this.client.offerclass.update({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: updatedClass
|
||||
});
|
||||
|
||||
console.log('Class update response');
|
||||
@@ -181,9 +175,8 @@ class DemoOffer {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.offerclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -207,10 +200,9 @@ class DemoOffer {
|
||||
'reviewStatus': 'UNDER_REVIEW'
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.offerclass.patch({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Class patch response');
|
||||
@@ -236,9 +228,8 @@ class DemoOffer {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.offerclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -251,10 +242,9 @@ class DemoOffer {
|
||||
}
|
||||
}
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}/addMessage`,
|
||||
method: 'POST',
|
||||
data: {
|
||||
response = await this.client.offerclass.addmessage({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: {
|
||||
'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
@@ -284,9 +274,8 @@ class DemoOffer {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.offerobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
|
||||
console.log(`Object ${issuerId}.${objectSuffix} already exists!`);
|
||||
@@ -374,10 +363,8 @@ class DemoOffer {
|
||||
}
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: this.objectUrl,
|
||||
method: 'POST',
|
||||
data: newObject
|
||||
response = await this.client.offerobject.insert({
|
||||
requestBody: newObject
|
||||
});
|
||||
|
||||
console.log('Object insert response');
|
||||
@@ -403,9 +390,8 @@ class DemoOffer {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.offerobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -434,10 +420,9 @@ class DemoOffer {
|
||||
updatedObject['linksModuleData']['uris'].push(newLink);
|
||||
}
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PUT',
|
||||
data: updatedObject
|
||||
response = await this.client.offerobject.update({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: updatedObject
|
||||
});
|
||||
|
||||
console.log('Object update response');
|
||||
@@ -461,9 +446,8 @@ class DemoOffer {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.offerobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -497,10 +481,9 @@ class DemoOffer {
|
||||
}
|
||||
patchBody['linksModuleData']['uris'].push(newLink);
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.offerobject.patch({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Object patch response');
|
||||
@@ -527,9 +510,8 @@ class DemoOffer {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.offerobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -547,10 +529,9 @@ class DemoOffer {
|
||||
'state': 'EXPIRED'
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.offerobject.patch({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Object expiration response');
|
||||
@@ -576,9 +557,8 @@ class DemoOffer {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.offerobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -591,10 +571,9 @@ class DemoOffer {
|
||||
}
|
||||
}
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}/addMessage`,
|
||||
method: 'POST',
|
||||
data: {
|
||||
response = await this.client.offerobject.addmessage({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: {
|
||||
'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
@@ -922,8 +901,8 @@ class DemoOffer {
|
||||
data += '--batch_createobjectbatch--';
|
||||
|
||||
// Invoke the batch API calls
|
||||
let response = await this.httpClient.request({
|
||||
url: this.batchUrl, // https://walletobjects.googleapis.com/batch
|
||||
let response = await this.client.context._options.auth.request({
|
||||
url: 'https://walletobjects.googleapis.com/batch',
|
||||
method: 'POST',
|
||||
data: data,
|
||||
headers: {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
// [START setup]
|
||||
// [START imports]
|
||||
const { GoogleAuth } = require('google-auth-library');
|
||||
const { google } = require('googleapis');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
// [END imports]
|
||||
@@ -31,12 +31,6 @@ class DemoTransit {
|
||||
* variable: GOOGLE_APPLICATION_CREDENTIALS.
|
||||
*/
|
||||
this.keyFilePath = process.env.GOOGLE_APPLICATION_CREDENTIALS || '/path/to/key.json';
|
||||
|
||||
this.baseUrl = 'https://walletobjects.googleapis.com/walletobjects/v1';
|
||||
this.batchUrl = 'https://walletobjects.googleapis.com/batch';
|
||||
this.classUrl = `${this.baseUrl}/transitClass`;
|
||||
this.objectUrl = `${this.baseUrl}/transitObject`;
|
||||
|
||||
this.auth();
|
||||
}
|
||||
// [END setup]
|
||||
@@ -46,11 +40,16 @@ class DemoTransit {
|
||||
* Create authenticated HTTP client using a service account file.
|
||||
*/
|
||||
auth() {
|
||||
const auth = new google.auth.GoogleAuth({
|
||||
keyFile: this.keyFilePath,
|
||||
scopes: ['https://www.googleapis.com/auth/wallet_object.issuer'],
|
||||
});
|
||||
|
||||
this.credentials = require(this.keyFilePath);
|
||||
|
||||
this.httpClient = new GoogleAuth({
|
||||
credentials: this.credentials,
|
||||
scopes: 'https://www.googleapis.com/auth/wallet_object.issuer'
|
||||
this.client = google.walletobjects({
|
||||
version: 'v1',
|
||||
auth: auth,
|
||||
});
|
||||
}
|
||||
// [END auth]
|
||||
@@ -69,9 +68,8 @@ class DemoTransit {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.transitclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
|
||||
console.log(`Class ${issuerId}.${classSuffix} already exists!`);
|
||||
@@ -105,10 +103,8 @@ class DemoTransit {
|
||||
'transitType': 'BUS'
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: this.classUrl,
|
||||
method: 'POST',
|
||||
data: newClass
|
||||
response = await this.client.transitclass.insert({
|
||||
requestBody: newClass
|
||||
});
|
||||
|
||||
console.log('Class insert response');
|
||||
@@ -134,9 +130,8 @@ class DemoTransit {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.transitclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -161,10 +156,9 @@ class DemoTransit {
|
||||
// Note: reviewStatus must be 'UNDER_REVIEW' or 'DRAFT' for updates
|
||||
updatedClass['reviewStatus'] = 'UNDER_REVIEW';
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'PUT',
|
||||
data: updatedClass
|
||||
response = await this.client.transitclass.update({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: updatedClass
|
||||
});
|
||||
|
||||
console.log('Class update response');
|
||||
@@ -190,9 +184,8 @@ class DemoTransit {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.transitclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -216,10 +209,9 @@ class DemoTransit {
|
||||
'reviewStatus': 'UNDER_REVIEW'
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.transitclass.patch({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Class patch response');
|
||||
@@ -245,9 +237,8 @@ class DemoTransit {
|
||||
|
||||
// Check if the class exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.transitclass.get({
|
||||
resourceId: `${issuerId}.${classSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -260,10 +251,9 @@ class DemoTransit {
|
||||
}
|
||||
}
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.classUrl}/${issuerId}.${classSuffix}/addMessage`,
|
||||
method: 'POST',
|
||||
data: {
|
||||
response = await this.client.transitclass.addmessage({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: {
|
||||
'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
@@ -293,9 +283,8 @@ class DemoTransit {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.transitobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
|
||||
console.log(`Object ${issuerId}.${objectSuffix} already exists!`);
|
||||
@@ -402,10 +391,8 @@ class DemoTransit {
|
||||
}
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: this.objectUrl,
|
||||
method: 'POST',
|
||||
data: newObject
|
||||
response = await this.client.transitobject.insert({
|
||||
requestBody: newObject
|
||||
});
|
||||
|
||||
console.log('Object insert response');
|
||||
@@ -431,9 +418,8 @@ class DemoTransit {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.transitobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -462,10 +448,9 @@ class DemoTransit {
|
||||
updatedObject['linksModuleData']['uris'].push(newLink);
|
||||
}
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PUT',
|
||||
data: updatedObject
|
||||
response = await this.client.transitobject.update({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: updatedObject
|
||||
});
|
||||
|
||||
console.log('Object update response');
|
||||
@@ -489,9 +474,8 @@ class DemoTransit {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.transitobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -525,10 +509,9 @@ class DemoTransit {
|
||||
}
|
||||
patchBody['linksModuleData']['uris'].push(newLink);
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.transitobject.patch({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Object patch response');
|
||||
@@ -555,9 +538,8 @@ class DemoTransit {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.transitobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -575,10 +557,9 @@ class DemoTransit {
|
||||
'state': 'EXPIRED'
|
||||
};
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'PATCH',
|
||||
data: patchBody
|
||||
response = await this.client.transitobject.patch({
|
||||
resourceId: `${issuerId}.${objectSuffix}`,
|
||||
requestBody: patchBody
|
||||
});
|
||||
|
||||
console.log('Object expiration response');
|
||||
@@ -604,9 +585,8 @@ class DemoTransit {
|
||||
|
||||
// Check if the object exists
|
||||
try {
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}`,
|
||||
method: 'GET'
|
||||
response = await this.client.transitobject.get({
|
||||
resourceId: `${issuerId}.${objectSuffix}`
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
@@ -619,10 +599,9 @@ class DemoTransit {
|
||||
}
|
||||
}
|
||||
|
||||
response = await this.httpClient.request({
|
||||
url: `${this.objectUrl}/${issuerId}.${objectSuffix}/addMessage`,
|
||||
method: 'POST',
|
||||
data: {
|
||||
response = await this.client.transitobject.addmessage({
|
||||
resourceId: `${issuerId}.${classSuffix}`,
|
||||
requestBody: {
|
||||
'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
@@ -997,8 +976,8 @@ class DemoTransit {
|
||||
data += '--batch_createobjectbatch--';
|
||||
|
||||
// Invoke the batch API calls
|
||||
let response = await this.httpClient.request({
|
||||
url: this.batchUrl, // https://walletobjects.googleapis.com/batch
|
||||
let response = await this.client.context._options.auth.request({
|
||||
url: 'https://walletobjects.googleapis.com/batch',
|
||||
method: 'POST',
|
||||
data: data,
|
||||
headers: {
|
||||
|
||||
51
nodejs/demo.js
Normal file
51
nodejs/demo.js
Normal file
@@ -0,0 +1,51 @@
|
||||
const { DemoEventTicket } = require('./demo-eventticket.js');
|
||||
const { DemoFlight } = require('./demo-flight.js');
|
||||
const { DemoGeneric } = require('./demo-generic.js');
|
||||
const { DemoGiftCard } = require('./demo-giftcard.js');
|
||||
const { DemoLoyalty } = require('./demo-loyalty.js');
|
||||
const { DemoOffer } = require('./demo-offer.js');
|
||||
const { DemoTransit } = require('./demo-transit.js');
|
||||
|
||||
async function main() {
|
||||
|
||||
// Create a demo class instance
|
||||
// Creates the authenticated HTTP client
|
||||
let demo = new DemoEventTicket(); // change to demo a different pass type
|
||||
|
||||
const issuer_id = process.env.WALLET_ISSUER_ID || 'your-issuer-id';
|
||||
const class_suffix = (process.env.WALLET_CLASS_SUFFIX || 'your-class-suffix') + demo.constructor.name;
|
||||
const object_suffix = (process.env.WALLET_OBJECT_SUFFIX || 'your-object-suffix') + demo.constructor.name;
|
||||
|
||||
// Create a pass class
|
||||
demo.createClass(issuer_id, class_suffix);
|
||||
|
||||
// Update a pass class
|
||||
demo.updateClass(issuer_id, class_suffix);
|
||||
|
||||
// Patch a pass class
|
||||
demo.patchClass(issuer_id, class_suffix);
|
||||
|
||||
// // Create a pass object
|
||||
demo.createObject(issuer_id, class_suffix, object_suffix);
|
||||
|
||||
// Update a pass object
|
||||
demo.updateObject(issuer_id, object_suffix);
|
||||
|
||||
// Patch a pass object
|
||||
demo.patchObject(issuer_id, object_suffix);
|
||||
|
||||
// Expire a pass object
|
||||
demo.expireObject(issuer_id, object_suffix);
|
||||
|
||||
// Generate an Add to Google Wallet link that creates a new pass class and object
|
||||
demo.createJwtNewObjects(issuer_id, class_suffix, object_suffix);
|
||||
|
||||
// Generate an Add to Google Wallet link that references existing pass object(s)
|
||||
demo.createJwtExistingObjects(issuer_id);
|
||||
|
||||
// // Create pass objects in batch
|
||||
demo.batchCreateObjects(issuer_id, class_suffix);
|
||||
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"google-auth-library": "^5.9.2",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"@googleapis/walletobjects": "^1.0.0",
|
||||
"googleapis": "^133.0.0",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"uuidv4": "^6.2.13"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,11 @@ creating a pass class, updating issuer permissions, and more.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
* PHP 8.x
|
||||
* PHP 7.4
|
||||
* Composer 2.x
|
||||
* Follow the steps outlined in the
|
||||
[Google Wallet prerequisites](https://developers.google.com/wallet/generic/web/prerequisites)
|
||||
to create the Google Wallet issuer account and Google Cloud service account
|
||||
* Download the PHP
|
||||
[Google Wallet API Client library](https://developers.google.com/wallet/generic/resources/libraries#php)
|
||||
|
||||
## Environment variables
|
||||
|
||||
@@ -45,59 +43,52 @@ for each class file.
|
||||
composer install
|
||||
```
|
||||
|
||||
2. Copy the path to the Google Wallet API Client library (`Walletobjects.php`
|
||||
file) you downloaded. If needed, update the path in the demo class PHP file
|
||||
(line 22).
|
||||
|
||||
```php
|
||||
// Download the PHP client library from the following URL
|
||||
// https://developers.google.com/wallet/generic/resources/libraries
|
||||
require __DIR__ . '/lib/Walletobjects.php';
|
||||
```
|
||||
|
||||
3. In your PHP code, import a demo class and call its method(s). An example
|
||||
2. In your PHP code, import a demo class and call its method(s). An example
|
||||
can be found below
|
||||
|
||||
```php
|
||||
// Import the demo class
|
||||
require __DIR__ . 'demo_eventticket.php';
|
||||
require __DIR__ . '/demo_eventticket.php';
|
||||
|
||||
// Your Issuer account ID (@see Prerequisites)
|
||||
$issuerId = '3388000000000000000';
|
||||
|
||||
// Create a demo class instance
|
||||
$demo = new DemoEventTicket();
|
||||
|
||||
// Create a pass class
|
||||
$demo->createClass('issuer_id', 'class_suffix');
|
||||
$demo->createClass($issuerId, 'class_suffix');
|
||||
|
||||
// Update a pass class
|
||||
$demo->updateClass('issuer_id', 'class_suffix');
|
||||
$demo->updateClass($issuerId, 'class_suffix');
|
||||
|
||||
// Patch a pass class
|
||||
$demo->patchClass('issuer_id', 'class_suffix');
|
||||
$demo->patchClass($issuerId, 'class_suffix');
|
||||
|
||||
// Add a message to a pass class
|
||||
$demo->addClassMessage('issuer_id', 'class_suffix', 'header', 'body');
|
||||
$demo->addClassMessage($issuerId, 'class_suffix', 'header', 'body');
|
||||
|
||||
// Create a pass object
|
||||
$demo->createObject('issuer_id', 'class_suffix', 'object_suffix');
|
||||
$demo->createObject($issuerId, 'class_suffix', 'object_suffix');
|
||||
|
||||
// Update a pass object
|
||||
$demo->updateObject('issuer_id', 'object_suffix');
|
||||
$demo->updateObject($issuerId, 'object_suffix');
|
||||
|
||||
// Patch a pass object
|
||||
$demo->patchObject('issuer_id', 'object_suffix');
|
||||
$demo->patchObject($issuerId, 'object_suffix');
|
||||
|
||||
// Add a message to a pass object
|
||||
$demo->addObjectMessage('issuer_id', 'object_suffix', 'header', 'body');
|
||||
$demo->addObjectMessage($issuerId, 'object_suffix', 'header', 'body');
|
||||
|
||||
// Expire a pass object
|
||||
$demo->expireObject('issuer_id', 'object_suffix');
|
||||
$demo->expireObject($issuerId, 'object_suffix');
|
||||
|
||||
// Generate an Add to Google Wallet link that creates a new pass class and object
|
||||
$demo->createJWTNewObjects('issuer_id', 'class_suffix', 'object_suffix');
|
||||
$demo->createJWTNewObjects($issuerId, 'class_suffix', 'object_suffix');
|
||||
|
||||
// Generate an Add to Google Wallet link that references existing pass object(s)
|
||||
$demo->createJWTExistingObjects('issuer_id');
|
||||
$demo->createJWTExistingObjects($issuerId);
|
||||
|
||||
// Create pass objects in batch
|
||||
$demo->batchCreateObjects('issuer_id', 'class_suffix');
|
||||
$demo->batchCreateObjects($issuerId, 'class_suffix');
|
||||
```
|
||||
|
||||
@@ -2,6 +2,15 @@
|
||||
"require": {
|
||||
"google/auth": "^1.18",
|
||||
"guzzlehttp/guzzle": "*",
|
||||
"google/apiclient": "^2.12"
|
||||
"google/apiclient": "^2.15",
|
||||
"google/apiclient-services": "~0.300"
|
||||
},
|
||||
"scripts": {
|
||||
"pre-autoload-dump": "Google\\Task\\Composer::cleanup"
|
||||
},
|
||||
"extra": {
|
||||
"google/apiclient-services": [
|
||||
"Walletobjects"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,20 +17,38 @@
|
||||
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
// Download the PHP client library from the following URL
|
||||
// https://developers.google.com/wallet/generic/resources/libraries
|
||||
require __DIR__ . '/lib/Walletobjects.php';
|
||||
|
||||
// [START setup]
|
||||
// [START imports]
|
||||
use Firebase\JWT\JWT;
|
||||
use Google\Auth\Credentials\ServiceAccountCredentials;
|
||||
use Google\Client as Google_Client;
|
||||
use Google\Client as GoogleClient;
|
||||
use Google\Service\Walletobjects;
|
||||
use Google\Service\Walletobjects\EventSeat;
|
||||
use Google\Service\Walletobjects\LatLongPoint;
|
||||
use Google\Service\Walletobjects\Barcode;
|
||||
use Google\Service\Walletobjects\ImageModuleData;
|
||||
use Google\Service\Walletobjects\LinksModuleData;
|
||||
use Google\Service\Walletobjects\TextModuleData;
|
||||
use Google\Service\Walletobjects\ImageUri;
|
||||
use Google\Service\Walletobjects\Image;
|
||||
use Google\Service\Walletobjects\EventTicketObject;
|
||||
use Google\Service\Walletobjects\Message;
|
||||
use Google\Service\Walletobjects\AddMessageRequest;
|
||||
use Google\Service\Walletobjects\Uri;
|
||||
use Google\Service\Walletobjects\TranslatedString;
|
||||
use Google\Service\Walletobjects\LocalizedString;
|
||||
use Google\Service\Walletobjects\EventTicketClass;
|
||||
// [END imports]
|
||||
|
||||
/** Demo class for creating and managing Event tickets in Google Wallet. */
|
||||
class DemoEventTicket
|
||||
{
|
||||
/**
|
||||
* The Google API Client
|
||||
* https://github.com/google/google-api-php-client
|
||||
*/
|
||||
public GoogleClient $client;
|
||||
|
||||
/**
|
||||
* Path to service account key file from Google Cloud Console. Environment
|
||||
* variable: GOOGLE_APPLICATION_CREDENTIALS.
|
||||
@@ -45,7 +63,7 @@ class DemoEventTicket
|
||||
/**
|
||||
* Google Wallet service client.
|
||||
*/
|
||||
public Google_Service_Walletobjects $service;
|
||||
public Walletobjects $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -61,20 +79,18 @@ class DemoEventTicket
|
||||
*/
|
||||
public function auth()
|
||||
{
|
||||
$scope = 'https://www.googleapis.com/auth/wallet_object.issuer';
|
||||
|
||||
$this->credentials = new ServiceAccountCredentials(
|
||||
$scope,
|
||||
Walletobjects::WALLET_OBJECT_ISSUER,
|
||||
$this->keyFilePath
|
||||
);
|
||||
|
||||
// Initialize Google Wallet API service
|
||||
$this->client = new Google_Client();
|
||||
$this->client = new GoogleClient();
|
||||
$this->client->setApplicationName('APPLICATION_NAME');
|
||||
$this->client->setScopes($scope);
|
||||
$this->client->setScopes(Walletobjects::WALLET_OBJECT_ISSUER);
|
||||
$this->client->setAuthConfig($this->keyFilePath);
|
||||
|
||||
$this->service = new Google_Service_Walletobjects($this->client);
|
||||
$this->service = new Walletobjects($this->client);
|
||||
}
|
||||
// [END auth]
|
||||
|
||||
@@ -105,10 +121,10 @@ class DemoEventTicket
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/tickets/events/rest/v1/eventticketclass
|
||||
$newClass = new Google_Service_Walletobjects_EventTicketClass([
|
||||
$newClass = new EventTicketClass([
|
||||
'eventId' => "{$issuerId}.{$classSuffix}",
|
||||
'eventName' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'eventName' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Event name'
|
||||
])
|
||||
@@ -156,7 +172,7 @@ class DemoEventTicket
|
||||
}
|
||||
|
||||
// Update the class by adding a homepage
|
||||
$updatedClass->setHomepageUri(new Google_Service_Walletobjects_Uri([
|
||||
$updatedClass->setHomepageUri(new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'Homepage description'
|
||||
]));
|
||||
@@ -202,8 +218,8 @@ class DemoEventTicket
|
||||
}
|
||||
|
||||
// Patch the class by adding a homepage
|
||||
$patchBody = new Google_Service_Walletobjects_EventTicketClass([
|
||||
'homepageUri' => new Google_Service_Walletobjects_Uri([
|
||||
$patchBody = new EventTicketClass([
|
||||
'homepageUri' => new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'Homepage description'
|
||||
]),
|
||||
@@ -249,8 +265,8 @@ class DemoEventTicket
|
||||
}
|
||||
}
|
||||
|
||||
$message = new Google_Service_Walletobjects_AddMessageRequest([
|
||||
'message' => new Google_Service_Walletobjects_Message([
|
||||
$message = new AddMessageRequest([
|
||||
'message' => new Message([
|
||||
'header' => $header,
|
||||
'body' => $body
|
||||
])
|
||||
@@ -293,36 +309,36 @@ class DemoEventTicket
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/tickets/events/rest/v1/eventticketobject
|
||||
$newObject = new Google_Service_Walletobjects_EventTicketObject([
|
||||
$newObject = new EventTicketObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -330,13 +346,13 @@ class DemoEventTicket
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -345,37 +361,37 @@ class DemoEventTicket
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'locations' => [
|
||||
new Google_Service_Walletobjects_LatLongPoint([
|
||||
new LatLongPoint([
|
||||
'latitude' => 37.424015499999996,
|
||||
'longitude' => -122.09259560000001
|
||||
])
|
||||
],
|
||||
'seatInfo' => new Google_Service_Walletobjects_EventSeat([
|
||||
'seat' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'seatInfo' => new EventSeat([
|
||||
'seat' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => '42'
|
||||
])
|
||||
]),
|
||||
'row' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'row' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'G3'
|
||||
])
|
||||
]),
|
||||
'section' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'section' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => '5'
|
||||
])
|
||||
]),
|
||||
'gate' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'gate' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'A'
|
||||
])
|
||||
@@ -422,7 +438,7 @@ class DemoEventTicket
|
||||
}
|
||||
|
||||
// Update the object by adding a link
|
||||
$newLink = new Google_Service_Walletobjects_Uri([
|
||||
$newLink = new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'New link description'
|
||||
]);
|
||||
@@ -430,7 +446,7 @@ class DemoEventTicket
|
||||
$linksModuleData = $updatedObject->getLinksModuleData();
|
||||
if (is_null($linksModuleData)) {
|
||||
// LinksModuleData was not set on the original object
|
||||
$linksModuleData = new Google_Service_Walletobjects_LinksModuleData([
|
||||
$linksModuleData = new LinksModuleData([
|
||||
'uris' => []
|
||||
]);
|
||||
}
|
||||
@@ -478,17 +494,17 @@ class DemoEventTicket
|
||||
}
|
||||
|
||||
// Patch the object by adding a link
|
||||
$newLink = new Google_Service_Walletobjects_Uri([
|
||||
$newLink = new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'New link description'
|
||||
]);
|
||||
|
||||
$patchBody = new Google_Service_Walletobjects_EventTicketObject();
|
||||
$patchBody = new EventTicketObject();
|
||||
|
||||
$linksModuleData = $existingObject->getLinksModuleData();
|
||||
if (is_null($linksModuleData)) {
|
||||
// LinksModuleData was not set on the original object
|
||||
$linksModuleData = new Google_Service_Walletobjects_LinksModuleData([
|
||||
$linksModuleData = new LinksModuleData([
|
||||
'uris' => []
|
||||
]);
|
||||
}
|
||||
@@ -539,7 +555,7 @@ class DemoEventTicket
|
||||
}
|
||||
|
||||
// Patch the object, setting the pass as expired
|
||||
$patchBody = new Google_Service_Walletobjects_EventTicketObject([
|
||||
$patchBody = new EventTicketObject([
|
||||
'state' => 'EXPIRED'
|
||||
]);
|
||||
|
||||
@@ -579,8 +595,8 @@ class DemoEventTicket
|
||||
}
|
||||
}
|
||||
|
||||
$message = new Google_Service_Walletobjects_AddMessageRequest([
|
||||
'message' => new Google_Service_Walletobjects_Message([
|
||||
$message = new AddMessageRequest([
|
||||
'message' => new Message([
|
||||
'header' => $header,
|
||||
'body' => $body
|
||||
])
|
||||
@@ -614,12 +630,12 @@ class DemoEventTicket
|
||||
{
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/tickets/events/rest/v1/eventticketclass
|
||||
$newClass = new Google_Service_Walletobjects_EventTicketClass([
|
||||
$newClass = new EventTicketClass([
|
||||
'id' => "{$issuerId}.{$classSuffix}",
|
||||
'issuerName' => 'Issuer name',
|
||||
'reviewStatus' => 'UNDER_REVIEW',
|
||||
'eventName' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'eventName' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Event name'
|
||||
])
|
||||
@@ -628,36 +644,36 @@ class DemoEventTicket
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/tickets/events/rest/v1/eventticketobject
|
||||
$newObject = new Google_Service_Walletobjects_EventTicketObject([
|
||||
$newObject = new EventTicketObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -665,13 +681,13 @@ class DemoEventTicket
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -680,37 +696,37 @@ class DemoEventTicket
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'locations' => [
|
||||
new Google_Service_Walletobjects_LatLongPoint([
|
||||
new LatLongPoint([
|
||||
'latitude' => 37.424015499999996,
|
||||
'longitude' => -122.09259560000001
|
||||
])
|
||||
],
|
||||
'seatInfo' => new Google_Service_Walletobjects_EventSeat([
|
||||
'seat' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'seatInfo' => new EventSeat([
|
||||
'seat' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => '42'
|
||||
])
|
||||
]),
|
||||
'row' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'row' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'G3'
|
||||
])
|
||||
]),
|
||||
'section' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'section' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => '5'
|
||||
])
|
||||
]),
|
||||
'gate' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'gate' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'A'
|
||||
])
|
||||
@@ -880,36 +896,36 @@ class DemoEventTicket
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/tickets/events/rest/v1/eventticketobject
|
||||
$batchObject = new Google_Service_Walletobjects_EventTicketObject([
|
||||
$batchObject = new EventTicketObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -917,13 +933,13 @@ class DemoEventTicket
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -932,37 +948,37 @@ class DemoEventTicket
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'locations' => [
|
||||
new Google_Service_Walletobjects_LatLongPoint([
|
||||
new LatLongPoint([
|
||||
'latitude' => 37.424015499999996,
|
||||
'longitude' => -122.09259560000001
|
||||
])
|
||||
],
|
||||
'seatInfo' => new Google_Service_Walletobjects_EventSeat([
|
||||
'seat' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'seatInfo' => new EventSeat([
|
||||
'seat' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => '42'
|
||||
])
|
||||
]),
|
||||
'row' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'row' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'G3'
|
||||
])
|
||||
]),
|
||||
'section' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'section' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => '5'
|
||||
])
|
||||
]),
|
||||
'gate' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'gate' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'A'
|
||||
])
|
||||
|
||||
@@ -17,20 +17,42 @@
|
||||
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
// Download the PHP client library from the following URL
|
||||
// https://developers.google.com/wallet/generic/resources/libraries
|
||||
require __DIR__ . '/lib/Walletobjects.php';
|
||||
|
||||
// [START setup]
|
||||
// [START imports]
|
||||
use Firebase\JWT\JWT;
|
||||
use Google\Auth\Credentials\ServiceAccountCredentials;
|
||||
use Google\Client as Google_Client;
|
||||
use Google\Client as GoogleClient;
|
||||
use Google\Service\Walletobjects;
|
||||
use Google\Service\Walletobjects\ReservationInfo;
|
||||
use Google\Service\Walletobjects\BoardingAndSeatingInfo;
|
||||
use Google\Service\Walletobjects\LatLongPoint;
|
||||
use Google\Service\Walletobjects\Barcode;
|
||||
use Google\Service\Walletobjects\ImageModuleData;
|
||||
use Google\Service\Walletobjects\LinksModuleData;
|
||||
use Google\Service\Walletobjects\TextModuleData;
|
||||
use Google\Service\Walletobjects\TranslatedString;
|
||||
use Google\Service\Walletobjects\LocalizedString;
|
||||
use Google\Service\Walletobjects\ImageUri;
|
||||
use Google\Service\Walletobjects\Image;
|
||||
use Google\Service\Walletobjects\FlightObject;
|
||||
use Google\Service\Walletobjects\Message;
|
||||
use Google\Service\Walletobjects\AddMessageRequest;
|
||||
use Google\Service\Walletobjects\Uri;
|
||||
use Google\Service\Walletobjects\AirportInfo;
|
||||
use Google\Service\Walletobjects\FlightCarrier;
|
||||
use Google\Service\Walletobjects\FlightClass;
|
||||
use Google\Service\Walletobjects\FlightHeader;
|
||||
// [END imports]
|
||||
|
||||
/** Demo class for creating and managing Flights in Google Wallet. */
|
||||
class DemoFlight
|
||||
{
|
||||
/**
|
||||
* The Google API Client
|
||||
* https://github.com/google/google-api-php-client
|
||||
*/
|
||||
public GoogleClient $client;
|
||||
|
||||
/**
|
||||
* Path to service account key file from Google Cloud Console. Environment
|
||||
* variable: GOOGLE_APPLICATION_CREDENTIALS.
|
||||
@@ -45,7 +67,7 @@ class DemoFlight
|
||||
/**
|
||||
* Google Wallet service client.
|
||||
*/
|
||||
public Google_Service_Walletobjects $service;
|
||||
public Walletobjects $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -61,20 +83,18 @@ class DemoFlight
|
||||
*/
|
||||
public function auth()
|
||||
{
|
||||
$scope = 'https://www.googleapis.com/auth/wallet_object.issuer';
|
||||
|
||||
$this->credentials = new ServiceAccountCredentials(
|
||||
$scope,
|
||||
Walletobjects::WALLET_OBJECT_ISSUER,
|
||||
$this->keyFilePath
|
||||
);
|
||||
|
||||
// Initialize Google Wallet API service
|
||||
$this->client = new Google_Client();
|
||||
$this->client = new GoogleClient();
|
||||
$this->client->setApplicationName('APPLICATION_NAME');
|
||||
$this->client->setScopes($scope);
|
||||
$this->client->setScopes(Walletobjects::WALLET_OBJECT_ISSUER);
|
||||
$this->client->setAuthConfig($this->keyFilePath);
|
||||
|
||||
$this->service = new Google_Service_Walletobjects($this->client);
|
||||
$this->service = new Walletobjects($this->client);
|
||||
}
|
||||
// [END auth]
|
||||
|
||||
@@ -105,23 +125,23 @@ class DemoFlight
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/tickets/boarding-passes/rest/v1/flightclass
|
||||
$newClass = new Google_Service_Walletobjects_FlightClass([
|
||||
$newClass = new FlightClass([
|
||||
'id' => "{$issuerId}.{$classSuffix}",
|
||||
'issuerName' => 'Issuer name',
|
||||
'reviewStatus' => 'UNDER_REVIEW',
|
||||
'localScheduledDepartureDateTime' => '2023-07-02T15:30:00',
|
||||
'flightHeader' => new Google_Service_Walletobjects_FlightHeader([
|
||||
'carrier' => new Google_Service_Walletobjects_FlightCarrier([
|
||||
'flightHeader' => new FlightHeader([
|
||||
'carrier' => new FlightCarrier([
|
||||
'carrierIataCode' => 'LX'
|
||||
]),
|
||||
'flightNumber' => '123'
|
||||
]),
|
||||
'origin' => new Google_Service_Walletobjects_AirportInfo([
|
||||
'origin' => new AirportInfo([
|
||||
'airportIataCode' => 'LAX',
|
||||
'terminal' => '1',
|
||||
'gate' => 'A2'
|
||||
]),
|
||||
'destination' => new Google_Service_Walletobjects_AirportInfo([
|
||||
'destination' => new AirportInfo([
|
||||
'airportIataCode' => 'SFO',
|
||||
'terminal' => '2',
|
||||
'gate' => 'C3'
|
||||
@@ -166,7 +186,7 @@ class DemoFlight
|
||||
}
|
||||
|
||||
// Update the class by adding a homepage
|
||||
$updatedClass->setHomepageUri(new Google_Service_Walletobjects_Uri([
|
||||
$updatedClass->setHomepageUri(new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'Homepage description'
|
||||
]));
|
||||
@@ -212,8 +232,8 @@ class DemoFlight
|
||||
}
|
||||
|
||||
// Patch the class by adding a homepage
|
||||
$patchBody = new Google_Service_Walletobjects_FlightClass([
|
||||
'homepageUri' => new Google_Service_Walletobjects_Uri([
|
||||
$patchBody = new FlightClass([
|
||||
'homepageUri' => new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'Homepage description'
|
||||
]),
|
||||
@@ -259,8 +279,8 @@ class DemoFlight
|
||||
}
|
||||
}
|
||||
|
||||
$message = new Google_Service_Walletobjects_AddMessageRequest([
|
||||
'message' => new Google_Service_Walletobjects_Message([
|
||||
$message = new AddMessageRequest([
|
||||
'message' => new Message([
|
||||
'header' => $header,
|
||||
'body' => $body
|
||||
])
|
||||
@@ -303,36 +323,36 @@ class DemoFlight
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/tickets/boarding-passes/rest/v1/flightobject
|
||||
$newObject = new Google_Service_Walletobjects_FlightObject([
|
||||
$newObject = new FlightObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -340,13 +360,13 @@ class DemoFlight
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -355,22 +375,22 @@ class DemoFlight
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'locations' => [
|
||||
new Google_Service_Walletobjects_LatLongPoint([
|
||||
new LatLongPoint([
|
||||
'latitude' => 37.424015499999996,
|
||||
'longitude' => -122.09259560000001
|
||||
])
|
||||
],
|
||||
'passengerName' => 'Passenger name',
|
||||
'boardingAndSeatingInfo' => new Google_Service_Walletobjects_BoardingAndSeatingInfo([
|
||||
'boardingAndSeatingInfo' => new BoardingAndSeatingInfo([
|
||||
'boardingGroup' => 'B',
|
||||
'seatNumber' => '42'
|
||||
]),
|
||||
'reservationInfo' => new Google_Service_Walletobjects_ReservationInfo([
|
||||
'reservationInfo' => new ReservationInfo([
|
||||
'confirmationCode' => 'Confirmation code'
|
||||
])
|
||||
]);
|
||||
@@ -412,7 +432,7 @@ class DemoFlight
|
||||
}
|
||||
|
||||
// Update the object by adding a link
|
||||
$newLink = new Google_Service_Walletobjects_Uri([
|
||||
$newLink = new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'New link description'
|
||||
]);
|
||||
@@ -420,7 +440,7 @@ class DemoFlight
|
||||
$linksModuleData = $updatedObject->getLinksModuleData();
|
||||
if (is_null($linksModuleData)) {
|
||||
// LinksModuleData was not set on the original object
|
||||
$linksModuleData = new Google_Service_Walletobjects_LinksModuleData([
|
||||
$linksModuleData = new LinksModuleData([
|
||||
'uris' => []
|
||||
]);
|
||||
}
|
||||
@@ -468,17 +488,17 @@ class DemoFlight
|
||||
}
|
||||
|
||||
// Patch the object by adding a link
|
||||
$newLink = new Google_Service_Walletobjects_Uri([
|
||||
$newLink = new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'New link description'
|
||||
]);
|
||||
|
||||
$patchBody = new Google_Service_Walletobjects_FlightObject();
|
||||
$patchBody = new FlightObject();
|
||||
|
||||
$linksModuleData = $existingObject->getLinksModuleData();
|
||||
if (is_null($linksModuleData)) {
|
||||
// LinksModuleData was not set on the original object
|
||||
$linksModuleData = new Google_Service_Walletobjects_LinksModuleData([
|
||||
$linksModuleData = new LinksModuleData([
|
||||
'uris' => []
|
||||
]);
|
||||
}
|
||||
@@ -529,7 +549,7 @@ class DemoFlight
|
||||
}
|
||||
|
||||
// Patch the object, setting the pass as expired
|
||||
$patchBody = new Google_Service_Walletobjects_FlightObject([
|
||||
$patchBody = new FlightObject([
|
||||
'state' => 'EXPIRED'
|
||||
]);
|
||||
|
||||
@@ -569,8 +589,8 @@ class DemoFlight
|
||||
}
|
||||
}
|
||||
|
||||
$message = new Google_Service_Walletobjects_AddMessageRequest([
|
||||
'message' => new Google_Service_Walletobjects_Message([
|
||||
$message = new AddMessageRequest([
|
||||
'message' => new Message([
|
||||
'header' => $header,
|
||||
'body' => $body
|
||||
])
|
||||
@@ -604,23 +624,23 @@ class DemoFlight
|
||||
{
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/tickets/boarding-passes/rest/v1/flightclass
|
||||
$newClass = new Google_Service_Walletobjects_FlightClass([
|
||||
$newClass = new FlightClass([
|
||||
'id' => "{$issuerId}.{$classSuffix}",
|
||||
'issuerName' => 'Issuer name',
|
||||
'reviewStatus' => 'UNDER_REVIEW',
|
||||
'localScheduledDepartureDateTime' => '2023-07-02T15:30:00',
|
||||
'flightHeader' => new Google_Service_Walletobjects_FlightHeader([
|
||||
'carrier' => new Google_Service_Walletobjects_FlightCarrier([
|
||||
'flightHeader' => new FlightHeader([
|
||||
'carrier' => new FlightCarrier([
|
||||
'carrierIataCode' => 'LX'
|
||||
]),
|
||||
'flightNumber' => '123'
|
||||
]),
|
||||
'origin' => new Google_Service_Walletobjects_AirportInfo([
|
||||
'origin' => new AirportInfo([
|
||||
'airportIataCode' => 'LAX',
|
||||
'terminal' => '1',
|
||||
'gate' => 'A2'
|
||||
]),
|
||||
'destination' => new Google_Service_Walletobjects_AirportInfo([
|
||||
'destination' => new AirportInfo([
|
||||
'airportIataCode' => 'SFO',
|
||||
'terminal' => '2',
|
||||
'gate' => 'C3'
|
||||
@@ -629,36 +649,36 @@ class DemoFlight
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/tickets/boarding-passes/rest/v1/flightobject
|
||||
$newObject = new Google_Service_Walletobjects_FlightObject([
|
||||
$newObject = new FlightObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -666,13 +686,13 @@ class DemoFlight
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -681,22 +701,22 @@ class DemoFlight
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'locations' => [
|
||||
new Google_Service_Walletobjects_LatLongPoint([
|
||||
new LatLongPoint([
|
||||
'latitude' => 37.424015499999996,
|
||||
'longitude' => -122.09259560000001
|
||||
])
|
||||
],
|
||||
'passengerName' => 'Passenger name',
|
||||
'boardingAndSeatingInfo' => new Google_Service_Walletobjects_BoardingAndSeatingInfo([
|
||||
'boardingAndSeatingInfo' => new BoardingAndSeatingInfo([
|
||||
'boardingGroup' => 'B',
|
||||
'seatNumber' => '42'
|
||||
]),
|
||||
'reservationInfo' => new Google_Service_Walletobjects_ReservationInfo([
|
||||
'reservationInfo' => new ReservationInfo([
|
||||
'confirmationCode' => 'Confirmation code'
|
||||
])
|
||||
]);
|
||||
@@ -861,36 +881,36 @@ class DemoFlight
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/tickets/boarding-passes/rest/v1/flightobject
|
||||
$batchObject = new Google_Service_Walletobjects_FlightObject([
|
||||
$batchObject = new FlightObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -898,13 +918,13 @@ class DemoFlight
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -913,22 +933,22 @@ class DemoFlight
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'locations' => [
|
||||
new Google_Service_Walletobjects_LatLongPoint([
|
||||
new LatLongPoint([
|
||||
'latitude' => 37.424015499999996,
|
||||
'longitude' => -122.09259560000001
|
||||
])
|
||||
],
|
||||
'passengerName' => 'Passenger name',
|
||||
'boardingAndSeatingInfo' => new Google_Service_Walletobjects_BoardingAndSeatingInfo([
|
||||
'boardingAndSeatingInfo' => new BoardingAndSeatingInfo([
|
||||
'boardingGroup' => 'B',
|
||||
'seatNumber' => '42'
|
||||
]),
|
||||
'reservationInfo' => new Google_Service_Walletobjects_ReservationInfo([
|
||||
'reservationInfo' => new ReservationInfo([
|
||||
'confirmationCode' => 'Confirmation code'
|
||||
])
|
||||
]);
|
||||
|
||||
@@ -17,20 +17,34 @@
|
||||
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
// Download the PHP client library from the following URL
|
||||
// https://developers.google.com/wallet/generic/resources/libraries
|
||||
require __DIR__ . '/lib/Walletobjects.php';
|
||||
|
||||
// [START setup]
|
||||
// [START imports]
|
||||
use Firebase\JWT\JWT;
|
||||
use Google\Auth\Credentials\ServiceAccountCredentials;
|
||||
use Google\Client as Google_Client;
|
||||
use Google\Client as GoogleClient;
|
||||
use Google\Service\Walletobjects;
|
||||
use Google\Service\Walletobjects\GenericObject;
|
||||
use Google\Service\Walletobjects\GenericClass;
|
||||
use Google\Service\Walletobjects\Barcode;
|
||||
use Google\Service\Walletobjects\ImageModuleData;
|
||||
use Google\Service\Walletobjects\LinksModuleData;
|
||||
use Google\Service\Walletobjects\TextModuleData;
|
||||
use Google\Service\Walletobjects\TranslatedString;
|
||||
use Google\Service\Walletobjects\LocalizedString;
|
||||
use Google\Service\Walletobjects\ImageUri;
|
||||
use Google\Service\Walletobjects\Image;
|
||||
use Google\Service\Walletobjects\Uri;
|
||||
// [END imports]
|
||||
|
||||
/** Demo class for creating and managing Generic passes in Google Wallet. */
|
||||
class DemoGeneric
|
||||
{
|
||||
/**
|
||||
* The Google API Client
|
||||
* https://github.com/google/google-api-php-client
|
||||
*/
|
||||
public GoogleClient $client;
|
||||
|
||||
/**
|
||||
* Path to service account key file from Google Cloud Console. Environment
|
||||
* variable: GOOGLE_APPLICATION_CREDENTIALS.
|
||||
@@ -45,7 +59,7 @@ class DemoGeneric
|
||||
/**
|
||||
* Google Wallet service client.
|
||||
*/
|
||||
public Google_Service_Walletobjects $service;
|
||||
public Walletobjects $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -61,20 +75,18 @@ class DemoGeneric
|
||||
*/
|
||||
public function auth()
|
||||
{
|
||||
$scope = 'https://www.googleapis.com/auth/wallet_object.issuer';
|
||||
|
||||
$this->credentials = new ServiceAccountCredentials(
|
||||
$scope,
|
||||
Walletobjects::WALLET_OBJECT_ISSUER,
|
||||
$this->keyFilePath
|
||||
);
|
||||
|
||||
// Initialize Google Wallet API service
|
||||
$this->client = new Google_Client();
|
||||
$this->client = new GoogleClient();
|
||||
$this->client->setApplicationName('APPLICATION_NAME');
|
||||
$this->client->setScopes($scope);
|
||||
$this->client->setScopes(Walletobjects::WALLET_OBJECT_ISSUER);
|
||||
$this->client->setAuthConfig($this->keyFilePath);
|
||||
|
||||
$this->service = new Google_Service_Walletobjects($this->client);
|
||||
$this->service = new Walletobjects($this->client);
|
||||
}
|
||||
// [END auth]
|
||||
|
||||
@@ -105,7 +117,7 @@ class DemoGeneric
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/generic/rest/v1/genericclass
|
||||
$newClass = new Google_Service_Walletobjects_GenericClass([
|
||||
$newClass = new GenericClass([
|
||||
'id' => "{$issuerId}.{$classSuffix}"
|
||||
]);
|
||||
|
||||
@@ -147,7 +159,7 @@ class DemoGeneric
|
||||
}
|
||||
|
||||
// Update the class by adding a homepage
|
||||
$newLink = new Google_Service_Walletobjects_Uri([
|
||||
$newLink = new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'Homepage description'
|
||||
]);
|
||||
@@ -155,7 +167,7 @@ class DemoGeneric
|
||||
$linksModuleData = $updatedClass->getLinksModuleData();
|
||||
if (is_null($linksModuleData)) {
|
||||
// LinksModuleData was not set on the original object
|
||||
$linksModuleData = new Google_Service_Walletobjects_LinksModuleData([
|
||||
$linksModuleData = new LinksModuleData([
|
||||
'uris' => []
|
||||
]);
|
||||
}
|
||||
@@ -206,17 +218,17 @@ class DemoGeneric
|
||||
}
|
||||
|
||||
// Patch the class by adding a homepage
|
||||
$newLink = new Google_Service_Walletobjects_Uri([
|
||||
$newLink = new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'Homepage description'
|
||||
]);
|
||||
|
||||
$patchBody = new Google_Service_Walletobjects_GenericClass();
|
||||
$patchBody = new GenericClass();
|
||||
|
||||
$linksModuleData = $existingClass->getLinksModuleData();
|
||||
if (is_null($linksModuleData)) {
|
||||
// LinksModuleData was not set on the original object
|
||||
$linksModuleData = new Google_Service_Walletobjects_LinksModuleData([
|
||||
$linksModuleData = new LinksModuleData([
|
||||
'uris' => []
|
||||
]);
|
||||
}
|
||||
@@ -266,36 +278,36 @@ class DemoGeneric
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/generic/rest/v1/genericobject
|
||||
$newObject = new Google_Service_Walletobjects_GenericObject([
|
||||
$newObject = new GenericObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -303,13 +315,13 @@ class DemoGeneric
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -318,29 +330,29 @@ class DemoGeneric
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'cardTitle' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'cardTitle' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Generic card title'
|
||||
])
|
||||
]),
|
||||
'header' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'header' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Generic header'
|
||||
])
|
||||
]),
|
||||
'hexBackgroundColor' => '#4285f4',
|
||||
'logo' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'logo' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://storage.googleapis.com/wallet-lab-tools-codelab-artifacts-public/pass_google_logo.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Generic card logo'
|
||||
])
|
||||
@@ -385,7 +397,7 @@ class DemoGeneric
|
||||
}
|
||||
|
||||
// Update the object by adding a link
|
||||
$newLink = new Google_Service_Walletobjects_Uri([
|
||||
$newLink = new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'New link description'
|
||||
]);
|
||||
@@ -393,7 +405,7 @@ class DemoGeneric
|
||||
$linksModuleData = $updatedObject->getLinksModuleData();
|
||||
if (is_null($linksModuleData)) {
|
||||
// LinksModuleData was not set on the original object
|
||||
$linksModuleData = new Google_Service_Walletobjects_LinksModuleData([
|
||||
$linksModuleData = new LinksModuleData([
|
||||
'uris' => []
|
||||
]);
|
||||
}
|
||||
@@ -441,17 +453,17 @@ class DemoGeneric
|
||||
}
|
||||
|
||||
// Patch the object by adding a link
|
||||
$newLink = new Google_Service_Walletobjects_Uri([
|
||||
$newLink = new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'New link description'
|
||||
]);
|
||||
|
||||
$patchBody = new Google_Service_Walletobjects_GenericObject();
|
||||
$patchBody = new GenericObject();
|
||||
|
||||
$linksModuleData = $existingObject->getLinksModuleData();
|
||||
if (is_null($linksModuleData)) {
|
||||
// LinksModuleData was not set on the original object
|
||||
$linksModuleData = new Google_Service_Walletobjects_LinksModuleData([
|
||||
$linksModuleData = new LinksModuleData([
|
||||
'uris' => []
|
||||
]);
|
||||
}
|
||||
@@ -502,7 +514,7 @@ class DemoGeneric
|
||||
}
|
||||
|
||||
// Patch the object, setting the pass as expired
|
||||
$patchBody = new Google_Service_Walletobjects_GenericObject([
|
||||
$patchBody = new GenericObject([
|
||||
'state' => 'EXPIRED'
|
||||
]);
|
||||
|
||||
@@ -534,42 +546,42 @@ class DemoGeneric
|
||||
{
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/generic/rest/v1/genericclass
|
||||
$newClass = new Google_Service_Walletobjects_GenericClass([
|
||||
$newClass = new GenericClass([
|
||||
'id' => "{$issuerId}.{$classSuffix}",
|
||||
]);
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/generic/rest/v1/genericobject
|
||||
$newObject = new Google_Service_Walletobjects_GenericObject([
|
||||
$newObject = new GenericObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -577,13 +589,13 @@ class DemoGeneric
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -592,29 +604,29 @@ class DemoGeneric
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'cardTitle' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'cardTitle' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Generic card title'
|
||||
])
|
||||
]),
|
||||
'header' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'header' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Generic header'
|
||||
])
|
||||
]),
|
||||
'hexBackgroundColor' => '#4285f4',
|
||||
'logo' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'logo' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://storage.googleapis.com/wallet-lab-tools-codelab-artifacts-public/pass_google_logo.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Generic card logo'
|
||||
])
|
||||
@@ -782,36 +794,36 @@ class DemoGeneric
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/generic/rest/v1/genericobject
|
||||
$batchObject = new Google_Service_Walletobjects_GenericObject([
|
||||
$batchObject = new GenericObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -819,13 +831,13 @@ class DemoGeneric
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -834,29 +846,29 @@ class DemoGeneric
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'cardTitle' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'cardTitle' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Generic card title'
|
||||
])
|
||||
]),
|
||||
'header' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'header' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Generic header'
|
||||
])
|
||||
]),
|
||||
'hexBackgroundColor' => '#4285f4',
|
||||
'logo' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'logo' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://storage.googleapis.com/wallet-lab-tools-codelab-artifacts-public/pass_google_logo.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Generic card logo'
|
||||
])
|
||||
|
||||
@@ -17,20 +17,39 @@
|
||||
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
// Download the PHP client library from the following URL
|
||||
// https://developers.google.com/wallet/generic/resources/libraries
|
||||
require __DIR__ . '/lib/Walletobjects.php';
|
||||
|
||||
// [START setup]
|
||||
// [START imports]
|
||||
use Firebase\JWT\JWT;
|
||||
use Google\Auth\Credentials\ServiceAccountCredentials;
|
||||
use Google\Client as Google_Client;
|
||||
use Google\Client as GoogleClient;
|
||||
use Google\Service\Walletobjects;
|
||||
use Google\Service\Walletobjects\DateTime;
|
||||
use Google\Service\Walletobjects\Money;
|
||||
use Google\Service\Walletobjects\LatLongPoint;
|
||||
use Google\Service\Walletobjects\Barcode;
|
||||
use Google\Service\Walletobjects\ImageModuleData;
|
||||
use Google\Service\Walletobjects\LinksModuleData;
|
||||
use Google\Service\Walletobjects\TextModuleData;
|
||||
use Google\Service\Walletobjects\TranslatedString;
|
||||
use Google\Service\Walletobjects\LocalizedString;
|
||||
use Google\Service\Walletobjects\ImageUri;
|
||||
use Google\Service\Walletobjects\Image;
|
||||
use Google\Service\Walletobjects\GiftCardObject;
|
||||
use Google\Service\Walletobjects\Message;
|
||||
use Google\Service\Walletobjects\AddMessageRequest;
|
||||
use Google\Service\Walletobjects\Uri;
|
||||
use Google\Service\Walletobjects\GiftCardClass;
|
||||
// [END imports]
|
||||
|
||||
/** Demo class for creating and managing Gift cards in Google Wallet. */
|
||||
class DemoGiftCard
|
||||
{
|
||||
/**
|
||||
* The Google API Client
|
||||
* https://github.com/google/google-api-php-client
|
||||
*/
|
||||
public GoogleClient $client;
|
||||
|
||||
/**
|
||||
* Path to service account key file from Google Cloud Console. Environment
|
||||
* variable: GOOGLE_APPLICATION_CREDENTIALS.
|
||||
@@ -45,7 +64,7 @@ class DemoGiftCard
|
||||
/**
|
||||
* Google Wallet service client.
|
||||
*/
|
||||
public Google_Service_Walletobjects $service;
|
||||
public Walletobjects $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -61,20 +80,18 @@ class DemoGiftCard
|
||||
*/
|
||||
public function auth()
|
||||
{
|
||||
$scope = 'https://www.googleapis.com/auth/wallet_object.issuer';
|
||||
|
||||
$this->credentials = new ServiceAccountCredentials(
|
||||
$scope,
|
||||
Walletobjects::WALLET_OBJECT_ISSUER,
|
||||
$this->keyFilePath
|
||||
);
|
||||
|
||||
// Initialize Google Wallet API service
|
||||
$this->client = new Google_Client();
|
||||
$this->client = new GoogleClient();
|
||||
$this->client->setApplicationName('APPLICATION_NAME');
|
||||
$this->client->setScopes($scope);
|
||||
$this->client->setScopes(Walletobjects::WALLET_OBJECT_ISSUER);
|
||||
$this->client->setAuthConfig($this->keyFilePath);
|
||||
|
||||
$this->service = new Google_Service_Walletobjects($this->client);
|
||||
$this->service = new Walletobjects($this->client);
|
||||
}
|
||||
// [END auth]
|
||||
|
||||
@@ -91,7 +108,7 @@ class DemoGiftCard
|
||||
{
|
||||
// Check if the class exists
|
||||
try {
|
||||
$this->service->eventticketclass->get("{$issuerId}.{$classSuffix}");
|
||||
$this->service->giftcardclass->get("{$issuerId}.{$classSuffix}");
|
||||
|
||||
print("Class {$issuerId}.{$classSuffix} already exists!");
|
||||
return "{$issuerId}.{$classSuffix}";
|
||||
@@ -105,7 +122,7 @@ class DemoGiftCard
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/retail/gift-cards/rest/v1/giftcardclass
|
||||
$newClass = new Google_Service_Walletobjects_GiftCardClass([
|
||||
$newClass = new GiftCardClass([
|
||||
'id' => "{$issuerId}.{$classSuffix}",
|
||||
'issuerName' => 'Issuer name',
|
||||
'reviewStatus' => 'UNDER_REVIEW'
|
||||
@@ -149,7 +166,7 @@ class DemoGiftCard
|
||||
}
|
||||
|
||||
// Update the class by adding a homepage
|
||||
$updatedClass->setHomepageUri(new Google_Service_Walletobjects_Uri([
|
||||
$updatedClass->setHomepageUri(new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'Homepage description'
|
||||
]));
|
||||
@@ -195,8 +212,8 @@ class DemoGiftCard
|
||||
}
|
||||
|
||||
// Patch the class by adding a homepage
|
||||
$patchBody = new Google_Service_Walletobjects_GiftCardClass([
|
||||
'homepageUri' => new Google_Service_Walletobjects_Uri([
|
||||
$patchBody = new GiftCardClass([
|
||||
'homepageUri' => new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'Homepage description'
|
||||
]),
|
||||
@@ -242,8 +259,8 @@ class DemoGiftCard
|
||||
}
|
||||
}
|
||||
|
||||
$message = new Google_Service_Walletobjects_AddMessageRequest([
|
||||
'message' => new Google_Service_Walletobjects_Message([
|
||||
$message = new AddMessageRequest([
|
||||
'message' => new Message([
|
||||
'header' => $header,
|
||||
'body' => $body
|
||||
])
|
||||
@@ -286,36 +303,36 @@ class DemoGiftCard
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/retail/gift-cards/rest/v1/giftcardobject
|
||||
$newObject = new Google_Service_Walletobjects_GiftCardObject([
|
||||
$newObject = new GiftCardObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -323,13 +340,13 @@ class DemoGiftCard
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -338,23 +355,23 @@ class DemoGiftCard
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'locations' => [
|
||||
new Google_Service_Walletobjects_LatLongPoint([
|
||||
new LatLongPoint([
|
||||
'latitude' => 37.424015499999996,
|
||||
'longitude' => -122.09259560000001
|
||||
])
|
||||
],
|
||||
'cardNumber' => 'Card number',
|
||||
'pin' => '1234',
|
||||
'balance' => new Google_Service_Walletobjects_Money([
|
||||
'balance' => new Money([
|
||||
'micros' => 20000000,
|
||||
'currencyCode' => 'USD'
|
||||
]),
|
||||
'balanceUpdateTime' => new Google_Service_Walletobjects_DateTime([
|
||||
'balanceUpdateTime' => new DateTime([
|
||||
'date' => '2020-04-12T16:20:50.52-04:00'
|
||||
])
|
||||
]);
|
||||
@@ -396,7 +413,7 @@ class DemoGiftCard
|
||||
}
|
||||
|
||||
// Update the object by adding a link
|
||||
$newLink = new Google_Service_Walletobjects_Uri([
|
||||
$newLink = new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'New link description'
|
||||
]);
|
||||
@@ -404,7 +421,7 @@ class DemoGiftCard
|
||||
$linksModuleData = $updatedObject->getLinksModuleData();
|
||||
if (is_null($linksModuleData)) {
|
||||
// LinksModuleData was not set on the original object
|
||||
$linksModuleData = new Google_Service_Walletobjects_LinksModuleData([
|
||||
$linksModuleData = new LinksModuleData([
|
||||
'uris' => []
|
||||
]);
|
||||
}
|
||||
@@ -452,17 +469,17 @@ class DemoGiftCard
|
||||
}
|
||||
|
||||
// Patch the object by adding a link
|
||||
$newLink = new Google_Service_Walletobjects_Uri([
|
||||
$newLink = new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'New link description'
|
||||
]);
|
||||
|
||||
$patchBody = new Google_Service_Walletobjects_GiftCardObject();
|
||||
$patchBody = new GiftCardObject();
|
||||
|
||||
$linksModuleData = $existingObject->getLinksModuleData();
|
||||
if (is_null($linksModuleData)) {
|
||||
// LinksModuleData was not set on the original object
|
||||
$linksModuleData = new Google_Service_Walletobjects_LinksModuleData([
|
||||
$linksModuleData = new LinksModuleData([
|
||||
'uris' => []
|
||||
]);
|
||||
}
|
||||
@@ -513,7 +530,7 @@ class DemoGiftCard
|
||||
}
|
||||
|
||||
// Patch the object, setting the pass as expired
|
||||
$patchBody = new Google_Service_Walletobjects_GiftCardObject([
|
||||
$patchBody = new GiftCardObject([
|
||||
'state' => 'EXPIRED'
|
||||
]);
|
||||
|
||||
@@ -553,8 +570,8 @@ class DemoGiftCard
|
||||
}
|
||||
}
|
||||
|
||||
$message = new Google_Service_Walletobjects_AddMessageRequest([
|
||||
'message' => new Google_Service_Walletobjects_Message([
|
||||
$message = new AddMessageRequest([
|
||||
'message' => new Message([
|
||||
'header' => $header,
|
||||
'body' => $body
|
||||
])
|
||||
@@ -588,7 +605,7 @@ class DemoGiftCard
|
||||
{
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/retail/gift-cards/rest/v1/giftcardclass
|
||||
$newClass = new Google_Service_Walletobjects_GiftCardClass([
|
||||
$newClass = new GiftCardClass([
|
||||
'id' => "{$issuerId}.{$classSuffix}",
|
||||
'issuerName' => 'Issuer name',
|
||||
'reviewStatus' => 'UNDER_REVIEW'
|
||||
@@ -596,36 +613,36 @@ class DemoGiftCard
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/retail/gift-cards/rest/v1/giftcardobject
|
||||
$newObject = new Google_Service_Walletobjects_GiftCardObject([
|
||||
$newObject = new GiftCardObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -633,13 +650,13 @@ class DemoGiftCard
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -648,23 +665,23 @@ class DemoGiftCard
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'locations' => [
|
||||
new Google_Service_Walletobjects_LatLongPoint([
|
||||
new LatLongPoint([
|
||||
'latitude' => 37.424015499999996,
|
||||
'longitude' => -122.09259560000001
|
||||
])
|
||||
],
|
||||
'cardNumber' => 'Card number',
|
||||
'pin' => '1234',
|
||||
'balance' => new Google_Service_Walletobjects_Money([
|
||||
'balance' => new Money([
|
||||
'micros' => 20000000,
|
||||
'currencyCode' => 'USD'
|
||||
]),
|
||||
'balanceUpdateTime' => new Google_Service_Walletobjects_DateTime([
|
||||
'balanceUpdateTime' => new DateTime([
|
||||
'date' => '2020-04-12T16:20:50.52-04:00'
|
||||
])
|
||||
]);
|
||||
@@ -829,36 +846,36 @@ class DemoGiftCard
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/retail/gift-cards/rest/v1/giftcardobject
|
||||
$batchObject = new Google_Service_Walletobjects_GiftCardObject([
|
||||
$batchObject = new GiftCardObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -866,13 +883,13 @@ class DemoGiftCard
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -881,23 +898,23 @@ class DemoGiftCard
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'locations' => [
|
||||
new Google_Service_Walletobjects_LatLongPoint([
|
||||
new LatLongPoint([
|
||||
'latitude' => 37.424015499999996,
|
||||
'longitude' => -122.09259560000001
|
||||
])
|
||||
],
|
||||
'cardNumber' => 'Card number',
|
||||
'pin' => '1234',
|
||||
'balance' => new Google_Service_Walletobjects_Money([
|
||||
'balance' => new Money([
|
||||
'micros' => 20000000,
|
||||
'currencyCode' => 'USD'
|
||||
]),
|
||||
'balanceUpdateTime' => new Google_Service_Walletobjects_DateTime([
|
||||
'balanceUpdateTime' => new DateTime([
|
||||
'date' => '2020-04-12T16:20:50.52-04:00'
|
||||
])
|
||||
]);
|
||||
|
||||
@@ -17,20 +17,39 @@
|
||||
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
// Download the PHP client library from the following URL
|
||||
// https://developers.google.com/wallet/generic/resources/libraries
|
||||
require __DIR__ . '/lib/Walletobjects.php';
|
||||
|
||||
// [START setup]
|
||||
// [START imports]
|
||||
use Firebase\JWT\JWT;
|
||||
use Google\Auth\Credentials\ServiceAccountCredentials;
|
||||
use Google\Client as Google_Client;
|
||||
use Google\Client as GoogleClient;
|
||||
use Google\Service\Walletobjects;
|
||||
use Google\Service\Walletobjects\LoyaltyPointsBalance;
|
||||
use Google\Service\Walletobjects\LoyaltyPoints;
|
||||
use Google\Service\Walletobjects\LoyaltyObject;
|
||||
use Google\Service\Walletobjects\LoyaltyClass;
|
||||
use Google\Service\Walletobjects\LatLongPoint;
|
||||
use Google\Service\Walletobjects\Barcode;
|
||||
use Google\Service\Walletobjects\ImageModuleData;
|
||||
use Google\Service\Walletobjects\LinksModuleData;
|
||||
use Google\Service\Walletobjects\TextModuleData;
|
||||
use Google\Service\Walletobjects\TranslatedString;
|
||||
use Google\Service\Walletobjects\LocalizedString;
|
||||
use Google\Service\Walletobjects\ImageUri;
|
||||
use Google\Service\Walletobjects\Image;
|
||||
use Google\Service\Walletobjects\Message;
|
||||
use Google\Service\Walletobjects\AddMessageRequest;
|
||||
use Google\Service\Walletobjects\Uri;
|
||||
// [END imports]
|
||||
|
||||
/** Demo class for creating and managing Loyalty cards in Google Wallet. */
|
||||
class DemoLoyalty
|
||||
{
|
||||
/**
|
||||
* The Google API Client
|
||||
* https://github.com/google/google-api-php-client
|
||||
*/
|
||||
public GoogleClient $client;
|
||||
|
||||
/**
|
||||
* Path to service account key file from Google Cloud Console. Environment
|
||||
* variable: GOOGLE_APPLICATION_CREDENTIALS.
|
||||
@@ -45,7 +64,7 @@ class DemoLoyalty
|
||||
/**
|
||||
* Google Wallet service client.
|
||||
*/
|
||||
public Google_Service_Walletobjects $service;
|
||||
public Walletobjects $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -61,20 +80,18 @@ class DemoLoyalty
|
||||
*/
|
||||
public function auth()
|
||||
{
|
||||
$scope = 'https://www.googleapis.com/auth/wallet_object.issuer';
|
||||
|
||||
$this->credentials = new ServiceAccountCredentials(
|
||||
$scope,
|
||||
Walletobjects::WALLET_OBJECT_ISSUER,
|
||||
$this->keyFilePath
|
||||
);
|
||||
|
||||
// Initialize Google Wallet API service
|
||||
$this->client = new Google_Client();
|
||||
$this->client = new GoogleClient();
|
||||
$this->client->setApplicationName('APPLICATION_NAME');
|
||||
$this->client->setScopes($scope);
|
||||
$this->client->setScopes(Walletobjects::WALLET_OBJECT_ISSUER);
|
||||
$this->client->setAuthConfig($this->keyFilePath);
|
||||
|
||||
$this->service = new Google_Service_Walletobjects($this->client);
|
||||
$this->service = new Walletobjects($this->client);
|
||||
}
|
||||
// [END auth]
|
||||
|
||||
@@ -105,17 +122,17 @@ class DemoLoyalty
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/retail/loyalty-cards/rest/v1/loyaltyclass
|
||||
$newClass = new Google_Service_Walletobjects_LoyaltyClass([
|
||||
$newClass = new LoyaltyClass([
|
||||
'id' => "{$issuerId}.{$classSuffix}",
|
||||
'issuerName' => 'Issuer name',
|
||||
'reviewStatus' => 'UNDER_REVIEW',
|
||||
'programName' => 'Program name',
|
||||
'programLogo' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'programLogo' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm8.staticflickr.com/7340/11177041185_a61a7f2139_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Logo description'
|
||||
])
|
||||
@@ -162,7 +179,7 @@ class DemoLoyalty
|
||||
}
|
||||
|
||||
// Update the class by adding a homepage
|
||||
$updatedClass->setHomepageUri(new Google_Service_Walletobjects_Uri([
|
||||
$updatedClass->setHomepageUri(new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'Homepage description'
|
||||
]));
|
||||
@@ -208,8 +225,8 @@ class DemoLoyalty
|
||||
}
|
||||
|
||||
// Patch the class by adding a homepage
|
||||
$patchBody = new Google_Service_Walletobjects_LoyaltyClass([
|
||||
'homepageUri' => new Google_Service_Walletobjects_Uri([
|
||||
$patchBody = new LoyaltyClass([
|
||||
'homepageUri' => new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'Homepage description'
|
||||
]),
|
||||
@@ -255,8 +272,8 @@ class DemoLoyalty
|
||||
}
|
||||
}
|
||||
|
||||
$message = new Google_Service_Walletobjects_AddMessageRequest([
|
||||
'message' => new Google_Service_Walletobjects_Message([
|
||||
$message = new AddMessageRequest([
|
||||
'message' => new Message([
|
||||
'header' => $header,
|
||||
'body' => $body
|
||||
])
|
||||
@@ -299,36 +316,36 @@ class DemoLoyalty
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/retail/loyalty-cards/rest/v1/loyaltyobject
|
||||
$newObject = new Google_Service_Walletobjects_LoyaltyObject([
|
||||
$newObject = new LoyaltyObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -336,13 +353,13 @@ class DemoLoyalty
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -351,20 +368,20 @@ class DemoLoyalty
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'locations' => [
|
||||
new Google_Service_Walletobjects_LatLongPoint([
|
||||
new LatLongPoint([
|
||||
'latitude' => 37.424015499999996,
|
||||
'longitude' => -122.09259560000001
|
||||
])
|
||||
],
|
||||
'accountId' => 'Account ID',
|
||||
'accountName' => 'Account name',
|
||||
'loyaltyPoints' => new Google_Service_Walletobjects_LoyaltyPoints([
|
||||
'balance' => new Google_Service_Walletobjects_LoyaltyPointsBalance([
|
||||
'loyaltyPoints' => new LoyaltyPoints([
|
||||
'balance' => new LoyaltyPointsBalance([
|
||||
'int' => 800
|
||||
])
|
||||
])
|
||||
@@ -407,7 +424,7 @@ class DemoLoyalty
|
||||
}
|
||||
|
||||
// Update the object by adding a link
|
||||
$newLink = new Google_Service_Walletobjects_Uri([
|
||||
$newLink = new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'New link description'
|
||||
]);
|
||||
@@ -415,7 +432,7 @@ class DemoLoyalty
|
||||
$linksModuleData = $updatedObject->getLinksModuleData();
|
||||
if (is_null($linksModuleData)) {
|
||||
// LinksModuleData was not set on the original object
|
||||
$linksModuleData = new Google_Service_Walletobjects_LinksModuleData([
|
||||
$linksModuleData = new LinksModuleData([
|
||||
'uris' => []
|
||||
]);
|
||||
}
|
||||
@@ -463,17 +480,17 @@ class DemoLoyalty
|
||||
}
|
||||
|
||||
// Patch the object by adding a link
|
||||
$newLink = new Google_Service_Walletobjects_Uri([
|
||||
$newLink = new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'New link description'
|
||||
]);
|
||||
|
||||
$patchBody = new Google_Service_Walletobjects_LoyaltyObject();
|
||||
$patchBody = new LoyaltyObject();
|
||||
|
||||
$linksModuleData = $existingObject->getLinksModuleData();
|
||||
if (is_null($linksModuleData)) {
|
||||
// LinksModuleData was not set on the original object
|
||||
$linksModuleData = new Google_Service_Walletobjects_LinksModuleData([
|
||||
$linksModuleData = new LinksModuleData([
|
||||
'uris' => []
|
||||
]);
|
||||
}
|
||||
@@ -524,7 +541,7 @@ class DemoLoyalty
|
||||
}
|
||||
|
||||
// Patch the object, setting the pass as expired
|
||||
$patchBody = new Google_Service_Walletobjects_LoyaltyObject([
|
||||
$patchBody = new LoyaltyObject([
|
||||
'state' => 'EXPIRED'
|
||||
]);
|
||||
|
||||
@@ -564,8 +581,8 @@ class DemoLoyalty
|
||||
}
|
||||
}
|
||||
|
||||
$message = new Google_Service_Walletobjects_AddMessageRequest([
|
||||
'message' => new Google_Service_Walletobjects_Message([
|
||||
$message = new AddMessageRequest([
|
||||
'message' => new Message([
|
||||
'header' => $header,
|
||||
'body' => $body
|
||||
])
|
||||
@@ -599,17 +616,17 @@ class DemoLoyalty
|
||||
{
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/retail/loyalty-cards/rest/v1/loyaltyclass
|
||||
$newClass = new Google_Service_Walletobjects_LoyaltyClass([
|
||||
$newClass = new LoyaltyClass([
|
||||
'id' => "{$issuerId}.{$classSuffix}",
|
||||
'issuerName' => 'Issuer name',
|
||||
'reviewStatus' => 'UNDER_REVIEW',
|
||||
'programName' => 'Program name',
|
||||
'programLogo' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'programLogo' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm8.staticflickr.com/7340/11177041185_a61a7f2139_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Logo description'
|
||||
])
|
||||
@@ -619,36 +636,36 @@ class DemoLoyalty
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/retail/loyalty-cards/rest/v1/loyaltyobject
|
||||
$newObject = new Google_Service_Walletobjects_LoyaltyObject([
|
||||
$newObject = new LoyaltyObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -656,13 +673,13 @@ class DemoLoyalty
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -671,20 +688,20 @@ class DemoLoyalty
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'locations' => [
|
||||
new Google_Service_Walletobjects_LatLongPoint([
|
||||
new LatLongPoint([
|
||||
'latitude' => 37.424015499999996,
|
||||
'longitude' => -122.09259560000001
|
||||
])
|
||||
],
|
||||
'accountId' => 'Account ID',
|
||||
'accountName' => 'Account name',
|
||||
'loyaltyPoints' => new Google_Service_Walletobjects_LoyaltyPoints([
|
||||
'balance' => new Google_Service_Walletobjects_LoyaltyPointsBalance([
|
||||
'loyaltyPoints' => new LoyaltyPoints([
|
||||
'balance' => new LoyaltyPointsBalance([
|
||||
'int' => 800
|
||||
])
|
||||
])
|
||||
@@ -850,36 +867,36 @@ class DemoLoyalty
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/retail/loyalty-cards/rest/v1/loyaltyobject
|
||||
$batchObject = new Google_Service_Walletobjects_LoyaltyObject([
|
||||
$batchObject = new LoyaltyObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -887,13 +904,13 @@ class DemoLoyalty
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -902,20 +919,20 @@ class DemoLoyalty
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'locations' => [
|
||||
new Google_Service_Walletobjects_LatLongPoint([
|
||||
new LatLongPoint([
|
||||
'latitude' => 37.424015499999996,
|
||||
'longitude' => -122.09259560000001
|
||||
])
|
||||
],
|
||||
'accountId' => 'Account ID',
|
||||
'accountName' => 'Account name',
|
||||
'loyaltyPoints' => new Google_Service_Walletobjects_LoyaltyPoints([
|
||||
'balance' => new Google_Service_Walletobjects_LoyaltyPointsBalance([
|
||||
'loyaltyPoints' => new LoyaltyPoints([
|
||||
'balance' => new LoyaltyPointsBalance([
|
||||
'int' => 800
|
||||
])
|
||||
])
|
||||
|
||||
@@ -17,20 +17,39 @@
|
||||
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
// Download the PHP client library from the following URL
|
||||
// https://developers.google.com/wallet/generic/resources/libraries
|
||||
require __DIR__ . '/lib/Walletobjects.php';
|
||||
|
||||
// [START setup]
|
||||
// [START imports]
|
||||
use Firebase\JWT\JWT;
|
||||
use Google\Auth\Credentials\ServiceAccountCredentials;
|
||||
use Google\Client as Google_Client;
|
||||
use Google\Client as GoogleClient;
|
||||
use Google\Service\Walletobjects;
|
||||
use Google\Service\Walletobjects\DateTime;
|
||||
use Google\Service\Walletobjects\TimeInterval;
|
||||
use Google\Service\Walletobjects\OfferObject;
|
||||
use Google\Service\Walletobjects\OfferClass;
|
||||
use Google\Service\Walletobjects\LatLongPoint;
|
||||
use Google\Service\Walletobjects\Barcode;
|
||||
use Google\Service\Walletobjects\ImageModuleData;
|
||||
use Google\Service\Walletobjects\LinksModuleData;
|
||||
use Google\Service\Walletobjects\TextModuleData;
|
||||
use Google\Service\Walletobjects\TranslatedString;
|
||||
use Google\Service\Walletobjects\LocalizedString;
|
||||
use Google\Service\Walletobjects\ImageUri;
|
||||
use Google\Service\Walletobjects\Image;
|
||||
use Google\Service\Walletobjects\Message;
|
||||
use Google\Service\Walletobjects\AddMessageRequest;
|
||||
use Google\Service\Walletobjects\Uri;
|
||||
// [END imports]
|
||||
|
||||
/** Demo class for creating and managing Offers in Google Wallet. */
|
||||
class DemoOffer
|
||||
{
|
||||
/**
|
||||
* The Google API Client
|
||||
* https://github.com/google/google-api-php-client
|
||||
*/
|
||||
public GoogleClient $client;
|
||||
|
||||
/**
|
||||
* Path to service account key file from Google Cloud Console. Environment
|
||||
* variable: GOOGLE_APPLICATION_CREDENTIALS.
|
||||
@@ -45,7 +64,7 @@ class DemoOffer
|
||||
/**
|
||||
* Google Wallet service client.
|
||||
*/
|
||||
public Google_Service_Walletobjects $service;
|
||||
public Walletobjects $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -61,20 +80,18 @@ class DemoOffer
|
||||
*/
|
||||
public function auth()
|
||||
{
|
||||
$scope = 'https://www.googleapis.com/auth/wallet_object.issuer';
|
||||
|
||||
$this->credentials = new ServiceAccountCredentials(
|
||||
$scope,
|
||||
Walletobjects::WALLET_OBJECT_ISSUER,
|
||||
$this->keyFilePath
|
||||
);
|
||||
|
||||
// Initialize Google Wallet API service
|
||||
$this->client = new Google_Client();
|
||||
$this->client = new GoogleClient();
|
||||
$this->client->setApplicationName('APPLICATION_NAME');
|
||||
$this->client->setScopes($scope);
|
||||
$this->client->setScopes(Walletobjects::WALLET_OBJECT_ISSUER);
|
||||
$this->client->setAuthConfig($this->keyFilePath);
|
||||
|
||||
$this->service = new Google_Service_Walletobjects($this->client);
|
||||
$this->service = new Walletobjects($this->client);
|
||||
}
|
||||
// [END auth]
|
||||
|
||||
@@ -105,7 +122,7 @@ class DemoOffer
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/retail/offers/rest/v1/offerclass
|
||||
$newClass = new Google_Service_Walletobjects_OfferClass([
|
||||
$newClass = new OfferClass([
|
||||
'id' => "{$issuerId}.{$classSuffix}",
|
||||
'issuerName' => 'Issuer name',
|
||||
'reviewStatus' => 'UNDER_REVIEW',
|
||||
@@ -152,7 +169,7 @@ class DemoOffer
|
||||
}
|
||||
|
||||
// Update the class by adding a homepage
|
||||
$updatedClass->setHomepageUri(new Google_Service_Walletobjects_Uri([
|
||||
$updatedClass->setHomepageUri(new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'Homepage description'
|
||||
]));
|
||||
@@ -198,8 +215,8 @@ class DemoOffer
|
||||
}
|
||||
|
||||
// Patch the class by adding a homepage
|
||||
$patchBody = new Google_Service_Walletobjects_OfferClass([
|
||||
'homepageUri' => new Google_Service_Walletobjects_Uri([
|
||||
$patchBody = new OfferClass([
|
||||
'homepageUri' => new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'Homepage description'
|
||||
]),
|
||||
@@ -245,8 +262,8 @@ class DemoOffer
|
||||
}
|
||||
}
|
||||
|
||||
$message = new Google_Service_Walletobjects_AddMessageRequest([
|
||||
'message' => new Google_Service_Walletobjects_Message([
|
||||
$message = new AddMessageRequest([
|
||||
'message' => new Message([
|
||||
'header' => $header,
|
||||
'body' => $body
|
||||
])
|
||||
@@ -289,36 +306,36 @@ class DemoOffer
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/retail/offers/rest/v1/offerobject
|
||||
$newObject = new Google_Service_Walletobjects_OfferObject([
|
||||
$newObject = new OfferObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -326,13 +343,13 @@ class DemoOffer
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -341,21 +358,21 @@ class DemoOffer
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'locations' => [
|
||||
new Google_Service_Walletobjects_LatLongPoint([
|
||||
new LatLongPoint([
|
||||
'latitude' => 37.424015499999996,
|
||||
'longitude' => -122.09259560000001
|
||||
])
|
||||
],
|
||||
'validTimeInterval' => new Google_Service_Walletobjects_TimeInterval([
|
||||
'start' => new Google_Service_Walletobjects_DateTime([
|
||||
'validTimeInterval' => new TimeInterval([
|
||||
'start' => new DateTime([
|
||||
'date' => '2023-06-12T23:20:50.52Z'
|
||||
]),
|
||||
'end' => new Google_Service_Walletobjects_DateTime([
|
||||
'end' => new DateTime([
|
||||
'date' => '2023-12-12T23:20:50.52Z'
|
||||
])
|
||||
])
|
||||
@@ -398,7 +415,7 @@ class DemoOffer
|
||||
}
|
||||
|
||||
// Update the object by adding a link
|
||||
$newLink = new Google_Service_Walletobjects_Uri([
|
||||
$newLink = new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'New link description'
|
||||
]);
|
||||
@@ -406,7 +423,7 @@ class DemoOffer
|
||||
$linksModuleData = $updatedObject->getLinksModuleData();
|
||||
if (is_null($linksModuleData)) {
|
||||
// LinksModuleData was not set on the original object
|
||||
$linksModuleData = new Google_Service_Walletobjects_LinksModuleData([
|
||||
$linksModuleData = new LinksModuleData([
|
||||
'uris' => []
|
||||
]);
|
||||
}
|
||||
@@ -454,17 +471,17 @@ class DemoOffer
|
||||
}
|
||||
|
||||
// Patch the object by adding a link
|
||||
$newLink = new Google_Service_Walletobjects_Uri([
|
||||
$newLink = new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'New link description'
|
||||
]);
|
||||
|
||||
$patchBody = new Google_Service_Walletobjects_OfferObject();
|
||||
$patchBody = new OfferObject();
|
||||
|
||||
$linksModuleData = $existingObject->getLinksModuleData();
|
||||
if (is_null($linksModuleData)) {
|
||||
// LinksModuleData was not set on the original object
|
||||
$linksModuleData = new Google_Service_Walletobjects_LinksModuleData([
|
||||
$linksModuleData = new LinksModuleData([
|
||||
'uris' => []
|
||||
]);
|
||||
}
|
||||
@@ -515,7 +532,7 @@ class DemoOffer
|
||||
}
|
||||
|
||||
// Patch the object, setting the pass as expired
|
||||
$patchBody = new Google_Service_Walletobjects_OfferObject([
|
||||
$patchBody = new OfferObject([
|
||||
'state' => 'EXPIRED'
|
||||
]);
|
||||
|
||||
@@ -555,8 +572,8 @@ class DemoOffer
|
||||
}
|
||||
}
|
||||
|
||||
$message = new Google_Service_Walletobjects_AddMessageRequest([
|
||||
'message' => new Google_Service_Walletobjects_Message([
|
||||
$message = new AddMessageRequest([
|
||||
'message' => new Message([
|
||||
'header' => $header,
|
||||
'body' => $body
|
||||
])
|
||||
@@ -590,7 +607,7 @@ class DemoOffer
|
||||
{
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/retail/offers/rest/v1/offerclass
|
||||
$newClass = new Google_Service_Walletobjects_OfferClass([
|
||||
$newClass = new OfferClass([
|
||||
'id' => "{$issuerId}.{$classSuffix}",
|
||||
'issuerName' => 'Issuer name',
|
||||
'reviewStatus' => 'UNDER_REVIEW',
|
||||
@@ -601,36 +618,36 @@ class DemoOffer
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/retail/offers/rest/v1/offerobject
|
||||
$newObject = new Google_Service_Walletobjects_OfferObject([
|
||||
$newObject = new OfferObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -638,13 +655,13 @@ class DemoOffer
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -653,21 +670,21 @@ class DemoOffer
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'locations' => [
|
||||
new Google_Service_Walletobjects_LatLongPoint([
|
||||
new LatLongPoint([
|
||||
'latitude' => 37.424015499999996,
|
||||
'longitude' => -122.09259560000001
|
||||
])
|
||||
],
|
||||
'validTimeInterval' => new Google_Service_Walletobjects_TimeInterval([
|
||||
'start' => new Google_Service_Walletobjects_DateTime([
|
||||
'validTimeInterval' => new TimeInterval([
|
||||
'start' => new DateTime([
|
||||
'date' => '2023-06-12T23:20:50.52Z'
|
||||
]),
|
||||
'end' => new Google_Service_Walletobjects_DateTime([
|
||||
'end' => new DateTime([
|
||||
'date' => '2023-12-12T23:20:50.52Z'
|
||||
])
|
||||
])
|
||||
@@ -833,36 +850,36 @@ class DemoOffer
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/retail/offers/rest/v1/offerobject
|
||||
$batchObject = new Google_Service_Walletobjects_OfferObject([
|
||||
$batchObject = new OfferObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -870,13 +887,13 @@ class DemoOffer
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -885,21 +902,21 @@ class DemoOffer
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'locations' => [
|
||||
new Google_Service_Walletobjects_LatLongPoint([
|
||||
new LatLongPoint([
|
||||
'latitude' => 37.424015499999996,
|
||||
'longitude' => -122.09259560000001
|
||||
])
|
||||
],
|
||||
'validTimeInterval' => new Google_Service_Walletobjects_TimeInterval([
|
||||
'start' => new Google_Service_Walletobjects_DateTime([
|
||||
'validTimeInterval' => new TimeInterval([
|
||||
'start' => new DateTime([
|
||||
'date' => '2023-06-12T23:20:50.52Z'
|
||||
]),
|
||||
'end' => new Google_Service_Walletobjects_DateTime([
|
||||
'end' => new DateTime([
|
||||
'date' => '2023-12-12T23:20:50.52Z'
|
||||
])
|
||||
])
|
||||
|
||||
@@ -17,20 +17,38 @@
|
||||
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
// Download the PHP client library from the following URL
|
||||
// https://developers.google.com/wallet/generic/resources/libraries
|
||||
require __DIR__ . '/lib/Walletobjects.php';
|
||||
|
||||
// [START setup]
|
||||
// [START imports]
|
||||
use Firebase\JWT\JWT;
|
||||
use Google\Auth\Credentials\ServiceAccountCredentials;
|
||||
use Google\Client as Google_Client;
|
||||
use Google\Client as GoogleClient;
|
||||
use Google\Service\Walletobjects;
|
||||
use Google\Service\Walletobjects\TicketLeg;
|
||||
use Google\Service\Walletobjects\LatLongPoint;
|
||||
use Google\Service\Walletobjects\Barcode;
|
||||
use Google\Service\Walletobjects\ImageModuleData;
|
||||
use Google\Service\Walletobjects\LinksModuleData;
|
||||
use Google\Service\Walletobjects\TextModuleData;
|
||||
use Google\Service\Walletobjects\TransitObject;
|
||||
use Google\Service\Walletobjects\Message;
|
||||
use Google\Service\Walletobjects\AddMessageRequest;
|
||||
use Google\Service\Walletobjects\Uri;
|
||||
use Google\Service\Walletobjects\TranslatedString;
|
||||
use Google\Service\Walletobjects\LocalizedString;
|
||||
use Google\Service\Walletobjects\ImageUri;
|
||||
use Google\Service\Walletobjects\Image;
|
||||
use Google\Service\Walletobjects\TransitClass;
|
||||
// [END imports]
|
||||
|
||||
/** Demo class for creating and managing Transit passes in Google Wallet. */
|
||||
class DemoTransit
|
||||
{
|
||||
/**
|
||||
* The Google API Client
|
||||
* https://github.com/google/google-api-php-client
|
||||
*/
|
||||
public GoogleClient $client;
|
||||
|
||||
/**
|
||||
* Path to service account key file from Google Cloud Console. Environment
|
||||
* variable: GOOGLE_APPLICATION_CREDENTIALS.
|
||||
@@ -45,7 +63,7 @@ class DemoTransit
|
||||
/**
|
||||
* Google Wallet service client.
|
||||
*/
|
||||
public Google_Service_Walletobjects $service;
|
||||
public Walletobjects $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -61,20 +79,18 @@ class DemoTransit
|
||||
*/
|
||||
public function auth()
|
||||
{
|
||||
$scope = 'https://www.googleapis.com/auth/wallet_object.issuer';
|
||||
|
||||
$this->credentials = new ServiceAccountCredentials(
|
||||
$scope,
|
||||
Walletobjects::WALLET_OBJECT_ISSUER,
|
||||
$this->keyFilePath
|
||||
);
|
||||
|
||||
// Initialize Google Wallet API service
|
||||
$this->client = new Google_Client();
|
||||
$this->client = new GoogleClient();
|
||||
$this->client->setApplicationName('APPLICATION_NAME');
|
||||
$this->client->setScopes($scope);
|
||||
$this->client->setScopes(Walletobjects::WALLET_OBJECT_ISSUER);
|
||||
$this->client->setAuthConfig($this->keyFilePath);
|
||||
|
||||
$this->service = new Google_Service_Walletobjects($this->client);
|
||||
$this->service = new Walletobjects($this->client);
|
||||
}
|
||||
// [END auth]
|
||||
|
||||
@@ -105,16 +121,16 @@ class DemoTransit
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/tickets/transit-passes/qr-code/rest/v1/transitclass
|
||||
$newClass = new Google_Service_Walletobjects_TransitClass([
|
||||
$newClass = new TransitClass([
|
||||
'id' => "{$issuerId}.{$classSuffix}",
|
||||
'issuerName' => 'Issuer name',
|
||||
'reviewStatus' => 'UNDER_REVIEW',
|
||||
'logo' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'logo' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://live.staticflickr.com/65535/48690277162_cd05f03f4d_o.png'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Logo description'
|
||||
])
|
||||
@@ -161,7 +177,7 @@ class DemoTransit
|
||||
}
|
||||
|
||||
// Update the class by adding a homepage
|
||||
$updatedClass->setHomepageUri(new Google_Service_Walletobjects_Uri([
|
||||
$updatedClass->setHomepageUri(new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'Homepage description'
|
||||
]));
|
||||
@@ -207,8 +223,8 @@ class DemoTransit
|
||||
}
|
||||
|
||||
// Patch the class by adding a homepage
|
||||
$patchBody = new Google_Service_Walletobjects_TransitClass([
|
||||
'homepageUri' => new Google_Service_Walletobjects_Uri([
|
||||
$patchBody = new TransitClass([
|
||||
'homepageUri' => new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'Homepage description'
|
||||
]),
|
||||
@@ -254,8 +270,8 @@ class DemoTransit
|
||||
}
|
||||
}
|
||||
|
||||
$message = new Google_Service_Walletobjects_AddMessageRequest([
|
||||
'message' => new Google_Service_Walletobjects_Message([
|
||||
$message = new AddMessageRequest([
|
||||
'message' => new Message([
|
||||
'header' => $header,
|
||||
'body' => $body
|
||||
])
|
||||
@@ -298,36 +314,36 @@ class DemoTransit
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/tickets/transit-passes/qr-code/rest/v1/transitobject
|
||||
$newObject = new Google_Service_Walletobjects_TransitObject([
|
||||
$newObject = new TransitObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -335,13 +351,13 @@ class DemoTransit
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -350,12 +366,12 @@ class DemoTransit
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'locations' => [
|
||||
new Google_Service_Walletobjects_LatLongPoint([
|
||||
new LatLongPoint([
|
||||
'latitude' => 37.424015499999996,
|
||||
'longitude' => -122.09259560000001
|
||||
])
|
||||
@@ -363,25 +379,25 @@ class DemoTransit
|
||||
'passengerType' => 'SINGLE_PASSENGER',
|
||||
'passengerNames' => 'Passenger names',
|
||||
'tripType' => 'ONE_WAY',
|
||||
'ticketLeg' => new Google_Service_Walletobjects_TicketLeg([
|
||||
'ticketLeg' => new TicketLeg([
|
||||
'originStationCode' => 'LA',
|
||||
'originName' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'originName' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Origin name'
|
||||
])
|
||||
]),
|
||||
'destinationStationCode' => 'SFO',
|
||||
'destinationName' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'destinationName' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Destination name'
|
||||
])
|
||||
]),
|
||||
'departureDateTime' => '2020-04-12T16:20:50.52Z',
|
||||
'arrivalDateTime' => '2020-04-12T20:20:50.52Z',
|
||||
'fareName' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'fareName' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Fare name'
|
||||
])
|
||||
@@ -426,7 +442,7 @@ class DemoTransit
|
||||
}
|
||||
|
||||
// Update the object by adding a link
|
||||
$newLink = new Google_Service_Walletobjects_Uri([
|
||||
$newLink = new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'New link description'
|
||||
]);
|
||||
@@ -434,7 +450,7 @@ class DemoTransit
|
||||
$linksModuleData = $updatedObject->getLinksModuleData();
|
||||
if (is_null($linksModuleData)) {
|
||||
// LinksModuleData was not set on the original object
|
||||
$linksModuleData = new Google_Service_Walletobjects_LinksModuleData([
|
||||
$linksModuleData = new LinksModuleData([
|
||||
'uris' => []
|
||||
]);
|
||||
}
|
||||
@@ -482,17 +498,17 @@ class DemoTransit
|
||||
}
|
||||
|
||||
// Patch the object by adding a link
|
||||
$newLink = new Google_Service_Walletobjects_Uri([
|
||||
$newLink = new Uri([
|
||||
'uri' => 'https://developers.google.com/wallet',
|
||||
'description' => 'New link description'
|
||||
]);
|
||||
|
||||
$patchBody = new Google_Service_Walletobjects_TransitObject();
|
||||
$patchBody = new TransitObject();
|
||||
|
||||
$linksModuleData = $existingObject->getLinksModuleData();
|
||||
if (is_null($linksModuleData)) {
|
||||
// LinksModuleData was not set on the original object
|
||||
$linksModuleData = new Google_Service_Walletobjects_LinksModuleData([
|
||||
$linksModuleData = new LinksModuleData([
|
||||
'uris' => []
|
||||
]);
|
||||
}
|
||||
@@ -543,7 +559,7 @@ class DemoTransit
|
||||
}
|
||||
|
||||
// Patch the object, setting the pass as expired
|
||||
$patchBody = new Google_Service_Walletobjects_TransitObject([
|
||||
$patchBody = new TransitObject([
|
||||
'state' => 'EXPIRED'
|
||||
]);
|
||||
|
||||
@@ -583,8 +599,8 @@ class DemoTransit
|
||||
}
|
||||
}
|
||||
|
||||
$message = new Google_Service_Walletobjects_AddMessageRequest([
|
||||
'message' => new Google_Service_Walletobjects_Message([
|
||||
$message = new AddMessageRequest([
|
||||
'message' => new Message([
|
||||
'header' => $header,
|
||||
'body' => $body
|
||||
])
|
||||
@@ -618,16 +634,16 @@ class DemoTransit
|
||||
{
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/tickets/transit-passes/qr-code/rest/v1/transitclass
|
||||
$newClass = new Google_Service_Walletobjects_TransitClass([
|
||||
$newClass = new TransitClass([
|
||||
'id' => "{$issuerId}.{$classSuffix}",
|
||||
'issuerName' => 'Issuer name',
|
||||
'reviewStatus' => 'UNDER_REVIEW',
|
||||
'logo' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'logo' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://live.staticflickr.com/65535/48690277162_cd05f03f4d_o.png'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Logo description'
|
||||
])
|
||||
@@ -638,36 +654,36 @@ class DemoTransit
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/tickets/transit-passes/qr-code/rest/v1/transitobject
|
||||
$newObject = new Google_Service_Walletobjects_TransitObject([
|
||||
$newObject = new TransitObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -675,13 +691,13 @@ class DemoTransit
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -690,12 +706,12 @@ class DemoTransit
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'locations' => [
|
||||
new Google_Service_Walletobjects_LatLongPoint([
|
||||
new LatLongPoint([
|
||||
'latitude' => 37.424015499999996,
|
||||
'longitude' => -122.09259560000001
|
||||
])
|
||||
@@ -703,25 +719,25 @@ class DemoTransit
|
||||
'passengerType' => 'SINGLE_PASSENGER',
|
||||
'passengerNames' => 'Passenger names',
|
||||
'tripType' => 'ONE_WAY',
|
||||
'ticketLeg' => new Google_Service_Walletobjects_TicketLeg([
|
||||
'ticketLeg' => new TicketLeg([
|
||||
'originStationCode' => 'LA',
|
||||
'originName' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'originName' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Origin name'
|
||||
])
|
||||
]),
|
||||
'destinationStationCode' => 'SFO',
|
||||
'destinationName' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'destinationName' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Destination name'
|
||||
])
|
||||
]),
|
||||
'departureDateTime' => '2020-04-12T16:20:50.52Z',
|
||||
'arrivalDateTime' => '2020-04-12T20:20:50.52Z',
|
||||
'fareName' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'fareName' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Fare name'
|
||||
])
|
||||
@@ -889,36 +905,36 @@ class DemoTransit
|
||||
|
||||
// See link below for more information on required properties
|
||||
// https://developers.google.com/wallet/tickets/transit-passes/qr-code/rest/v1/transitobject
|
||||
$batchObject = new Google_Service_Walletobjects_TransitObject([
|
||||
$batchObject = new TransitObject([
|
||||
'id' => "{$issuerId}.{$objectSuffix}",
|
||||
'classId' => "{$issuerId}.{$classSuffix}",
|
||||
'state' => 'ACTIVE',
|
||||
'heroImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
'heroImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Hero image description'
|
||||
])
|
||||
])
|
||||
]),
|
||||
'textModulesData' => [
|
||||
new Google_Service_Walletobjects_TextModuleData([
|
||||
new TextModuleData([
|
||||
'header' => 'Text module header',
|
||||
'body' => 'Text module body',
|
||||
'id' => 'TEXT_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'linksModuleData' => new Google_Service_Walletobjects_LinksModuleData([
|
||||
'linksModuleData' => new LinksModuleData([
|
||||
'uris' => [
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'http://maps.google.com/',
|
||||
'description' => 'Link module URI description',
|
||||
'id' => 'LINK_MODULE_URI_ID'
|
||||
]),
|
||||
new Google_Service_Walletobjects_Uri([
|
||||
new Uri([
|
||||
'uri' => 'tel:6505555555',
|
||||
'description' => 'Link module tel description',
|
||||
'id' => 'LINK_MODULE_TEL_ID'
|
||||
@@ -926,13 +942,13 @@ class DemoTransit
|
||||
]
|
||||
]),
|
||||
'imageModulesData' => [
|
||||
new Google_Service_Walletobjects_ImageModuleData([
|
||||
'mainImage' => new Google_Service_Walletobjects_Image([
|
||||
'sourceUri' => new Google_Service_Walletobjects_ImageUri([
|
||||
new ImageModuleData([
|
||||
'mainImage' => new Image([
|
||||
'sourceUri' => new ImageUri([
|
||||
'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
|
||||
]),
|
||||
'contentDescription' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'contentDescription' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Image module description'
|
||||
])
|
||||
@@ -941,12 +957,12 @@ class DemoTransit
|
||||
'id' => 'IMAGE_MODULE_ID'
|
||||
])
|
||||
],
|
||||
'barcode' => new Google_Service_Walletobjects_Barcode([
|
||||
'barcode' => new Barcode([
|
||||
'type' => 'QR_CODE',
|
||||
'value' => 'QR code value'
|
||||
]),
|
||||
'locations' => [
|
||||
new Google_Service_Walletobjects_LatLongPoint([
|
||||
new LatLongPoint([
|
||||
'latitude' => 37.424015499999996,
|
||||
'longitude' => -122.09259560000001
|
||||
])
|
||||
@@ -954,25 +970,25 @@ class DemoTransit
|
||||
'passengerType' => 'SINGLE_PASSENGER',
|
||||
'passengerNames' => 'Passenger names',
|
||||
'tripType' => 'ONE_WAY',
|
||||
'ticketLeg' => new Google_Service_Walletobjects_TicketLeg([
|
||||
'ticketLeg' => new TicketLeg([
|
||||
'originStationCode' => 'LA',
|
||||
'originName' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'originName' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Origin name'
|
||||
])
|
||||
]),
|
||||
'destinationStationCode' => 'SFO',
|
||||
'destinationName' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'destinationName' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Destination name'
|
||||
])
|
||||
]),
|
||||
'departureDateTime' => '2020-04-12T16:20:50.52Z',
|
||||
'arrivalDateTime' => '2020-04-12T20:20:50.52Z',
|
||||
'fareName' => new Google_Service_Walletobjects_LocalizedString([
|
||||
'defaultValue' => new Google_Service_Walletobjects_TranslatedString([
|
||||
'fareName' => new LocalizedString([
|
||||
'defaultValue' => new TranslatedString([
|
||||
'language' => 'en-US',
|
||||
'value' => 'Fare name'
|
||||
])
|
||||
|
||||
@@ -4,6 +4,7 @@ verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
googleapiclient = "*"
|
||||
google-auth = "*"
|
||||
requests = "*"
|
||||
|
||||
|
||||
62
python/demo.py
Normal file
62
python/demo.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import os
|
||||
|
||||
from demo_eventticket import DemoEventTicket
|
||||
from demo_flight import DemoFlight
|
||||
from demo_generic import DemoGeneric
|
||||
from demo_giftcard import DemoGiftCard
|
||||
from demo_loyalty import DemoLoyalty
|
||||
from demo_offer import DemoOffer
|
||||
from demo_transit import DemoTransit
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Create a demo class instance
|
||||
# Creates the authenticated HTTP client
|
||||
demo = DemoTransit() # change to demo a different pass type
|
||||
|
||||
issuer_id = os.environ.get("WALLET_ISSUER_ID", "your-issuer-id")
|
||||
class_suffix = os.environ.get("WALLET_CLASS_SUFFIX", "your-class-suffix") + demo.__class__.__name__
|
||||
object_suffix = os.environ.get("WALLET_OBJECT_SUFFIX", "your-object-suffix") + demo.__class__.__name__
|
||||
|
||||
# Create a pass class
|
||||
demo.create_class(issuer_id=issuer_id,
|
||||
class_suffix=class_suffix)
|
||||
|
||||
# Update a pass class
|
||||
demo.update_class(issuer_id=issuer_id,
|
||||
class_suffix=class_suffix)
|
||||
|
||||
# Patch a pass class
|
||||
demo.patch_class(issuer_id=issuer_id,
|
||||
class_suffix=class_suffix)
|
||||
|
||||
# Create a pass object
|
||||
demo.create_object(issuer_id=issuer_id,
|
||||
class_suffix=class_suffix,
|
||||
object_suffix=object_suffix)
|
||||
|
||||
# Update a pass object
|
||||
demo.update_object(issuer_id=issuer_id,
|
||||
object_suffix=object_suffix)
|
||||
|
||||
# Patch a pass object
|
||||
demo.patch_object(issuer_id=issuer_id,
|
||||
object_suffix=object_suffix)
|
||||
|
||||
# Expire a pass object
|
||||
demo.expire_object(issuer_id=issuer_id,
|
||||
object_suffix=object_suffix)
|
||||
|
||||
# Create an "Add to Google Wallet" link
|
||||
# that generates a new pass class and object
|
||||
demo.create_jwt_new_objects(issuer_id=issuer_id,
|
||||
class_suffix=class_suffix,
|
||||
object_suffix=object_suffix)
|
||||
|
||||
# Create an "Add to Google Wallet" link
|
||||
# that references existing pass classes and objects
|
||||
demo.create_jwt_existing_objects(issuer_id=issuer_id)
|
||||
|
||||
# Create pass objects in batch
|
||||
demo.batch_create_objects(issuer_id=issuer_id,
|
||||
class_suffix=class_suffix)
|
||||
@@ -21,7 +21,8 @@ import json
|
||||
import os
|
||||
import uuid
|
||||
|
||||
from google.auth.transport.requests import AuthorizedSession
|
||||
from googleapiclient.discovery import build
|
||||
from googleapiclient.errors import HttpError
|
||||
from google.oauth2.service_account import Credentials
|
||||
from google.auth import jwt, crypt
|
||||
# [END imports]
|
||||
@@ -39,11 +40,6 @@ class DemoEventTicket:
|
||||
def __init__(self):
|
||||
self.key_file_path = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS',
|
||||
'/path/to/key.json')
|
||||
self.base_url = 'https://walletobjects.googleapis.com/walletobjects/v1'
|
||||
self.batch_url = 'https://walletobjects.googleapis.com/batch'
|
||||
self.class_url = f'{self.base_url}/eventTicketClass'
|
||||
self.object_url = f'{self.base_url}/eventTicketObject'
|
||||
|
||||
# Set up authenticated client
|
||||
self.auth()
|
||||
|
||||
@@ -56,7 +52,7 @@ class DemoEventTicket:
|
||||
self.key_file_path,
|
||||
scopes=['https://www.googleapis.com/auth/wallet_object.issuer'])
|
||||
|
||||
self.http_client = AuthorizedSession(self.credentials)
|
||||
self.client = build('walletobjects', 'v1', credentials=self.credentials)
|
||||
|
||||
# [END auth]
|
||||
|
||||
@@ -73,16 +69,16 @@ class DemoEventTicket:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 200:
|
||||
try:
|
||||
self.client.eventticketclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
print(f'Class {issuer_id}.{class_suffix} already exists!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# See link below for more information on required properties
|
||||
# https://developers.google.com/wallet/tickets/events/rest/v1/eventticketclass
|
||||
@@ -99,12 +95,12 @@ class DemoEventTicket:
|
||||
'reviewStatus': 'UNDER_REVIEW'
|
||||
}
|
||||
|
||||
response = self.http_client.post(url=self.class_url, json=new_class)
|
||||
response = self.client.eventticketclass().insert(body=new_class).execute()
|
||||
|
||||
print('Class insert response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END createClass]
|
||||
|
||||
@@ -123,19 +119,19 @@ class DemoEventTicket:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
try:
|
||||
response = self.client.eventticketclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# Class exists
|
||||
updated_class = response.json()
|
||||
updated_class = response
|
||||
|
||||
# Update the class by adding a homepage
|
||||
updated_class['homepageUri'] = {
|
||||
@@ -146,14 +142,14 @@ class DemoEventTicket:
|
||||
# Note: reviewStatus must be 'UNDER_REVIEW' or 'DRAFT' for updates
|
||||
updated_class['reviewStatus'] = 'UNDER_REVIEW'
|
||||
|
||||
response = self.http_client.put(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}',
|
||||
json=updated_class)
|
||||
response = self.client.eventticketclass().update(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body=updated_class).execute()
|
||||
|
||||
print('Class update response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END updateClass]
|
||||
|
||||
@@ -172,16 +168,16 @@ class DemoEventTicket:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
try:
|
||||
response = self.client.eventticketclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# Patch the class by adding a homepage
|
||||
patch_body = {
|
||||
@@ -194,13 +190,14 @@ class DemoEventTicket:
|
||||
'reviewStatus': 'UNDER_REVIEW'
|
||||
}
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}', json=patch_body)
|
||||
response = self.client.eventticketclass().patch(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Class patch response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END patchClass]
|
||||
|
||||
@@ -220,28 +217,28 @@ class DemoEventTicket:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
try:
|
||||
response = self.client.eventticketclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
response = self.http_client.post(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}/addMessage',
|
||||
json={'message': {
|
||||
response = self.client.eventticketclass().addmessage(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body={'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
}})
|
||||
}}).execute()
|
||||
|
||||
print('Class addMessage response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END addMessageClass]
|
||||
|
||||
@@ -260,16 +257,15 @@ class DemoEventTicket:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 200:
|
||||
try:
|
||||
self.client.eventticketobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
print(f'Object {issuer_id}.{object_suffix} already exists!')
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# See link below for more information on required properties
|
||||
@@ -360,12 +356,12 @@ class DemoEventTicket:
|
||||
}
|
||||
|
||||
# Create the object
|
||||
response = self.http_client.post(url=self.object_url, json=new_object)
|
||||
response = self.client.eventticketobject().insert(body=new_object).execute()
|
||||
|
||||
print('Object insert response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END createObject]
|
||||
|
||||
@@ -384,19 +380,19 @@ class DemoEventTicket:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.eventticketobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Object exists
|
||||
updated_object = response.json()
|
||||
updated_object = response
|
||||
|
||||
# Update the object by adding a link
|
||||
new_link = {
|
||||
@@ -407,14 +403,14 @@ class DemoEventTicket:
|
||||
updated_object['linksModuleData'] = {'uris': []}
|
||||
updated_object['linksModuleData']['uris'].append(new_link)
|
||||
|
||||
response = self.http_client.put(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=updated_object)
|
||||
response = self.client.eventticketobject().update(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=updated_object).execute()
|
||||
|
||||
print('Object update response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END updateObject]
|
||||
|
||||
@@ -431,19 +427,19 @@ class DemoEventTicket:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.eventticketobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Object exists
|
||||
existing_object = response.json()
|
||||
existing_object = response
|
||||
|
||||
# Patch the object by adding a link
|
||||
patch_body = {}
|
||||
@@ -458,14 +454,14 @@ class DemoEventTicket:
|
||||
patch_body['linksModuleData'] = {'uris': []}
|
||||
patch_body['linksModuleData']['uris'].append(new_link)
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=patch_body)
|
||||
response = self.client.eventticketobject().patch(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Object patch response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END patchObject]
|
||||
|
||||
@@ -485,28 +481,28 @@ class DemoEventTicket:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.eventticketobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Patch the object, setting the pass as expired
|
||||
patch_body = {'state': 'EXPIRED'}
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=patch_body)
|
||||
response = self.client.eventticketobject().patch(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Object expiration response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END expireObject]
|
||||
|
||||
@@ -526,28 +522,28 @@ class DemoEventTicket:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
try:
|
||||
response = self.client.eventticketobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
response = self.http_client.post(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}/addMessage',
|
||||
json={'message': {
|
||||
response = self.client.eventticketobject().addmessage(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body={'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
}})
|
||||
}}).execute()
|
||||
|
||||
print('Object addMessage response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END addMessageObject]
|
||||
|
||||
@@ -797,7 +793,7 @@ class DemoEventTicket:
|
||||
issuer_id (str): The issuer ID being used for this request.
|
||||
class_suffix (str): Developer-defined unique ID for this pass class.
|
||||
"""
|
||||
data = ''
|
||||
batch = self.client.new_batch_http_request()
|
||||
|
||||
# Example: Generate three new pass objects
|
||||
for _ in range(3):
|
||||
@@ -891,25 +887,11 @@ class DemoEventTicket:
|
||||
'ticketNumber': 'Ticket number'
|
||||
}
|
||||
|
||||
data += '--batch_createobjectbatch\n'
|
||||
data += 'Content-Type: application/json\n\n'
|
||||
data += 'POST /walletobjects/v1/eventTicketObject/\n\n'
|
||||
|
||||
data += json.dumps(batch_object) + '\n\n'
|
||||
|
||||
data += '--batch_createobjectbatch--'
|
||||
batch.add(self.client.eventticketobject().insert(body=batch_object))
|
||||
|
||||
# Invoke the batch API calls
|
||||
response = self.http_client.post(
|
||||
url=self.batch_url, # https://walletobjects.googleapis.com/batch
|
||||
data=data,
|
||||
headers={
|
||||
# `boundary` is the delimiter between API calls in the batch request
|
||||
'Content-Type':
|
||||
'multipart/mixed; boundary=batch_createobjectbatch'
|
||||
})
|
||||
response = batch.execute()
|
||||
|
||||
print('Batch insert response')
|
||||
print(response.content.decode('UTF-8'))
|
||||
print('Batch complete')
|
||||
|
||||
# [END batch]
|
||||
|
||||
@@ -21,7 +21,8 @@ import json
|
||||
import os
|
||||
import uuid
|
||||
|
||||
from google.auth.transport.requests import AuthorizedSession
|
||||
from googleapiclient.discovery import build
|
||||
from googleapiclient.errors import HttpError
|
||||
from google.oauth2.service_account import Credentials
|
||||
from google.auth import jwt, crypt
|
||||
# [END imports]
|
||||
@@ -39,11 +40,6 @@ class DemoFlight:
|
||||
def __init__(self):
|
||||
self.key_file_path = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS',
|
||||
'/path/to/key.json')
|
||||
self.base_url = 'https://walletobjects.googleapis.com/walletobjects/v1'
|
||||
self.batch_url = 'https://walletobjects.googleapis.com/batch'
|
||||
self.class_url = f'{self.base_url}/flightClass'
|
||||
self.object_url = f'{self.base_url}/flightObject'
|
||||
|
||||
# Set up authenticated client
|
||||
self.auth()
|
||||
|
||||
@@ -56,7 +52,7 @@ class DemoFlight:
|
||||
self.key_file_path,
|
||||
scopes=['https://www.googleapis.com/auth/wallet_object.issuer'])
|
||||
|
||||
self.http_client = AuthorizedSession(self.credentials)
|
||||
self.client = build('walletobjects', 'v1', credentials=self.credentials)
|
||||
|
||||
# [END auth]
|
||||
|
||||
@@ -73,16 +69,16 @@ class DemoFlight:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 200:
|
||||
try:
|
||||
self.client.flightclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
print(f'Class {issuer_id}.{class_suffix} already exists!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# See link below for more information on required properties
|
||||
# https://developers.google.com/wallet/tickets/events/rest/v1/eventticketclass
|
||||
@@ -109,12 +105,12 @@ class DemoFlight:
|
||||
}
|
||||
}
|
||||
|
||||
response = self.http_client.post(url=self.class_url, json=new_class)
|
||||
response = self.client.flightclass().insert(body=new_class).execute()
|
||||
|
||||
print('Class insert response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END createClass]
|
||||
|
||||
@@ -133,19 +129,19 @@ class DemoFlight:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
try:
|
||||
response = self.client.flightclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# Class exists
|
||||
updated_class = response.json()
|
||||
updated_class = response
|
||||
|
||||
# Update the class by adding a homepage
|
||||
updated_class['homepageUri'] = {
|
||||
@@ -156,14 +152,14 @@ class DemoFlight:
|
||||
# Note: reviewStatus must be 'UNDER_REVIEW' or 'DRAFT' for updates
|
||||
updated_class['reviewStatus'] = 'UNDER_REVIEW'
|
||||
|
||||
response = self.http_client.put(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}',
|
||||
json=updated_class)
|
||||
response = self.client.flightclass().update(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body=updated_class).execute()
|
||||
|
||||
print('Class update response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END updateClass]
|
||||
|
||||
@@ -182,16 +178,16 @@ class DemoFlight:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
try:
|
||||
response = self.client.flightclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# Patch the class by adding a homepage
|
||||
patch_body = {
|
||||
@@ -204,13 +200,14 @@ class DemoFlight:
|
||||
'reviewStatus': 'UNDER_REVIEW'
|
||||
}
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}', json=patch_body)
|
||||
response = self.client.flightclass().patch(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Class patch response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END patchClass]
|
||||
|
||||
@@ -230,28 +227,28 @@ class DemoFlight:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
try:
|
||||
response = self.client.flightclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
response = self.http_client.post(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}/addMessage',
|
||||
json={'message': {
|
||||
response = self.client.flightclass().addmessage(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body={'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
}})
|
||||
}}).execute()
|
||||
|
||||
print('Class addMessage response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END addMessageClass]
|
||||
|
||||
@@ -270,16 +267,15 @@ class DemoFlight:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 200:
|
||||
try:
|
||||
self.client.flightobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
print(f'Object {issuer_id}.{object_suffix} already exists!')
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# See link below for more information on required properties
|
||||
@@ -350,12 +346,12 @@ class DemoFlight:
|
||||
}
|
||||
|
||||
# Create the object
|
||||
response = self.http_client.post(url=self.object_url, json=new_object)
|
||||
response = self.client.flightobject().insert(body=new_object).execute()
|
||||
|
||||
print('Object insert response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END createObject]
|
||||
|
||||
@@ -374,19 +370,19 @@ class DemoFlight:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.flightobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Object exists
|
||||
updated_object = response.json()
|
||||
updated_object = response
|
||||
|
||||
# Update the object by adding a link
|
||||
new_link = {
|
||||
@@ -397,14 +393,14 @@ class DemoFlight:
|
||||
updated_object['linksModuleData'] = {'uris': []}
|
||||
updated_object['linksModuleData']['uris'].append(new_link)
|
||||
|
||||
response = self.http_client.put(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=updated_object)
|
||||
response = self.client.flightobject().update(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=updated_object).execute()
|
||||
|
||||
print('Object update response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END updateObject]
|
||||
|
||||
@@ -421,19 +417,19 @@ class DemoFlight:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.flightobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Object exists
|
||||
existing_object = response.json()
|
||||
existing_object = response
|
||||
|
||||
# Patch the object by adding a link
|
||||
patch_body = {}
|
||||
@@ -448,14 +444,14 @@ class DemoFlight:
|
||||
patch_body['linksModuleData'] = {'uris': []}
|
||||
patch_body['linksModuleData']['uris'].append(new_link)
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=patch_body)
|
||||
response = self.client.flightobject().patch(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Object patch response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END patchObject]
|
||||
|
||||
@@ -475,28 +471,28 @@ class DemoFlight:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.flightobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Patch the object, setting the pass as expired
|
||||
patch_body = {'state': 'EXPIRED'}
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=patch_body)
|
||||
response = self.client.flightobject().patch(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Object expiration response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END expireObject]
|
||||
|
||||
@@ -516,28 +512,28 @@ class DemoFlight:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
try:
|
||||
response = self.client.flightobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
response = self.http_client.post(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}/addMessage',
|
||||
json={'message': {
|
||||
response = self.client.flightobject().addmessage(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body={'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
}})
|
||||
}}).execute()
|
||||
|
||||
print('Object addMessage response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END addMessageObject]
|
||||
|
||||
@@ -778,7 +774,7 @@ class DemoFlight:
|
||||
issuer_id (str): The issuer ID being used for this request.
|
||||
class_suffix (str): Developer-defined unique ID for this pass class.
|
||||
"""
|
||||
data = ''
|
||||
batch = self.client.new_batch_http_request()
|
||||
|
||||
# Example: Generate three new pass objects
|
||||
for _ in range(3):
|
||||
@@ -852,25 +848,11 @@ class DemoFlight:
|
||||
}
|
||||
}
|
||||
|
||||
data += '--batch_createobjectbatch\n'
|
||||
data += 'Content-Type: application/json\n\n'
|
||||
data += 'POST /walletobjects/v1/flightObject/\n\n'
|
||||
|
||||
data += json.dumps(batch_object) + '\n\n'
|
||||
|
||||
data += '--batch_createobjectbatch--'
|
||||
batch.add(self.client.flightobject().insert(body=batch_object))
|
||||
|
||||
# Invoke the batch API calls
|
||||
response = self.http_client.post(
|
||||
url=self.batch_url, # https://walletobjects.googleapis.com/batch
|
||||
data=data,
|
||||
headers={
|
||||
# `boundary` is the delimiter between API calls in the batch request
|
||||
'Content-Type':
|
||||
'multipart/mixed; boundary=batch_createobjectbatch'
|
||||
})
|
||||
response = batch.execute()
|
||||
|
||||
print('Batch insert response')
|
||||
print(response.content.decode('UTF-8'))
|
||||
print('Batch complete')
|
||||
|
||||
# [END batch]
|
||||
|
||||
@@ -21,7 +21,8 @@ import json
|
||||
import os
|
||||
import uuid
|
||||
|
||||
from google.auth.transport.requests import AuthorizedSession
|
||||
from googleapiclient.discovery import build
|
||||
from googleapiclient.errors import HttpError
|
||||
from google.oauth2.service_account import Credentials
|
||||
from google.auth import jwt, crypt
|
||||
# [END imports]
|
||||
@@ -39,11 +40,6 @@ class DemoGeneric:
|
||||
def __init__(self):
|
||||
self.key_file_path = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS',
|
||||
'/path/to/key.json')
|
||||
self.base_url = 'https://walletobjects.googleapis.com/walletobjects/v1'
|
||||
self.batch_url = 'https://walletobjects.googleapis.com/batch'
|
||||
self.class_url = f'{self.base_url}/genericClass'
|
||||
self.object_url = f'{self.base_url}/genericObject'
|
||||
|
||||
# Set up authenticated client
|
||||
self.auth()
|
||||
|
||||
@@ -56,7 +52,7 @@ class DemoGeneric:
|
||||
self.key_file_path,
|
||||
scopes=['https://www.googleapis.com/auth/wallet_object.issuer'])
|
||||
|
||||
self.http_client = AuthorizedSession(self.credentials)
|
||||
self.client = build('walletobjects', 'v1', credentials=self.credentials)
|
||||
|
||||
# [END auth]
|
||||
|
||||
@@ -73,27 +69,27 @@ class DemoGeneric:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 200:
|
||||
try:
|
||||
self.client.genericclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
print(f'Class {issuer_id}.{class_suffix} already exists!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# See link below for more information on required properties
|
||||
# https://developers.google.com/wallet/generic/rest/v1/genericclass
|
||||
new_class = {'id': f'{issuer_id}.{class_suffix}'}
|
||||
|
||||
response = self.http_client.post(url=self.class_url, json=new_class)
|
||||
response = self.client.genericclass().insert(body=new_class).execute()
|
||||
|
||||
print('Class insert response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END createClass]
|
||||
|
||||
@@ -112,19 +108,19 @@ class DemoGeneric:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
try:
|
||||
response = self.client.genericclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# Class exists
|
||||
updated_class = response.json()
|
||||
updated_class = response
|
||||
|
||||
# Update the class by adding a link
|
||||
new_link = {
|
||||
@@ -138,14 +134,14 @@ class DemoGeneric:
|
||||
# Note: reviewStatus must be 'UNDER_REVIEW' or 'DRAFT' for updates
|
||||
updated_class['reviewStatus'] = 'UNDER_REVIEW'
|
||||
|
||||
response = self.http_client.put(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}',
|
||||
json=updated_class)
|
||||
response = self.client.genericclass().update(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body=updated_class).execute()
|
||||
|
||||
print('Class update response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END updateClass]
|
||||
|
||||
@@ -164,19 +160,19 @@ class DemoGeneric:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
try:
|
||||
response = self.client.genericclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# Class exists
|
||||
existing_class = response.json()
|
||||
existing_class = response
|
||||
|
||||
# Patch the class by adding a link
|
||||
patch_body = {}
|
||||
@@ -195,57 +191,17 @@ class DemoGeneric:
|
||||
# Note: reviewStatus must be 'UNDER_REVIEW' or 'DRAFT' for patches
|
||||
patch_body['reviewStatus'] = 'UNDER_REVIEW'
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}', json=patch_body)
|
||||
response = self.client.genericclass().patch(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Class patch response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END patchClass]
|
||||
|
||||
# [START addMessageClass]
|
||||
def add_class_message(self, issuer_id: str, class_suffix: str, header: str,
|
||||
body: str) -> str:
|
||||
"""Add a message to a pass class.
|
||||
|
||||
Args:
|
||||
issuer_id (str): The issuer ID being used for this request.
|
||||
class_suffix (str): Developer-defined unique ID for this pass class.
|
||||
header (str): The message header.
|
||||
body (str): The message body.
|
||||
|
||||
Returns:
|
||||
The pass class ID: f"{issuer_id}.{class_suffix}"
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
response = self.http_client.post(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}/addMessage',
|
||||
json={'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
}})
|
||||
|
||||
print('Class addMessage response')
|
||||
print(response.text)
|
||||
|
||||
return response.json().get('id')
|
||||
|
||||
# [END addMessageClass]
|
||||
|
||||
# [START createObject]
|
||||
def create_object(self, issuer_id: str, class_suffix: str,
|
||||
object_suffix: str) -> str:
|
||||
@@ -261,16 +217,15 @@ class DemoGeneric:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 200:
|
||||
try:
|
||||
self.client.genericobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
print(f'Object {issuer_id}.{object_suffix} already exists!')
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# See link below for more information on required properties
|
||||
@@ -354,12 +309,12 @@ class DemoGeneric:
|
||||
}
|
||||
|
||||
# Create the object
|
||||
response = self.http_client.post(url=self.object_url, json=new_object)
|
||||
response = self.client.genericobject().insert(body=new_object).execute()
|
||||
|
||||
print('Object insert response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END createObject]
|
||||
|
||||
@@ -378,19 +333,19 @@ class DemoGeneric:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.genericobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Object exists
|
||||
updated_object = response.json()
|
||||
updated_object = response
|
||||
|
||||
# Update the object by adding a link
|
||||
new_link = {
|
||||
@@ -401,14 +356,14 @@ class DemoGeneric:
|
||||
updated_object['linksModuleData'] = {'uris': []}
|
||||
updated_object['linksModuleData']['uris'].append(new_link)
|
||||
|
||||
response = self.http_client.put(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=updated_object)
|
||||
response = self.client.genericobject().update(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=updated_object).execute()
|
||||
|
||||
print('Object update response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END updateObject]
|
||||
|
||||
@@ -425,19 +380,19 @@ class DemoGeneric:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.genericobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Object exists
|
||||
existing_object = response.json()
|
||||
existing_object = response
|
||||
|
||||
# Patch the object by adding a link
|
||||
patch_body = {}
|
||||
@@ -452,14 +407,14 @@ class DemoGeneric:
|
||||
patch_body['linksModuleData'] = {'uris': []}
|
||||
patch_body['linksModuleData']['uris'].append(new_link)
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=patch_body)
|
||||
response = self.client.genericobject().patch(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Object patch response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END patchObject]
|
||||
|
||||
@@ -479,72 +434,31 @@ class DemoGeneric:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.genericobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Patch the object, setting the pass as expired
|
||||
patch_body = {'state': 'EXPIRED'}
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=patch_body)
|
||||
response = self.client.genericobject().patch(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Object expiration response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END expireObject]
|
||||
|
||||
# [START addMessageObject]
|
||||
def add_object_message(self, issuer_id: str, object_suffix: str,
|
||||
header: str, body: str) -> str:
|
||||
"""Add a message to a pass object.
|
||||
|
||||
Args:
|
||||
issuer_id (str): The issuer ID being used for this request.
|
||||
object_suffix (str): Developer-defined unique ID for this pass object.
|
||||
header (str): The message header.
|
||||
body (str): The message body.
|
||||
|
||||
Returns:
|
||||
The pass class ID: f"{issuer_id}.{class_suffix}"
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
response = self.http_client.post(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}/addMessage',
|
||||
json={'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
}})
|
||||
|
||||
print('Object addMessage response')
|
||||
print(response.text)
|
||||
|
||||
return response.json().get('id')
|
||||
|
||||
# [END addMessageObject]
|
||||
|
||||
# [START jwtNew]
|
||||
def create_jwt_new_objects(self, issuer_id: str, class_suffix: str,
|
||||
object_suffix: str) -> str:
|
||||
@@ -774,7 +688,7 @@ class DemoGeneric:
|
||||
issuer_id (str): The issuer ID being used for this request.
|
||||
class_suffix (str): Developer-defined unique ID for this pass class.
|
||||
"""
|
||||
data = ''
|
||||
batch = self.client.new_batch_http_request()
|
||||
|
||||
# Example: Generate three new pass objects
|
||||
for _ in range(3):
|
||||
@@ -861,25 +775,11 @@ class DemoGeneric:
|
||||
}
|
||||
}
|
||||
|
||||
data += '--batch_createobjectbatch\n'
|
||||
data += 'Content-Type: application/json\n\n'
|
||||
data += 'POST /walletobjects/v1/genericObject/\n\n'
|
||||
|
||||
data += json.dumps(batch_object) + '\n\n'
|
||||
|
||||
data += '--batch_createobjectbatch--'
|
||||
batch.add(self.client.genericobject().insert(body=batch_object))
|
||||
|
||||
# Invoke the batch API calls
|
||||
response = self.http_client.post(
|
||||
url=self.batch_url, # https://walletobjects.googleapis.com/batch
|
||||
data=data,
|
||||
headers={
|
||||
# `boundary` is the delimiter between API calls in the batch request
|
||||
'Content-Type':
|
||||
'multipart/mixed; boundary=batch_createobjectbatch'
|
||||
})
|
||||
response = batch.execute()
|
||||
|
||||
print('Batch insert response')
|
||||
print(response.content.decode('UTF-8'))
|
||||
print('Batch complete')
|
||||
|
||||
# [END batch]
|
||||
|
||||
@@ -21,7 +21,8 @@ import json
|
||||
import os
|
||||
import uuid
|
||||
|
||||
from google.auth.transport.requests import AuthorizedSession
|
||||
from googleapiclient.discovery import build
|
||||
from googleapiclient.errors import HttpError
|
||||
from google.oauth2.service_account import Credentials
|
||||
from google.auth import jwt, crypt
|
||||
# [END imports]
|
||||
@@ -39,11 +40,6 @@ class DemoGiftCard:
|
||||
def __init__(self):
|
||||
self.key_file_path = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS',
|
||||
'/path/to/key.json')
|
||||
self.base_url = 'https://walletobjects.googleapis.com/walletobjects/v1'
|
||||
self.batch_url = 'https://walletobjects.googleapis.com/batch'
|
||||
self.class_url = f'{self.base_url}/giftCardClass'
|
||||
self.object_url = f'{self.base_url}/giftCardObject'
|
||||
|
||||
# Set up authenticated client
|
||||
self.auth()
|
||||
|
||||
@@ -56,7 +52,7 @@ class DemoGiftCard:
|
||||
self.key_file_path,
|
||||
scopes=['https://www.googleapis.com/auth/wallet_object.issuer'])
|
||||
|
||||
self.http_client = AuthorizedSession(self.credentials)
|
||||
self.client = build('walletobjects', 'v1', credentials=self.credentials)
|
||||
|
||||
# [END auth]
|
||||
|
||||
@@ -73,16 +69,16 @@ class DemoGiftCard:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 200:
|
||||
try:
|
||||
self.client.giftcardclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
print(f'Class {issuer_id}.{class_suffix} already exists!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# See link below for more information on required properties
|
||||
# https://developers.google.com/wallet/retail/gift-cards/rest/v1/giftcardclass
|
||||
@@ -92,12 +88,12 @@ class DemoGiftCard:
|
||||
'reviewStatus': 'UNDER_REVIEW'
|
||||
}
|
||||
|
||||
response = self.http_client.post(url=self.class_url, json=new_class)
|
||||
response = self.client.giftcardclass().insert(body=new_class).execute()
|
||||
|
||||
print('Class insert response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END createClass]
|
||||
|
||||
@@ -116,19 +112,19 @@ class DemoGiftCard:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
try:
|
||||
response = self.client.giftcardclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# Class exists
|
||||
updated_class = response.json()
|
||||
updated_class = response
|
||||
|
||||
# Update the class by adding a homepage
|
||||
updated_class['homepageUri'] = {
|
||||
@@ -139,14 +135,14 @@ class DemoGiftCard:
|
||||
# Note: reviewStatus must be 'UNDER_REVIEW' or 'DRAFT' for updates
|
||||
updated_class['reviewStatus'] = 'UNDER_REVIEW'
|
||||
|
||||
response = self.http_client.put(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}',
|
||||
json=updated_class)
|
||||
response = self.client.giftcardclass().update(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body=updated_class).execute()
|
||||
|
||||
print('Class update response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END updateClass]
|
||||
|
||||
@@ -165,16 +161,16 @@ class DemoGiftCard:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
try:
|
||||
response = self.client.giftcardclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# Patch the class by adding a homepage
|
||||
patch_body = {
|
||||
@@ -187,13 +183,14 @@ class DemoGiftCard:
|
||||
'reviewStatus': 'UNDER_REVIEW'
|
||||
}
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}', json=patch_body)
|
||||
response = self.client.giftcardclass().patch(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Class patch response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END patchClass]
|
||||
|
||||
@@ -213,28 +210,28 @@ class DemoGiftCard:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
try:
|
||||
response = self.client.giftcardclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
response = self.http_client.post(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}/addMessage',
|
||||
json={'message': {
|
||||
response = self.client.giftcardclass().addmessage(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body={'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
}})
|
||||
}}).execute()
|
||||
|
||||
print('Class addMessage response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END addMessageClass]
|
||||
|
||||
@@ -253,16 +250,15 @@ class DemoGiftCard:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 200:
|
||||
try:
|
||||
self.client.giftcardobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
print(f'Object {issuer_id}.{object_suffix} already exists!')
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# See link below for more information on required properties
|
||||
@@ -334,12 +330,12 @@ class DemoGiftCard:
|
||||
}
|
||||
|
||||
# Create the object
|
||||
response = self.http_client.post(url=self.object_url, json=new_object)
|
||||
response = self.client.giftcardobject().insert(body=new_object).execute()
|
||||
|
||||
print('Object insert response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END createObject]
|
||||
|
||||
@@ -358,19 +354,19 @@ class DemoGiftCard:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.giftcardobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Object exists
|
||||
updated_object = response.json()
|
||||
updated_object = response
|
||||
|
||||
# Update the object by adding a link
|
||||
new_link = {
|
||||
@@ -381,14 +377,14 @@ class DemoGiftCard:
|
||||
updated_object['linksModuleData'] = {'uris': []}
|
||||
updated_object['linksModuleData']['uris'].append(new_link)
|
||||
|
||||
response = self.http_client.put(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=updated_object)
|
||||
response = self.client.giftcardobject().update(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=updated_object).execute()
|
||||
|
||||
print('Object update response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END updateObject]
|
||||
|
||||
@@ -405,19 +401,19 @@ class DemoGiftCard:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.giftcardobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Object exists
|
||||
existing_object = response.json()
|
||||
existing_object = response
|
||||
|
||||
# Patch the object by adding a link
|
||||
patch_body = {}
|
||||
@@ -432,14 +428,14 @@ class DemoGiftCard:
|
||||
patch_body['linksModuleData'] = {'uris': []}
|
||||
patch_body['linksModuleData']['uris'].append(new_link)
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=patch_body)
|
||||
response = self.client.giftcardobject().patch(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Object patch response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END patchObject]
|
||||
|
||||
@@ -459,28 +455,28 @@ class DemoGiftCard:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.giftcardobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Patch the object, setting the pass as expired
|
||||
patch_body = {'state': 'EXPIRED'}
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=patch_body)
|
||||
response = self.client.giftcardobject().patch(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Object expiration response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END expireObject]
|
||||
|
||||
@@ -500,28 +496,28 @@ class DemoGiftCard:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
try:
|
||||
response = self.client.giftcardobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
response = self.http_client.post(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}/addMessage',
|
||||
json={'message': {
|
||||
response = self.client.giftcardobject().addmessage(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body={'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
}})
|
||||
}}).execute()
|
||||
|
||||
print('Object addMessage response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END addMessageObject]
|
||||
|
||||
@@ -746,7 +742,7 @@ class DemoGiftCard:
|
||||
issuer_id (str): The issuer ID being used for this request.
|
||||
class_suffix (str): Developer-defined unique ID for this pass class.
|
||||
"""
|
||||
data = ''
|
||||
batch = self.client.new_batch_http_request()
|
||||
|
||||
# Example: Generate three new pass objects
|
||||
for _ in range(3):
|
||||
@@ -821,25 +817,11 @@ class DemoGiftCard:
|
||||
}
|
||||
}
|
||||
|
||||
data += '--batch_createobjectbatch\n'
|
||||
data += 'Content-Type: application/json\n\n'
|
||||
data += 'POST /walletobjects/v1/giftCardObject/\n\n'
|
||||
|
||||
data += json.dumps(batch_object) + '\n\n'
|
||||
|
||||
data += '--batch_createobjectbatch--'
|
||||
batch.add(self.client.giftcardobject().insert(body=batch_object))
|
||||
|
||||
# Invoke the batch API calls
|
||||
response = self.http_client.post(
|
||||
url=self.batch_url, # https://walletobjects.googleapis.com/batch
|
||||
data=data,
|
||||
headers={
|
||||
# `boundary` is the delimiter between API calls in the batch request
|
||||
'Content-Type':
|
||||
'multipart/mixed; boundary=batch_createobjectbatch'
|
||||
})
|
||||
response = batch.execute()
|
||||
|
||||
print('Batch insert response')
|
||||
print(response.content.decode('UTF-8'))
|
||||
print('Batch complete')
|
||||
|
||||
# [END batch]
|
||||
|
||||
@@ -21,7 +21,8 @@ import json
|
||||
import os
|
||||
import uuid
|
||||
|
||||
from google.auth.transport.requests import AuthorizedSession
|
||||
from googleapiclient.discovery import build
|
||||
from googleapiclient.errors import HttpError
|
||||
from google.oauth2.service_account import Credentials
|
||||
from google.auth import jwt, crypt
|
||||
# [END imports]
|
||||
@@ -39,11 +40,6 @@ class DemoLoyalty:
|
||||
def __init__(self):
|
||||
self.key_file_path = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS',
|
||||
'/path/to/key.json')
|
||||
self.base_url = 'https://walletobjects.googleapis.com/walletobjects/v1'
|
||||
self.batch_url = 'https://walletobjects.googleapis.com/batch'
|
||||
self.class_url = f'{self.base_url}/loyaltyClass'
|
||||
self.object_url = f'{self.base_url}/loyaltyObject'
|
||||
|
||||
# Set up authenticated client
|
||||
self.auth()
|
||||
|
||||
@@ -56,7 +52,7 @@ class DemoLoyalty:
|
||||
self.key_file_path,
|
||||
scopes=['https://www.googleapis.com/auth/wallet_object.issuer'])
|
||||
|
||||
self.http_client = AuthorizedSession(self.credentials)
|
||||
self.client = build('walletobjects', 'v1', credentials=self.credentials)
|
||||
|
||||
# [END auth]
|
||||
|
||||
@@ -73,16 +69,16 @@ class DemoLoyalty:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 200:
|
||||
try:
|
||||
self.client.loyaltyclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
print(f'Class {issuer_id}.{class_suffix} already exists!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# See link below for more information on required properties
|
||||
# https://developers.google.com/wallet/retail/loyalty-cards/rest/v1/loyaltyclass
|
||||
@@ -105,12 +101,12 @@ class DemoLoyalty:
|
||||
}
|
||||
}
|
||||
|
||||
response = self.http_client.post(url=self.class_url, json=new_class)
|
||||
response = self.client.loyaltyclass().insert(body=new_class).execute()
|
||||
|
||||
print('Class insert response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END createClass]
|
||||
|
||||
@@ -129,19 +125,19 @@ class DemoLoyalty:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
try:
|
||||
response = self.client.loyaltyclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# Class exists
|
||||
updated_class = response.json()
|
||||
updated_class = response
|
||||
|
||||
# Update the class by adding a homepage
|
||||
updated_class['homepageUri'] = {
|
||||
@@ -152,14 +148,14 @@ class DemoLoyalty:
|
||||
# Note: reviewStatus must be 'UNDER_REVIEW' or 'DRAFT' for updates
|
||||
updated_class['reviewStatus'] = 'UNDER_REVIEW'
|
||||
|
||||
response = self.http_client.put(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}',
|
||||
json=updated_class)
|
||||
response = self.client.loyaltyclass().update(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body=updated_class).execute()
|
||||
|
||||
print('Class update response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END updateClass]
|
||||
|
||||
@@ -178,16 +174,16 @@ class DemoLoyalty:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
try:
|
||||
response = self.client.loyaltyclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# Patch the class by adding a homepage
|
||||
patch_body = {
|
||||
@@ -200,13 +196,14 @@ class DemoLoyalty:
|
||||
'reviewStatus': 'UNDER_REVIEW'
|
||||
}
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}', json=patch_body)
|
||||
response = self.client.loyaltyclass().patch(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Class patch response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END patchClass]
|
||||
|
||||
@@ -226,28 +223,28 @@ class DemoLoyalty:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
try:
|
||||
response = self.client.loyaltyclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
response = self.http_client.post(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}/addMessage',
|
||||
json={'message': {
|
||||
response = self.client.loyaltyclass().addmessage(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body={'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
}})
|
||||
}}).execute()
|
||||
|
||||
print('Class addMessage response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END addMessageClass]
|
||||
|
||||
@@ -266,16 +263,15 @@ class DemoLoyalty:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 200:
|
||||
try:
|
||||
self.client.loyaltyobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
print(f'Object {issuer_id}.{object_suffix} already exists!')
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# See link below for more information on required properties
|
||||
@@ -346,12 +342,12 @@ class DemoLoyalty:
|
||||
}
|
||||
|
||||
# Create the object
|
||||
response = self.http_client.post(url=self.object_url, json=new_object)
|
||||
response = self.client.loyaltyobject().insert(body=new_object).execute()
|
||||
|
||||
print('Object insert response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END createObject]
|
||||
|
||||
@@ -370,19 +366,19 @@ class DemoLoyalty:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.loyaltyobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Object exists
|
||||
updated_object = response.json()
|
||||
updated_object = response
|
||||
|
||||
# Update the object by adding a link
|
||||
new_link = {
|
||||
@@ -393,14 +389,14 @@ class DemoLoyalty:
|
||||
updated_object['linksModuleData'] = {'uris': []}
|
||||
updated_object['linksModuleData']['uris'].append(new_link)
|
||||
|
||||
response = self.http_client.put(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=updated_object)
|
||||
response = self.client.loyaltyobject().update(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=updated_object).execute()
|
||||
|
||||
print('Object update response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END updateObject]
|
||||
|
||||
@@ -417,19 +413,19 @@ class DemoLoyalty:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.loyaltyobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Object exists
|
||||
existing_object = response.json()
|
||||
existing_object = response
|
||||
|
||||
# Patch the object by adding a link
|
||||
patch_body = {}
|
||||
@@ -444,14 +440,14 @@ class DemoLoyalty:
|
||||
patch_body['linksModuleData'] = {'uris': []}
|
||||
patch_body['linksModuleData']['uris'].append(new_link)
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=patch_body)
|
||||
response = self.client.loyaltyobject().patch(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Object patch response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END patchObject]
|
||||
|
||||
@@ -471,28 +467,28 @@ class DemoLoyalty:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.loyaltyobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Patch the object, setting the pass as expired
|
||||
patch_body = {'state': 'EXPIRED'}
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=patch_body)
|
||||
response = self.client.loyaltyobject().patch(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Object expiration response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END expireObject]
|
||||
|
||||
@@ -512,28 +508,28 @@ class DemoLoyalty:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
try:
|
||||
response = self.client.loyaltyobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
response = self.http_client.post(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}/addMessage',
|
||||
json={'message': {
|
||||
response = self.client.loyaltyobject().addmessage(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body={'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
}})
|
||||
}}).execute()
|
||||
|
||||
print('Object addMessage response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END addMessageObject]
|
||||
|
||||
@@ -770,7 +766,7 @@ class DemoLoyalty:
|
||||
issuer_id (str): The issuer ID being used for this request.
|
||||
class_suffix (str): Developer-defined unique ID for this pass class.
|
||||
"""
|
||||
data = ''
|
||||
batch = self.client.new_batch_http_request()
|
||||
|
||||
# Example: Generate three new pass objects
|
||||
for _ in range(3):
|
||||
@@ -844,25 +840,11 @@ class DemoLoyalty:
|
||||
}
|
||||
}
|
||||
|
||||
data += '--batch_createobjectbatch\n'
|
||||
data += 'Content-Type: application/json\n\n'
|
||||
data += 'POST /walletobjects/v1/loyaltyObject/\n\n'
|
||||
|
||||
data += json.dumps(batch_object) + '\n\n'
|
||||
|
||||
data += '--batch_createobjectbatch--'
|
||||
batch.add(self.client.loyaltyobject().insert(body=batch_object))
|
||||
|
||||
# Invoke the batch API calls
|
||||
response = self.http_client.post(
|
||||
url=self.batch_url, # https://walletobjects.googleapis.com/batch
|
||||
data=data,
|
||||
headers={
|
||||
# `boundary` is the delimiter between API calls in the batch request
|
||||
'Content-Type':
|
||||
'multipart/mixed; boundary=batch_createobjectbatch'
|
||||
})
|
||||
response = batch.execute()
|
||||
|
||||
print('Batch insert response')
|
||||
print(response.content.decode('UTF-8'))
|
||||
print('Batch complete')
|
||||
|
||||
# [END batch]
|
||||
|
||||
@@ -21,7 +21,8 @@ import json
|
||||
import os
|
||||
import uuid
|
||||
|
||||
from google.auth.transport.requests import AuthorizedSession
|
||||
from googleapiclient.discovery import build
|
||||
from googleapiclient.errors import HttpError
|
||||
from google.oauth2.service_account import Credentials
|
||||
from google.auth import jwt, crypt
|
||||
# [END imports]
|
||||
@@ -39,11 +40,6 @@ class DemoOffer:
|
||||
def __init__(self):
|
||||
self.key_file_path = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS',
|
||||
'/path/to/key.json')
|
||||
self.base_url = 'https://walletobjects.googleapis.com/walletobjects/v1'
|
||||
self.batch_url = 'https://walletobjects.googleapis.com/batch'
|
||||
self.class_url = f'{self.base_url}/offerClass'
|
||||
self.object_url = f'{self.base_url}/offerObject'
|
||||
|
||||
# Set up authenticated client
|
||||
self.auth()
|
||||
|
||||
@@ -56,7 +52,7 @@ class DemoOffer:
|
||||
self.key_file_path,
|
||||
scopes=['https://www.googleapis.com/auth/wallet_object.issuer'])
|
||||
|
||||
self.http_client = AuthorizedSession(self.credentials)
|
||||
self.client = build('walletobjects', 'v1', credentials=self.credentials)
|
||||
|
||||
# [END auth]
|
||||
|
||||
@@ -73,16 +69,16 @@ class DemoOffer:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 200:
|
||||
try:
|
||||
self.client.offerclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
print(f'Class {issuer_id}.{class_suffix} already exists!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# See link below for more information on required properties
|
||||
# https://developers.google.com/wallet/retail/offers/rest/v1/offerclass
|
||||
@@ -95,12 +91,12 @@ class DemoOffer:
|
||||
'redemptionChannel': 'ONLINE'
|
||||
}
|
||||
|
||||
response = self.http_client.post(url=self.class_url, json=new_class)
|
||||
response = self.client.offerclass().insert(body=new_class).execute()
|
||||
|
||||
print('Class insert response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END createClass]
|
||||
|
||||
@@ -119,19 +115,19 @@ class DemoOffer:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
try:
|
||||
response = self.client.offerclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# Class exists
|
||||
updated_class = response.json()
|
||||
updated_class = response
|
||||
|
||||
# Update the class by adding a homepage
|
||||
updated_class['homepageUri'] = {
|
||||
@@ -142,14 +138,14 @@ class DemoOffer:
|
||||
# Note: reviewStatus must be 'UNDER_REVIEW' or 'DRAFT' for updates
|
||||
updated_class['reviewStatus'] = 'UNDER_REVIEW'
|
||||
|
||||
response = self.http_client.put(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}',
|
||||
json=updated_class)
|
||||
response = self.client.offerclass().update(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body=updated_class).execute()
|
||||
|
||||
print('Class update response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END updateClass]
|
||||
|
||||
@@ -168,16 +164,16 @@ class DemoOffer:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
try:
|
||||
response = self.client.offerclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# Patch the class by adding a homepage
|
||||
patch_body = {
|
||||
@@ -190,13 +186,14 @@ class DemoOffer:
|
||||
'reviewStatus': 'UNDER_REVIEW'
|
||||
}
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}', json=patch_body)
|
||||
response = self.client.offerclass().patch(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Class patch response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END patchClass]
|
||||
|
||||
@@ -216,28 +213,28 @@ class DemoOffer:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
try:
|
||||
response = self.client.offerclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
response = self.http_client.post(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}/addMessage',
|
||||
json={'message': {
|
||||
response = self.client.offerclass().addmessage(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body={'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
}})
|
||||
}}).execute()
|
||||
|
||||
print('Class addMessage response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END addMessageClass]
|
||||
|
||||
@@ -256,16 +253,15 @@ class DemoOffer:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 200:
|
||||
try:
|
||||
self.client.offerobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
print(f'Object {issuer_id}.{object_suffix} already exists!')
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# See link below for more information on required properties
|
||||
@@ -336,12 +332,12 @@ class DemoOffer:
|
||||
}
|
||||
|
||||
# Create the object
|
||||
response = self.http_client.post(url=self.object_url, json=new_object)
|
||||
response = self.client.offerobject().insert(body=new_object).execute()
|
||||
|
||||
print('Object insert response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END createObject]
|
||||
|
||||
@@ -360,19 +356,19 @@ class DemoOffer:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.offerobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Object exists
|
||||
updated_object = response.json()
|
||||
updated_object = response
|
||||
|
||||
# Update the object by adding a link
|
||||
new_link = {
|
||||
@@ -383,14 +379,14 @@ class DemoOffer:
|
||||
updated_object['linksModuleData'] = {'uris': []}
|
||||
updated_object['linksModuleData']['uris'].append(new_link)
|
||||
|
||||
response = self.http_client.put(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=updated_object)
|
||||
response = self.client.offerobject().update(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=updated_object).execute()
|
||||
|
||||
print('Object update response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END updateObject]
|
||||
|
||||
@@ -407,19 +403,19 @@ class DemoOffer:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.offerobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Object exists
|
||||
existing_object = response.json()
|
||||
existing_object = response
|
||||
|
||||
# Patch the object by adding a link
|
||||
patch_body = {}
|
||||
@@ -434,14 +430,14 @@ class DemoOffer:
|
||||
patch_body['linksModuleData'] = {'uris': []}
|
||||
patch_body['linksModuleData']['uris'].append(new_link)
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=patch_body)
|
||||
response = self.client.offerobject().patch(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Object patch response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END patchObject]
|
||||
|
||||
@@ -461,28 +457,28 @@ class DemoOffer:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.offerobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Patch the object, setting the pass as expired
|
||||
patch_body = {'state': 'EXPIRED'}
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=patch_body)
|
||||
response = self.client.offerobject().patch(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Object expiration response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END expireObject]
|
||||
|
||||
@@ -502,28 +498,28 @@ class DemoOffer:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
try:
|
||||
response = self.client.offerobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
response = self.http_client.post(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}/addMessage',
|
||||
json={'message': {
|
||||
response = self.client.offerobject().addmessage(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body={'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
}})
|
||||
}}).execute()
|
||||
|
||||
print('Object addMessage response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END addMessageObject]
|
||||
|
||||
@@ -750,7 +746,7 @@ class DemoOffer:
|
||||
issuer_id (str): The issuer ID being used for this request.
|
||||
class_suffix (str): Developer-defined unique ID for this pass class.
|
||||
"""
|
||||
data = ''
|
||||
batch = self.client.new_batch_http_request()
|
||||
|
||||
# Example: Generate three new pass objects
|
||||
for _ in range(3):
|
||||
@@ -824,25 +820,11 @@ class DemoOffer:
|
||||
}
|
||||
}
|
||||
|
||||
data += '--batch_createobjectbatch\n'
|
||||
data += 'Content-Type: application/json\n\n'
|
||||
data += 'POST /walletobjects/v1/offerObject/\n\n'
|
||||
|
||||
data += json.dumps(batch_object) + '\n\n'
|
||||
|
||||
data += '--batch_createobjectbatch--'
|
||||
batch.add(self.client.offerobject().insert(body=batch_object))
|
||||
|
||||
# Invoke the batch API calls
|
||||
response = self.http_client.post(
|
||||
url=self.batch_url, # https://walletobjects.googleapis.com/batch
|
||||
data=data,
|
||||
headers={
|
||||
# `boundary` is the delimiter between API calls in the batch request
|
||||
'Content-Type':
|
||||
'multipart/mixed; boundary=batch_createobjectbatch'
|
||||
})
|
||||
response = batch.execute()
|
||||
|
||||
print('Batch insert response')
|
||||
print(response.content.decode('UTF-8'))
|
||||
print('Batch complete')
|
||||
|
||||
# [END batch]
|
||||
|
||||
@@ -21,7 +21,9 @@ import json
|
||||
import os
|
||||
import uuid
|
||||
|
||||
from google.auth.transport.requests import AuthorizedSession
|
||||
from googleapiclient.discovery import build
|
||||
from googleapiclient.errors import HttpError
|
||||
from googleapiclient.http import BatchHttpRequest
|
||||
from google.oauth2.service_account import Credentials
|
||||
from google.auth import jwt, crypt
|
||||
# [END imports]
|
||||
@@ -39,11 +41,6 @@ class DemoTransit:
|
||||
def __init__(self):
|
||||
self.key_file_path = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS',
|
||||
'/path/to/key.json')
|
||||
self.base_url = 'https://walletobjects.googleapis.com/walletobjects/v1'
|
||||
self.batch_url = 'https://walletobjects.googleapis.com/batch'
|
||||
self.class_url = f'{self.base_url}/transitClass'
|
||||
self.object_url = f'{self.base_url}/transitObject'
|
||||
|
||||
# Set up authenticated client
|
||||
self.auth()
|
||||
|
||||
@@ -56,7 +53,7 @@ class DemoTransit:
|
||||
self.key_file_path,
|
||||
scopes=['https://www.googleapis.com/auth/wallet_object.issuer'])
|
||||
|
||||
self.http_client = AuthorizedSession(self.credentials)
|
||||
self.client = build('walletobjects', 'v1', credentials=self.credentials)
|
||||
|
||||
# [END auth]
|
||||
|
||||
@@ -73,16 +70,16 @@ class DemoTransit:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 200:
|
||||
try:
|
||||
self.client.transitclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
print(f'Class {issuer_id}.{class_suffix} already exists!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# See link below for more information on required properties
|
||||
# https://developers.google.com/wallet/tickets/transit-passes/qr-code/rest/v1/transitclass
|
||||
@@ -105,12 +102,12 @@ class DemoTransit:
|
||||
'transitType': 'BUS'
|
||||
}
|
||||
|
||||
response = self.http_client.post(url=self.class_url, json=new_class)
|
||||
response = self.client.transitclass().insert(body=new_class).execute()
|
||||
|
||||
print('Class insert response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END createClass]
|
||||
|
||||
@@ -129,19 +126,19 @@ class DemoTransit:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
try:
|
||||
response = self.client.transitclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# Class exists
|
||||
updated_class = response.json()
|
||||
updated_class = response
|
||||
|
||||
# Update the class by adding a homepage
|
||||
updated_class['homepageUri'] = {
|
||||
@@ -152,14 +149,14 @@ class DemoTransit:
|
||||
# Note: reviewStatus must be 'UNDER_REVIEW' or 'DRAFT' for updates
|
||||
updated_class['reviewStatus'] = 'UNDER_REVIEW'
|
||||
|
||||
response = self.http_client.put(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}',
|
||||
json=updated_class)
|
||||
response = self.client.transitclass().update(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body=updated_class).execute()
|
||||
|
||||
print('Class update response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END updateClass]
|
||||
|
||||
@@ -178,16 +175,16 @@ class DemoTransit:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
try:
|
||||
response = self.client.transitclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# Patch the class by adding a homepage
|
||||
patch_body = {
|
||||
@@ -200,13 +197,14 @@ class DemoTransit:
|
||||
'reviewStatus': 'UNDER_REVIEW'
|
||||
}
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}', json=patch_body)
|
||||
response = self.client.transitclass().patch(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Class patch response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END patchClass]
|
||||
|
||||
@@ -226,28 +224,28 @@ class DemoTransit:
|
||||
"""
|
||||
|
||||
# Check if the class exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}')
|
||||
try:
|
||||
response = self.client.transitclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Class {issuer_id}.{class_suffix} not found!')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
response = self.http_client.post(
|
||||
url=f'{self.class_url}/{issuer_id}.{class_suffix}/addMessage',
|
||||
json={'message': {
|
||||
response = self.client.transitclass().addmessage(
|
||||
resourceId=f'{issuer_id}.{class_suffix}',
|
||||
body={'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
}})
|
||||
}}).execute()
|
||||
|
||||
print('Class addMessage response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{class_suffix}'
|
||||
|
||||
# [END addMessageClass]
|
||||
|
||||
@@ -266,16 +264,15 @@ class DemoTransit:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 200:
|
||||
try:
|
||||
self.client.transitobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
print(f'Object {issuer_id}.{object_suffix} already exists!')
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 404:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# See link below for more information on required properties
|
||||
@@ -365,12 +362,12 @@ class DemoTransit:
|
||||
}
|
||||
|
||||
# Create the object
|
||||
response = self.http_client.post(url=self.object_url, json=new_object)
|
||||
response = self.client.transitobject().insert(body=new_object).execute()
|
||||
|
||||
print('Object insert response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END createObject]
|
||||
|
||||
@@ -389,19 +386,19 @@ class DemoTransit:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.transitobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Object exists
|
||||
updated_object = response.json()
|
||||
updated_object = response
|
||||
|
||||
# Update the object by adding a link
|
||||
new_link = {
|
||||
@@ -412,14 +409,14 @@ class DemoTransit:
|
||||
updated_object['linksModuleData'] = {'uris': []}
|
||||
updated_object['linksModuleData']['uris'].append(new_link)
|
||||
|
||||
response = self.http_client.put(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=updated_object)
|
||||
response = self.client.transitobject().update(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=updated_object).execute()
|
||||
|
||||
print('Object update response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END updateObject]
|
||||
|
||||
@@ -436,19 +433,19 @@ class DemoTransit:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.transitobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Object exists
|
||||
existing_object = response.json()
|
||||
existing_object = response
|
||||
|
||||
# Patch the object by adding a link
|
||||
patch_body = {}
|
||||
@@ -463,14 +460,14 @@ class DemoTransit:
|
||||
patch_body['linksModuleData'] = {'uris': []}
|
||||
patch_body['linksModuleData']['uris'].append(new_link)
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=patch_body)
|
||||
response = self.client.transitobject().patch(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Object patch response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END patchObject]
|
||||
|
||||
@@ -490,28 +487,28 @@ class DemoTransit:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
try:
|
||||
response = self.client.transitobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# Patch the object, setting the pass as expired
|
||||
patch_body = {'state': 'EXPIRED'}
|
||||
|
||||
response = self.http_client.patch(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}',
|
||||
json=patch_body)
|
||||
response = self.client.transitobject().patch(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body=patch_body).execute()
|
||||
|
||||
print('Object expiration response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END expireObject]
|
||||
|
||||
@@ -531,28 +528,28 @@ class DemoTransit:
|
||||
"""
|
||||
|
||||
# Check if the object exists
|
||||
response = self.http_client.get(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}')
|
||||
try:
|
||||
response = self.client.transitobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
|
||||
except HttpError as e:
|
||||
if e.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
else:
|
||||
# Something else went wrong...
|
||||
print(e.error_details)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
if response.status_code == 404:
|
||||
print(f'Object {issuer_id}.{object_suffix} not found!')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
elif response.status_code != 200:
|
||||
# Something else went wrong...
|
||||
print(response.text)
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
response = self.http_client.post(
|
||||
url=f'{self.object_url}/{issuer_id}.{object_suffix}/addMessage',
|
||||
json={'message': {
|
||||
response = self.client.transitobject().addmessage(
|
||||
resourceId=f'{issuer_id}.{object_suffix}',
|
||||
body={'message': {
|
||||
'header': header,
|
||||
'body': body
|
||||
}})
|
||||
}}).execute()
|
||||
|
||||
print('Object addMessage response')
|
||||
print(response.text)
|
||||
print(response)
|
||||
|
||||
return response.json().get('id')
|
||||
return f'{issuer_id}.{object_suffix}'
|
||||
|
||||
# [END addMessageObject]
|
||||
|
||||
@@ -808,7 +805,7 @@ class DemoTransit:
|
||||
issuer_id (str): The issuer ID being used for this request.
|
||||
class_suffix (str): Developer-defined unique ID for this pass class.
|
||||
"""
|
||||
data = ''
|
||||
batch = self.client.new_batch_http_request()
|
||||
|
||||
# Example: Generate three new pass objects
|
||||
for _ in range(3):
|
||||
@@ -901,25 +898,11 @@ class DemoTransit:
|
||||
}
|
||||
}
|
||||
|
||||
data += '--batch_createobjectbatch\n'
|
||||
data += 'Content-Type: application/json\n\n'
|
||||
data += 'POST /walletobjects/v1/transitObject/\n\n'
|
||||
|
||||
data += json.dumps(batch_object) + '\n\n'
|
||||
|
||||
data += '--batch_createobjectbatch--'
|
||||
batch.add(self.client.transitobject().insert(body=batch_object))
|
||||
|
||||
# Invoke the batch API calls
|
||||
response = self.http_client.post(
|
||||
url=self.batch_url, # https://walletobjects.googleapis.com/batch
|
||||
data=data,
|
||||
headers={
|
||||
# `boundary` is the delimiter between API calls in the batch request
|
||||
'Content-Type':
|
||||
'multipart/mixed; boundary=batch_createobjectbatch'
|
||||
})
|
||||
response = batch.execute()
|
||||
|
||||
print('Batch insert response')
|
||||
print(response.content.decode('UTF-8'))
|
||||
print('Batch complete')
|
||||
|
||||
# [END batch]
|
||||
|
||||
Reference in New Issue
Block a user