예제 #1
0
        public QuickBooksAdapter(IToken accessToken, String appToken, String consumerKey, String consumerSecret, String baseUrl)
        {
            var oauthValidator = new OAuthRequestValidator(accessToken.Token, accessToken.TokenSecret, consumerKey, consumerSecret);

            Context = new ServiceContext(appToken, accessToken.Realm, IntuitServicesType.QBO, oauthValidator);
            Context.IppConfiguration.BaseUrl.Qbo = baseUrl;
        }
		public void PlatformDisconnectValidOauth(String oauthtoken,String oauthtokensecret)
		{
           try
           {
                PlatformService.PlatformService.Disconnect(ValidConsumerKey, ValidConsumerSecret,
                     oauthtoken, oauthtokensecret);
           }
           catch (PlatformException pex)
           {
               Console.WriteLine("PlatformDisconnect throw PlatformException errCode:" + pex.ErrorCode + " errMsg:" + pex.ErrorMessage + " serverTime:" + pex.ServerTime);
                Assert.Fail();
           }

           OAuthRequestValidator ioAuthRequestValidatorQbo = new OAuthRequestValidator(oauthtoken, oauthtokensecret, ValidConsumerKey, ValidConsumerSecret);
           ServiceContext iqboContextOAuth = new ServiceContext(realmIAQBO, IntuitServicesType.QBO, ioAuthRequestValidatorQbo);
           Customer customer = QBOHelper.CreateCustomer(iqboContextOAuth);
           try
           {
               Customer added = Helper.Add<Customer>(iqboContextOAuth, customer);
           }
           catch (InvalidTokenException e)
           {
               Assert.AreEqual("Unauthorized-401", e.Message);
               return;
           }
           Assert.Fail();
        }
예제 #3
0
        public static Customer FindCustomer(string name)
        {
            var oauthValidator = new OAuthRequestValidator(
                ConfigurationManager.AppSettings["accessToken"].ToString(CultureInfo.InvariantCulture),
                ConfigurationManager.AppSettings["accessTokenSecret"].ToString(CultureInfo.InvariantCulture),
                ConfigurationManager.AppSettings["consumerKey"].ToString(CultureInfo.InvariantCulture),
                ConfigurationManager.AppSettings["consumerKeySecret"].ToString(CultureInfo.InvariantCulture));

            var context = new ServiceContext(
                oauthValidator,
                ConfigurationManager.AppSettings["realmId"].ToString(CultureInfo.InvariantCulture),
                IntuitServicesType.QBO);



            var customerQuery = new CustomerQuery
            {
                Name = name
            };

            var findCustomer = customerQuery.ExecuteQuery <Customer>(context).First <Customer>();


            return(findCustomer);
        }
예제 #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            realmId = HttpContext.Current.Session["realm"].ToString();
            string accessToken       = HttpContext.Current.Session["accessToken"].ToString();
            string accessTokenSecret = HttpContext.Current.Session["accessTokenSecret"].ToString();
            string consumerKey       = HttpContext.Current.Session["consumerKey"].ToString();
            string consumerSecret    = HttpContext.Current.Session["consumerSecret"].ToString();

            //Oauth1 validator
            OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);

            //Calling Oauth1 to Oauth2 migration helper
            OAuth1ToOAuth2TokenMigrationHelper objMigrationHelper = new OAuth1ToOAuth2TokenMigrationHelper(EnvironmentForMigration.Sandbox);

            MigratedTokenResponse oauth2Tokens = objMigrationHelper.GetOAuth2Tokens(scopes, redirectUrl, clientId, clientSecret, oauthValidator);

            if (oauth2Tokens.HttpStatusCode == HttpStatusCode.OK)
            {
                output("Oauth1 tokens migrated to oauth2 ones successfully!");
                //Making QBO API call
                output("Making QBO Api call!");
                TestQBOCallUsingOAuth2Token(oauth2Tokens.AccessToken, oauth2Tokens.RefreshToken, oauth2Tokens.RealmId);
            }
            else
            {
                output("Oauth1 tokens migrated to oauth2 ones failed!");
            }
        }
예제 #5
0
        /// <summary>
        /// Action Results for Index
        /// </summary>
        /// <returns>Action Result.</returns>
        public ActionResult Index()
        {
            realmId           = Session["realm"].ToString();
            accessToken       = Session["accessToken"].ToString();
            accessTokenSecret = Session["accessTokenSecret"].ToString();
            consumerKey       = ConfigurationManager.AppSettings["consumerKey"].ToString();
            consumerSecret    = ConfigurationManager.AppSettings["consumerSecret"].ToString();
            dataSourcetype    = Session["dataSource"].ToString();

            OAuthRequestValidator oauthValidator = Initializer.InitializeOAuthValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
            ServiceContext        context        = Initializer.InitializeServiceContext(oauthValidator, realmId, string.Empty, string.Empty, dataSourcetype);

            try
            {
                Intuit.Ipp.QueryFilter.QueryService <Intuit.Ipp.Data.Customer> customerQueryService = new Intuit.Ipp.QueryFilter.QueryService <Intuit.Ipp.Data.Customer>(context);
                List <Intuit.Ipp.Data.Customer> customers = customerQueryService.Select(s => s).ToList();
                ViewBag.MyCollection  = customers;
                ViewBag.CustomerCount = customers.Count();
            }
            catch (Intuit.Ipp.Exception.InvalidTokenException exp)
            {
                //Remove the Oauth access token from the OauthAccessTokenStorage.xml
                OauthAccessTokenStorageHelper.RemoveInvalidOauthAccessToken(Session["FriendlyEmail"].ToString(), this);

                Session["show"] = true;
                return(Redirect("/Home/index"));
            }
            catch (System.Exception exp)
            {
                throw exp;
            }

            return(View());
        }
