예제 #1
0
        public async void Should_AccountApi_Has_Invoices()
        {
            var(accessToken, xeroTenantId) = await _access.GetAccessToken();

            var sevenDaysAgo   = DateTime.Now.AddDays(-30).ToString("yyyy, MM, dd");
            var invoicesFilter = "Date >= DateTime(" + sevenDaysAgo + ")";

            var response = await _accountingApi.GetInvoicesAsync(accessToken, xeroTenantId, null, invoicesFilter);

            var invoices = response._Invoices;
        }
예제 #2
0
        public async Task <IActionResult> WebhookPayloadGenerator(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "XeroWebhooks/WebhookPayloadGenerator")] HttpRequest req
            , [Queue(WebhookQueueNames.ProcessWebhookEvents)] CloudQueue processQueue
            , ILogger log
            )
        {
            var(accessToken, xeroTenantId) = await _tenantAccess.GetAccessToken();

            var sevenDaysAgo   = DateTime.Now.AddDays(-30).ToString("yyyy, MM, dd");
            var invoicesFilter = "Date >= DateTime(" + sevenDaysAgo + ")";

            var response = await _accountingApi.GetInvoicesAsync(accessToken, xeroTenantId, null, invoicesFilter);

            var events = response._Invoices.Select(i => new Event()
            {
                TenantId      = Guid.Parse(xeroTenantId),
                ResourceId    = i?.InvoiceID ?? Guid.NewGuid(),
                EventType     = "Update",
                EventCategory = "INVOICE",
                EventDateUtc  = i?.UpdatedDateUTC ?? DateTime.Now.ToUniversalTime(),
                ResourceUrl   = i?.Url,
                TenantType    = "ORGANISATION",
            }).ToList();

            var keys = await _storeTable.Store(new Payload
            {
                Events             = events,
                Entropy            = "test",
                LastEventSequence  = events.Count(),
                FirstEventSequence = 1
            }.ToJson());

            // queue and trigger WebhookServiceNames.ProcessWebhookEvents
            await keys.AddMessageToAsync(processQueue);

            return(new JsonResult(events));
        }