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

            try
            {
                response = service.Transitobject.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);
        }
Beispiel #2
0
        /// <summary>
        /// Insert class with Google Pay API for Passes REST API
        /// See https://developers.google.com/pay/passes/reference/v1/giftcardclass/insert
        /// </summary>
        /// <param name="theClass">represents gift card class resource</param>
        /// <returns>Class</returns>
        public GiftCardClass insertGiftCardClass(GiftCardClass theClass)
        {
            GiftCardClass response = null;
            // Uses the Google Pay API for Passes C# client lib to insert the 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/insert
            WalletobjectsService service = new WalletobjectsService(new Google.Apis.Services.BaseClientService.Initializer()
            {
                HttpClientInitializer = this.credential
            });

            try
            {
                response = service.Giftcardclass.Insert(theClass).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 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);
            }
        }
    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);
      }
    }