예제 #6
0
        /// <summary>
        /// Helper method to initialize the OAuthValidator
        /// </summary>
        /// <param name="accessToken">Value for AccessToken</param>
        /// <param name="accessTokenSecret">Value for AccessTokenSecret</param>
        /// <param name="consumerKey">Value for ConsumerKey</param>
        /// <param name="consumerSecret">Value for ConsumerSecret</param>
        /// <returns>Object of OAuthRequestValidator</returns>
        internal static OAuthRequestValidator InitializeOAuthValidator(string accessToken, string accessTokenSecret, string consumerKey, string consumerSecret)
        {
            OAuthRequestValidator oauthValidator =
                new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);

            return(oauthValidator);
        }
        public void BatchTest()
        {
            string accessTokenQBO       = ConfigurationManager.AppSettings["AccessTokenQBO"];
            string accessTokenSecretQBO = ConfigurationManager.AppSettings["AccessTokenSecretQBO"];
            string consumerKeyQBO       = ConfigurationManager.AppSettings["ConsumerKeyQBO"];
            string ConsumerSecretQBO    = ConfigurationManager.AppSettings["ConsumerSecretQBO"];
            string realmIAQBO           = ConfigurationManager.AppSettings["RealmIAQBO"];
            OAuthRequestValidator oAuthRequestValidator = new OAuthRequestValidator(accessTokenQBO, accessTokenSecretQBO, consumerKeyQBO, ConsumerSecretQBO);
            ServiceContext        context = new ServiceContext(realmIAQBO, IntuitServicesType.QBO, oAuthRequestValidator);
            DataService           service = new DataService(context);

            context.IppConfiguration.Message.Response.CompressionFormat   = Intuit.Ipp.Core.Configuration.CompressionFormat.GZip;
            context.IppConfiguration.Message.Response.SerializationFormat = Intuit.Ipp.Core.Configuration.SerializationFormat.Json;
            Customer customer = new Customer();
            string   guid     = Guid.NewGuid().ToString("N");

            customer.GivenName   = guid.Substring(0, 25);
            customer.Title       = guid.Substring(0, 15);
            customer.MiddleName  = guid.Substring(0, 5);
            customer.FamilyName  = guid.Substring(0, 25);
            customer.DisplayName = guid.Substring(0, 20);

            try
            {
                Batch batch = service.CreateNewBatch();
                batch.Add(customer, "addCustomer", OperationEnum.create);
                batch.Add(new CDCQuery()
                {
                    ChangedSince = DateTime.Now.AddDays(-1), ChangedSinceSpecified = true, Entities = "Customer"
                }, "cdcOpration");
                batch.Execute();
                IntuitBatchResponse addCustomerResponse = batch.IntuitBatchItemResponses[0];
                if (addCustomerResponse.ResponseType != ResponseType.Exception)
                {
                    Customer addedcustomer = addCustomerResponse.Entity as Customer;
                    Assert.IsNotNull(addedcustomer);
                    Assert.IsFalse(string.IsNullOrEmpty(addedcustomer.Id));
                }
                IntuitBatchResponse CDCQueryResponse = batch.IntuitBatchItemResponses[1];
                if (CDCQueryResponse.ResponseType != ResponseType.Exception)
                {
                    Dictionary <string, List <IEntity> > cdcCustomers = CDCQueryResponse.CDCResponse.entities;
                    Assert.IsNotNull(cdcCustomers);
                    Assert.IsTrue(cdcCustomers.Count > 0);
                    foreach (KeyValuePair <string, List <IEntity> > entry in cdcCustomers)
                    {
                        Assert.IsTrue(entry.Value.ElementAt(0).GetType() == new Customer().GetType());
                    }
                }
                else
                {
                    Assert.Fail();
                }
            }
            catch (Ipp.Exception.IdsException ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        private static ServiceContext getServiceContext(RestProfile profile)
        {
            var consumerKey    = ConfigurationManager.AppSettings["consumerKey"].ToString();
            var consumerSecret = ConfigurationManager.AppSettings["consumerSecret"].ToString();
            OAuthRequestValidator oauthValidator = new OAuthRequestValidator(profile.OAuthAccessToken, profile.OAuthAccessTokenSecret, consumerKey, consumerSecret);

            return(new ServiceContext(profile.RealmId, (IntuitServicesType)profile.DataSource, oauthValidator));
        }
예제 #9
0
        public static ServiceContext GetServiceContext()
        {
            var oAuthValiator = new OAuthRequestValidator(ConstValues.AccessToken, ConstValues.AccessTokenSecret, ConstValues.ConsumerKey, ConstValues.ConsumerSecret);

            var serviceContext = new ServiceContext(ConstValues.AppToken, ConstValues.CompanyId, IntuitServicesType.QBO, oAuthValiator);

            return(serviceContext);
        }
        /// <summary>
        /// Page Load Event, pulls Customer data from QuickBooks using SDK and Binds it to Grid
        /// </summary>
        /// <param name="sender">Sender of the event.</param>
        /// <param name="e">Event Args.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (HttpContext.Current.Session.Keys.Count > 0)
            {
                realmId           = HttpContext.Current.Session["realm"].ToString();
                accessToken       = HttpContext.Current.Session["accessToken"].ToString();
                accessTokenSecret = HttpContext.Current.Session["accessTokenSecret"].ToString();
                consumerKey       = ConfigurationManager.AppSettings["consumerKey"].ToString(CultureInfo.InvariantCulture);
                consumerSecret    = ConfigurationManager.AppSettings["consumerSecret"];
                dataSourcetype    = HttpContext.Current.Session["dataSource"].ToString().ToLower() == "qbd" ? IntuitServicesType.QBD : IntuitServicesType.QBO;

                OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
                ServiceContext        context        = new ServiceContext(oauthValidator, realmId, dataSourcetype);
                DataServices          commonService  = new DataServices(context);

                try
                {
                    switch (dataSourcetype)
                    {
                    case IntuitServicesType.QBD:
                        var qbdCustomerQuery = new Intuit.Ipp.Data.Qbd.CustomerQuery();
                        qbdCustomerQuery.ItemElementName = Intuit.Ipp.Data.Qbd.ItemChoiceType4.StartPage;
                        qbdCustomerQuery.Item            = "1";
                        qbdCustomerQuery.ChunkSize       = "10";
                        var qbdCustomers = qbdCustomerQuery.ExecuteQuery <Intuit.Ipp.Data.Qbd.Customer>(context).ToList();
                        grdQuickBooksCustomers.DataSource = qbdCustomers;
                        break;

                    case IntuitServicesType.QBO:
                        var qboCustomer  = new Intuit.Ipp.Data.Qbo.Customer();
                        var qboCustomers = commonService.FindAll(qboCustomer, 1, 10).ToList();
                        grdQuickBooksCustomers.DataSource = qboCustomers;
                        break;
                    }

                    grdQuickBooksCustomers.DataBind();

                    if (grdQuickBooksCustomers.Rows.Count > 0)
                    {
                        GridLocation.Visible    = true;
                        MessageLocation.Visible = false;
                    }
                    else
                    {
                        GridLocation.Visible    = false;
                        MessageLocation.Visible = true;
                    }
                }
                catch (Intuit.Ipp.Exception.InvalidTokenException)
                {
                    //Remove the Oauth access token from the OauthAccessTokenStorage.xml
                    OauthAccessTokenStorageHelper.RemoveInvalidOauthAccessToken(Session["FriendlyEmail"].ToString(), Page);

                    Session["show"] = true;
                    Response.Redirect("~/Default.aspx");
                }
            }
        }
        /// <summary>
        /// Page Load Event, pulls Customer data from QuickBooks using SDK and Binds it to Grid
        /// </summary>
        /// <param name="sender">Sender of the event.</param>
        /// <param name="e">Event Args.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (HttpContext.Current.Session.Keys.Count > 0)
            {
                realmId = HttpContext.Current.Session["realm"].ToString();
                accessToken = HttpContext.Current.Session["accessToken"].ToString();
                accessTokenSecret = HttpContext.Current.Session["accessTokenSecret"].ToString();
                consumerKey = ConfigurationManager.AppSettings["consumerKey"].ToString(CultureInfo.InvariantCulture);
                consumerSecret = ConfigurationManager.AppSettings["consumerSecret"];
                dataSourcetype = HttpContext.Current.Session["dataSource"].ToString().ToLower() == "qbd" ? IntuitServicesType.QBD : IntuitServicesType.QBO;

                OAuthRequestValidator oauthValidator =  new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
                ServiceContext context = new ServiceContext(oauthValidator, realmId, dataSourcetype);
                DataServices commonService = new DataServices(context);

                try
                {
                    switch(dataSourcetype)
                    {
                        case IntuitServicesType.QBD:
                            var qbdCustomerQuery = new Intuit.Ipp.Data.Qbd.CustomerQuery();
                            qbdCustomerQuery.ItemElementName = Intuit.Ipp.Data.Qbd.ItemChoiceType4.StartPage;
                            qbdCustomerQuery.Item = "1";
                            qbdCustomerQuery.ChunkSize = "10";
                            var qbdCustomers = qbdCustomerQuery.ExecuteQuery<Intuit.Ipp.Data.Qbd.Customer>(context).ToList();
                            grdQuickBooksCustomers.DataSource = qbdCustomers;
                            break;
                        case IntuitServicesType.QBO:
                            var qboCustomer = new Intuit.Ipp.Data.Qbo.Customer();
                            var qboCustomers = commonService.FindAll(qboCustomer, 1, 10).ToList();
                            grdQuickBooksCustomers.DataSource = qboCustomers;
                            break;
                    }

                    grdQuickBooksCustomers.DataBind();

                    if (grdQuickBooksCustomers.Rows.Count > 0)
                    {
                        GridLocation.Visible = true;
                        MessageLocation.Visible = false;
                    }
                    else
                    {
                        GridLocation.Visible = false;
                        MessageLocation.Visible = true;
                    }
                }
                catch (Intuit.Ipp.Exception.InvalidTokenException)
                {
                    //Remove the Oauth access token from the OauthAccessTokenStorage.xml
                    OauthAccessTokenStorageHelper.RemoveInvalidOauthAccessToken(Session["FriendlyEmail"].ToString(), Page);

                    Session["show"] = true;
                    Response.Redirect("~/Default.aspx");
                }
            }
        }
        internal static ServiceContext InitializeQBOServiceContextUsingoAuth()
        {
            Initialize();
            OAuthRequestValidator reqValidator = new OAuthRequestValidator(accessTokenQBO, accessTokenSecretQBO, consumerKeyQBO, consumerKeySecretQBO);
            ServiceContext        context      = new ServiceContext(realmIdIAQBO, IntuitServicesType.QBO, reqValidator);

            context.IppConfiguration.MinorVersion.Qbo = "8";
            return(context);
        }
