コード例 #1
0
        /// <summary>
        /// Get an object with Google Pay API for Passes REST API
        /// See https://developers.google.com/pay/passes/reference/v1/loyaltyobject/get
        /// </summary>
        /// <param name="Id">represents loyalty object resource</param>
        /// <returns>object</returns>
        public LoyaltyObject getLoyaltyObject(string Id)
        {
            LoyaltyObject response = null;
            // Uses the Google Pay API for Passes C# client lib to get a Loyalty object
            // 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/loyaltyobject/get
            WalletobjectsService service = new WalletobjectsService(new Google.Apis.Services.BaseClientService.Initializer()
            {
                HttpClientInitializer = this.credential
            });

            try
            {
                response = service.Loyaltyobject.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);
        }
コード例 #2
0
 public void addLoyaltyObject(LoyaltyObject loyaltyObject)
 {
     if (this.payload.loyaltyObjects == null)
     {
         this.payload.loyaltyObjects = new List <LoyaltyObject>();
     }
     this.payload.loyaltyObjects.Add(loyaltyObject);
 }
コード例 #3
0
        public virtual void ProcessRequest(HttpContext context)
        {
            try {
                HttpRequest request = context.Request;

                // get credentials and settings
                WobCredentials credentials = new WobCredentials(
                    WebConfigurationManager.AppSettings["ServiceAccountId"],
                    WebConfigurationManager.AppSettings["ServiceAccountPrivateKey"],
                    WebConfigurationManager.AppSettings["ApplicationName"],
                    WebConfigurationManager.AppSettings["IssuerId"]);

                string loyaltyClassId   = WebConfigurationManager.AppSettings["LoyaltyClassId"];
                string loyaltyObjectId  = WebConfigurationManager.AppSettings["LoyaltyObjectId"];
                string offerClassId     = WebConfigurationManager.AppSettings["OfferClassId"];
                string offerObjectId    = WebConfigurationManager.AppSettings["OfferObjectId"];
                string giftCardClassId  = WebConfigurationManager.AppSettings["GiftCardClassId"];
                string giftCardObjectId = WebConfigurationManager.AppSettings["GiftCardObjectId"];

                // OAuth - setup certificate based on private key file
                X509Certificate2 certificate = new X509Certificate2(
                    AppDomain.CurrentDomain.BaseDirectory + credentials.serviceAccountPrivateKey,
                    "notasecret",
                    X509KeyStorageFlags.Exportable);

                WobUtils utils = new WobUtils(credentials.serviceAccountId, certificate);

                // get the object type
                string type = request.Params["type"];

                if (type.Equals("loyalty"))
                {
                    LoyaltyObject loyaltyObject = Loyalty.generateLoyaltyObject(credentials.IssuerId, loyaltyClassId, loyaltyObjectId);
                    utils.addObject(loyaltyObject);
                }
                else if (type.Equals("offer"))
                {
                    OfferObject offerObject = Offer.generateOfferObject(credentials.IssuerId, offerClassId, offerObjectId);
                    utils.addObject(offerObject);
                }
                else if (type.Equals("giftcard"))
                {
                    GiftCardObject giftCardObject = GiftCard.generateGiftCardObject(credentials.IssuerId, giftCardClassId, giftCardObjectId);
                    utils.addObject(giftCardObject);
                }

                // generate the JWT
                string jwt = utils.GenerateJwt();

                HttpResponse response = context.Response;
                response.Write(jwt);
                //response.ContentType = "text/xml";
            }
            catch (Exception e) {
                Console.Write(e.StackTrace);
            }
        }
コード例 #4
0
        /// <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.");
                    }
コード例 #5
0
        public void TestInsertLoyaltyClassAndObject()
        {
            RestMethods         restMethods         = RestMethods.getInstance();
            ResourceDefinitions resourceDefinitions = ResourceDefinitions.getInstance();
            VerticalType        verticalType        = Services.VerticalType.LOYALTY;
            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}";
            LoyaltyClass  classResponse  = restMethods.insertLoyaltyClass(resourceDefinitions.makeLoyaltyClassResource(classId));
            LoyaltyObject objectResponse = restMethods.insertLoyaltyObject(resourceDefinitions.makeLoyaltyObjectResource(objectId, classId));

            Assert.NotNull(classResponse);
            Assert.NotNull(objectResponse);
        }
