.NET suite: getting started
The Paylera .NET suite is two packages on NuGet:
| Package | Layer |
|---|---|
Paylera.Sdk | Typed HTTP client (.NET 8+). |
Paylera.AspNetCore | DI + MapPayleraRelay + MapPayleraWebhooks. |
You can use the typed client by itself for server-side jobs (Blazor Server, background workers, console tools); add the ASP.NET Core package on top when you also want the browser-safe relay or the inbound webhook receiver.
Install
dotnet add package Paylera.Sdkdotnet add package Paylera.AspNetCore # only for ASP.NET Core appsBoth packages target net8.0. The same code compiles unchanged against
net9.0 and net10.0.
Token convention
The SDK auto-routes to the right Paylera environment based on the token
prefix — no separate BaseUrl to remember:
| Token prefix | Effective BaseUrl |
|---|---|
pl_live_* | https://api.paylera.dev |
pl_test_* | https://api.test.paylera.dev |
For self-hosted Paylera or local-stack tests, override explicitly:
opts.BaseUrl = new Uri("https://paylera.acme.internal");Standalone client
The smallest possible call:
using Paylera.Sdk;
using var client = new PayleraClient("pl_test_abcdef0123456789");
var plans = await client.Api.ListPlansAsync( product_id: null, code: null, status: PlanStatus.Active, limit: 25, cursor: null, sort: null);PayleraClient is a thin facade that owns an internal HttpClient with
the auth handler, retry handler, and problem-details handler pre-wired.
Construct it once and reuse it; it is thread-safe.
DI registration
In an ASP.NET Core or generic-host app, use the DI extension instead of the standalone constructor:
using Paylera.Sdk;
builder.Services.AddPaylera(opts =>{ opts.ApiToken = builder.Configuration["Paylera:ApiToken"]; opts.ApiVersion = "2026-05-01";});Inject IPayleraClient directly:
public sealed class CheckoutService{ private readonly IPayleraClient _paylera;
public CheckoutService(IPayleraClient paylera) => _paylera = paylera;
public Task<CheckResponse> CheckAsync(Guid subId, string featureCode, CancellationToken ct) => _paylera.CheckEntitlementAsync(new CheckRequest { Subscription_id = subId, Feature_code = featureCode, Required_usage = "1", }, cancellationToken: ct);}The DI pipeline registers IPayleraClient via IHttpClientFactory, so
it picks up your host’s existing logging, metrics, and DNS-rotation
behaviour for free.
Add the ASP.NET Core relay
To expose the browser-safe relay for @paylera/react (or any
browser-side Paylera SDK) to call:
using Paylera.AspNetCore;
builder.Services.AddPaylera(opts =>{ opts.ApiToken = builder.Configuration["Paylera:ApiToken"]; opts.IdentifyCustomer = ctx => new PayleraCustomerIdentity { CustomerId = ctx.User.FindFirstValue("paylera_customer_id"), Email = ctx.User.FindFirstValue(ClaimTypes.Email), Name = ctx.User.Identity?.Name, }; opts.AutoCreateCustomer = true; opts.Csrf.Enabled = true;});
app.MapPayleraRelay("/api/paylera").RequireAuthorization();AddPaylera from Paylera.AspNetCore is a superset of AddPaylera
from Paylera.Sdk — it transparently registers both surfaces, so
IPayleraClient is still injectable for server-side calls that don’t
want the relay shape.
See aspnetcore for the full set of relay routes, CSRF behaviour, customer auto-create, and webhook receiver.
Examples
Two runnable example apps live in
examples/dotnet/:
examples/dotnet/AspNetCoreMinimalApi/— minimal-API host with JWT auth, the relay enabled, and a bundled SPA-style HTML page that exercises every relay route.examples/dotnet/BlazorServer/— Blazor Server app that drives a pricing page offListPlansAsyncand an entitlement gate offCheckEntitlementAsync— no relay needed because the runtime is server-side.
Both reference the workspace SDK packages via <ProjectReference>; the
references flip to <PackageReference> at v1 split-time.
Next steps
- ASP.NET Core integration — relay + webhook receiver
- Webhooks — verification, retries, typed events
- Idempotency and retries — Polly pipeline, UUID v7
- OpenTelemetry — span names, attribute keys