/// <summary>
        /// Workflow to create Vendor, Bill, VendorCredit, BillPayment
        /// </summary>
        public async Task <ActionResult> BillingWorkflow()
        {
            //Make QBO api calls using .Net SDK
            if (Session["realmId"] != null)
            {
                string realmId = Session["realmId"].ToString();

                try
                {
                    //Initialize OAuth2RequestValidator and ServiceContext
                    ServiceContext serviceContext = base.IntializeContext(realmId);


                    //Create a Vendor
                    Vendor vendor = CreateVendor(serviceContext);
                    //Add Bill for this Vendor
                    Bill bill = CreateBill(serviceContext, vendor);
                    //Add BillPayment for this Vendor
                    BillPayment billPayment = CreateBillPaymentCreditCard(serviceContext, vendor, bill);
                    //Create & Apply Vendor Credit
                    VendorCredit vendorCredit = CreateVendorCredit(serviceContext, vendor);

                    return(View("Index", (object)("QBO API calls Success!")));
                }
                catch (Exception ex)
                {
                    return(View("Index", (object)"QBO API calls Failed!"));
                }
            }
            else
            {
                return(View("Index", (object)"QBO API call Failed!"));
            }
        }
예제 #2
0
 public void VendorCreditAddTestUsingoAuth(ServiceContext qboContextoAuth)
 {
     //Creating the VendorCredit for Add
     VendorCredit vendorCredit = QBOHelper.CreateVendorCredit(qboContextoAuth);
     //Adding the VendorCredit
     VendorCredit added = Helper.Add <VendorCredit>(qboContextoAuth, vendorCredit);
 }
예제 #3
0
        public void VendorCreditAddAsyncTestsUsingoAuth(ServiceContext qboContextoAuth)
        {
            //Creating the VendorCredit for Add
            VendorCredit entity = QBOHelper.CreateVendorCredit(qboContextoAuth);

            VendorCredit added = Helper.AddAsync <VendorCredit>(qboContextoAuth, entity);
        }
예제 #4
0
        /// <summary>
        ///     Gets the vendor creditlist.
        /// </summary>
        /// <param name="response">The response.</param>
        /// <returns>VendorCreditList.</returns>
        internal static VendorCreditList getVendorCreditlist(HttpResponseMessage response)
        {
            var vendorCreditList = new VendorCreditList();
            var jsonObject       =
                JsonConvert.DeserializeObject <Dictionary <string, object> >(response.Content.ReadAsStringAsync().Result);

            if (jsonObject.ContainsKey("vendor_credits"))
            {
                var vendorCreditsArray =
                    JsonConvert.DeserializeObject <List <object> >(jsonObject["vendor_credits"].ToString());
                foreach (var vendorCreditObj in vendorCreditsArray)
                {
                    var vendorCredit = new VendorCredit();
                    vendorCredit = JsonConvert.DeserializeObject <VendorCredit>(vendorCreditObj.ToString());
                    vendorCreditList.Add(vendorCredit);
                }
            }
            if (jsonObject.ContainsKey("page_context"))
            {
                var pageContext = new PageContext();
                pageContext = JsonConvert.DeserializeObject <PageContext>(jsonObject["page_context"].ToString());
                vendorCreditList.page_context = pageContext;
            }
            return(vendorCreditList);
        }
예제 #5
0
        public void VendorCreditAddAsyncTestsUsingoAuth()
        {
            //Creating the VendorCredit for Add
            VendorCredit entity = QBOHelper.CreateVendorCredit(qboContextoAuth);

            VendorCredit added = Helper.AddAsync <VendorCredit>(qboContextoAuth, entity);

            QBOHelper.VerifyVendorCredit(entity, added);
        }
예제 #6
0
        [TestMethod][Ignore]  //IgnoreReason: Not supported
        public void VendorCreditVoidAsyncTestsUsingoAuth()
        {
            //Creating the VendorCredit for Adding
            VendorCredit entity = QBOHelper.CreateVendorCredit(qboContextoAuth);
            //Adding the VendorCredit
            VendorCredit added = Helper.Add <VendorCredit>(qboContextoAuth, entity);

            Helper.VoidAsync <VendorCredit>(qboContextoAuth, added);
        }
예제 #7
0
        [TestMethod] //[Ignore]  //IgnoreReason: Not Supported
        public void VendorCreditQueryUsingoAuth()
        {
            QueryService <VendorCredit> entityQuery = new QueryService <VendorCredit>(qboContextoAuth);
            VendorCredit existing = Helper.FindOrAdd <VendorCredit>(qboContextoAuth, new VendorCredit());
            //List<VendorCredit> entities = entityQuery.Where(c => c.Id == existing.Id).ToList();
            List <VendorCredit> entities = entityQuery.ExecuteIdsQuery("SELECT * FROM VendorCredit where Id='" + existing.Id + "'").ToList <VendorCredit>();

            Assert.IsTrue(entities.Count() > 0);
        }
예제 #8
0
        public void VendorCreditAddTestUsingoAuth()
        {
            //Creating the VendorCredit for Add
            VendorCredit vendorCredit = QBOHelper.CreateVendorCredit(qboContextoAuth);
            //Adding the VendorCredit
            VendorCredit added = Helper.Add <VendorCredit>(qboContextoAuth, vendorCredit);

            //Verify the added VendorCredit
            QBOHelper.VerifyVendorCredit(vendorCredit, added);
        }
