/// <summary> /// Get a class with Google Pay API for Passes REST API /// See https://developers.google.com/pay/passes/reference/v1/eventticketclass/get /// </summary> /// <param name="id">id of the class</param> /// <returns>class</returns> public EventTicketClass getEventTicketClass(string id) { EventTicketClass response = null; // Uses the Google Pay API for Passes C# client lib to get a EventTicket class // check the devsite for newest client lib: https://developers.google.com/pay/passes/support/libraries#libraries // check reference API to see the underlying REST call: // https://developers.google.com/pay/passes/reference/v1/eventticketclass/get WalletobjectsService service = new WalletobjectsService(new Google.Apis.Services.BaseClientService.Initializer() { HttpClientInitializer = this.credential }); try { response = service.Eventticketclass.Get(id).Execute(); } catch (Google.GoogleApiException ge) { System.Console.WriteLine(">>>> [START] Google Server Error response:"); System.Console.WriteLine(ge.Message); System.Console.WriteLine(">>>> [END] Google Server Error response\n"); } catch (System.Exception e) { System.Console.WriteLine(e.StackTrace); } return(response); }
public void addEventTicketClass(EventTicketClass eventTicketClass) { if (this.payload.eventTicketClasses == null) { this.payload.eventTicketClasses = new List <EventTicketClass>(); } this.payload.eventTicketClasses.Add(eventTicketClass); }
public void TestInsertEventTicketClassAndObject() { RestMethods restMethods = RestMethods.getInstance(); ResourceDefinitions resourceDefinitions = ResourceDefinitions.getInstance(); VerticalType verticalType = Services.VerticalType.EVENTTICKET; Config config = Config.getInstance(); string UUID = Guid.NewGuid().ToString(); string classUid = $"{verticalType.ToString()}_CLASS_{UUID}"; string classId = $"{config.getIssuerId()}.{classUid}"; string UUIDobj = Guid.NewGuid().ToString(); string objectUid = $"{verticalType.ToString()}_OBJECT_{UUIDobj}"; string objectId = $"{config.getIssuerId()}.{objectUid}"; EventTicketClass classResponse = restMethods.insertEventTicketClass(resourceDefinitions.makeEventTicketClassResource(classId)); EventTicketObject objectResponse = restMethods.insertEventTicketObject(resourceDefinitions.makeEventTicketObjectResource(objectId, classId)); Assert.NotNull(classResponse); Assert.NotNull(objectResponse); }
/// <summary> /// Generate a event ticket class /// See https://developers.google.com/pay/passes/reference/v1/eventticketclass /// </summary> /// <param name="classId"> the unique identifier for a class</param> /// <returns>the inserted event ticket class</returns> public EventTicketClass makeEventTicketClassResource(string classId) { // Define the resource representation of the Class // values should be from your DB/services; here we hardcode information // below defines an event ticket class. For more properties, check: //// https://developers.google.com/pay/passes/reference/v1/eventticketclass/insert //// https://developers.google.com/pay/passes/guides/pass-verticals/event-tickets/design // There is a client lib to help make the data structure. Newest client is on // devsite: //// https://developers.google.com/pay/passes/support/libraries#libraries EventTicketClass payload = new EventTicketClass(); //required fields payload.Id = classId; payload.IssuerName = "Baconrista Stadium"; payload.ReviewStatus = "underReview"; payload.EventName = new LocalizedString() { DefaultValue = new TranslatedString() { Language = "en-US", Value = "Bacon Coffee Fun Event" } }; //optional fields. See design and reference api for more payload.TextModulesData = new List <TextModuleData>() { new TextModuleData() { Header = "Custom Details", Body = "Baconrista events have pushed the limits since its founding." } }; payload.LinksModuleData = new LinksModuleData() { Uris = new List <Uri>() { new Uri() { UriValue = "http://maps.google.com/", Description = "Nearby Locations" }, new Uri() { UriValue = "tel:6505555555", Description = "Call Customer Service" } } }; payload.ImageModulesData = new List <ImageModuleData>() { new ImageModuleData() { MainImage = new Image() { SourceUri = new Uri() { UriValue = "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg", Description = "Coffee beans" } } } }; payload.Logo = new Image() { SourceUri = new Uri() { UriValue = "https://farm8.staticflickr.com/7340/11177041185_a61a7f2139_o.jpg", Description = "Baconrista stadium logo" } }; payload.Locations = new List <LatLongPoint>() { new LatLongPoint() { Latitude = 37.424015499999996, Longitude = -122.09259560000001 } }; payload.Venue = new EventVenue() { Name = new LocalizedString() { DefaultValue = new TranslatedString() { Language = "en-US", Value = "Baconrista Stadium" } }, Address = new LocalizedString() { DefaultValue = new TranslatedString() { Language = "en-US", Value = "101 Baconrista Dr." } } }; payload.DateTime = new EventDateTime() { Start = "2023-04-12T11:20:50.52Z", End = "2023-04-12T16:20:50.52Z" }; return(payload); }
/// <summary> /// Generates a signed "fat" JWT. /// No REST calls made. /// Use fat JWT in JS web button. /// Fat JWT is too long to be used in Android intents. /// Possibly might break in redirects. /// </summary> /// <param name="verticalType"> pass type to created</param> /// <param name="classId">the unique identifier for the class</param> /// <param name="objectId">the unique identifier for the object</param> /// <returns></returns> public string makeFatJwt(VerticalType verticalType, string classId, string objectId) { ResourceDefinitions resourceDefinitions = ResourceDefinitions.getInstance(); RestMethods restMethods = RestMethods.getInstance(); // create JWT to put objects and class into JSON Web Token (JWT) format for Google Pay API for Passes Jwt googlePassJwt = new Jwt(); // get class definition, object definition and see if Ids exist. for a fat JWT, first time a user hits the save button, the class and object are inserted try { switch (verticalType) { case VerticalType.OFFER: OfferClass offerClass = resourceDefinitions.makeOfferClassResource(classId); OfferObject offerObject = resourceDefinitions.makeOfferObjectResource(objectId, classId); System.Console.WriteLine("\nMaking REST call to get class and object to see if they exist."); OfferClass classResponse = restMethods.getOfferClass(classId); OfferObject objectResponse = restMethods.getOfferObject(objectId); // check responses if (!(classResponse is null)) { System.Console.WriteLine($"classId: {classId} already exists."); } if (!(objectResponse is null)) { System.Console.WriteLine($"objectId: {objectId} already exists."); } if (!(classResponse is null) && objectResponse.ClassId != offerObject.ClassId) { System.Console.WriteLine($"the classId of inserted object is ({objectResponse.ClassId}). " + $"It does not match the target classId ({offerObject.ClassId}). The saved object will not " + "have the class properties you expect."); } // need to add both class and object resource definitions into JWT because no REST calls made to pre-insert googlePassJwt.addOfferClass(offerClass); googlePassJwt.addOfferObject(offerObject); break; case VerticalType.LOYALTY: LoyaltyClass loyaltyClass = resourceDefinitions.makeLoyaltyClassResource(classId); LoyaltyObject loyaltyObject = resourceDefinitions.makeLoyaltyObjectResource(objectId, classId); System.Console.WriteLine("\nMaking REST call to get class and object to see if they exist."); LoyaltyClass loyaltyClassResponse = restMethods.getLoyaltyClass(classId); LoyaltyObject loyaltyObjectResponse = restMethods.getLoyaltyObject(objectId); // check responses if (!(loyaltyClassResponse is null)) { System.Console.WriteLine($"classId: {classId} already exists."); } if (!(loyaltyObjectResponse is null)) { System.Console.WriteLine($"objectId: {objectId} already exists."); } if (!(loyaltyClassResponse is null) && loyaltyObjectResponse.ClassId != loyaltyObject.ClassId) { System.Console.WriteLine($"the classId of inserted object is ({loyaltyObjectResponse.ClassId}). " + $"It does not match the target classId ({loyaltyObject.ClassId}). The saved object will not " + "have the class properties you expect."); } // need to add both class and object resource definitions into JWT because no REST calls made to pre-insert googlePassJwt.addLoyaltyClass(loyaltyClass); googlePassJwt.addLoyaltyObject(loyaltyObject); break; case VerticalType.EVENTTICKET: EventTicketClass eventTicketClass = resourceDefinitions.makeEventTicketClassResource(classId); EventTicketObject eventTicketObject = resourceDefinitions.makeEventTicketObjectResource(objectId, classId); System.Console.WriteLine("\nMaking REST call to get class and object to see if they exist."); EventTicketClass eventTicketClassResponse = restMethods.getEventTicketClass(classId); EventTicketObject eventTicketObjectResponse = restMethods.getEventTicketObject(objectId); // check responses if (!(eventTicketClassResponse is null)) { System.Console.WriteLine($"classId: {classId} already exists."); } if (!(eventTicketObjectResponse is null)) { System.Console.WriteLine($"objectId: {objectId} already exists."); } if (!(eventTicketClassResponse is null) && eventTicketObjectResponse.ClassId != eventTicketObject.ClassId) { System.Console.WriteLine($"the classId of inserted object is ({eventTicketObjectResponse.ClassId}). " + $"It does not match the target classId ({eventTicketObject.ClassId}). The saved object will not " + "have the class properties you expect."); } // need to add both class and object resource definitions into JWT because no REST calls made to pre-insert googlePassJwt.addEventTicketClass(eventTicketClass); googlePassJwt.addEventTicketObject(eventTicketObject); break; case VerticalType.FLIGHT: FlightClass flightClass = resourceDefinitions.makeFlightClassResource(classId); FlightObject flightObject = resourceDefinitions.makeFlightObjectResource(objectId, classId); System.Console.WriteLine("\nMaking REST call to get class and object to see if they exist."); FlightClass flightClassResponse = restMethods.getFlightClass(classId); FlightObject flightObjectResponse = restMethods.getFlightObject(objectId); // check responses if (!(flightClassResponse is null)) { System.Console.WriteLine($"classId: {classId} already exists."); } if (!(flightObjectResponse is null)) { System.Console.WriteLine($"objectId: {objectId} already exists."); } if (!(flightClassResponse is null) && flightObjectResponse.ClassId != flightObject.ClassId) { System.Console.WriteLine($"the classId of inserted object is ({flightObjectResponse.ClassId}). " + $"It does not match the target classId ({flightObject.ClassId}). The saved object will not " + "have the class properties you expect."); } // need to add both class and object resource definitions into JWT because no REST calls made to pre-insert googlePassJwt.addFlightClass(flightClass); googlePassJwt.addFlightObject(flightObject); break; case VerticalType.GIFTCARD: GiftCardClass giftCardClass = resourceDefinitions.makeGiftCardClassResource(classId); GiftCardObject giftCardObject = resourceDefinitions.makeGiftCardObjectResource(objectId, classId); System.Console.WriteLine("\nMaking REST call to get class and object to see if they exist."); GiftCardClass giftCardClassResponse = restMethods.getGiftCardClass(classId); GiftCardObject giftCardObjectResponse = restMethods.getGiftCardObject(objectId); // check responses if (!(giftCardClassResponse is null)) { System.Console.WriteLine($"classId: {classId} already exists."); } if (!(giftCardObjectResponse is null)) { System.Console.WriteLine($"objectId: {objectId} already exists."); } if (!(giftCardClassResponse is null) && giftCardObjectResponse.ClassId != giftCardObject.ClassId) { System.Console.WriteLine($"the classId of inserted object is ({giftCardObjectResponse.ClassId}). " + $"It does not match the target classId ({giftCardObject.ClassId}). The saved object will not " + "have the class properties you expect."); } // need to add both class and object resource definitions into JWT because no REST calls made to pre-insert googlePassJwt.addGiftCardClass(giftCardClass); googlePassJwt.addGiftCardObject(giftCardObject); break; case VerticalType.TRANSIT: TransitClass transitClass = resourceDefinitions.makeTransitClassResource(classId); TransitObject transitObject = resourceDefinitions.makeTransitObjectResource(objectId, classId); System.Console.WriteLine("\nMaking REST call to get class and object to see if they exist."); TransitClass transitClassResponse = restMethods.getTransitClass(classId); TransitObject transitObjectResponse = restMethods.getTransitObject(objectId); // check responses if (!(transitClassResponse is null)) { System.Console.WriteLine($"classId: {classId} already exists."); } if (!(transitObjectResponse is null)) { System.Console.WriteLine($"objectId: {objectId} already exists."); } if (!(transitClassResponse is null) && transitObjectResponse.ClassId != transitObject.ClassId) { System.Console.WriteLine($"the classId of inserted object is ({transitObjectResponse.ClassId}). " + $"It does not match the target classId ({transitObject.ClassId}). The saved object will not " + "have the class properties you expect."); } // need to add both class and object resource definitions into JWT because no REST calls made to pre-insert googlePassJwt.addTransitClass(transitClass); googlePassJwt.addTransitObject(transitObject); break; } // return "fat" JWT. Try putting it into JS web button // note button needs to be rendered in local web server who's domain matches the ORIGINS // defined in the JWT. See https://developers.google.com/pay/passes/reference/s2w-reference return(googlePassJwt.generateSignedJwt()); } catch (System.Exception e) { System.Console.WriteLine(e.Message); return(null); } }