예제 #13
0
        private ServiceContext GetContext(string realmId)
        {
            var permission     = _oAuthService.Get(realmId);
            var oauthValidator = new OAuthRequestValidator(permission.AccessToken,
                                                           permission.AccessTokenSecret, _consumerKey, _consumerSecret);
            var context = new ServiceContext(_appToken, permission.RealmId, IntuitServicesType,
                                             oauthValidator);

            return(context);
        }
        /// <summary>
        /// Page Load Event, pulls Customer data from QuickBooks using SDK and Binds it to Grid
        /// </summary>
        /// <param name="sender">Sender of the event.</param>
        /// <param name="e">Event Args.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (HttpContext.Current.Session.Keys.Count > 0)
            {
                String realmId = HttpContext.Current.Session["realm"].ToString();
                String accessToken = HttpContext.Current.Session["accessToken"].ToString();
                String accessTokenSecret = HttpContext.Current.Session["accessTokenSecret"].ToString();
                String consumerKey = ConfigurationManager.AppSettings["consumerKey"].ToString(CultureInfo.InvariantCulture);
                String consumerSecret = ConfigurationManager.AppSettings["consumerSecret"].ToString(CultureInfo.InvariantCulture);
                IntuitServicesType intuitServiceType = (IntuitServicesType)HttpContext.Current.Session["intuitServiceType"];

                OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
                ServiceContext context = new ServiceContext(oauthValidator, realmId, intuitServiceType);
                DataServices commonService = new DataServices(context);

                try
                {
                    switch(intuitServiceType )
                    {
                        case IntuitServicesType.QBO:
                            Intuit.Ipp.Data.Qbo.Customer qboCustomer = new Intuit.Ipp.Data.Qbo.Customer();
                            IEnumerable<Intuit.Ipp.Data.Qbo.Customer> qboCustomers =  commonService.FindAll(qboCustomer, 1, 10) as IEnumerable<Intuit.Ipp.Data.Qbo.Customer>;
                            grdQuickBooksCustomers.DataSource = qboCustomers;
                            break;
                        case IntuitServicesType.QBD:
                            //FindAll() is a GET operation for QBD, so we need to use the respective Query object instead to POST the start page and records per page (ChunkSize).
                            Intuit.Ipp.Data.Qbd.CustomerQuery qbdCustomerQuery = new Intuit.Ipp.Data.Qbd.CustomerQuery();
                            qbdCustomerQuery.ItemElementName = Intuit.Ipp.Data.Qbd.ItemChoiceType4.StartPage;
                            qbdCustomerQuery.Item = "1";
                            qbdCustomerQuery.ChunkSize = "10";
                            IEnumerable<Intuit.Ipp.Data.Qbd.Customer> qbdCustomers = qbdCustomerQuery.ExecuteQuery<Intuit.Ipp.Data.Qbd.Customer>(context) as IEnumerable<Intuit.Ipp.Data.Qbd.Customer>;
                            grdQuickBooksCustomers.DataSource = qbdCustomers;
                            break;
                        default:
                            throw new Exception("Data Source not defined.");
                    }

                    grdQuickBooksCustomers.DataBind();
                    if (grdQuickBooksCustomers.Rows.Count > 0)
                    {
                        GridLocation.Visible = true;
                        MessageLocation.Visible = false;
                    }
                    else
                    {
                        GridLocation.Visible = false;
                        MessageLocation.Visible = true;
                    }
                }
                catch
                {
                    throw;
                }
            }
        }
        public void OAuthRequestValidatorConstructorTestWithApplicationToken()
        {
            string applicationToken = ConfigurationManager.AppSettings["ApplicationToken"];

            OAuthRequestValidator target = new OAuthRequestValidator(applicationToken);

            Assert.AreEqual(target.AccessToken, null);
            Assert.AreEqual(target.AccessTokenSecret, null);
            Assert.AreEqual(target.ConsumerKey, applicationToken);
            Assert.AreEqual(target.ConsumerSecret, null);
        }
        internal static ServiceContext InitializeQBOServiceContextUsingoAuth()
        {
            Initialize();
            OAuthRequestValidator reqValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
            ServiceContext        context      = new ServiceContext(realmId, IntuitServicesType.QBO, reqValidator);

            //MinorVersion represents the latest features/fields in the xsd supported by the QBO apis.
            //Read more details here- https://developer.intuit.com/docs/0100_quickbooks_online/0200_dev_guides/accounting/querying_data

            context.IppConfiguration.MinorVersion.Qbo = "8";
            return(context);
        }
        internal static ServiceContext InitializeServiceContextQbo()
        {
            string accessToken                   = ConfigurationManager.AppSettings["AccessTokenQBO"];
            string accessTokenSecret             = ConfigurationManager.AppSettings["AccessTokenSecretQBO"];
            string consumerKey                   = ConfigurationManager.AppSettings["ConsumerKeyQBO"];
            string consumerSecret                = ConfigurationManager.AppSettings["ConsumerSecretQBO"];
            string realmId                       = ConfigurationManager.AppSettings["realmIAQBO"];
            OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
            ServiceContext        serviceContext = new ServiceContext(realmId, IntuitServicesType.QBO, oauthValidator);

            return(serviceContext);
        }