コード例 #6
0
        /// <summary>
        /// Generate a loyalty object
        /// See https://developers.google.com/pay/passes/reference/v1/loyaltyobject
        /// </summary>
        /// <param name="objectId"> the unique identifier for a object</param>
        /// <returns>the inserted loyalty object</returns>
        public LoyaltyObject makeLoyaltyObjectResource(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 loyalty object. For more properties, check:
            //// https://developers.google.com/pay/passes/reference/v1/loyaltyobject/insert
            //// https://developers.google.com/pay/passes/guides/pass-verticals/loyalty/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
            LoyaltyObject payload = new LoyaltyObject();

            //required fields
            payload.Id      = objectId;
            payload.ClassId = classId;
            payload.State   = "active";
            //optional fields. See design and reference api for more
            payload.AccountId   = "12345678890";
            payload.AccountName = "Jane Doe";
            payload.Barcode     = new Barcode()
            {
                Type          = "qrCode",
                Value         = "1234abc",
                AlternateText = "1234abc"
            };
            payload.TextModulesData = new List <TextModuleData>()
            {
                new TextModuleData()
                {
                    Header = "Jane\"s Baconrista Rewards",
                    Body   = "Save more at your local Mountain View store Jane. "
                             + " You get 1 bacon fat latte for every 5 coffees purchased.  "
                             + "Also just for you, 10% off all pastries in the Mountain View store."
                }
            };
            payload.LinksModuleData = new LinksModuleData()
            {
                Uris = new List <Uri>()
                {
                    new Uri()
                    {
                        UriValue    = "http://www.google.com/",
                        Description = "My Baconrista Account"
                    }
                }
            };
            payload.InfoModuleData = new InfoModuleData()
            {
                LabelValueRows = new List <LabelValueRow>()
                {
                    new LabelValueRow()
                    {
                        Columns = new List <LabelValue>()
                        {
                            new LabelValue()
                            {
                                Label = "Next Reward in",
                                Value = "2 coffees"
                            },
                            new LabelValue()
                            {
                                Label = "Member Since",
                                Value = "01/15/2013"
                            }
                        }
                    },
                    new LabelValueRow()
                    {
                        Columns = new List <LabelValue>()
                        {
                            new LabelValue()
                            {
                                Label = "Local Store",
                                Value = "Mountain View"
                            }
                        }
                    }
                }
            };
            payload.InfoModuleData.ShowLastUpdateTime = true;
            payload.Messages = new List <Message>()
            {
                new Message()
                {
                    Header = "Jane, welcome to Banconrista Rewards",
                    Body   = "Thanks for joining our program. Show this message to "
                             + "our barista for your first free coffee on us!"
                }
            };
            payload.LoyaltyPoints = new LoyaltyPoints()
            {
                Balance = new LoyaltyPointsBalance()
                {
                    String__ = "800"
                },
                Label = "Points"
            };
            payload.Locations = new List <LatLongPoint>()
            {
                new LatLongPoint()
                {
                    Latitude  = 37.424015499999996,
                    Longitude = -122.09259560000001
                },
                new LatLongPoint()
                {
                    Latitude  = 37.7901435,
                    Longitude = -122.09508869999999
                },
                new LatLongPoint()
                {
                    Latitude  = 37.424354,
                    Longitude = -122.39026709999997
                },
                new LatLongPoint()
                {
                    Latitude  = 40.7406578,
                    Longitude = -74.00208940000002
                }
            };
            return(payload);
        }
コード例 #7
0
 public void addObject(LoyaltyObject obj)
 {
     loyaltyObjects.Add(obj);
 }
