Exemple #1
0
        public IHttpActionResult post()
        {
            WebHookLog dbwl = new WebHookLog();

            // retrieve xero key
            var    xerosignature      = Request.Headers.GetValues("x-xero-signature").FirstOrDefault();
            var    payload            = Request.Content.ReadAsStringAsync().Result;
            String app_key            = "4q1NTvJRtUuiUCvpo3FKSd3NlAUom53uY+ODoyr4sskmxPa9JSZifVM7g8S8G8k7Ipwde6Hj3MFVXMnmyrD9pg==";
            string generatedsignature = "";

            using (var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(app_key)))
            {
                var messageBytes = Encoding.UTF8.GetBytes(payload);
                var hash         = hmac.ComputeHash(messageBytes);
                generatedsignature = Convert.ToBase64String(hash);
            }

            var isValid = generatedsignature == xerosignature;

            if (!isValid)
            {
                dbwl.body = "Invalid Xerosignature";
                dbwl.Date = DateTime.Now;
                db.WebHookLogs.Add(dbwl);
                db.SaveChanges();
                return(Unauthorized());
            }

            var xevents = JsonConvert.DeserializeObject <XeroWebhookEvents>(payload);

            foreach (Xerowebhookevent xevent in xevents.events)
            {
                switch (xevent.eventCategory)
                {
                case "INVOICE":

                    dbwl.body = "received xero web hook invoice ";
                    dbwl.Date = DateTime.Now;
                    db.WebHookLogs.Add(dbwl);
                    db.SaveChanges();
                    dbwl.body = payload;
                    dbwl.Date = DateTime.Now;
                    db.WebHookLogs.Add(dbwl);
                    db.SaveChanges();
                    var res1 = UNMSHelper.addPaymentFromXero(XeroHelper.getXeroInvoice(xevent.resourceId));
                    break;
                }
            }
            dbwl.body = "OK Valid";
            dbwl.Date = DateTime.Now;
            db.WebHookLogs.Add(dbwl);
            db.SaveChanges();
            return(Ok());
        }
Exemple #2
0
        public IHttpActionResult post()
        {
            WebHookLog dbwl    = new WebHookLog();
            var        payload = Request.Content.ReadAsStringAsync().Result;

            dbwl.body = payload;
            dbwl.Date = DateTime.Now;
            db.WebHookLogs.Add(dbwl);
            db.SaveChanges();

            WebhookEvent uwebhook = JsonConvert.DeserializeObject <WebhookEvent>(payload);

            dbwl.body = uwebhook.entity.ToString();
            dbwl.Date = DateTime.Now;
            db.WebHookLogs.Add(dbwl);
            db.SaveChanges();



            switch (uwebhook.entity)
            {
            case "invoice":
                WebhookEventInvoice webhookinvoice = JsonConvert.DeserializeObject <WebhookEventInvoice>(payload);
                UNMSHelper.addorupdateInvoiceFromUNMS(webhookinvoice.extraData.entity);
                break;

            case "payment":
                WebhookEventPayment webhookpayment = JsonConvert.DeserializeObject <WebhookEventPayment>(payload);
                // check if it came from xero originally
                if (webhookpayment.extraData.entity.Note != "from Xero")
                {
                    UNMSHelper.addorupdatePaymentFromUNMS(webhookpayment.extraData.entity);
                }
                break;

            case "client":
                WebhookEventClient webhookclient = JsonConvert.DeserializeObject <WebhookEventClient>(payload);
                UNMSHelper.addorupdateClientFromUNMS(webhookclient.extraData.entity);
                break;

            case "ticket":
                WebhookEventTicket webhookticket = JsonConvert.DeserializeObject <WebhookEventTicket>(payload);
                UNMSHelper.editTicketFromUNMS(webhookticket.extraData.entity);
                break;
            }



            return(Ok());
        }
Exemple #3
0
        public IHttpActionResult get()
        {
            string payload = db.WebHookLogs.Where(a => a.Id == 20446).Select(a => a.body).FirstOrDefault();
            var    xevents = JsonConvert.DeserializeObject <XeroWebhookEvents>(payload);

            foreach (Xerowebhookevent xevent in xevents.events)
            {
                switch (xevent.eventCategory)
                {
                case "INVOICE":
                    // just update payment at this time
                    var res1 = UNMSHelper.addPaymentFromXero(XeroHelper.getXeroInvoice(xevent.resourceURL.Substring(xevent.resourceURL.Length - 36)));
                    break;
                }
            }
            return(Ok());
        }