예제 #18
0
        /// <summary>
        /// Get Access token.
        /// </summary>
        private void getAccessToken()
        {
            IOAuthSession clientSession = CreateSession();
            IToken        accessToken   = clientSession.ExchangeRequestTokenForAccessToken((IToken)HttpContext.Current.Session["requestToken"], HttpContext.Current.Session["oauthVerifyer"].ToString());

            HttpContext.Current.Session["accessToken"]       = accessToken.Token;
            HttpContext.Current.Session["accessTokenSecret"] = accessToken.TokenSecret;

            String realmId = HttpContext.Current.Session["accessTokenSecret"].ToString();
            OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken.Token, accessToken.TokenSecret, consumerKey, consumerSecret);
            ServiceContext        serviceContext = new ServiceContext(realmId, IntuitServicesType.QBO, oauthValidator);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            realmId = HttpContext.Current.Session["realm"].ToString();
            string accessToken       = HttpContext.Current.Session["accessToken"].ToString();
            string accessTokenSecret = HttpContext.Current.Session["accessTokenSecret"].ToString();
            string consumerKey       = HttpContext.Current.Session["consumerKey"].ToString();
            string consumerSecret    = HttpContext.Current.Session["consumerSecret"].ToString();

            OAuthRequestValidator o = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);

            MigrateTokensOAuth1ToOAuth2(consumerKey, consumerSecret, accessToken, accessTokenSecret, realmId, clientId, clientSecret, scopes, redirectUrl);
        }
        public static void MyClassInitialize(TestContext testContext)
        {
            string accessTokenQBO       = ConfigurationManager.AppSettings["AccessTokenQBO"];
            string accessTokenSecretQBO = ConfigurationManager.AppSettings["AccessTokenSecretQBO"];
            string consumerKeyQBO       = ConfigurationManager.AppSettings["ConsumerKeyQBO"];
            string ConsumerSecretQBO    = ConfigurationManager.AppSettings["ConsumerSecretQBO"];
            string realmIAQBO           = ConfigurationManager.AppSettings["RealmIAQBO"];
            OAuthRequestValidator oAuthRequestValidator = new OAuthRequestValidator(accessTokenQBO, accessTokenSecretQBO, consumerKeyQBO, ConsumerSecretQBO);
            ServiceContext        context = new ServiceContext(realmIAQBO, IntuitServicesType.QBO, oAuthRequestValidator);

            entitlementServiceTestCases = new EntitlementService(context);
        }
 public void ServiceContextConstructorWithAppTokenForQBOTest()
 {
     try
     {
         OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessTokenQbo, accessTokenSecretQbo, consumerKeyQbo, consumerSecretQbo);
         ServiceContext        context        = new ServiceContext(appTokenQbo, realmIdIAQbo, IntuitServicesType.QBO, oauthValidator);
     }
     catch (System.Exception ex)
     {
         Assert.Fail(ex.Message);
     }
 }
        public void GetResponseInvalidTokenExceptionTest()
        {
            OAuthRequestValidator validator  = new OAuthRequestValidator("adfas", "afd", "adfas", "asdfa");
            string            realmId        = ConfigurationManager.AppSettings["RealmIAQBO"];
            ServiceContext    serviceContext = new ServiceContext(realmId, IntuitServicesType.QBO, validator);
            IRestHandler      handler        = new SyncRestHandler(serviceContext);
            string            resourceUri    = string.Format("v3/company/{0}/customer", serviceContext.RealmId);
            RequestParameters parameters     = new RequestParameters(resourceUri, HttpVerbType.POST, CoreConstants.CONTENTTYPE_APPLICATIONXML);

            Intuit.Ipp.Data.Customer customer = new Data.Customer();
            HttpWebRequest           request  = handler.PrepareRequest(parameters, customer);
            string response = handler.GetResponse(request);
        }