コード例 #8
0
    /// <summary>
    /// Generates a Loyalty Object
    /// </summary>
    /// <param name="issuerId"> </param>
    /// <param name="classId"> </param>
    /// <param name="objectId"> </param>
    /// <returns> loyaltyObject </returns>
    public static LoyaltyObject generateLoyaltyObject(string issuerId, string classId, string objectId)
    {
      // Define Barcode
      Barcode barcode = new Barcode() {
        Type = "qrCode",
        Value = "28343E3",
        AlternateText = "12345"
      };

      // Define Points
      LoyaltyPoints points = new LoyaltyPoints() {
        Label = "Points",
        PointsType = "points",
        Balance = new LoyaltyPointsBalance() { String = "500" }
      };

      // Define Text Module Data
      IList<TextModuleData> textModulesData = new List<TextModuleData>();
      TextModuleData textModuleData = new TextModuleData() {
        Header = "Jane's Baconrista Rewards",
        Body = "Save more at your local Mountain View store Jane.  " +
        "You get 1 bacon fat latte for every 5 coffees purchased.  " +
        "Also just for you, 10% off all pastries in the Mountain View store."
      };
      textModulesData.Add(textModuleData);

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

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

      // Define Info Module
      IList<LabelValue> row0cols = new List<LabelValue>();
      LabelValue row0col0 = new LabelValue() { Label = "Next Reward in", Value = "2 coffees" };
      LabelValue row0col1 = new LabelValue() { Label = "Member Since", Value = "01/15/2013" };
      row0cols.Add(row0col0);
      row0cols.Add(row0col1);

      IList<LabelValue> row1cols = new List<LabelValue>();
      LabelValue row1col0 = new LabelValue() { Label = "Local Store", Value = "Mountain View" };
      row1cols.Add(row1col0);

      IList<LabelValueRow> rows = new List<LabelValueRow>();
      LabelValueRow row0 = new LabelValueRow() {
        Columns = row0cols
      };
      LabelValueRow row1 = new LabelValueRow() {
        Columns = row1cols
      };

      rows.Add(row0);
      rows.Add(row1);

      InfoModuleData infoModuleData = new InfoModuleData() {
        ShowLastUpdateTime = true,
        LabelValueRows = rows
      };

      // Define general messages
      IList<WalletObjectMessage> messages = new List<WalletObjectMessage>();
      WalletObjectMessage message = new WalletObjectMessage() {
        Header = "Hi Jane!",
        Body = "Thanks for joining our program. Show this message to " +
                "our barista for your first free coffee on us!",
        ActionUri = new Uri() { UriValue = "http://baconrista.com" }
      };

      messages.Add(message);

      // Define Wallet Instance
      LoyaltyObject loyaltyObj = new LoyaltyObject() {
        ClassId = issuerId + "." + classId,
        Id = issuerId + "." + objectId,
        Version = 1,
        State = "active",
        Barcode = barcode,
        AccountName = "Jane Doe",
        AccountId = "1234567890",
        LoyaltyPoints = points,
        Messages = messages,
        InfoModuleData = infoModuleData,
        TextModulesData = textModulesData,
        LinksModuleData = linksModuleData
      };

      return loyaltyObj;
    }
コード例 #9
0
 public void addObject(LoyaltyObject obj)
 {
     loyaltyObjects.Add(obj);
 }