예제 #9
0
        public void VendorCreditFindbyIdTestUsingoAuth()
        {
            //Creating the VendorCredit for Adding
            VendorCredit vendorCredit = QBOHelper.CreateVendorCredit(qboContextoAuth);
            //Adding the VendorCredit
            VendorCredit added = Helper.Add <VendorCredit>(qboContextoAuth, vendorCredit);
            VendorCredit found = Helper.FindById <VendorCredit>(qboContextoAuth, added);

            QBOHelper.VerifyVendorCredit(found, added);
        }
예제 #10
0
        public void VendorCreditFindByIdAsyncTestsUsingoAuth(ServiceContext qboContextoAuth)
        {
            //Creating the VendorCredit for Adding
            VendorCredit entity = QBOHelper.CreateVendorCredit(qboContextoAuth);
            //Adding the VendorCredit
            VendorCredit added = Helper.Add <VendorCredit>(qboContextoAuth, entity);

            //FindById and verify
            Helper.FindByIdAsync <VendorCredit>(qboContextoAuth, added);
        }
예제 #11
0
 public void VendorCreditSparseUpdateTestUsingoAuth(ServiceContext qboContextoAuth)
 {
     //Creating the VendorCredit for Adding
     VendorCredit vendorCredit = QBOHelper.CreateVendorCredit(qboContextoAuth);
     //Adding the VendorCredit
     VendorCredit added = Helper.Add <VendorCredit>(qboContextoAuth, vendorCredit);
     //Change the data of added entity
     VendorCredit changed = QBOHelper.UpdateVendorCreditSparse(qboContextoAuth, added.Id, added.SyncToken, added.VendorRef);
     //Update the returned entity data
     VendorCredit updated = Helper.Update <VendorCredit>(qboContextoAuth, changed);//Verify the updated VendorCredit
 }
        /// <summary>
        /// Updates the specified vendor_credit_id.
        /// </summary>
        /// <param name="vendor_credit_id">The vendor_credit_id.</param>
        /// <param name="update_info">The update_info.</param>
        /// <returns>VendorCredit.</returns>
        public VendorCredit Update(string vendor_credit_id, VendorCredit update_info)
        {
            var url        = baseAddress + "/" + vendor_credit_id;
            var json       = JsonConvert.SerializeObject(update_info);
            var parameters = new Dictionary <object, object>();

            parameters.Add("JSONString", json);
            var response = ZohoHttpClient.put(url, getQueryParameters(parameters));

            return(VendorCreditParser.getVendorCredit(response));
        }
예제 #13
0
        /// <summary>
        /// Gets the vendor credit.
        /// </summary>
        /// <param name="response">The response.</param>
        /// <returns>VendorCredit.</returns>
        internal static VendorCredit getVendorCredit(HttpResponseMessage response)
        {
            var vendorCredit = new VendorCredit();
            var jsonObject   = JsonConvert.DeserializeObject <Dictionary <string, object> >(response.Content.ReadAsStringAsync().Result);

            if (jsonObject.ContainsKey("vendor_credit"))
            {
                vendorCredit = JsonConvert.DeserializeObject <VendorCredit>(jsonObject["vendor_credit"].ToString());
            }
            return(vendorCredit);
        }
예제 #14
0
        public void VendorCreditUpdatedAsyncTestsUsingoAuth(ServiceContext qboContextoAuth)
        {
            //Creating the VendorCredit for Adding
            VendorCredit entity = QBOHelper.CreateVendorCredit(qboContextoAuth);
            //Adding the VendorCredit
            VendorCredit added = Helper.Add <VendorCredit>(qboContextoAuth, entity);

            //Update the VendorCredit
            VendorCredit updated = QBOHelper.UpdateVendorCredit(qboContextoAuth, added);
            //Call the service
            VendorCredit updatedReturned = Helper.UpdateAsync <VendorCredit>(qboContextoAuth, updated);
        }
예제 #15
0
        public void VendorCreditUpdateTestUsingoAuth()
        {
            //Creating the VendorCredit for Adding
            VendorCredit vendorCredit = QBOHelper.CreateVendorCredit(qboContextoAuth);
            //Adding the VendorCredit
            VendorCredit added = Helper.Add <VendorCredit>(qboContextoAuth, vendorCredit);
            //Change the data of added entity
            VendorCredit changed = QBOHelper.UpdateVendorCredit(qboContextoAuth, added);
            //Update the returned entity data
            VendorCredit updated = Helper.Update <VendorCredit>(qboContextoAuth, changed);//Verify the updated VendorCredit

            QBOHelper.VerifyVendorCredit(changed, updated);
        }
        /// <summary>
        /// Creates the specified new_vendor_credit_info.
        /// </summary>
        /// <param name="new_vendor_credit_info">The new_vendor_credit_info.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns>VendorCredit.</returns>
        public VendorCredit Create(VendorCredit new_vendor_credit_info, Dictionary <object, object> parameters)
        {
            var url  = baseAddress;
            var json = JsonConvert.SerializeObject(new_vendor_credit_info);

            if (parameters == null)
            {
                parameters = new Dictionary <object, object>();
            }
            parameters.Add("JSONString", json);
            var response = ZohoHttpClient.post(url, getQueryParameters(parameters));

            return(VendorCreditParser.getVendorCredit(response));
        }
예제 #17
0
        public void VendorCreditDeleteTestUsingoAuth(ServiceContext qboContextoAuth)
        {
            //Creating the VendorCredit for Adding
            VendorCredit vendorCredit = QBOHelper.CreateVendorCredit(qboContextoAuth);
            //Adding the VendorCredit
            VendorCredit added = Helper.Add <VendorCredit>(qboContextoAuth, vendorCredit);

            //Delete the returned entity
            try
            {
                VendorCredit deleted = Helper.Delete <VendorCredit>(qboContextoAuth, added);
            }
            catch (IdsException ex)
            {
            }
        }