예제 #23
0
        public static void MyClassInitialize(TestContext testContext)
        {
            string accessTokenQBO       = ConfigurationManager.AppSettings["AccessTokenQBO"];
            string accessTokenSecretQBO = ConfigurationManager.AppSettings["AccessTokenSecretQBO"];
            string consumerKeyQBO       = ConfigurationManager.AppSettings["ConsumerKeyQBO"];
            string ConsumerSecretQBO    = ConfigurationManager.AppSettings["ConsumerSecretQBO"];
            string realmIAQBO           = ConfigurationManager.AppSettings["RealmIAQBO"];

            OAuthRequestValidator oAuthRequestValidatorQbo = new OAuthRequestValidator(accessTokenQBO, accessTokenSecretQBO, consumerKeyQBO, ConsumerSecretQBO);
            ServiceContext        qboContext = new ServiceContext(realmIAQBO, IntuitServicesType.QBO, oAuthRequestValidatorQbo);

            qboService = new DataService(qboContext);
        }
        public void OAuthRequestValidatorConstructorTest()
        {
            string accessToken           = ConfigurationManager.AppSettings["AccessTokenQBO"];
            string accessTokenSecret     = ConfigurationManager.AppSettings["AccessTokenSecretQBO"];
            string consumerKey           = ConfigurationManager.AppSettings["ConsumerKeyQBO"];
            string consumerKeySecret     = ConfigurationManager.AppSettings["ConsumerSecretQBO"];
            OAuthRequestValidator target = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerKeySecret);

            Assert.AreEqual(target.AccessToken, accessToken);
            Assert.AreEqual(target.AccessTokenSecret, accessTokenSecret);
            Assert.AreEqual(target.ConsumerKey, consumerKey);
            Assert.AreEqual(target.ConsumerSecret, consumerKeySecret);
        }
        public static void MyClassInitialize(TestContext testContext)
        {
            string accessTokenQBO       = ConfigurationManager.AppSettings["AccessTokenQBO"];
            string accessTokenSecretQBO = ConfigurationManager.AppSettings["AccessTokenSecretQBO"];
            string consumerKeyQBO       = ConfigurationManager.AppSettings["ConsumerKeyQBO"];
            string ConsumerSecretQBO    = ConfigurationManager.AppSettings["ConsumerSecretQBO"];
            string realmIAQBO           = ConfigurationManager.AppSettings["RealmIAQBO"];
            OAuthRequestValidator oAuthRequestValidator = new OAuthRequestValidator(accessTokenQBO, accessTokenSecretQBO, consumerKeyQBO, ConsumerSecretQBO);
            ServiceContext        context = new ServiceContext(realmIAQBO, IntuitServicesType.QBO, oAuthRequestValidator);

            context.IppConfiguration.Message.Response.SerializationFormat = Intuit.Ipp.Core.Configuration.SerializationFormat.Json;
            reportServiceTestCases = new ReportService(context);
        }
        internal static ServiceContext InitializeQueryServiceContextUsingoAuth(bool isQBO)
        {
            Initialize();
            ServiceContext context = null;

            if (isQBO)
            {
                OAuthRequestValidator reqValidator = new OAuthRequestValidator(accessTokenQBO, accessTokenSecretQBO, consumerKeyQBO, consumerKeySecretQBO);
                context = new ServiceContext(realmIdIAQBO, IntuitServicesType.QBO, reqValidator);
            }

            return(context);
        }
        public void AuthorizeTest()
        {
            string                accessToken       = ConfigurationManager.AppSettings["AccessTokenQBO"];
            string                accessTokenSecret = ConfigurationManager.AppSettings["AccessTokenSecretQBO"];
            string                consumerKey       = ConfigurationManager.AppSettings["ConsumerKeyQBO"];
            string                consumerKeySecret = ConfigurationManager.AppSettings["ConsumerSecretQBO"];
            string                requestUri        = "https://appcenter.intuit.com/Developer/Create";
            WebRequest            webRequest        = WebRequest.Create(requestUri);
            OAuthRequestValidator target            = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerKeySecret);

            target.Authorize(webRequest, string.Empty);
            Assert.IsTrue(webRequest.Headers.Count > 0);
        }
        private Batch GetBatch()
        {
            string accessTokenQBO       = ConfigurationManager.AppSettings["AccessTokenQBO"];
            string accessTokenSecretQBO = ConfigurationManager.AppSettings["AccessTokenSecretQBO"];
            string consumerKeyQBO       = ConfigurationManager.AppSettings["ConsumerKeyQBO"];
            string ConsumerSecretQBO    = ConfigurationManager.AppSettings["ConsumerSecretQBO"];
            string realmIAQBO           = ConfigurationManager.AppSettings["RealmIAQBO"];
            OAuthRequestValidator oAuthRequestValidator = new OAuthRequestValidator(accessTokenQBO, accessTokenSecretQBO, consumerKeyQBO, ConsumerSecretQBO);
            ServiceContext        context = new ServiceContext(realmIAQBO, IntuitServicesType.QBO, oAuthRequestValidator);
            DataService           service = new DataService(context);

            return(service.CreateNewBatch());
        }