コード例 #10
0
        /// <summary>
        /// Generates a Loyalty Object
        /// </summary>
        /// <param name="issuerId"> </param>
        /// <param name="classId"> </param>
        /// <param name="objectId"> </param>
        /// <returns> loyaltyObject </returns>
        public static LoyaltyObject generateLoyaltyObject(string issuerId, string classId, string objectId)
        {
            // Define Barcode
            Barcode barcode = new Barcode()
            {
                Type          = "qrCode",
                Value         = "28343E3",
                AlternateText = "12345"
            };

            // Define Points
            LoyaltyPoints points = new LoyaltyPoints()
            {
                Label      = "Points",
                PointsType = "points",
                Balance    = new LoyaltyPointsBalance()
                {
                    String = "500"
                }
            };

            // Define Text Module Data
            IList <TextModuleData> textModulesData = new List <TextModuleData>();
            TextModuleData         textModuleData  = new TextModuleData()
            {
                Header = "Jane's Baconrista Rewards",
                Body   = "Save more at your local Mountain View store Jane.  " +
                         "You get 1 bacon fat latte for every 5 coffees purchased.  " +
                         "Also just for you, 10% off all pastries in the Mountain View store."
            };

            textModulesData.Add(textModuleData);

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

            uris.Add(uri1);

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

            // Define Info Module
            IList <LabelValue> row0cols = new List <LabelValue>();
            LabelValue         row0col0 = new LabelValue()
            {
                Label = "Next Reward in", Value = "2 coffees"
            };
            LabelValue row0col1 = new LabelValue()
            {
                Label = "Member Since", Value = "01/15/2013"
            };

            row0cols.Add(row0col0);
            row0cols.Add(row0col1);

            IList <LabelValue> row1cols = new List <LabelValue>();
            LabelValue         row1col0 = new LabelValue()
            {
                Label = "Local Store", Value = "Mountain View"
            };

            row1cols.Add(row1col0);

            IList <LabelValueRow> rows = new List <LabelValueRow>();
            LabelValueRow         row0 = new LabelValueRow()
            {
                Columns = row0cols
            };
            LabelValueRow row1 = new LabelValueRow()
            {
                Columns = row1cols
            };

            rows.Add(row0);
            rows.Add(row1);

            InfoModuleData infoModuleData = new InfoModuleData()
            {
                ShowLastUpdateTime = true,
                LabelValueRows     = rows
            };

            // Define general messages
            IList <WalletObjectMessage> messages = new List <WalletObjectMessage>();
            WalletObjectMessage         message  = new WalletObjectMessage()
            {
                Header = "Hi Jane!",
                Body   = "Thanks for joining our program. Show this message to " +
                         "our barista for your first free coffee on us!",
                ActionUri = new Uri()
                {
                    UriValue = "http://baconrista.com"
                }
            };

            messages.Add(message);

            // Define Wallet Instance
            LoyaltyObject loyaltyObj = new LoyaltyObject()
            {
                ClassId         = issuerId + "." + classId,
                Id              = issuerId + "." + objectId,
                Version         = 1,
                State           = "active",
                Barcode         = barcode,
                AccountName     = "Jane Doe",
                AccountId       = "1234567890",
                LoyaltyPoints   = points,
                Messages        = messages,
                InfoModuleData  = infoModuleData,
                TextModulesData = textModulesData,
                LinksModuleData = linksModuleData
            };

            return(loyaltyObj);
        }
コード例 #11
0
 /// <summary>Updates the loyalty 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(LoyaltyObject body, string resourceId)
 {
     return(new UpdateRequest(service, body, resourceId));
 }
コード例 #12
0
 /// <summary>Updates the loyalty 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(LoyaltyObject body, string resourceId)
 {
     return(new PatchRequest(service, body, resourceId));
 }
コード例 #13
0
 /// <summary>Inserts an loyalty object with the given ID and properties.</summary>
 /// <param name="body">The body of the request.</param>
 public virtual InsertRequest Insert(LoyaltyObject body)
 {
     return(new InsertRequest(service, body));
 }
コード例 #14
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);
            }
        }
コード例 #15
0
        public virtual void ProcessRequest(HttpContext context)
        {
            try {
                HttpRequest request = context.Request;

                WobCredentials credentials = new WobCredentials(
                    WebConfigurationManager.AppSettings["ServiceAccountId"],
                    WebConfigurationManager.AppSettings["ServiceAccountPrivateKey"],
                    WebConfigurationManager.AppSettings["ApplicationName"],
                    WebConfigurationManager.AppSettings["IssuerId"]);

                // OAuth - setup certificate based on private key file
                X509Certificate2 certificate = new X509Certificate2(
                    AppDomain.CurrentDomain.BaseDirectory + credentials.serviceAccountPrivateKey,
                    "notasecret",
                    X509KeyStorageFlags.Exportable);

                WobUtils          utils      = null;
                WebserviceRequest webRequest = null;
                JsonWebToken.Payload.WebserviceResponse webResponse = null;
                string jwt = null;

                ReadEntityBodyMode read        = request.ReadEntityBodyMode;
                Stream             inputStream = null;

                if (read == ReadEntityBodyMode.None)
                {
                    inputStream = request.GetBufferedInputStream();
                }
                else
                {
                    inputStream = request.InputStream;
                }

                webRequest = NewtonsoftJsonSerializer.Instance.Deserialize <WebserviceRequest>(inputStream);

                if (webRequest.Method.Equals("signup"))
                {
                    webResponse = new JsonWebToken.Payload.WebserviceResponse()
                    {
                        Message = "Welcome to baconrista",
                        Result  = "approved"
                    };
                }
                else
                {
                    webResponse = new JsonWebToken.Payload.WebserviceResponse()
                    {
                        Message = "Thanks for linking to baconrista",
                        Result  = "approved"
                    };
                }

                utils = new WobUtils(credentials.IssuerId, certificate);

                string        linkId        = webRequest.Params.LinkingId;
                LoyaltyObject loyaltyObject = Loyalty.generateLoyaltyObject(credentials.IssuerId, "LoyaltyClass", (linkId != null) ? linkId : "LoyaltyObject");
                utils.addObject(loyaltyObject);

                jwt = utils.GenerateWsJwt(webResponse);

                HttpResponse response = context.Response;
                response.Write(jwt);
            }
            catch (Exception e) {
                Console.Write(e.StackTrace);
            }
        }