예제 #18
0
        [TestMethod][Ignore]  //IgnoreReason: Not supported
        public void VendorCreditVoidTestUsingoAuth()
        {
            //Creating the VendorCredit for Adding
            VendorCredit vendorCredit = QBOHelper.CreateVendorCredit(qboContextoAuth);
            //Adding the VendorCredit
            VendorCredit added = Helper.Add <VendorCredit>(qboContextoAuth, vendorCredit);

            try
            {
                VendorCredit voided = Helper.Void <VendorCredit>(qboContextoAuth, added);
                Assert.AreEqual(EntityStatusEnum.Voided, voided.status);
            }
            catch (IdsException ex)
            {
                Assert.Fail();
            }
        }
예제 #19
0
        public void VendorCreditDeleteTestUsingoAuth()
        {
            //Creating the VendorCredit for Adding
            VendorCredit vendorCredit = QBOHelper.CreateVendorCredit(qboContextoAuth);
            //Adding the VendorCredit
            VendorCredit added = Helper.Add <VendorCredit>(qboContextoAuth, vendorCredit);

            //Delete the returned entity
            try
            {
                VendorCredit deleted = Helper.Delete <VendorCredit>(qboContextoAuth, added);
                Assert.AreEqual(EntityStatusEnum.Deleted, deleted.status);
            }
            catch (IdsException ex)
            {
                Assert.Fail();
            }
        }
예제 #20
0
        public string CreateEntity(string accessToken, string realmID, string refreshToken, int entityType, string XML, bool IsProd)
        {
            try
            {
                if (!string.IsNullOrEmpty(accessToken) && !string.IsNullOrEmpty(realmID))
                {
                    string         output         = "";
                    ServiceContext serviceContext = BuildServiceContext(accessToken, realmID, IsProd);
                    DataService    dataService    = new DataService(serviceContext);
                    QBObjectType   QBEntityType   = (QBObjectType)entityType;

                    Output("Making CreateEntity " + QBEntityType + " API Call.");

                    switch (QBEntityType)
                    {
                    case QBObjectType.Customer:
                        XmlSerializer customerSerializer = new XmlSerializer(typeof(Customer));
                        StringReader  customerReader     = new StringReader(XML);
                        Customer      customer           = (Customer)customerSerializer.Deserialize(customerReader);
                        Customer      newCustomer        = dataService.Add(customer);

                        StringWriter customerWriter = new StringWriter();
                        customerSerializer.Serialize(customerWriter, newCustomer);

                        output = customerWriter.ToString();
                        break;

                    case QBObjectType.Invoice:
                        XmlSerializer invoiceSerializer = new XmlSerializer(typeof(Invoice));
                        StringReader  invoiceReader     = new StringReader(XML);
                        Invoice       invoice           = (Invoice)invoiceSerializer.Deserialize(invoiceReader);
                        Invoice       newInvoice        = dataService.Add(invoice);

                        StringWriter invoiceWriter = new StringWriter();
                        invoiceSerializer.Serialize(invoiceWriter, newInvoice);

                        output = invoiceWriter.ToString();
                        break;

                    case QBObjectType.InvoiceCreditMemo:
                        XmlSerializer creditMemoSerializer = new XmlSerializer(typeof(CreditMemo));
                        StringReader  creditMemoReader     = new StringReader(XML);
                        CreditMemo    creditMemo           = (CreditMemo)creditMemoSerializer.Deserialize(creditMemoReader);
                        CreditMemo    newCreditMemo        = dataService.Add(creditMemo);

                        StringWriter creditMemoWriter = new StringWriter();
                        creditMemoSerializer.Serialize(creditMemoWriter, newCreditMemo);

                        output = creditMemoWriter.ToString();
                        break;

                    case QBObjectType.Vendor:
                    case QBObjectType.VendorDeduction:
                        XmlSerializer vendorSerializer = new XmlSerializer(typeof(Vendor));
                        StringReader  reader           = new StringReader(XML);
                        Vendor        vendor           = (Vendor)vendorSerializer.Deserialize(reader);
                        Vendor        newVendor        = dataService.Add(vendor);

                        StringWriter vendorWriter = new StringWriter();
                        vendorSerializer.Serialize(vendorWriter, newVendor);

                        output = vendorWriter.ToString();
                        break;

                    case QBObjectType.CarrierPay:
                    case QBObjectType.DriverPay:
                        XmlSerializer billSerializer = new XmlSerializer(typeof(Bill));
                        StringReader  billReader     = new StringReader(XML);
                        Bill          bill           = (Bill)billSerializer.Deserialize(billReader);
                        Bill          newBill        = dataService.Add(bill);

                        StringWriter billWriter = new StringWriter();
                        billSerializer.Serialize(billWriter, newBill);

                        output = billWriter.ToString();
                        break;

                    case QBObjectType.DriverDeduction:
                        XmlSerializer vendorCreditSerializer = new XmlSerializer(typeof(VendorCredit));
                        StringReader  vendorCreditReader     = new StringReader(XML);
                        VendorCredit  vendorCredit           = (VendorCredit)vendorCreditSerializer.Deserialize(vendorCreditReader);
                        VendorCredit  newVendorCredit        = dataService.Add(vendorCredit);

                        StringWriter vendorCreditWriter = new StringWriter();
                        vendorCreditSerializer.Serialize(vendorCreditWriter, newVendorCredit);

                        output = vendorCreditWriter.ToString();
                        break;

                    case QBObjectType.TaxCode:
                        XmlSerializer taxCodeSerializer = new XmlSerializer(typeof(TaxCode));
                        StringReader  taxCodeReader     = new StringReader(XML);
                        TaxCode       taxCode           = (TaxCode)taxCodeSerializer.Deserialize(taxCodeReader);
                        TaxCode       newTaxCode        = dataService.Add(taxCode);

                        StringWriter taxCodeWriter = new StringWriter();
                        taxCodeSerializer.Serialize(taxCodeWriter, newTaxCode);

                        output = taxCodeWriter.ToString();
                        break;

                    case QBObjectType.TaxRate:
                        XmlSerializer taxRateSerializer = new XmlSerializer(typeof(TaxRate));
                        StringReader  taxRateReader     = new StringReader(XML);
                        TaxRate       taxRate           = (TaxRate)taxRateSerializer.Deserialize(taxRateReader);
                        TaxRate       newTaxRate        = dataService.Add(taxRate);

                        StringWriter taxRateWriter = new StringWriter();
                        taxRateSerializer.Serialize(taxRateWriter, newTaxRate);

                        output = taxRateWriter.ToString();
                        break;
                    }
                    Output("QBO CreateEntity successful.");
                    return(output);
                }
                else
                {
                    Output("AccessToken or RealmID cannot be empty");
                }
            }
            catch (IdsException ex)
            {
                if (ex.Message == "Unauthorized-401")
                {
                    Output("Invalid/Expired Access Token.");

                    RefreshTokens(refreshToken);

                    if (oauthTokens.ContainsKey("accessToken") && oauthTokens.ContainsKey("refreshToken"))
                    {
                        Output("Refreshed Access Token");
                        return(CreateEntity(oauthTokens["accessToken"], realmID, oauthTokens["refreshToken"], entityType, XML, IsProd));
                    }
                    else
                    {
                        Output("Error while refreshing tokens");
                        return("REVOKE");
                    }
                }
                else if (ex.Message == "429")
                {
                    Output("Too Many Concurrent Requests - Retrying in 1 minute...");
                    System.Threading.Thread.Sleep(60000);
                    return(CreateEntity(accessToken, realmID, refreshToken, entityType, XML, IsProd));
                }
                else
                {
                    Output("IdsException = " + ex.Message);
                    return(ex.Message);
                }
            }
            catch (Exception ex)
            {
                Output("Exception = " + ex.Message);
                return(ex.Message);
            }
            return("");
        }
