From 5b237b0a8b1689678cbdd8398a5b98d413115a1f Mon Sep 17 00:00:00 2001 From: eiximenis Date: Wed, 6 Feb 2019 19:59:26 +0100 Subject: [PATCH] webhooks flow finished. Only missing bug in api that don't show the hooks --- docker-compose-tests.yml | 20 +++++----- docker-compose.yml | 40 +++++++++---------- k8s/helm/webhooks-api/templates/service.yaml | 2 +- k8s/helm/webhooks-api/values.yaml | 4 +- .../webhooks-web/templates/configmap.yaml | 3 +- k8s/helm/webhooks-web/templates/service.yaml | 2 +- k8s/helm/webhooks-web/values.yaml | 4 +- .../WebHost.Customization.csproj | 2 +- src/Services/Catalog/Catalog.API/Startup.cs | 2 +- ...rderStatusChangedToPaidIntegrationEvent.cs | 33 +++++++++++++++ ...tusChangedToPaidIntegrationEventHandler.cs | 32 +++++++++++++++ ...ChangedToShippedIntegrationEventHandler.cs | 7 +++- .../Webhooks.API/Model/WebhookType.cs | 3 +- src/Services/Webhooks/Webhooks.API/Startup.cs | 9 ++--- .../Controllers/WebhooksReceivedController.cs | 19 +++++++-- src/Web/WebhookClient/Models/WebhookData.cs | 6 +-- .../Pages/RegisterWebhook.cshtml | 2 +- .../Pages/RegisterWebhook.cshtml.cs | 2 +- src/Web/WebhookClient/Startup.cs | 9 ++++- src/Web/WebhookClient/appsettings.json | 2 +- 20 files changed, 144 insertions(+), 59 deletions(-) create mode 100644 src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToPaidIntegrationEvent.cs create mode 100644 src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToPaidIntegrationEventHandler.cs diff --git a/docker-compose-tests.yml b/docker-compose-tests.yml index d05f7e27e..7794d1a0e 100644 --- a/docker-compose-tests.yml +++ b/docker-compose-tests.yml @@ -14,7 +14,7 @@ services: image: mongo identity-api-test: - image: eshop/identity-api-test:${TAG:-latest} + image: ${REGISTRY:-eshop}/identity-api-test:${TAG:-latest} build: context: . dockerfile: src/Services/Identity/Identity.API/Dockerfile @@ -22,7 +22,7 @@ services: - sql-data-test basket-api-test: - image: eshop/basket-api-test:${TAG:-latest} + image: ${REGISTRY:-eshop}/basket-api-test:${TAG:-latest} build: context: . dockerfile: src/Services/Basket/Basket.API/Dockerfile @@ -35,7 +35,7 @@ services: - ${BUILD_ARTIFACTSTAGINGDIRECTORY:-./tests-results/}:/tests basket-api-unit-test: - image: eshop/basket-api-test:${TAG:-latest} + image: ${REGISTRY:-eshop}/basket-api-test:${TAG:-latest} build: context: . dockerfile: src/Services/Basket/Basket.API/Dockerfile @@ -48,7 +48,7 @@ services: - ${BUILD_ARTIFACTSTAGINGDIRECTORY:-./tests-results/}:/tests catalog-api-test: - image: eshop/catalog-api-test:${TAG:-latest} + image: ${REGISTRY:-eshop}/catalog-api-test:${TAG:-latest} build: context: . dockerfile: src/Services/Catalog/Catalog.API/Dockerfile @@ -60,7 +60,7 @@ services: - ${BUILD_ARTIFACTSTAGINGDIRECTORY:-./tests-results/}:/tests catalog-api-unit-test: - image: eshop/catalog-api-test:${TAG:-latest} + image: ${REGISTRY:-eshop}/catalog-api-test:${TAG:-latest} build: context: . dockerfile: src/Services/Catalog/Catalog.API/Dockerfile @@ -72,7 +72,7 @@ services: - ${BUILD_ARTIFACTSTAGINGDIRECTORY:-./tests-results/}:/tests ordering-api-test: - image: eshop/ordering-api-test:${TAG:-latest} + image: ${REGISTRY:-eshop}/ordering-api-test:${TAG:-latest} build: context: . dockerfile: src/Services/Ordering/Ordering.API/Dockerfile @@ -84,7 +84,7 @@ services: - ${BUILD_ARTIFACTSTAGINGDIRECTORY:-./tests-results/}:/tests ordering-api-unit-test: - image: eshop/ordering-api-test:${TAG:-latest} + image: ${REGISTRY:-eshop}/ordering-api-test:${TAG:-latest} build: context: . dockerfile: src/Services/Ordering/Ordering.API/Dockerfile @@ -96,7 +96,7 @@ services: - ${BUILD_ARTIFACTSTAGINGDIRECTORY:-./tests-results/}:/tests marketing-api-test: - image: eshop/marketing-api-test:${TAG:-latest} + image: ${REGISTRY:-eshop}/marketing-api-test:${TAG:-latest} build: context: . dockerfile: src/Services/Marketing/Marketing.API/Dockerfile @@ -110,7 +110,7 @@ services: - ${BUILD_ARTIFACTSTAGINGDIRECTORY:-./tests-results/}:/tests payment-api-test: - image: eshop/payment-api-test:${TAG:-latest} + image: ${REGISTRY:-eshop}/payment-api-test:${TAG:-latest} build: context: . dockerfile: src/Services/Payment/Payment.API/Dockerfile @@ -118,7 +118,7 @@ services: - rabbitmq-test locations-api-test: - image: eshop/locations-api-test:${TAG:-latest} + image: ${REGISTRY:-eshop}/locations-api-test:${TAG:-latest} build: context: . dockerfile: src/Services/Location/Locations.API/Dockerfile diff --git a/docker-compose.yml b/docker-compose.yml index 2bfab23fc..194d7e06c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,7 @@ services: image: rabbitmq:3-management-alpine identity.api: - image: eshop/identity.api:${TAG:-latest} + image: ${REGISTRY:-eshop}/identity.api:${TAG:-latest} build: context: . dockerfile: src/Services/Identity/Identity.API/Dockerfile @@ -22,7 +22,7 @@ services: - sql.data basket.api: - image: eshop/basket.api:${TAG:-latest} + image: ${REGISTRY:-eshop}/basket.api:${TAG:-latest} build: context: . dockerfile: src/Services/Basket/Basket.API/Dockerfile @@ -32,7 +32,7 @@ services: - rabbitmq catalog.api: - image: eshop/catalog.api:${TAG:-latest} + image: ${REGISTRY:-eshop}/catalog.api:${TAG:-latest} build: context: . dockerfile: src/Services/Catalog/Catalog.API/Dockerfile @@ -41,7 +41,7 @@ services: - rabbitmq ordering.api: - image: eshop/ordering.api:${TAG:-latest} + image: ${REGISTRY:-eshop}/ordering.api:${TAG:-latest} build: context: . dockerfile: src/Services/Ordering/Ordering.API/Dockerfile @@ -50,7 +50,7 @@ services: - rabbitmq ordering.backgroundtasks: - image: eshop/ordering.backgroundtasks:${TAG:-latest} + image: ${REGISTRY:-eshop}/ordering.backgroundtasks:${TAG:-latest} build: context: . dockerfile: src/Services/Ordering/Ordering.BackgroundTasks/Dockerfile @@ -59,7 +59,7 @@ services: - rabbitmq marketing.api: - image: eshop/marketing.api:${TAG:-latest} + image: ${REGISTRY:-eshop}/marketing.api:${TAG:-latest} build: context: . dockerfile: src/Services/Marketing/Marketing.API/Dockerfile @@ -70,7 +70,7 @@ services: - rabbitmq payment.api: - image: eshop/payment.api:${TAG:-latest} + image: ${REGISTRY:-eshop}/payment.api:${TAG:-latest} build: context: . dockerfile: src/Services/Payment/Payment.API/Dockerfile @@ -78,7 +78,7 @@ services: - rabbitmq locations.api: - image: eshop/locations.api:${TAG:-latest} + image: ${REGISTRY:-eshop}/locations.api:${TAG:-latest} build: context: . dockerfile: src/Services/Location/Locations.API/Dockerfile @@ -87,7 +87,7 @@ services: - rabbitmq webhooks.api: - image: eshop/webhooks.api:${TAG:-latest} + image: ${REGISTRY:-eshop}/webhooks.api:${TAG:-latest} build: context: . dockerfile: src/Services/Webhooks/Webhooks.API/Dockerfile @@ -95,7 +95,7 @@ services: - sql.data mobileshoppingapigw: - image: eshop/ocelotapigw:${TAG:-latest} + image: ${REGISTRY:-eshop}/ocelotapigw:${TAG:-latest} build: context: . dockerfile: src/ApiGateways/ApiGw-Base/Dockerfile @@ -110,7 +110,7 @@ services: - basket.api mobilemarketingapigw: - image: eshop/ocelotapigw:${TAG:-latest} + image: ${REGISTRY:-eshop}/ocelotapigw:${TAG:-latest} build: context: . dockerfile: src/ApiGateways/ApiGw-Base/Dockerfile @@ -125,7 +125,7 @@ services: - basket.api webshoppingapigw: - image: eshop/ocelotapigw:${TAG:-latest} + image: ${REGISTRY:-eshop}/ocelotapigw:${TAG:-latest} build: context: . dockerfile: src/ApiGateways/ApiGw-Base/Dockerfile @@ -140,7 +140,7 @@ services: - basket.api webmarketingapigw: - image: eshop/ocelotapigw:${TAG:-latest} + image: ${REGISTRY:-eshop}/ocelotapigw:${TAG:-latest} build: context: . dockerfile: src/ApiGateways/ApiGw-Base/Dockerfile @@ -155,7 +155,7 @@ services: - basket.api mobileshoppingagg: - image: eshop/mobileshoppingagg:${TAG:-latest} + image: ${REGISTRY:-eshop}/mobileshoppingagg:${TAG:-latest} build: context: . dockerfile: src/ApiGateways/Mobile.Bff.Shopping/aggregator/Dockerfile @@ -170,7 +170,7 @@ services: - basket.api webshoppingagg: - image: eshop/webshoppingagg:${TAG:-latest} + image: ${REGISTRY:-eshop}/webshoppingagg:${TAG:-latest} build: context: . dockerfile: src/ApiGateways/Web.Bff.Shopping/aggregator/Dockerfile @@ -185,7 +185,7 @@ services: - basket.api ordering.signalrhub: - image: eshop/ordering.signalrhub:${TAG:-latest} + image: ${REGISTRY:-eshop}/ordering.signalrhub:${TAG:-latest} build: context: . dockerfile: src/Services/Ordering/Ordering.SignalrHub/Dockerfile @@ -200,13 +200,13 @@ services: - basket.api webstatus: - image: eshop/webstatus:${TAG:-latest} + image: ${REGISTRY:-eshop}/webstatus:${TAG:-latest} build: context: . dockerfile: src/Web/WebStatus/Dockerfile webspa: - image: eshop/webspa:${TAG:-latest} + image: ${REGISTRY:-eshop}/webspa:${TAG:-latest} build: context: . dockerfile: src/Web/WebSPA/Dockerfile @@ -216,7 +216,7 @@ services: # - webmarketingapigw webmvc: - image: eshop/webmvc:${TAG:-latest} + image: ${REGISTRY:-eshop}/webmvc:${TAG:-latest} build: context: . dockerfile: src/Web/WebMVC/Dockerfile @@ -226,7 +226,7 @@ services: - webmarketingapigw webhooks.client: - image: eshop/webhooks.client:${TAG:-latest} + image: ${REGISTRY:-eshop}/webhooks.client:${TAG:-latest} build: context: . dockerfile: src/Web/WebhookClient/Dockerfile diff --git a/k8s/helm/webhooks-api/templates/service.yaml b/k8s/helm/webhooks-api/templates/service.yaml index 46f258171..d8a02ba65 100644 --- a/k8s/helm/webhooks-api/templates/service.yaml +++ b/k8s/helm/webhooks-api/templates/service.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: Service metadata: - name: {{ .Values.app.svc.ordering }} + name: {{ .Values.app.svc.webhooks }} labels: app: {{ template "webhooks-api.name" . }} chart: {{ template "webhooks-api.chart" . }} diff --git a/k8s/helm/webhooks-api/values.yaml b/k8s/helm/webhooks-api/values.yaml index 7580f4dfc..f6b1957e9 100644 --- a/k8s/helm/webhooks-api/values.yaml +++ b/k8s/helm/webhooks-api/values.yaml @@ -3,7 +3,7 @@ clusterName: eshop-aks pathBase: /webhooks-api image: - repository: eshop/ordering.api + repository: eshop/webhooks.api tag: latest pullPolicy: IfNotPresent @@ -12,7 +12,7 @@ service: port: 80 ingress: - enabled: false + enabled: true annotations: {} hosts: - chart-example.local diff --git a/k8s/helm/webhooks-web/templates/configmap.yaml b/k8s/helm/webhooks-web/templates/configmap.yaml index 2896a03f0..8852c7586 100644 --- a/k8s/helm/webhooks-web/templates/configmap.yaml +++ b/k8s/helm/webhooks-web/templates/configmap.yaml @@ -1,6 +1,7 @@ {{- $name := include "webhooks-web.fullname" . -}} {{- $identity := include "url-of" (list .Values.app.ingress.entries.identity .) -}} {{- $webhooksweb := include "url-of" (list .Values.app.ingress.entries.webhooksweb .) -}} +{{- $webhooks := include "url-of" (list .Values.app.ingress.entries.webhooks .) -}} apiVersion: v1 kind: ConfigMap @@ -12,7 +13,7 @@ metadata: release: {{ .Release.Name }} heritage: {{ .Release.Service }} data: - urls__webhooks: Server={{ $sqlsrv }};Initial Catalog={{ .Values.inf.sql.webhooks.db }};User Id={{ .Values.inf.sql.common.user }};Password={{ .Values.inf.sql.common.pwd }}; + urls__webhooks: http://{{ $webhooks }} identity_e: http://{{ $identity }} webhooksweb_e: http://{{ $webhooksweb }} urls_webhooksweb: http://{{ .Values.app.svc.webhooksweb }} diff --git a/k8s/helm/webhooks-web/templates/service.yaml b/k8s/helm/webhooks-web/templates/service.yaml index b5cc607b4..873ebcc0e 100644 --- a/k8s/helm/webhooks-web/templates/service.yaml +++ b/k8s/helm/webhooks-web/templates/service.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: Service metadata: - name: {{ .Values.app.svc.ordering }} + name: {{ .Values.app.svc.webhooksweb }} labels: app: {{ template "webhooks-web.name" . }} chart: {{ template "webhooks-web.chart" . }} diff --git a/k8s/helm/webhooks-web/values.yaml b/k8s/helm/webhooks-web/values.yaml index f4466228d..0e5b04b57 100644 --- a/k8s/helm/webhooks-web/values.yaml +++ b/k8s/helm/webhooks-web/values.yaml @@ -3,7 +3,7 @@ clusterName: eshop-aks pathBase: /webhooks-web image: - repository: eshop/webhooksweb + repository: eshop/webhooks.client tag: latest pullPolicy: IfNotPresent @@ -12,7 +12,7 @@ service: port: 80 ingress: - enabled: false + enabled: true annotations: {} hosts: - chart-example.local diff --git a/src/BuildingBlocks/WebHostCustomization/WebHost.Customization/WebHost.Customization.csproj b/src/BuildingBlocks/WebHostCustomization/WebHost.Customization/WebHost.Customization.csproj index 2c5f8b773..1d4ea7a2d 100644 --- a/src/BuildingBlocks/WebHostCustomization/WebHost.Customization/WebHost.Customization.csproj +++ b/src/BuildingBlocks/WebHostCustomization/WebHost.Customization/WebHost.Customization.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/Services/Catalog/Catalog.API/Startup.cs b/src/Services/Catalog/Catalog.API/Startup.cs index d9985ec12..5c77d37c8 100644 --- a/src/Services/Catalog/Catalog.API/Startup.cs +++ b/src/Services/Catalog/Catalog.API/Startup.cs @@ -274,7 +274,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API services.AddTransient>( sp => (DbConnection c) => new IntegrationEventLogService(c)); - // services.AddTransient(); + services.AddTransient(); if (configuration.GetValue("AzureServiceBusEnabled")) { diff --git a/src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToPaidIntegrationEvent.cs b/src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToPaidIntegrationEvent.cs new file mode 100644 index 000000000..c4adda56e --- /dev/null +++ b/src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToPaidIntegrationEvent.cs @@ -0,0 +1,33 @@ +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Webhooks.API.IntegrationEvents +{ + public class OrderStatusChangedToPaidIntegrationEvent : IntegrationEvent + { + public int OrderId { get; } + public IEnumerable OrderStockItems { get; } + + public OrderStatusChangedToPaidIntegrationEvent(int orderId, + IEnumerable orderStockItems) + { + OrderId = orderId; + OrderStockItems = orderStockItems; + } + } + + public class OrderStockItem + { + public int ProductId { get; } + public int Units { get; } + + public OrderStockItem(int productId, int units) + { + ProductId = productId; + Units = units; + } + } +} diff --git a/src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToPaidIntegrationEventHandler.cs b/src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToPaidIntegrationEventHandler.cs new file mode 100644 index 000000000..2503bdca7 --- /dev/null +++ b/src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToPaidIntegrationEventHandler.cs @@ -0,0 +1,32 @@ +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Webhooks.API.Model; +using Webhooks.API.Services; +using Microsoft.Extensions.Logging; + +namespace Webhooks.API.IntegrationEvents +{ + public class OrderStatusChangedToPaidIntegrationEventHandler : IIntegrationEventHandler + { + private readonly IWebhooksRetriever _retriever; + private readonly IWebhooksSender _sender; + private readonly ILogger _logger; + public OrderStatusChangedToPaidIntegrationEventHandler(IWebhooksRetriever retriever, IWebhooksSender sender, ILogger logger ) + { + _retriever = retriever; + _sender = sender; + _logger = logger; + } + + public async Task Handle(OrderStatusChangedToPaidIntegrationEvent @event) + { + var subscriptions = await _retriever.GetSubscriptionsOfType(WebhookType.OrderPaid); + _logger.LogInformation($"Received OrderStatusChangedToShippedIntegrationEvent and got {subscriptions.Count()} subscriptions to process"); + var whook = new WebhookData(WebhookType.OrderPaid, @event); + await _sender.SendAll(subscriptions, whook); + } + } +} diff --git a/src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToShippedIntegrationEventHandler.cs b/src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToShippedIntegrationEventHandler.cs index 688e05055..9a1dea33d 100644 --- a/src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToShippedIntegrationEventHandler.cs +++ b/src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToShippedIntegrationEventHandler.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading.Tasks; using Webhooks.API.Model; using Webhooks.API.Services; +using Microsoft.Extensions.Logging; namespace Webhooks.API.IntegrationEvents { @@ -12,16 +13,18 @@ namespace Webhooks.API.IntegrationEvents { private readonly IWebhooksRetriever _retriever; private readonly IWebhooksSender _sender; - public OrderStatusChangedToShippedIntegrationEventHandler(IWebhooksRetriever retriever, IWebhooksSender sender ) + private readonly ILogger _logger; + public OrderStatusChangedToShippedIntegrationEventHandler(IWebhooksRetriever retriever, IWebhooksSender sender, ILogger logger ) { _retriever = retriever; _sender = sender; + _logger = logger; } public async Task Handle(OrderStatusChangedToShippedIntegrationEvent @event) { var subscriptions = await _retriever.GetSubscriptionsOfType(WebhookType.OrderShipped); - + _logger.LogInformation($"Received OrderStatusChangedToShippedIntegrationEvent and got {subscriptions.Count()} subscriptions to process"); var whook = new WebhookData(WebhookType.OrderShipped, @event); await _sender.SendAll(subscriptions, whook); } diff --git a/src/Services/Webhooks/Webhooks.API/Model/WebhookType.cs b/src/Services/Webhooks/Webhooks.API/Model/WebhookType.cs index 0f287cfcf..eceb15913 100644 --- a/src/Services/Webhooks/Webhooks.API/Model/WebhookType.cs +++ b/src/Services/Webhooks/Webhooks.API/Model/WebhookType.cs @@ -8,6 +8,7 @@ namespace Webhooks.API.Model public enum WebhookType { CatalogItemPriceChange = 1, - OrderShipped = 2 + OrderShipped = 2, + OrderPaid = 3 } } diff --git a/src/Services/Webhooks/Webhooks.API/Startup.cs b/src/Services/Webhooks/Webhooks.API/Startup.cs index 36c3d6dfc..ba3ccfe3d 100644 --- a/src/Services/Webhooks/Webhooks.API/Startup.cs +++ b/src/Services/Webhooks/Webhooks.API/Startup.cs @@ -128,6 +128,7 @@ namespace Webhooks.API var eventBus = app.ApplicationServices.GetRequiredService(); eventBus.Subscribe(); eventBus.Subscribe(); + eventBus.Subscribe(); } } @@ -264,9 +265,9 @@ namespace Webhooks.API } services.AddSingleton(); - - //services.AddTransient(); - + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); return services; } @@ -303,8 +304,6 @@ namespace Webhooks.API services.AddTransient>( sp => (DbConnection c) => new IntegrationEventLogService(c)); - // services.AddTransient(); - if (configuration.GetValue("AzureServiceBusEnabled")) { services.AddSingleton(sp => diff --git a/src/Web/WebhookClient/Controllers/WebhooksReceivedController.cs b/src/Web/WebhookClient/Controllers/WebhooksReceivedController.cs index 849f5092f..880bc0ade 100644 --- a/src/Web/WebhookClient/Controllers/WebhooksReceivedController.cs +++ b/src/Web/WebhookClient/Controllers/WebhooksReceivedController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; @@ -15,28 +16,38 @@ namespace WebhookClient.Controllers { private readonly Settings _settings; + private readonly ILogger _logger; - public WebhooksReceivedController(IOptions settings) + public WebhooksReceivedController(IOptions settings, ILogger logger) { _settings = settings.Value; + _logger = logger; } + [HttpPost] public IActionResult NewWebhook(WebhookData hook) { var header = Request.Headers[HeaderNames.WebHookCheckHeader]; var token = header.FirstOrDefault(); + + _logger.LogInformation($"Received hook with token {token}. My token is {_settings.Token}. Token validation is set to {_settings.ValidateToken}"); + if (!_settings.ValidateToken || _settings.Token == token) { + _logger.LogInformation($"Received hook is processed"); var received = HttpContext.Session.Get>(SessionKeys.HooksKey)?.ToList() ?? new List(); - received.Add(new WebHookReceived() + var newHook = new WebHookReceived() { Data = hook.Payload, When = hook.When, Token = token - }); - return Ok(); + }; + received.Add(newHook); + HttpContext.Session.Set>(SessionKeys.HooksKey, received); + return Ok(newHook); } + _logger.LogInformation($"Received hook is NOT processed - Bad Request returned."); return BadRequest(); } } diff --git a/src/Web/WebhookClient/Models/WebhookData.cs b/src/Web/WebhookClient/Models/WebhookData.cs index a20d46635..7172d2aaa 100644 --- a/src/Web/WebhookClient/Models/WebhookData.cs +++ b/src/Web/WebhookClient/Models/WebhookData.cs @@ -7,10 +7,10 @@ namespace WebhookClient.Models { public class WebhookData { - public DateTime When { get; } + public DateTime When { get; set; } - public string Payload { get; } + public string Payload { get; set; } - public string Type { get; } + public string Type { get; set; } } } diff --git a/src/Web/WebhookClient/Pages/RegisterWebhook.cshtml b/src/Web/WebhookClient/Pages/RegisterWebhook.cshtml index 4eee00b8c..c0e76b208 100644 --- a/src/Web/WebhookClient/Pages/RegisterWebhook.cshtml +++ b/src/Web/WebhookClient/Pages/RegisterWebhook.cshtml @@ -6,7 +6,7 @@

