Example #1
0
        /// <summary>
        /// Get a class with Google Pay API for Passes REST API
        /// See https://developers.google.com/pay/passes/reference/v1/giftcardclass/get
        /// </summary>
        /// <param name="id">id of the class</param>
        /// <returns>Class</returns>
        public GiftCardClass getGiftCardClass(string id)
        {
            GiftCardClass response = null;
            // Uses the Google Pay API for Passes C# client lib to get a GiftCard 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/giftcardclass/get
            WalletobjectsService service = new WalletobjectsService(new Google.Apis.Services.BaseClientService.Initializer()
            {
                HttpClientInitializer = this.credential
            });

            try
            {
                response = service.Giftcardclass.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);
        }
Example #2
0
 public void addGiftCardClass(GiftCardClass giftCardClass)
 {
     if (this.payload.giftCardClasses == null)
     {
         this.payload.giftCardClasses = new List <GiftCardClass>();
     }
     this.payload.giftCardClasses.Add(giftCardClass);
 }
        /// <summary>
        /// Generate a gift card class
        /// See https://developers.google.com/pay/passes/reference/v1/giftcardclass
        /// </summary>
        /// <param name="classId"> the unique identifier for a class</param>
        /// <returns>the inserted gift card class</returns>
        public GiftCardClass makeGiftCardClassResource(string classId)
        {
            // Define the resource representation of the Class
            // values should be from your DB/services; here we hardcode information
            // below defines an gift card class. For more properties, check:
            //// https://developers.google.com/pay/passes/reference/v1/giftcardclass/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
            GiftCardClass payload = new GiftCardClass();

            //required fields
            payload.Id           = classId;
            payload.IssuerName   = "Baconrista";
            payload.ReviewStatus = "underReview";
            //optional fields. See design and reference api for more
            payload.MerchantName = "Baconrista";
            payload.ProgramLogo  = new Image()
            {
                SourceUri = new ImageUri()
                {
                    Uri = "http://farm8.staticflickr.com/7340/11177041185_a61a7f2139_o.jpg"
                }
            };
            payload.TextModulesData = new List <TextModuleData>()
            {
                new TextModuleData()
                {
                    Header = "Where to redeem",
                    Body   = "All US gift cards are redeemable in any US and Puerto Rico"
                             + " Baconrista retail locations, or online at Baconrista.com where"
                             + " available, for merchandise or services."
                }
            };
            payload.LinksModuleData = new LinksModuleData()
            {
                Uris = new List <Uri>()
                {
                    new Uri()
                    {
                        UriValue    = "http://maps.google.com/",
                        Description = "Baconrista"
                    }
                }
            };
            payload.Locations = new List <LatLongPoint>()
            {
                new LatLongPoint()
                {
                    Latitude  = 37.424015499999996,
                    Longitude = -122.09259560000001
                }
            };
            return(payload);
        }
        public void TestInsertGiftCardClassAndObject()
        {
            RestMethods         restMethods         = RestMethods.getInstance();
            ResourceDefinitions resourceDefinitions = ResourceDefinitions.getInstance();
            VerticalType        verticalType        = Services.VerticalType.GIFTCARD;
            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}";
            GiftCardClass  classResponse  = restMethods.insertGiftCardClass(resourceDefinitions.makeGiftCardClassResource(classId));
            GiftCardObject objectResponse = restMethods.insertGiftCardObject(resourceDefinitions.makeGiftCardObjectResource(objectId, classId));

            Assert.NotNull(classResponse);
            Assert.NotNull(objectResponse);
        }
Example #5
0
 /// <summary>Updates the gift card 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(GiftCardClass body, string resourceId)
 {
     return(new UpdateRequest(service, body, resourceId));
 }
Example #6
0
 /// <summary>Updates the gift card 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(GiftCardClass body, string resourceId)
 {
     return(new PatchRequest(service, body, resourceId));
 }
Example #7
0
 /// <summary>Inserts an gift card class with the given ID and properties.</summary>
 /// <param name="body">The body of the request.</param>
 public virtual InsertRequest Insert(GiftCardClass body)
 {
     return(new InsertRequest(service, body));
 }
