/// <summary> //// Generate an offer class /// See https://developers.google.com/pay/passes/reference/v1/offerclass /// </summary> /// <param name="classId"> the unique identifier for a class</param> /// <returns>the inserted offer class</returns> public OfferClass makeOfferClassResource(string classId) { // Define the resource representation of the Class // values should be from your DB/services; here we hardcode information // below defines an offer class. For more properties, check: //// https://developers.google.com/pay/passes/reference/v1/offerclass/insert //// https://developers.google.com/pay/passes/guides/pass-verticals/offers/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 OfferClass payload = new OfferClass(); //required fields payload.Id = classId; payload.IssuerName = "Baconrista Coffee"; payload.Provider = "Baconrista Deals"; payload.RedemptionChannel = "online"; payload.ReviewStatus = "underReview"; payload.Title = "Baconrista Deals"; //optional fields. See design and reference api for more payload.TitleImage = new Image() { SourceUri = new ImageUri() { Uri = "http://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg" } }; return(payload); }
/// <summary> /// Get a class with Google Pay API for Passes REST API /// See https://developers.google.com/pay/passes/reference/v1/offerclass/get /// </summary> /// <param name="id">id of the class</param> /// <returns>class</returns> public OfferClass getOfferClass(string id) { OfferClass response = null; // Uses the Google Pay API for Passes C# client lib to get an offer 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/offerclass/get WalletobjectsService service = new WalletobjectsService(new Google.Apis.Services.BaseClientService.Initializer() { HttpClientInitializer = this.credential }); try { response = service.Offerclass.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 static OfferClass generateOfferClass(string issuerId, string classId) { IList<RenderSpec> renderSpec = new List<RenderSpec>(); RenderSpec listRenderSpec = new RenderSpec(); listRenderSpec.ViewName = "g_list"; listRenderSpec.TemplateFamily = "1.offer1_list"; RenderSpec expandedRenderSpec = new RenderSpec(); expandedRenderSpec.ViewName = "g_expanded"; expandedRenderSpec.TemplateFamily = "1.offer1_expanded"; renderSpec.Add(listRenderSpec); renderSpec.Add(expandedRenderSpec); IList<LatLongPoint> locations = new List<LatLongPoint>(); LatLongPoint llp1 = new LatLongPoint(); llp1.Latitude = 37.442087; llp1.Longitude = -122.161446; LatLongPoint llp2 = new LatLongPoint(); llp2.Latitude = 37.429379; llp2.Longitude = -122.122730; LatLongPoint llp3 = new LatLongPoint(); llp3.Latitude = 37.333646; llp3.Longitude = -121.884853; locations.Add(llp1); locations.Add(llp2); locations.Add(llp3); OfferClass wobClass = new OfferClass(); wobClass.Id = issuerId + "." + classId; wobClass.Version = "1"; wobClass.IssuerName = "Baconrista Coffee"; wobClass.Title = "20% off one cup of coffee"; wobClass.Provider = "Baconrista Deals"; wobClass.Details = "20% off one cup of coffee at all Baconristas"; Uri homepageUri = new Uri(); homepageUri.UriValue = "http://baconrista.com/"; homepageUri.Description = "Website"; wobClass.HomepageUri = homepageUri; Uri imageUri = new Uri(); imageUri.UriValue = "http://3.bp.blogspot.com/-AvC1agljv9Y/TirbDXOBIPI/AAAAAAAACK0/hR2gs5h2H6A/s1600/Bacon%2BWallpaper.png"; Image titleImage = new Image(); titleImage.SourceUri = imageUri; wobClass.TitleImage = titleImage; wobClass.RenderSpecs = renderSpec; wobClass.RedemptionChannel = "both"; wobClass.ReviewStatus = "underReview"; wobClass.Locations = locations; wobClass.AllowMultipleUsersPerObject = true; return wobClass; }
public async Task SendHttp(OfferClassDTO offerClassDTO) { //var stringForJson = JsonConvert.SerializeObject(new OfferClass //{ // OfferNumber = Guid.NewGuid().ToString(), // OfferType = offerClassDTO.OfferType, // FullName = offerClassDTO.FullName, // EmailAddress = offerClassDTO.EmailAddress, // Message = offerClassDTO?.Message //}); var stringForJson = new OfferClass { OfferNumber = Guid.NewGuid().ToString(), OfferType = offerClassDTO.OfferType, FullName = offerClassDTO.FullName, EmailAddress = offerClassDTO.EmailAddress, Message = offerClassDTO?.Message }; //var content = new StringContent(stringForJson, Encoding.UTF8, "text/plain"); //var request = new HttpRequestMessage //{ // Method = HttpMethod.Post, // RequestUri = new Uri(Endpoints.MessageSenderEndpoint), // Content = new StringContent(stringForJson, Encoding.UTF8, "text/plain") //}; var endpoint = Endpoints.MessageSenderEndpoint; var result = await _httpClient.PostAsJsonAsync(endpoint, stringForJson); }
public void addOfferClass(OfferClass offerClass) { if (this.payload.offerClasses == null) { this.payload.offerClasses = new List <OfferClass>(); } this.payload.offerClasses.Add(offerClass); }
public virtual void ProcessRequest(HttpContext context) { try { HttpRequest request = context.Request; // get settings WobCredentials credentials = new WobCredentials( WebConfigurationManager.AppSettings["ServiceAccountId"], WebConfigurationManager.AppSettings["ServiceAccountPrivateKey"], WebConfigurationManager.AppSettings["ApplicationName"], WebConfigurationManager.AppSettings["IssuerId"]); string loyaltyClassId = WebConfigurationManager.AppSettings["LoyaltyClassId"]; string offerClassId = WebConfigurationManager.AppSettings["OfferClassId"]; // OAuth - setup certificate based on private key file X509Certificate2 certificate = new X509Certificate2( AppDomain.CurrentDomain.BaseDirectory + credentials.serviceAccountPrivateKey, "notasecret", X509KeyStorageFlags.Exportable); // create service account credential ServiceAccountCredential credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(credentials.serviceAccountId) { Scopes = new[] { "https://www.googleapis.com/auth/wallet_object.issuer" } }.FromCertificate(certificate)); // create the service var woService = new WalletobjectsService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "Wallet Objects API Sample", }); // get the class type string type = request.Params["type"]; // insert the class if (type.Equals("loyalty")) { LoyaltyClass loyaltyClass = Loyalty.generateLoyaltyClass(credentials.IssuerId, loyaltyClassId); woService.Loyaltyclass.Insert(loyaltyClass).Execute(); } else if (type.Equals("offer")) { OfferClass offerClass = Offer.generateOfferClass(credentials.IssuerId, offerClassId); woService.Offerclass.Insert(offerClass).Execute(); } } catch (Exception e) { Console.Write(e.StackTrace); } }
/// <summary> /// Generates a signed "object" JWT. /// 1 REST call is made to pre-insert class. /// If this JWT only contains 1 object, usually isn't too long; can be used in Android intents/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 makeObjectJwt(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, object definitions, insert class (check in Merchant center GUI: https://pay.google.com/gp/m/issuer/list) try { switch (verticalType) { case VerticalType.OFFER: OfferClass offerClass = resourceDefinitions.makeOfferClassResource(classId); OfferObject offerObject = resourceDefinitions.makeOfferObjectResource(objectId, classId); System.Console.WriteLine("\nMaking REST call to insert class"); OfferClass classResponse = restMethods.insertOfferClass(offerClass); System.Console.WriteLine("\nMaking REST call to get object to see if it exists."); OfferObject objectResponse = restMethods.getOfferObject(objectId); // check responses if (!(classResponse is null)) { System.Console.WriteLine($"classId: {classId} inserted."); } else { System.Console.WriteLine($"classId: {classId} insertion failed. See above Server Response for more information."); } if (!(objectResponse is null)) { System.Console.WriteLine($"objectId: {objectId} already exists."); } if (!(objectResponse 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 only object because class was pre-inserted 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 insert class"); LoyaltyClass loyaltyClassResponse = restMethods.insertLoyaltyClass(loyaltyClass); System.Console.WriteLine("\nMaking REST call to get object to see if it exists."); LoyaltyObject loyaltyObjectResponse = restMethods.getLoyaltyObject(objectId); // check responses if (!(loyaltyClassResponse is null)) { System.Console.WriteLine($"classId: {classId} inserted."); }
private void ResetToDefault() { ElementsForOffer = null; SelectedElement = null; Description = string.Empty; Number = 0; DeliveryTime = 0; Discount = 0; PaymentTime = 0; OfferValidity = 0; _offer = null; Image = string.Empty; }
private void CreateNewOffer() { _offer = new OfferClass() { ID = OfferNumber, CivilCustomer = _civilCustomer, PublicCustomer = _publicCustomer, Year = DateTime.Now.Year, ElementList = ElementsForOffer, DeliveryTime = DeliveryTime, Discount = Discount, OfferValidity = OfferValidity, PaymentTime = PaymentTime }; }
public bool InsertOffer(OfferClass offer, User user) { try { long customerID = 0; if (offer.CivilCustomer != null) { customerID = offer.CivilCustomer.ID; } else if (offer.PublicCustomer != null) { customerID = offer.PublicCustomer.ID; } _conn.Open(); SqlCommand cmdOffer = new SqlCommand($"insert into Ponuda (PonudaID, Godina, DatumIzrade, RokIsporuke, RokZaPlacanje, VazenjePonude, StatusPonude, ProdavacID, KupacID) values " + $"({offer.ID}, {offer.Year}, '{offer.Year}', {offer.DeliveryTime}, {offer.PaymentTime}, {offer.OfferValidity}, 'NA CEKANJU', {user.ID}, {customerID})", _conn); cmdOffer.ExecuteScalar(); for (int i = 0; i < offer.ElementList.Count; i++) { SqlCommand cmd = new SqlCommand($"insert into SadrzajPonude (PonudaID, Godina, ProizvodID, NazivArtikla, Dimenzije, Cena, Kolicina, OpisArtikla) values " + $"({offer.ID}, {offer.Year}, {offer.ElementList[i].ProductID}, '{offer.ElementList[i].ProductName}', " + $"'{offer.ElementList[i].Dimension}', " + $"{offer.ElementList[i].Price}, {offer.ElementList[i].Quantity}, '{offer.ElementList[i].Description}')", _conn); cmd.ExecuteScalar(); } return(true); } catch (Exception e) { MessageBox.Show($"Greska\n {e.Message}"); return(false); } finally { if (_conn.State == System.Data.ConnectionState.Open) { _conn.Close(); } } }
public void TestInsertOfferClassAndObject() { RestMethods restMethods = RestMethods.getInstance(); ResourceDefinitions resourceDefinitions = ResourceDefinitions.getInstance(); VerticalType verticalType = Services.VerticalType.OFFER; 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}"; OfferClass classResponse = restMethods.insertOfferClass(resourceDefinitions.makeOfferClassResource(classId)); OfferObject objectResponse = restMethods.insertOfferObject(resourceDefinitions.makeOfferObjectResource(objectId, classId)); Assert.NotNull(classResponse); Assert.NotNull(objectResponse); }
/// <summary>Updates the offer class referenced by the given class ID.</summary> /// <param name="body">The body of the request.</param> /// <param name="resourceId">The unique identifier for a class. This ID must be unique across all classes 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(OfferClass body, string resourceId) { return(new UpdateRequest(service, body, resourceId)); }
/// <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); } }
public static OfferClass generateOfferClass(string issuerId, string classId) { // Define the Image Module Data IList <ImageModuleData> imageModulesData = new List <ImageModuleData>(); ImageModuleData image = new ImageModuleData() { MainImage = new Image() { SourceUri = new Uri() { UriValue = "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg", Description = "Coffee beans" } } }; imageModulesData.Add(image); // Define Links Module Data IList <Uri> uris = new List <Uri>(); Uri uri1 = new Uri() { Description = "Nearby Locations", UriValue = "http://maps.google.com/maps?q=google" }; Uri uri2 = new Uri() { Description = "Call Customer Service", UriValue = "tel:6505555555" }; uris.Add(uri1); uris.Add(uri2); LinksModuleData linksModuleData = new LinksModuleData() { Uris = uris }; // Define Text Module Data IList <TextModuleData> textModulesData = new List <TextModuleData>(); TextModuleData details = new TextModuleData() { Header = "Details", Body = "20% off one cup of coffee at all Baconrista Coffee locations. " + "Only one can be used per visit." }; TextModuleData finePrint = new TextModuleData() { Header = "About Baconrista", Body = "Since 2013, Baconrista Coffee has been committed to making high quality bacon coffee. " + "Visit us in our stores or online at www.baconrista.com." }; textModulesData.Add(details); textModulesData.Add(finePrint); // Define Geofence locations IList <LatLongPoint> locations = new List <LatLongPoint>(); locations.Add(new LatLongPoint() { Latitude = 37.422601, Longitude = -122.085286 }); locations.Add(new LatLongPoint() { Latitude = 37.424354, Longitude = -122.09508869999999 }); locations.Add(new LatLongPoint() { Latitude = 40.7406578, Longitude = -74.00208940000002 }); // Create Offer class OfferClass wobClass = new OfferClass() { Id = issuerId + "." + classId, IssuerName = "Baconrista Coffee", Title = "20% off one cup of coffee", Provider = "Baconrista Deals", TitleImage = new Image() { SourceUri = new Uri() { UriValue = "http://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg" } }, RedemptionChannel = "both", ReviewStatus = "underReview", Locations = locations, AllowMultipleUsersPerObject = true, ImageModulesData = imageModulesData, TextModulesData = textModulesData, LinksModuleData = linksModuleData }; return(wobClass); }
/// <summary>Inserts an offer class with the given ID and properties.</summary> /// <param name="body">The body of the request.</param> public virtual InsertRequest Insert(OfferClass body) { return(new InsertRequest(service, body)); }
/// <summary>Updates the offer class referenced by the given class ID. This method supports patch /// semantics.</summary> /// <param name="body">The body of the request.</param> /// <param name="resourceId">The unique identifier for a class. This ID must be unique across all classes 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(OfferClass body, string resourceId) { return(new PatchRequest(service, body, resourceId)); }
public static OfferClass generateOfferClass(string issuerId, string classId) { // Define rendering templates per view IList<RenderSpec> renderSpec = new List<RenderSpec>(); RenderSpec listRenderSpec = new RenderSpec() { ViewName = "g_list", TemplateFamily = "1.offer_list" }; RenderSpec expandedRenderSpec = new RenderSpec() { ViewName = "g_expanded", TemplateFamily = "1.offer_expanded" }; renderSpec.Add(listRenderSpec); renderSpec.Add(expandedRenderSpec); // Define the Image Module Data IList<ImageModuleData> imageModulesData = new List<ImageModuleData>(); ImageModuleData image = new ImageModuleData() { MainImage = new Image() { SourceUri = new Uri() { UriValue = "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg", Description = "Coffee beans" } } }; imageModulesData.Add(image); // Define Links Module Data IList<Uri> uris = new List<Uri>(); Uri uri1 = new Uri() { Description = "Nearby Locations", UriValue = "http://maps.google.com/maps?q=google" }; Uri uri2 = new Uri() { Description = "Call Customer Service", UriValue = "tel:6505555555" }; uris.Add(uri1); uris.Add(uri2); LinksModuleData linksModuleData = new LinksModuleData() { Uris = uris }; // Define Text Module Data IList<TextModuleData> textModulesData = new List<TextModuleData>(); TextModuleData details = new TextModuleData() { Header = "Details", Body = "20% off one cup of coffee at all Baconrista Coffee locations. " + "Only one can be used per visit." }; TextModuleData finePrint = new TextModuleData() { Header = "About Baconrista", Body = "Since 2013, Baconrista Coffee has been committed to making high quality bacon coffee. " + "Visit us in our stores or online at www.baconrista.com." }; textModulesData.Add(details); textModulesData.Add(finePrint); // Define Geofence locations IList<LatLongPoint> locations = new List<LatLongPoint>(); locations.Add(new LatLongPoint() { Latitude = 37.422601, Longitude = -122.085286 }); locations.Add(new LatLongPoint() { Latitude = 37.424354, Longitude = -122.09508869999999 }); locations.Add(new LatLongPoint() { Latitude = 40.7406578, Longitude = -74.00208940000002 }); // Create Offer class OfferClass wobClass = new OfferClass() { Id = issuerId + "." + classId, IssuerName = "Baconrista Coffee", Title = "20% off one cup of coffee", Provider = "Baconrista Deals", TitleImage = new Image() { SourceUri = new Uri() { UriValue = "http://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg" } }, RenderSpecs = renderSpec, RedemptionChannel = "both", ReviewStatus = "underReview", Locations = locations, AllowMultipleUsersPerObject = true, ImageModulesData = imageModulesData, TextModulesData = textModulesData, LinksModuleData = linksModuleData }; return wobClass; }