Esempio n. 1
0
        public async static Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log)
        {
            try
            {
                var stripeEvent = StripeEventUtility.ParseEvent(await req.ReadAsStringAsync());
                log.LogInformation($"Received stripe event of type: {stripeEvent.Type}");

                var(accessToken, clientSecret) = await LoadSettingsAsync(stripeEvent.LiveMode);

                var fortnoxClient = new FortnoxClient(accessToken, clientSecret, log);

                var response = await HandleStripeEvent(stripeEvent, fortnoxClient);

                if (response.IsSuccessStatusCode)
                {
                    return(new OkObjectResult(await response.Content.ReadAsStringAsync()));
                }

                return(new BadRequestObjectResult(await response.Content.ReadAsStringAsync()));
            }
            catch (Exception ex)
            {
                log.LogError(ex, $"Something went wrong ({ex.Message})"); // whytf is the exception not logged?
                return(new BadRequestObjectResult(ex.Message));
            }
        }
Esempio n. 2
0
        public async static Task <HttpResponseMessage> HandleStripeEvent(StripeEvent stripeEvent, FortnoxClient fortnoxClient)
        {
            if (stripeEvent.Type == StripeEvents.CustomerCreated)
            {
                return(await fortnoxClient.HandleCustomerCreatedAsync(Mapper <StripeCustomer> .MapFromJson((String)stripeEvent.Data.Object.ToString())));
            }
            else if (stripeEvent.Type == StripeEvents.InvoiceCreated)
            {
                return(await fortnoxClient.HandleInvoiceCreatedAsync(Mapper <StripeInvoice> .MapFromJson((String)stripeEvent.Data.Object.ToString())));
            }

            throw new NotImplementedException($"No handler for {stripeEvent.Type}");
        }