예제 #21
0
        public string MakeQBOQuery(string accessToken, string realmID, string refreshToken, int queryType, string query, bool IsProd)
        {
            try
            {
                if (!string.IsNullOrEmpty(accessToken) && !string.IsNullOrEmpty(realmID))
                {
                    ServiceContext serviceContext = BuildServiceContext(accessToken, realmID, IsProd);
                    string         output         = "";
                    QBObjectType   QBQueryType    = (QBObjectType)queryType;

                    Output("Making MakeQBOQuery " + QBQueryType + " API Call.");

                    switch (QBQueryType)
                    {
                    case QBObjectType.cClass:
                        QueryService <Class> classQuerySvc = new QueryService <Class>(serviceContext);
                        Class classQuery = classQuerySvc.ExecuteIdsQuery(query).FirstOrDefault();

                        XmlSerializer classSerializer = new XmlSerializer(typeof(Class));
                        StringWriter  classWriter     = new StringWriter();
                        classSerializer.Serialize(classWriter, classQuery);

                        output = classWriter.ToString();
                        break;

                    case QBObjectType.Customer:
                        QueryService <Customer> customerQuery = new QueryService <Customer>(serviceContext);
                        Customer customer = customerQuery.ExecuteIdsQuery(query).FirstOrDefault();

                        XmlSerializer customerSerializer = new XmlSerializer(typeof(Customer));
                        StringWriter  customerWriter     = new StringWriter();
                        customerSerializer.Serialize(customerWriter, customer);

                        output = customerWriter.ToString();
                        break;

                    case QBObjectType.Invoice:
                        QueryService <Invoice> invoiceQuery = new QueryService <Invoice>(serviceContext);
                        Invoice invoice = invoiceQuery.ExecuteIdsQuery(query).FirstOrDefault();

                        XmlSerializer invoiceSerializer = new XmlSerializer(typeof(Invoice));
                        StringWriter  invoiceWriter     = new StringWriter();
                        invoiceSerializer.Serialize(invoiceWriter, invoice);

                        output = invoiceWriter.ToString();
                        break;

                    case QBObjectType.InvoiceCreditMemo:
                        QueryService <CreditMemo> creditMemoQuery = new QueryService <CreditMemo>(serviceContext);
                        CreditMemo creditMemo = creditMemoQuery.ExecuteIdsQuery(query).FirstOrDefault();

                        XmlSerializer creditMemoSerializer = new XmlSerializer(typeof(CreditMemo));
                        StringWriter  creditMemoWriter     = new StringWriter();
                        creditMemoSerializer.Serialize(creditMemoWriter, creditMemo);

                        output = creditMemoWriter.ToString();
                        break;

                    case QBObjectType.Vendor:
                    case QBObjectType.VendorDeduction:
                        QueryService <Vendor> vendorQuery = new QueryService <Vendor>(serviceContext);
                        Vendor vendor = vendorQuery.ExecuteIdsQuery(query).FirstOrDefault();

                        XmlSerializer vendorSerializer = new XmlSerializer(typeof(Vendor));
                        StringWriter  vendorWriter     = new StringWriter();
                        vendorSerializer.Serialize(vendorWriter, vendor);

                        output = vendorWriter.ToString();
                        break;

                    case QBObjectType.CarrierPay:
                    case QBObjectType.DriverPay:
                        QueryService <Bill> billQuery = new QueryService <Bill>(serviceContext);
                        Bill bill = billQuery.ExecuteIdsQuery(query).FirstOrDefault();

                        XmlSerializer billSerializer = new XmlSerializer(typeof(Bill));
                        StringWriter  billWriter     = new StringWriter();
                        billSerializer.Serialize(billWriter, bill);

                        output = billWriter.ToString();
                        break;

                    case QBObjectType.DriverDeduction:
                        QueryService <VendorCredit> vendorCreditQuery = new QueryService <VendorCredit>(serviceContext);
                        VendorCredit vendorCredit = vendorCreditQuery.ExecuteIdsQuery(query).FirstOrDefault();

                        XmlSerializer vendorCreditSerializer = new XmlSerializer(typeof(VendorCredit));
                        StringWriter  vendorCreditWriter     = new StringWriter();
                        vendorCreditSerializer.Serialize(vendorCreditWriter, vendorCredit);

                        output = vendorCreditWriter.ToString();
                        break;

                    case QBObjectType.Term:
                        QueryService <Term> termQuery = new QueryService <Term>(serviceContext);
                        Term term = termQuery.ExecuteIdsQuery(query).FirstOrDefault();

                        XmlSerializer termSerializer = new XmlSerializer(typeof(Term));
                        StringWriter  termWriter     = new StringWriter();
                        termSerializer.Serialize(termWriter, term);

                        output = termWriter.ToString();
                        break;

                    case QBObjectType.COA:
                        QueryService <Account> accountQuery = new QueryService <Account>(serviceContext);
                        Account account = accountQuery.ExecuteIdsQuery(query).FirstOrDefault();

                        XmlSerializer accountSerializer = new XmlSerializer(typeof(Account));
                        StringWriter  accountWriter     = new StringWriter();
                        accountSerializer.Serialize(accountWriter, account);

                        output = accountWriter.ToString();
                        break;

                    case QBObjectType.TaxCode:
                        QueryService <TaxCode> taxCodeQuery = new QueryService <TaxCode>(serviceContext);
                        TaxCode taxCode = taxCodeQuery.ExecuteIdsQuery(query).FirstOrDefault();

                        XmlSerializer taxCodeSerializer = new XmlSerializer(typeof(TaxCode));
                        StringWriter  taxCodeWriter     = new StringWriter();
                        taxCodeSerializer.Serialize(taxCodeWriter, taxCode);

                        output = taxCodeWriter.ToString();
                        break;

                    case QBObjectType.TaxRate:
                        QueryService <TaxRate> taxRateQuery = new QueryService <TaxRate>(serviceContext);
                        TaxRate taxRate = taxRateQuery.ExecuteIdsQuery(query).FirstOrDefault();

                        XmlSerializer taxRateSerializer = new XmlSerializer(typeof(TaxRate));
                        StringWriter  taxRateWriter     = new StringWriter();
                        taxRateSerializer.Serialize(taxRateWriter, taxRate);

                        output = taxRateWriter.ToString();
                        break;

                    case QBObjectType.Item:
                        QueryService <Item> itemQuery = new QueryService <Item>(serviceContext);
                        Item item = itemQuery.ExecuteIdsQuery(query).FirstOrDefault();

                        XmlSerializer itemSerializer = new XmlSerializer(typeof(Item));
                        StringWriter  itemWriter     = new StringWriter();
                        itemSerializer.Serialize(itemWriter, item);

                        output = itemWriter.ToString();
                        break;
                    }

                    Output("MakeQBOQuery call successful.");
                    return(output);
                }
                else
                {
                    Output("AccessToken or RealmID cannot be empty");
                }
            }
            catch (IdsException ex)
            {
                if (ex.Message == "Unauthorized-401")
                {
                    Output("Invalid/Expired Access Token.");

                    RefreshTokens(refreshToken);

                    if (oauthTokens.ContainsKey("accessToken") && oauthTokens.ContainsKey("refreshToken"))
                    {
                        Output("Refreshed Access Token");
                        return(MakeQBOQuery(oauthTokens["accessToken"], realmID, oauthTokens["refreshToken"], queryType, query, IsProd));
                    }
                    else
                    {
                        Output("Error while refreshing tokens");
                        return("REVOKE");
                    }
                }
                else if (ex.Message == "429")
                {
                    Output("Too Many Concurrent Requests - Retrying in 1 minute...");
                    System.Threading.Thread.Sleep(60000);
                    return(MakeQBOQuery(accessToken, realmID, refreshToken, queryType, query, IsProd));
                }
                else
                {
                    Output("IdsException = " + ex.Message);
                }
            }
            catch (Exception ex)
            {
                Output("Exception = " + ex.Message);
                Output("StackTrace = " + ex.StackTrace);
                Output("HelpLink = " + ex.HelpLink);
                Output("InnerException.Message = " + ex.InnerException.Message);
            }
            return("");
        }
