private FortnoxDataCopier( ILogger logger, FortnoxApiKeys fortnoxApiKeys, WebcrmClient webcrmClient) { Logger = logger; FortnoxClient = new FortnoxClient(fortnoxApiKeys); WebcrmClient = webcrmClient; }
internal static async Task <FortnoxDataCopier> Create( ILogger logger, WebcrmClientFactory webcrmClientFactory, FortnoxConfiguration configuration) { var webcrmClient = await webcrmClientFactory.Create(configuration.WebcrmApiKey); var fortnoxApiKeys = new FortnoxApiKeys(configuration.FortnoxAccessToken, configuration.FortnoxClientSecret); return(new FortnoxDataCopier(logger, fortnoxApiKeys, webcrmClient)); }
public FortnoxClient(FortnoxApiKeys fortnoxApiKeys) { Client = new HttpClient { DefaultRequestHeaders = { { "Access-Token", fortnoxApiKeys.AccessToken }, { "Client-Secret", fortnoxApiKeys.ClientSecret } } }; }
public FortnoxClient(FortnoxApiKeys fortnoxApiKeys) { // TODO 1911: Where is the OAuth2 request to get the access token using the authorization code and the client secret? https://developer.fortnox.se/documentation/general/authentication/. Client = new HttpClient { DefaultRequestHeaders = { { "Access-Token", fortnoxApiKeys.AccessToken }, { "Client-Secret", fortnoxApiKeys.ClientSecret } } }; }
internal async Task EnqueueUpsertedInvoices( DateTime upsertedAfterUtc, FortnoxConfiguration configuration) { var fortnoxApiKeys = new FortnoxApiKeys(configuration.FortnoxAccessToken, configuration.FortnoxClientSecret); var fortnoxClient = new FortnoxClient(fortnoxApiKeys); // Convert utc date we pass in to either CEST or CET. var dateTimeSinceUpsertedSwedish = upsertedAfterUtc.FromUtcToSwedish(); var upsertedInvoices = await fortnoxClient.GetRecentlyUpsertedInvoices(dateTimeSinceUpsertedSwedish); Logger.LogInformation($"Found {upsertedInvoices.Count} upserted invoices in Fortnox upserted since {dateTimeSinceUpsertedSwedish:yyyy-MM-dd HH:mm:ss}."); foreach (var invoice in upsertedInvoices) { var payload = new UpsertDeliveryFromFortnoxPayload(invoice.CustomerNumber, invoice.DocumentNumber, configuration.WebcrmSystemId); await FortnoxQueue.Enqueue(new FortnoxQueueMessage(FortnoxQueueAction.UpsertFortnoxDelivery, payload)); } }