예제 #29
0
        /// <summary>
        /// Action Results for Index
        /// </summary>
        /// <returns>Action Result.</returns>
        public ActionResult Index()
        {
            realmId           = Session["realm"].ToString();
            accessToken       = Session["accessToken"].ToString();
            accessTokenSecret = Session["accessTokenSecret"].ToString();
            consumerKey       = ConfigurationManager.AppSettings["consumerKey"].ToString();
            consumerSecret    = ConfigurationManager.AppSettings["consumerSecret"].ToString();
            dataSourcetype    = Session["dataSource"].ToString();

            OAuthRequestValidator oauthValidator = Initializer.InitializeOAuthValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
            ServiceContext        context        = Initializer.InitializeServiceContext(oauthValidator, realmId, string.Empty, string.Empty, dataSourcetype);
            DataServices          commonService  = new DataServices(context);

            try
            {
                // Specify a Request validator
                if (dataSourcetype.ToLower() == "qbd")
                {
                    Intuit.Ipp.Data.Qbd.CustomerQuery qbdCustomerQuery = new Intuit.Ipp.Data.Qbd.CustomerQuery();
                    qbdCustomerQuery.ItemElementName = Intuit.Ipp.Data.Qbd.ItemChoiceType4.StartPage;
                    qbdCustomerQuery.Item            = "1";
                    qbdCustomerQuery.ChunkSize       = "10";
                    IEnumerable <Intuit.Ipp.Data.Qbd.Customer> customers = qbdCustomerQuery.ExecuteQuery <Intuit.Ipp.Data.Qbd.Customer>
                                                                               (context) as IEnumerable <Intuit.Ipp.Data.Qbd.Customer>;
                }
                else
                {
                    Intuit.Ipp.Data.Qbo.Customer qboCustomer             = new Intuit.Ipp.Data.Qbo.Customer();
                    IEnumerable <Intuit.Ipp.Data.Qbo.Customer> customers = commonService.FindAll(qboCustomer, 1, 10) as IEnumerable <Intuit.Ipp.Data.Qbo.Customer>;
                    ViewBag.MyCollection  = customers;
                    ViewBag.CustomerCount = customers.Count();
                }
            }
            catch (Intuit.Ipp.Exception.InvalidTokenException exp)
            {
                //Remove the Oauth access token from the OauthAccessTokenStorage.xml
                OauthAccessTokenStorageHelper.RemoveInvalidOauthAccessToken(Session["FriendlyEmail"].ToString(), this);
                //show a message to the user that token is invalid
                string message = "<SCRIPT LANGUAGE='JavaScript' >alert('Your authorization to this application to access your quickbook data is no longer Valid.Please provide authorization again.')</SCRIPT>";
                // show user the connect to quickbook page again
                Response.Write(message);
                Redirect("/Home/index");
            }
            catch (System.Exception exp)
            {
                throw exp;
            }

            return(View());
        }
        /// <summary>
        /// Action Results for Index
        /// </summary>
        /// <returns>Action Result.</returns>
        public ActionResult Index()
        {
            realmId = Session["realm"].ToString();
            accessToken = Session["accessToken"].ToString();
            accessTokenSecret = Session["accessTokenSecret"].ToString();
            consumerKey = ConfigurationManager.AppSettings["consumerKey"].ToString();
            consumerSecret = ConfigurationManager.AppSettings["consumerSecret"].ToString();
            dataSourcetype = Session["dataSource"].ToString().ToLower();


            try
            {
                IntuitServicesType intuitServicesType = new IntuitServicesType();
                switch (dataSourcetype)
                {
                    case "qbo":
                        intuitServicesType = IntuitServicesType.QBO;
                        break;
                    case "qbd":
                        intuitServicesType = IntuitServicesType.QBD;
                        break;
                    default:
                        throw new Exception("Data source type not found.");
                        break;

                }

                OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
                ServiceContext context = new ServiceContext(realmId, intuitServicesType, oauthValidator);
                DataService dataService = new DataService(context);
                List<Customer> customers = dataService.FindAll(new Customer(), 1, 100).ToList();
                ViewBag.MyCollection = customers;
                ViewBag.CustomerCount = customers.Count();

            }
            catch (InvalidTokenException exp)
            {
                //Remove the Oauth access token from the OauthAccessTokenStorage.xml
                OauthAccessTokenStorageHelper.RemoveInvalidOauthAccessToken(Session["FriendlyEmail"].ToString(), this);

                Session["show"] = true;
                return Redirect("/Home/index");
            }
            catch (System.Exception exp)
            {
                throw exp;
            }

            return View();
        }