Exemple #4
0
        public IHttpActionResult Get(int current, int rowCount, string sortBy = "Username", string sortDir = "asc", string searchPhrase = "", int _ = 1, string currentFilter = "")

        {
            List <InvoiceReadOnly>             invoices    = UNMSHelper.getinvoices();
            List <bootgridinvoiceSummary_list> invoicelist = (from x in invoices
                                                              where x.Status != InvoiceStatusEnum.ENUM_3
                                                              group x by new { firstName = x.ClientFirstName, lastName = x.ClientLastName } into g
                                                              orderby g.Key.firstName, g.Key.lastName
                                                              select new bootgridinvoiceSummary_list
            {
                Name = g.Key.firstName + " " + g.Key.lastName,
                Jan = g.Where(x => DateTime.Parse(x.CreatedDate).Month == 1).Sum(z => z.Total),
                Feb = g.Where(x => DateTime.Parse(x.CreatedDate).Month == 2).Sum(z => z.Total),
                Mar = g.Where(x => DateTime.Parse(x.CreatedDate).Month == 3).Sum(z => z.Total),
                Apr = g.Where(x => DateTime.Parse(x.CreatedDate).Month == 4).Sum(z => z.Total),
                May = g.Where(x => DateTime.Parse(x.CreatedDate).Month == 5).Sum(z => z.Total),
                Jun = g.Where(x => DateTime.Parse(x.CreatedDate).Month == 6).Sum(z => z.Total),
                Jul = g.Where(x => DateTime.Parse(x.CreatedDate).Month == 7).Sum(z => z.Total),
                Aug = g.Where(x => DateTime.Parse(x.CreatedDate).Month == 8).Sum(z => z.Total),
                Sep = g.Where(x => DateTime.Parse(x.CreatedDate).Month == 9).Sum(z => z.Total),
                Oct = g.Where(x => DateTime.Parse(x.CreatedDate).Month == 10).Sum(z => z.Total),
                Nov = g.Where(x => DateTime.Parse(x.CreatedDate).Month == 11).Sum(z => z.Total),
                Dec = g.Where(x => DateTime.Parse(x.CreatedDate).Month == 12).Sum(z => z.Total),
                Tot = g.Sum(z => z.Total)
            }).ToList();



            Bootgrid_invoicesummary bgru = new Bootgrid_invoicesummary();


            //   bgru.current = 1;
            //    bgru.rowCount = 20;
            bgru.current  = current;
            bgru.rowCount = Convert.ToInt32(rowCount);
            bgru.total    = invoicelist.Count();
            bgru.rows     = invoicelist;

            return(Json(bgru));
        }
Exemple #5
0
        public IHttpActionResult get()
        {
            var          test     = db.WebHookLogs.Where(a => a.Id == 19935).Select(a => a.body).FirstOrDefault();
            WebhookEvent uwebhook = JsonConvert.DeserializeObject <WebhookEvent>(test);

            switch (uwebhook.entity)
            {
            case "invoice":
                WebhookEventInvoice webhookinvoice = JsonConvert.DeserializeObject <WebhookEventInvoice>(test);
                UNMSHelper.addorupdateInvoiceFromUNMS(webhookinvoice.extraData.entity);
                break;

            case "payment":
                WebhookEventPayment webhookpayment = JsonConvert.DeserializeObject <WebhookEventPayment>(test);
                if (webhookpayment.extraData.entity.Note != "from Xero")
                {
                    UNMSHelper.addorupdatePaymentFromUNMS(webhookpayment.extraData.entity);
                }
                break;

            case "client":
                WebhookEventClient webhookclient = JsonConvert.DeserializeObject <WebhookEventClient>(test);
                UNMSHelper.addorupdateClientFromUNMS(webhookclient.extraData.entity);
                break;

            case "ticket":
                WebhookEventTicket webhookticket = JsonConvert.DeserializeObject <WebhookEventTicket>(test);
                UNMSHelper.editTicketFromUNMS(webhookticket.extraData.entity);
                break;

            case "service":
                WebhookEventService webhookservice = JsonConvert.DeserializeObject <WebhookEventService>(test);
                UNMSHelper.suspendServiceFromUNMS(webhookservice.extraData.entity);
                break;
            }
            return(Ok());
        }