コード例 #16
0
        /// <summary>
        /// Generates a Loyalty Object
        /// </summary>
        /// <param name="issuerId"> </param>
        /// <param name="classId"> </param>
        /// <param name="objectId"> </param>
        /// <returns> loyaltyObject </returns>
        public static LoyaltyObject generateLoyaltyObject(string issuerId, string classId, string objectId)
        {
            // Define Barcode
              Barcode barcode = new Barcode() {
            Type = "qrCode",
            Value = "28343E3"
              };

              // Define Points
              LoyaltyPoints points = new LoyaltyPoints() {
            Label = "Points",
            Balance = new LoyaltyPointsBalance() { String = "500" }
              };

              // Define Text Module Data
              IList<TextModuleData> textModulesData = new List<TextModuleData>();

              TextModuleData textModuleData = new TextModuleData() {
            Header = "Jane's Baconrista Rewards",
            Body = "You are 5 coffees away from receiving a free bacon fat latte"
              };

              textModulesData.Add(textModuleData);

              // Define Uris
              IList<Uri> uris = new List<Uri>();
              Uri uri1 = new Uri() {
            Description = "My Baconrista Account",
            UriValue = "http://www.baconrista.com/myaccount?id=1234567890"
              };
              Uri uri2 = new Uri() {
            Description = "uri 2 description",
            UriValue = "http://www.google.com"
              };

              uris.Add(uri1);
              uris.Add(uri2);

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

              // Define Info Module
              IList<LabelValue> row0cols = new List<LabelValue>();
              LabelValue row0col0 = new LabelValue() { Label = "Member Name", Value = "Jane Doe" };
              LabelValue row0col1 = new LabelValue() { Label = "Membership #", Value = "1234567890" };
              row0cols.Add(row0col0);
              row0cols.Add(row0col1);

              IList<LabelValue> row1cols = new List<LabelValue>();
              LabelValue row1col0 = new LabelValue() { Label = "Next Reward in", Value = "2 coffees" };
              LabelValue row1col1 = new LabelValue() { Label = "Member Since", Value = "01/15/2013" };
              row1cols.Add(row1col0);
              row1cols.Add(row1col1);

              IList<LabelValueRow> rows = new List<LabelValueRow>();
              LabelValueRow row0 = new LabelValueRow() { HexBackgroundColor = "#BBCCFC", Columns = row0cols };
              LabelValueRow row1 = new LabelValueRow() { HexBackgroundColor = "#FFFB00", Columns = row1cols };

              rows.Add(row0);
              rows.Add(row1);

              InfoModuleData infoModuleData = new InfoModuleData() {
            HexFontColor = "#FFFFFF",
            HexBackgroundColor = "#FC058C",
            ShowLastUpdateTime = true,
            LabelValueRows = rows
              };

              // Define Wallet Instance
              LoyaltyObject loyaltyObj = new LoyaltyObject()
              {
            ClassId = issuerId + "." + classId,
            Id = issuerId + "." + objectId,
            Version = "1",
            State = "active",
            Barcode = barcode,
            AccountName = "Jane Doe",
            AccountId = "1234567890",
            LoyaltyPoints = points,
            InfoModuleData = infoModuleData,
            TextModulesData = textModulesData,
            LinksModuleData = linksModuleData
              };

              return loyaltyObj;
        }