예제 #31
0
        /// <summary>
        /// Action Results for Index
        /// </summary>
        /// <returns>Action Result.</returns>
        public ActionResult Index()
        {
            realmId           = Session["realm"].ToString();
            accessToken       = Session["accessToken"].ToString();
            accessTokenSecret = Session["accessTokenSecret"].ToString();
            consumerKey       = ConfigurationManager.AppSettings["consumerKey"].ToString();
            consumerSecret    = ConfigurationManager.AppSettings["consumerSecret"].ToString();
            dataSourcetype    = Session["dataSource"].ToString().ToLower();


            try
            {
                IntuitServicesType intuitServicesType = new IntuitServicesType();
                switch (dataSourcetype)
                {
                case "qbo":
                    intuitServicesType = IntuitServicesType.QBO;
                    break;

                case "qbd":
                    intuitServicesType = IntuitServicesType.QBD;
                    break;

                default:
                    throw new Exception("Data source type not found.");
                    break;
                }

                OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
                ServiceContext        context        = new ServiceContext(realmId, intuitServicesType, oauthValidator);
                DataService           dataService    = new DataService(context);
                List <Customer>       customers      = dataService.FindAll(new Customer(), 1, 100).ToList();
                ViewBag.MyCollection  = customers;
                ViewBag.CustomerCount = customers.Count();
            }
            catch (InvalidTokenException exp)
            {
                //Remove the Oauth access token from the OauthAccessTokenStorage.xml
                OauthAccessTokenStorageHelper.RemoveInvalidOauthAccessToken(Session["FriendlyEmail"].ToString(), this);

                Session["show"] = true;
                return(Redirect("/Home/index"));
            }
            catch (System.Exception exp)
            {
                throw exp;
            }

            return(View());
        }