예제 #22
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string 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 oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);

            ServiceContext serviceContext = new ServiceContext(realmId, IntuitServicesType.QBO, oauthValidator);

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

            serviceContext.IppConfiguration.Message.Request.SerializationFormat  = Intuit.Ipp.Core.Configuration.SerializationFormat.Xml;
            serviceContext.IppConfiguration.Message.Response.SerializationFormat = Intuit.Ipp.Core.Configuration.SerializationFormat.Xml;
            serviceContext.IppConfiguration.MinorVersion.Qbo = "11";


            // serviceContext.IppConfiguration.RetryPolicy = new Intuit.Ipp.Retry.IntuitRetryPolicy(serviceContext,3, new TimeSpan(0, 0, 10));
            // serviceContext.IppConfiguration.Logger.RequestLog.EnableRequestResponseLogging = true;
            // serviceContext.IppConfiguration.Logger.RequestLog.ServiceRequestLoggingLocation = @"F:\Logs";

            //serviceContext.RequestId = "897kjhjjhkh9";

            DataService commonServiceQBO = new DataService(serviceContext);

            #region 'testing for Retry'

            //try
            //{
            //    Item it = new Item();
            //    it.Name = "Hindi";

            //    var ResultIt1 = commonServiceQBO.Add<Item>(it);

            //    //var ResultIt = AddAsync<Item>(serviceContext, it);
            //}

            //catch (RetryExceededException ex)
            //{
            //    throw ex;
            //}
            //catch (IdsException ex)
            //{
            //    throw ex;
            //}
            //catch (Exception ex)
            //{
            //    throw ex;
            //}


            #endregion

            try
            {
                QueryService <VendorCredit> inService1 = new QueryService <VendorCredit>(serviceContext);
                VendorCredit In1 = inService1.ExecuteIdsQuery("SELECT * FROM VendorCredit").FirstOrDefault();
            }
            catch (RetryExceededException ex)
            {
                throw ex;
            }
            catch (IdsException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }



            //var bill = new Intuit.Ipp.Data.Bill() { Id = "‼" };
            //var result = commonServiceQBO.FindById(bill);
            //QueryService<Item> inService1 = new QueryService<Item>(serviceContext);
            //Item In1 = inService1.ExecuteIdsQuery("SELECT * FROM Item").FirstOrDefault();

            //List<Account> accounts = commonServiceQBO.FindAll<Account>(new Account(), 1, 100).ToList<Account>();


            //QueryService <Invoice> inService = new QueryService<Invoice>(serviceContext);
            //Invoice In = inService.ExecuteIdsQuery("SELECT * FROM Invoice where Id='337'").FirstOrDefault();
            //var j = inService.ExecuteIdsQuery("SELECT * FROM Invoice where Id='337'").ToList<Invoice>();

            #region Attachable
            //string imagePath = string.Concat(AppDomain.CurrentDomain.BaseDirectory, "\\", "Resource\\my_data.xlsx");
            //System.IO.FileInfo file = new System.IO.FileInfo(imagePath);
            //Attachable attachable = new Attachable();
            //attachable.Lat = "25.293112341223";
            //attachable.Long = "-21.3253249834";
            //attachable.PlaceName = "Fake Place";
            //attachable.Note = "Attachable note123 ";
            //attachable.Tag = "Attachable tag123 ";

            //AttachableRef[] attachments = new AttachableRef[1];
            //AttachableRef ar = new AttachableRef();
            //ar.EntityRef = new ReferenceType();
            //ar.EntityRef.type = objectNameEnumType.Invoice.ToString();
            //ar.EntityRef.name = objectNameEnumType.Invoice.ToString();
            //ar.EntityRef.Value = "337";
            ////ar.EntityRef.type = objectNameEnumType.Bill.ToString();
            ////ar.EntityRef.name = objectNameEnumType.Bill.ToString();
            ////ar.EntityRef.Value = "1484";
            //attachments[0] = ar;
            //attachable.AttachableRef = attachments;

            //using (System.IO.FileStream fs = file.OpenRead())
            //{
            //    //attachable.ContentType = "image/bmp";
            //    ////attachable.FileName = file.Name;
            //    //attachable.FileName = "image.bmp";
            //    //Attachable attachableUploaded = commonServiceQBO.Upload(attachable, fs);
            //    //byte[] responseByte = commonServiceQBO.Download(attachableUploaded);
            //    //fs.Close();
            //    attachable.ContentType = "application/vnd.ms-excel";//application pdf
            //    //attachable.FileName = file.Name;
            //    attachable.FileName = "my_data.xlsx";
            //    Attachable attachableUploaded = commonServiceQBO.Upload(attachable, fs);
            //    byte[] responseByte = commonServiceQBO.Download(attachableUploaded);
            //    fs.Close();
            //}

            //Attachable res11 = commonServiceQBO.Add<Attachable>(attachable);
            #endregion
        }
