/// <summary> /// Generates a GiftCard Object /// </summary> /// <param name="issuerId"> </param> /// <param name="classId"> </param> /// <param name="objectId"> </param> /// <returns> GiftCardObject </returns> public static GiftCardObject generateGiftCardObject(string issuerId, string classId, string objectId) { // Define Barcode Barcode barcode = new Barcode() { Type = "qrCode", Value = "28343E3", AlternateText = "12345" }; Money balance = new Money { CurrencyCode = "USD", Micros = 20000000L }; // TODO(samstern): balanceUpdateTime // Define Text Module Data IList<TextModuleData> textModulesData = new List<TextModuleData>(); TextModuleData textModuleData = new TextModuleData() { Header = "Earn double points", Body = "Jane, don't forget to use your Baconrista Rewards when " + "paying with this gift card to earn additional points" }; textModulesData.Add(textModuleData); // Define Links Module Data IList<Uri> uris = new List<Uri>(); Uri uri1 = new Uri() { Description = "My Baconrista Gift Card Purchases", UriValue = "http://www.baconrista.com/mybalance?id=1234567890" }; uris.Add(uri1); LinksModuleData linksModuleData = new LinksModuleData() { Uris = uris }; // Define Wallet Instance GiftCardObject GiftCardObj = new GiftCardObject() { ClassId = issuerId + "." + classId, Id = issuerId + "." + objectId, State = "active", Version = 1, Barcode = barcode, TextModulesData = textModulesData, LinksModuleData = linksModuleData, Balance = balance, EventNumber = "123456", CardNumber = "123jkl4889", Pin = "1111" }; return GiftCardObj; }
/// <summary> /// Generate a gift card object /// See https://developers.google.com/pay/passes/reference/v1/giftcardobject /// </summary> /// <param name="objectId"> the unique identifier for an object</param> /// <returns>the inserted gift card object</returns> public GiftCardObject makeGiftCardObjectResource(string objectId, string classId) { // Define the resource representation of the Object // values should be from your DB/services; here we hardcode information // below defines an giftcard object. For more properties, check: //// https://developers.google.com/pay/passes/reference/v1/giftcardobject/insert //// https://developers.google.com/pay/passes/guides/pass-verticals/gift-cards/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 GiftCardObject payload = new GiftCardObject(); //required fields payload.Id = objectId; payload.ClassId = classId; payload.State = "active"; payload.CardNumber = "123abc"; //optional fields. See design and reference api for more payload.Barcode = new Barcode() { Type = "qrCode", Value = "1234abc", AlternateText = "1234abc" }; payload.Pin = "1111"; payload.Balance = new Money() { CurrencyCode = "USD", Micros = 20000000L }; payload.BalanceUpdateTime = new DateTime() { Date = "2019-09-26T17:08:03.798329Z" }; payload.TextModulesData = new List <TextModuleData>() { new TextModuleData() { Header = "Earn double points", Body = "Save more at your local Mountain View store Jane. " + "Jane, don\"t forget to use your Baconrista Rewards when " + "paying with this gift card to earn additional points. " } }; payload.LinksModuleData = new LinksModuleData() { Uris = new List <Uri>() { new Uri() { UriValue = "http://www.google.com/", Description = "My Baconrista Gift Card Purchases" } } }; payload.Locations = new List <LatLongPoint>() { new LatLongPoint() { Latitude = 37.424015499999996, Longitude = -122.09259560000001 } }; return(payload); }
public void addObject(GiftCardObject obj) { giftCardObjects.Add(obj); }
/// <summary>Updates the gift card object referenced by the given object ID.</summary> /// <param name="body">The body of the request.</param> /// <param name="resourceId">The unique identifier for an object. This ID must be unique across all objects from an /// issuer. This value should follow the format issuer ID.identifier where the former is issued by Google and latter is /// chosen by you. Your unique identifier should only include alphanumeric characters, '.', '_', or '-'.</param> public virtual UpdateRequest Update(GiftCardObject body, string resourceId) { return(new UpdateRequest(service, body, resourceId)); }
/// <summary>Updates the gift card object referenced by the given object ID. This method supports patch /// semantics.</summary> /// <param name="body">The body of the request.</param> /// <param name="resourceId">The unique identifier for an object. This ID must be unique across all objects from an /// issuer. This value should follow the format issuer ID.identifier where the former is issued by Google and latter is /// chosen by you. Your unique identifier should only include alphanumeric characters, '.', '_', or '-'.</param> public virtual PatchRequest Patch(GiftCardObject body, string resourceId) { return(new PatchRequest(service, body, resourceId)); }
/// <summary>Inserts an gift card object with the given ID and properties.</summary> /// <param name="body">The body of the request.</param> public virtual InsertRequest Insert(GiftCardObject body) { return(new InsertRequest(service, body)); }
/// <summary> /// Generates a GiftCard Object /// </summary> /// <param name="issuerId"> </param> /// <param name="classId"> </param> /// <param name="objectId"> </param> /// <returns> GiftCardObject </returns> public static GiftCardObject generateGiftCardObject(string issuerId, string classId, string objectId) { // Define Barcode Barcode barcode = new Barcode() { Type = "qrCode", Value = "28343E3", AlternateText = "12345" }; Money balance = new Money { CurrencyCode = "USD", Micros = 20000000L }; // TODO(samstern): balanceUpdateTime // Define Text Module Data IList <TextModuleData> textModulesData = new List <TextModuleData>(); TextModuleData textModuleData = new TextModuleData() { Header = "Earn double points", Body = "Jane, don't forget to use your Baconrista Rewards when " + "paying with this gift card to earn additional points" }; textModulesData.Add(textModuleData); // Define Links Module Data IList <Uri> uris = new List <Uri>(); Uri uri1 = new Uri() { Description = "My Baconrista Gift Card Purchases", UriValue = "http://www.baconrista.com/mybalance?id=1234567890" }; uris.Add(uri1); LinksModuleData linksModuleData = new LinksModuleData() { Uris = uris }; // Define Wallet Instance GiftCardObject GiftCardObj = new GiftCardObject() { ClassId = issuerId + "." + classId, Id = issuerId + "." + objectId, State = "active", Version = 1, Barcode = barcode, TextModulesData = textModulesData, LinksModuleData = linksModuleData, Balance = balance, EventNumber = "123456", CardNumber = "123jkl4889", Pin = "1111" }; return(GiftCardObj); }
/// <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.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; } // 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); } }