예제 #32
0
        public ServiceContext CreateServiceContext(AuthorizationToken authToken, IHubCommunicator hubCommunicator)
        {
            var      tokens            = authToken.Token.Split(new[] { Authenticator.TokenSeparator }, StringSplitOptions.None);
            var      accessToken       = tokens[0];
            var      accessTokenSecret = tokens[1];
            var      companyId         = tokens[2];
            var      expiresAt         = tokens[3];
            DateTime expiresDate;

            if (DateTime.TryParse(expiresAt, out expiresDate) == false)
            {
                //EventManager.TokenValidationFailed(authToken.Token, "Terminal Quickbooks token is invalid");
                throw new ArgumentException("Terminal Quickbooks token is invalid", nameof(expiresAt));
            }
            // Token renew should fit into 151-180 days period,
            // See https://developer.intuit.com/docs/0100_accounting/0060_authentication_and_authorization/connect_from_within_your_app#/manage
            //
            if (DateTime.Now > expiresDate.AddDays(-30) && DateTime.Now <= expiresDate)
            {
                authToken = _authenticator.RefreshAuthToken(authToken).Result;
                var tokenDto = new AuthorizationTokenDTO
                {
                    Id = authToken.Id.ToString(),
                    ExternalAccountId = authToken.ExternalAccountId,
                    Token             = authToken.Token
                };

                hubCommunicator.RenewToken(tokenDto);

                // After token refresh we need to get new accessToken and accessTokenSecret from it
                tokens            = authToken.Token.Split(new[] { Authenticator.TokenSeparator }, StringSplitOptions.None);
                accessToken       = tokens[0];
                accessTokenSecret = tokens[1];
            }

            if (DateTime.Now > expiresDate)
            {
                var message = "Quickbooks token is expired. Please, get the new one";
                //EventManager.TokenValidationFailed(authToken.Token, message);
                throw new TerminalQuickbooksTokenExpiredException(message);
            }

            var oauthValidator = new OAuthRequestValidator(
                accessToken,
                accessTokenSecret,
                Authenticator.ConsumerKey,
                Authenticator.ConsumerSecret);

            return(new ServiceContext(AppToken, companyId, IntuitServicesType.QBO, oauthValidator));
        }
 public void ServiceContextTimeoutNullTest()
 {
     try
     {
         OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessTokenQbo, accessTokenSecretQbo, consumerKeyQbo, consumerSecretQbo);
         ServiceContext        context        = new ServiceContext(realmIdIAQbo, IntuitServicesType.QBO, oauthValidator);
         context.Timeout = null;
         Assert.IsNull(context.Timeout);
     }
     catch (System.Exception ex)
     {
         Assert.Fail(ex.Message);
     }
 }
 /// <summary>
 /// allocate memory for service context objects
 /// </summary>
 /// <param name="oAuthorization"></param>
 public DataserviceFactory(OAuthorizationdto oAuthorization)
 {
     try
     {
         oAuthRequestValidator = new OAuthRequestValidator(
         oAuthorization.AccessToken, 
         oAuthorization.AccessTokenSecret, 
         oAuthorization.ConsumerKey, 
         oAuthorization.ConsumerSecret);
     intuitServicesType = oAuthorization.DataSource == "QBO" ? IntuitServicesType.QBO : IntuitServicesType.None;
     serviceContext = new ServiceContext(oAuthorization.Realmid.ToString(), intuitServicesType, oAuthRequestValidator);
     serviceContext.IppConfiguration.BaseUrl.Qbo = ConfigurationManager.AppSettings["ServiceContext.BaseUrl.Qbo"];
     serviceContext.IppConfiguration.Logger.RequestLog.EnableRequestResponseLogging = true;
     serviceContext.IppConfiguration.Logger.RequestLog.ServiceRequestLoggingLocation = ConfigurationManager.AppSettings["ServiceRequestLoggingLocation"];
     getServiceContext = serviceContext;
     dataService = new DataService(serviceContext);
     }
     catch (Intuit.Ipp.Exception.FaultException ex)
     {
         throw ex;
     }
 }
예제 #35
0
        public ServiceContext getServiceContext()
        {
            if (qbsc == null)
            {
                var qbc = (from i in DbUtil.Db.QBConnections
                           where i.Active == 1
                           select i).SingleOrDefault();

                var orv = new OAuthRequestValidator(qbc.Token, qbc.Secret, getKey(), getSecret());

                if (qbc.DataSource == "QBO")
                    qbsc = new ServiceContext(orv, getToken(), qbc.RealmID, IntuitServicesType.QBO);
                else
                    qbsc = new ServiceContext(orv, getToken(), qbc.RealmID, IntuitServicesType.QBD);
            }

            return qbsc;
        }
 private static ServiceContext getServiceContext(IppRealmOAuthProfile profile)
 {
     var consumerKey = ConfigurationManager.AppSettings["consumerKey"].ToString();
     var consumerSecret = ConfigurationManager.AppSettings["consumerSecret"].ToString();
     OAuthRequestValidator oauthValidator = new OAuthRequestValidator(profile.accessToken, profile.accessSecret, consumerKey, consumerSecret);
     return new ServiceContext(profile.realmId, (IntuitServicesType)profile.dataSource, oauthValidator);
 }
예제 #37
0
 private void displayCustomers()
 {
     string consumerKey = ConfigurationSettings.AppSettings["consumerKey"];
     string consumerSecret = ConfigurationSettings.AppSettings["consumerSecret"];
     OAuthRequestValidator oauthRequestValidator = new OAuthRequestValidator(_ippRealmOAuthProfile.accessToken, _ippRealmOAuthProfile.accessSecret, consumerKey, consumerSecret);
     ServiceContext serviceContext = new ServiceContext(_ippRealmOAuthProfile.realmId, IntuitServicesType.QBO, oauthRequestValidator);
     DataService dataService = new DataService(serviceContext);
     QueryService<Customer> customerQueryService = new QueryService<Customer>(serviceContext);
     dataGridView1.DataSource = customerQueryService.ExecuteIdsQuery("Select * From Customer MaxResults 50").ToList();
 }