예제 #23
0
 static void Main(string[] args)
 {
     try
     {
         var service = new ZohoBooks();
         service.initialize("{authtoken}", "{organization id}");
         var vendorCreditsApi = service.GetVendorCreditsApi();
         Console.WriteLine("--------------------VendorCreditList--------------");
         var vendorCredits = vendorCreditsApi.GetVendorCredits(null);
         foreach (var tempVendorCredit in vendorCredits)
             Console.WriteLine("Id:{0},Vendor name:{1},Status:{2}",tempVendorCredit.vendor_credit_id,tempVendorCredit.vendor_name,tempVendorCredit.status);
         Console.WriteLine("----------------------------------Specified Vendor Credit-----------------------");
         var vendorCredit = vendorCreditsApi.Get(vendorCredits[0].vendor_credit_id,null);
         Console.WriteLine("Id:{0},Vendor name:{1},Status:{2}", vendorCredit.vendor_credit_id, vendorCredit.vendor_name, vendorCredit.status);
         Console.WriteLine("Line items:");
         var lineitems = vendorCredit.line_items;
         foreach (var tempLineItem in lineitems)
             Console.WriteLine("name:{0},desc:{1},rate:{2}", tempLineItem.name, tempLineItem.description, tempLineItem.rate);
         Console.WriteLine("------------------New Vendor Credit---------");
         var newCreditInfo = new VendorCredit()
         {
             vendor_id=vendorCredit.vendor_id,
             line_items = new List<LineItem>()
             {
                 new LineItem(){
                     item_id=lineitems[0].item_id,
                     rate=360,
                 },
             },
         };
         var newVendorCredit = vendorCreditsApi.Create(newCreditInfo, null);
         Console.WriteLine("Id:{0},Vendor name:{1},Status:{2},amount:{3}", newVendorCredit.vendor_credit_id, newVendorCredit.vendor_name, newVendorCredit.status,newVendorCredit.total);
         Console.WriteLine("-------------------------Update Vendor Credit------------");
         var creditUpdateInfo = new VendorCredit()
         {
             
             line_items = new List<LineItem>()
             {
                 new LineItem(){
                     item_id=lineitems[0].item_id,
                     rate=560,
                 },
             },
         };
         var updatedVendorCredit = vendorCreditsApi.Update(newVendorCredit.vendor_credit_id, creditUpdateInfo);
         Console.WriteLine("Id:{0},Vendor name:{1},Status:{2},amount:{3}", updatedVendorCredit.vendor_credit_id, updatedVendorCredit.vendor_name, updatedVendorCredit.status, updatedVendorCredit.total);
         Console.WriteLine("-----------------------Delete Vendor Credit----------------");
         var deleteVendorcredit = vendorCreditsApi.Delete(updatedVendorCredit.vendor_credit_id);
         Console.WriteLine(deleteVendorcredit);
         Console.WriteLine("------------------Statuses----------------");
         var convertToOpen = vendorCreditsApi.ConvertToOpen(vendorCredits[0].vendor_credit_id);
         Console.WriteLine(convertToOpen);
         var markAsVoid = vendorCreditsApi.MarkAsVoid(vendorCredits[1].vendor_credit_id);
         Console.WriteLine(markAsVoid);
         Console.WriteLine("---------------------------------Bills credited-------------------------------");
         var bills = vendorCreditsApi.GetBillsCredited(vendorCredits[0].vendor_credit_id);
         foreach (var tempBill in bills)
             Console.WriteLine("Bill id:{0},vendor credit bill id:{1},amount:{2}",tempBill.bill_id,tempBill.vendor_credit_bill_id,tempBill.amount);
         var billsToApply = new ApplyToBills()
         {
             bills = new List<Bill>()
             {
                 new Bill(){
                     bill_id=bills[0].bill_id,
                     amount_applied=100
                  },
             }
         };
         var applyCredits = vendorCreditsApi.ApplyCreditsToBill(vendorCredits[0].vendor_credit_id, billsToApply);
         Console.WriteLine(applyCredits);
         var deleteBillsCredited = vendorCreditsApi.DeleteBillsCredited(vendorCredits[0].vendor_credit_id, bills[0].vendor_credit_bill_id);
         Console.WriteLine(deleteBillsCredited);
         Console.WriteLine("------------------------------------Refunds------------------------");
         var allRefunds = vendorCreditsApi.GetRefunds(null);
         foreach (var tempRefund in allRefunds)
             Console.WriteLine("Refund id:{0},vendor name:{1},amount:{2}",tempRefund.vendor_credit_refund_id,tempRefund.vendor_name,tempRefund.amount_fcy);
         var refundsOfCredit = vendorCreditsApi.GetRefundsOfVendorCredit(vendorCredits[0].vendor_credit_id);
         foreach (var tempRefund in refundsOfCredit)
             Console.WriteLine("Refund id:{0},vendor name:{1},amount:{2}", tempRefund.vendor_credit_refund_id, tempRefund.vendor_name, tempRefund.amount_fcy);
         var refund = vendorCreditsApi.GetVendorCreditRefund(vendorCredits[0].vendor_credit_id, refundsOfCredit[0].vendor_credit_refund_id);
         Console.WriteLine("Specified Refund \n Refund id:{0},vendor name:{1},amount:{2}", refund.vendor_credit_refund_id, refund.vendor_name, refund.amount);
         var newRefundInfo = new VendorCreditRefund()
         {
             date="2014-11-25",
             account_id=refund.account_id,
             amount=20
         };
         var newRefund = vendorCreditsApi.AddRefund(vendorCredits[0].vendor_credit_id, newRefundInfo);
         Console.WriteLine("New Refund \n Refund id:{0},vendor name:{1},amount:{2}", newRefund.vendor_credit_refund_id, newRefund.vendor_name, newRefund.amount);
         var updateInfo = new VendorCreditRefund()
         {
             amount = 25
         };
         var updatedRefund = vendorCreditsApi.UpdateRefund(vendorCredits[0].vendor_credit_id, newRefund.vendor_credit_refund_id, updateInfo);
         Console.WriteLine("Updated Refund \n Refund id:{0},vendor name:{1},amount:{2}", updatedRefund.vendor_credit_refund_id, updatedRefund.vendor_name, updatedRefund.amount);
         var deleteRefund = vendorCreditsApi.DeleteRefund(vendorCredits[0].vendor_credit_id, updatedRefund.vendor_credit_refund_id);
         Console.WriteLine(deleteRefund);
         Console.WriteLine("--------------------------Comments-------------------");
         var comments = vendorCreditsApi.GetComments(vendorCredits[0].vendor_credit_id);
         foreach (var comment in comments)
             Console.WriteLine("id:{0},description:{1},commented by:{2}", comment.comment_id, comment.description, comment.commented_by);
         var newCommentInfo = new Comment()
         {
             description="test comment",
         };
         var newComment = vendorCreditsApi.AddComment(vendorCredits[0].vendor_credit_id, newCommentInfo);
         Console.WriteLine("New comment \nid:{0},description:{1},commented by:{2}", newComment.comment_id, newComment.description, newComment.commented_by);
         var deleteComment = vendorCreditsApi.DeleteComment(newComment.vendor_credit_id, newComment.comment_id);
         Console.WriteLine(deleteComment);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
     Console.ReadKey();
 }
        /*
         * Creates a VendorCredit
         * The VendorCredit object is an accounts payable transaction that represents a refund or credit of payment for goods or services.
         * It is a credit that a vendor owes you for various reasons such as overpaid bill, returned merchandise, or other reasons.
         */
        private VendorCredit CreateVendorCredit(ServiceContext serviceContext, Vendor vendor)
        {
            DataService            dataService     = new DataService(serviceContext);
            QueryService <Account> accountQuerySvc = new QueryService <Account>(serviceContext);
            //Create a VendorCredut and add a reference to a Vendor
            VendorCredit vendorCredit = new VendorCredit();

            vendorCredit.VendorRef = new ReferenceType()
            {
                name  = vendor.DisplayName,
                Value = vendor.Id
            };

            //Create a Liability Account and add a reference to the Vendor Credit. If not present create a  Liability Account
            #region create liability account

            //Get a liability account. If not present create one

            Account liabilityAccount = accountQuerySvc.ExecuteIdsQuery("SELECT * FROM Account WHERE AccountType='Accounts Payable' AND Classification='Liability'").FirstOrDefault();
            if (liabilityAccount == null)
            {
                Account accountp = new Account();
                String  guid     = Guid.NewGuid().ToString("N");
                accountp.Name = "Name_" + guid;

                //accountp.FullyQualifiedName = liabilityAccount.Name;

                accountp.Classification          = AccountClassificationEnum.Liability;
                accountp.ClassificationSpecified = true;
                accountp.AccountType             = AccountTypeEnum.AccountsPayable;
                accountp.AccountTypeSpecified    = true;

                accountp.CurrencyRef = new ReferenceType()
                {
                    name  = "United States Dollar",
                    Value = "USD"
                };
                liabilityAccount = dataService.Add <Account>(accountp);
            }
            #endregion
            vendorCredit.APAccountRef = new ReferenceType()
            {
                name  = liabilityAccount.Name,
                Value = liabilityAccount.Id
            };

            //Add Vendor credit details
            vendorCredit.TotalAmt          = new Decimal(50.00);
            vendorCredit.TotalAmtSpecified = true;
            vendorCredit.TxnDate           = DateTime.UtcNow.Date;
            vendorCredit.TxnDateSpecified  = true;

            //Create a line and add it to the Vendor Credit
            List <Line> lineList = new List <Line>();
            Line        line     = new Line();
            line.Description         = "Description";
            line.Amount              = new Decimal(50.00);
            line.AmountSpecified     = true;
            line.DetailType          = LineDetailTypeEnum.AccountBasedExpenseLineDetail;
            line.DetailTypeSpecified = true;

            #region create expense account
            //Get a Expense account. If not present create one
            Account expenseAccount = accountQuerySvc.ExecuteIdsQuery("SELECT * FROM Account WHERE AccountType='Expense' AND Classification='Expense'").FirstOrDefault();
            if (expenseAccount == null)
            {
                Account accounte = new Account();
                String  guid     = Guid.NewGuid().ToString("N");
                accounte.Name = "Name_" + guid;

                // accounte.FullyQualifiedName = expenseAccount.Name;

                accounte.Classification          = AccountClassificationEnum.Liability;
                accounte.ClassificationSpecified = true;
                accounte.AccountType             = AccountTypeEnum.AccountsPayable;
                accounte.AccountTypeSpecified    = true;

                accounte.CurrencyRef = new ReferenceType()
                {
                    name  = "United States Dollar",
                    Value = "USD"
                };
                expenseAccount = dataService.Add <Account>(accounte);
            }
            #endregion


            line.AnyIntuitObject = new AccountBasedExpenseLineDetail()
            {
                AccountRef = new ReferenceType()
                {
                    name = expenseAccount.Name, Value = expenseAccount.Id
                }
            };
            lineList.Add(line);
            vendorCredit.Line = lineList.ToArray();
            VendorCredit vendorcreditAdded = dataService.Add <VendorCredit>(vendorCredit);

            return(vendorcreditAdded);
        }
예제 #25
0
 public void VendorCreditQueryUsingoAuth(ServiceContext qboContextoAuth)
 {
     QueryService <VendorCredit> entityQuery = new QueryService <VendorCredit>(qboContextoAuth);
     VendorCredit        existing            = Helper.FindOrAdd <VendorCredit>(qboContextoAuth, new VendorCredit());
     List <VendorCredit> test = entityQuery.ExecuteIdsQuery("SELECT * FROM VendorCredit where Id='" + existing.Id + "'").ToList <VendorCredit>();
 }