SDK .NET para Portugal
CorpMerch.SDK no NuGet — .NET 8, HttpClientFactory, modelos AOT-friendly via source-gen para Portugal.
Arquitectura — Instalação e init para Portugal
NuGet: dotnet add package CorpMerch.SDK. Init em Program.cs: builder.Services.AddCorpMerch(o => { o.ApiKey = builder.Configuration["CorpMerch:ApiKey"]; o.Country = "Portugal"; });. Usa HttpClientFactory com políticas Polly v8. IVA 23% aplicado no servidor; canal AT para facturas. .NET 8 / .NET Standard 2.1.
Como integrar — Quickstart com cancelamento
var order = await _cm.Orders.CreateAsync(new OrderCreateOptions { IdempotencyKey = Guid.NewGuid().ToString(), Buyer = new() { VatId = "EU…" }, Lines = [new() { Sku = "TSH-001", Qty = 200 }] }, cancellationToken);. Serializadores System.Text.Json source-generated — AOT-friendly, cold start rápido em Azure Functions e AWS Lambda.
Operação e casos extremos — Verificação de webhook (ASP.NET Core)
Mapeia um endpoint: app.MapPost("/wh", async (HttpRequest req, ICorpMerchWebhooks wh) => { var ev = await wh.ConstructEventAsync(req); return Results.Ok(); });. Lança SignatureVerificationException em assinatura inválida — ligada a 400. Minimal APIs e MVC. IDs de notificação Portal das Finanças (AT) em InvoiceEvent.AcknowledgementId.
Perguntas frequentes
Suporte de frameworks?
.NET 8 e .NET Standard 2.1. .NET Framework 4.8 na SDK legacy 1.x.
AOT e trimming?
Sim — source-generated System.Text.Json, sem reflection em runtime. Pronto para AOT publish e trimmed builds.
Retries com Polly?
Retry, timeout e circuit-breaker integrados via Polly v8. Configurável com AddCorpMerch(o => { o.Retry.MaxAttempts = 5; }).
Suporte a F#?
Sim — assembly .NET puro, funciona a partir de F#. Wrappers discriminated union em pacote companion.
IVA 23% e AT?
country: 'Portugal' aplica IVA 23%. Eventos webhook de facturas incluem id de notificação AT.