Example #8
0
        /// <summary>
        /// Generates a GiftCard Class
        /// </summary>
        /// <param name="issuerId"> </param>
        /// <param name="classId"> </param>
        /// <returns> GiftCardClass </returns>
        public static GiftCardClass generateGiftCardClass(string issuerId, string classId)
        {
            // Define Text Module Data
            IList <TextModuleData> textModulesData = new List <TextModuleData>();
            TextModuleData         textModuleData  = new TextModuleData()
            {
                Header = "Where to Redeem",
                Body   = "All US gift cards are redeemable in any US and Puerto Rico " +
                         "Baconrista retail locations, or online at Baconrista.com where" +
                         "available, for merchandise or services."
            };

            textModulesData.Add(textModuleData);

            // Define Links Module Data
            IList <Uri> uris = new List <Uri>();
            Uri         uri1 = new Uri()
            {
                Description = "Baconrista",
                UriValue    = "http://www.baconrista.com/"
            };

            uris.Add(uri1);

            LinksModuleData linksModuleData = new LinksModuleData()
            {
                Uris = uris
            };

            // Define Info Module
            InfoModuleData infoModuleData = new InfoModuleData()
            {
                ShowLastUpdateTime = true
            };

            // 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 GiftCard class
            GiftCardClass wobClass = new GiftCardClass()
            {
                Id           = issuerId + "." + classId,
                IssuerName   = "Baconrista",
                MerchantName = "Baconrista",
                ProgramLogo  = new Image()
                {
                    SourceUri = new Uri()
                    {
                        UriValue = "http://farm8.staticflickr.com/7340/11177041185_a61a7f2139_o.jpg"
                    }
                },
                TextModulesData = textModulesData,
                LinksModuleData = linksModuleData,
                ReviewStatus    = "underReview",
                Locations       = locations
            };

            return(wobClass);
        }
Example #9
0
        /// <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);
            }
        }
    /// <summary>
    /// Generates a GiftCard Class
    /// </summary>
    /// <param name="issuerId"> </param>
    /// <param name="classId"> </param>
    /// <returns> GiftCardClass </returns>
    public static GiftCardClass generateGiftCardClass(string issuerId, string classId)
    {
        // Define rendering templates per view
        IList<RenderSpec> renderSpec = new List<RenderSpec>();

        RenderSpec listRenderSpec = new RenderSpec() {
          ViewName = "g_list",
          TemplateFamily = "1.giftCard1_list"
        };

        RenderSpec expandedRenderSpec = new RenderSpec() {
          ViewName = "g_expanded",
          TemplateFamily = "1.giftCard1_expanded"
        };

        renderSpec.Add(listRenderSpec);
        renderSpec.Add(expandedRenderSpec);

        // Define Text Module Data
        IList<TextModuleData> textModulesData = new List<TextModuleData>();
        TextModuleData textModuleData = new TextModuleData() {
          Header = "Where to Redeem",
          Body = "All US gift cards are redeemable in any US and Puerto Rico " +
                "Baconrista retail locations, or online at Baconrista.com where" +
                "available, for merchandise or services."
        };
        textModulesData.Add(textModuleData);

        // Define Links Module Data
        IList<Uri> uris = new List<Uri>();
        Uri uri1 = new Uri() {
          Description = "Baconrista",
          UriValue = "http://www.baconrista.com/"
        };
        uris.Add(uri1);

        LinksModuleData linksModuleData = new LinksModuleData() {
          Uris = uris
        };

        // Define Info Module
        InfoModuleData infoModuleData = new InfoModuleData() {
          ShowLastUpdateTime = true
        };

        // 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 GiftCard class
        GiftCardClass wobClass = new GiftCardClass() {
          Id = issuerId + "." + classId,
          IssuerName = "Baconrista",
          MerchantName = "Baconrista",
          ProgramLogo = new Image() {
            SourceUri = new Uri() {
              UriValue = "http://farm8.staticflickr.com/7340/11177041185_a61a7f2139_o.jpg"
            }
          },
          TextModulesData = textModulesData,
          LinksModuleData = linksModuleData,
          RenderSpecs = renderSpec,
          ReviewStatus = "underReview",
          Locations = locations
        };

        return wobClass;
    }