Register webhook

-

This page registers the "OrderShipped" Webhook by sending a POST to webhooks.

+

This page registers the "OrderPaid" Webhook by sending a POST to webhooks.

Token:

diff --git a/src/Web/WebhookClient/Pages/RegisterWebhook.cshtml.cs b/src/Web/WebhookClient/Pages/RegisterWebhook.cshtml.cs index 594ba8dfd..cd8a7a49a 100644 --- a/src/Web/WebhookClient/Pages/RegisterWebhook.cshtml.cs +++ b/src/Web/WebhookClient/Pages/RegisterWebhook.cshtml.cs @@ -54,7 +54,7 @@ namespace WebhookClient.Pages var payload = new WebhookSubscriptionRequest() { - Event = "OrderShipped", + Event = "OrderPaid", GrantUrl = granturl, Url = url, Token = Token diff --git a/src/Web/WebhookClient/Startup.cs b/src/Web/WebhookClient/Startup.cs index 886e1eac0..ba8b2a954 100644 --- a/src/Web/WebhookClient/Startup.cs +++ b/src/Web/WebhookClient/Startup.cs @@ -41,6 +41,13 @@ namespace WebhookClient // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { + + var pathBase = Configuration["PATH_BASE"]; + if (!string.IsNullOrEmpty(pathBase)) + { + app.UsePathBase(pathBase); + } + if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); @@ -49,10 +56,8 @@ namespace WebhookClient { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); } app.UseAuthentication(); - app.UseHttpsRedirection(); app.Map("/check", capp => { capp.Run(async (context) => diff --git a/src/Web/WebhookClient/appsettings.json b/src/Web/WebhookClient/appsettings.json index def9159a7..6a845cfd4 100644 --- a/src/Web/WebhookClient/appsettings.json +++ b/src/Web/WebhookClient/appsettings.json @@ -1,7 +1,7 @@ { "Logging": { "LogLevel": { - "Default": "Warning" + "Default": "Information" } }, "AllowedHosts": "*"