/// <summary>
        /// Initializes a new instance of the <see cref="ServiceContext"/> class.
        /// </summary>
        /// <param name="appToken">Application Token.</param>
        /// <param name="realmId">The realm id.</param>
        /// <param name="serviceType">Service Type - QBO.</param>
        /// <param name="requestValidator">The request validate.</param>
        /// <returns>Returns ServiceContext object.</returns>
        /// <exception cref="Intuit.Ipp.Exception.IdsException">If arguments are null or empty.</exception>
        /// <exception cref="Intuit.Ipp.Exception.InvalidRealmException">If realm id is invalid.</exception>
        /// <exception cref="Intuit.Ipp.Exception.InvalidTokenException">If the token is invalid.</exception>
        public ServiceContext(string appToken, string realmId, IntuitServicesType serviceType, IRequestValidator requestValidator = null)
            : this()
        {
            // Validate Parameters
            if (string.IsNullOrWhiteSpace(appToken))
            {
                IdsExceptionManager.HandleException(new IdsException(Properties.Resources.ParameterNotNullMessage, new ArgumentNullException(Properties.Resources.AppTokenParameterName, Properties.Resources.ParameterNotNullMessage)));
            }

            if (string.IsNullOrWhiteSpace(realmId))
            {
                IdsExceptionManager.HandleException(new InvalidRealmException(Properties.Resources.ParameterNotNullEmptyMessage, new ArgumentException(Properties.Resources.ParameterNotNullMessage, Properties.Resources.RealmIdParameterName)));
            }

            this.realmId     = realmId;
            this.serviceType = serviceType;
            this.appToken    = appToken;
            if (requestValidator != null)
            {
                this.IppConfiguration.Security = requestValidator;
            }

            if (this.IppConfiguration.Security == null)
            {
                throw new InvalidTokenException("Atleast one security mechanism has to be specified for the SDK to work. Either use config file or use constructor to specify the authenticatio type.");
            }

            this.baseserviceURL = this.GetBaseURL();
            this.isCreateMethod = false;
        }
        /// <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");
                }
            }
        }
        /// <summary>
        /// Populates the values of the service context like realmId, service type to the Data Services being targetted.
        /// </summary>
        public void UseDataServices()
        {
            if (this.isCreateMethod)
            {
                this.serviceType = IntuitServicesType.QBO;

                // Get the base Uri for the new service type
                this.baseserviceURL = this.GetBaseURL();
                this.RevertConfiguration();
            }
        }
Example #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().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());
        }
        /// <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();
        }
Example #7
0
        /// <summary>
        /// Helper method used to initialize the Service Context
        /// </summary>
        /// <param name="oauthValidator">Object of OAutheValidator</param>
        /// <param name="realmId">Value for RealmId</param>
        /// <param name="appToken">Value for AppToken</param>
        /// <param name="appDBId">Value for AppDBId</param>
        /// <param name="serviceType">Service Type Qbd or Qbo</param>
        /// <returns>Object of ServiceContext</returns>
        internal static ServiceContext InitializeServiceContext(OAuthRequestValidator oauthValidator, string realmId, string appToken, string appDBId, string serviceType)
        {
            ServiceContext     context           = null;
            IntuitServicesType intuitServiceType = IntuitServicesType.QBD;

            if (serviceType.Equals("QBO"))
            {
                intuitServiceType = IntuitServicesType.QBO;
            }
            else
            {
                intuitServiceType = IntuitServicesType.QBD;
            }

            context = new ServiceContext(realmId, intuitServiceType, oauthValidator);
            return(context);
        }
        static List <Purchase> GetExpenses(int n)
        {
            consumerKey    = "qyprdmVtxDr9NCiZ296Wnw77hon440";           // sandbox
            consumerSecret = "qDd2Y7KM9motf3JqqjbtM58ACP1qDXkhNQUfEMD7"; // sandbox

            realmId           = "123146024163879";                       // sandbox
            accessToken       = "<replace with access token>";
            accessTokenSecret = "<replace with access token secret>";

            IntuitServicesType    intuitServicesType = IntuitServicesType.QBO;
            OAuthRequestValidator oauthValidator     = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
            ServiceContext        context            = new ServiceContext(realmId, intuitServicesType, oauthValidator);

            context.IppConfiguration.BaseUrl.Qbo = "https://sandbox-quickbooks.api.intuit.com/";

            DataService     dataService = new DataService(context);
            List <Purchase> expenses    = dataService.FindAll(new Purchase(), 1, n).ToList();

            return(expenses);
        }
        public IEnumerable <Purchase> GetExpenses(int n)
        {
            consumerKey    = ConfigurationManager.AppSettings["consumerKey"].ToString();
            consumerSecret = ConfigurationManager.AppSettings["consumerSecret"].ToString();

            realmId           = HttpContext.Current.Session["realm"].ToString();
            accessToken       = HttpContext.Current.Session["accessToken"].ToString();
            accessTokenSecret = HttpContext.Current.Session["accessTokenSecret"].ToString();

            IntuitServicesType    intuitServicesType = IntuitServicesType.QBO;
            OAuthRequestValidator oauthValidator     = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
            ServiceContext        context            = new ServiceContext(realmId, intuitServicesType, oauthValidator);

            context.IppConfiguration.BaseUrl.Qbo = ConfigurationManager.AppSettings["ServiceContext.BaseUrl.Qbo"].ToString();

            DataService     dataService = new DataService(context);
            List <Purchase> expenses    = dataService.FindAll(new Purchase(), 1, n).ToList();

            return(expenses);
        }
 /// <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;
     }
 }
Example #11
0
 /// <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;
     }
 }
 protected OauthConnectionInfo(IntuitServicesType servicesType)
 {
     ServicesType = servicesType;
 }
 /// <summary>
 /// Populates the values of the service context like service type and base url to Platform Services.
 /// </summary>
 public void UsePlatformServices()
 {
     this.serviceType    = IntuitServicesType.IPS;
     this.baseserviceURL = this.GetBaseURL();
 }