Primeros Pasos con EricksonLopez.Webhooks
L3StableNuGet: v1.0.0Local HEAD: v2.1.0AOT: Full
Instala EricksonLopez.Webhooks y EricksonLopez.Webhooks.AspNetCore (1.0.0 en NuGet).
dotnet add package EricksonLopez.Webhooks --version 1.0.0<PackageReference Include="EricksonLopez.Webhooks" Version="1.0.0" /><PackageVersion Include="EricksonLopez.Webhooks" Version="1.0.0" />dotnet add package EricksonLopez.Webhooks.AspNetCore --version 1.0.0dotnet add package EricksonLopez.Webhooks.Redis --version 1.0.0Nota de Publicación:
EricksonLopez.Webhooks.PaymentGatewaysexiste únicamente en el workspace local2.1.0y no está publicado en NuGet.org.
Inicio Rápido: Emisor Saliente y Receptor Entrante (ValidateOnBuild=true)
Sección titulada «Inicio Rápido: Emisor Saliente y Receptor Entrante (ValidateOnBuild=true)»Pasa la clave secreta desde configuración o variables de entorno (ELS0003 detecta secretos literales en código):
using System;using EricksonLopez.Webhooks;using EricksonLopez.Webhooks.AspNetCore;using Microsoft.Extensions.DependencyInjection;
namespace Example.WebhooksQuickStart;
public static class WebhooksUsage{ public static void Register(string webhookSecret) { var services = new ServiceCollection(); services.AddLogging(); services.AddWebhooks(options => { options.Timeout = TimeSpan.FromSeconds(10); options.EnableSsrfProtection = true; options.Protocol = WebhookSenderProtocol.EricksonLopez; });
services.AddWebhookReceiver(options => { options.RoutePath = "/api/webhooks/incoming"; options.SecretKey = webhookSecret; }); services.AddInMemoryReplayDetector(TimeSpan.FromMinutes(5));
using var provider = services.BuildServiceProvider( new ServiceProviderOptions { ValidateOnBuild = true, ValidateScopes = true });
var sender = provider.GetRequiredService<IWebhookSender>(); var validator = provider.GetRequiredService<IWebhookValidator>(); if (sender is null || validator is null) { throw new InvalidOperationException("Webhook services were not registered."); } }}