Send seller payouts through Paystream from the back office

C# · ASP.NET Core · advanced · modification

Finance pays sellers today by creating each transfer in Paystream's dashboard and pasting its id into Mark as sent. This PR gives the back office a Send button's endpoint instead: `POST /api/admin/payouts/{id}/send` creates the transfer through Paystream's API and records it on the payout. `PaystreamClient.cs` (new) is a typed `HttpClient` that posts the transfer and returns its id, with its options class. `PayoutsModule.cs` gains `AddPayouts`, which binds and validates the `Paystream` options at startup and registers the client with the standard resilience handler (5 second attempts, two retries) so a slow or briefly unavailable Paystream does not fail the press, and maps the new route in the existing finance group. `Program.cs` calls `AddPayouts`, and `Marketplace.Api.csproj` adds `Microsoft.Extensions.Http.Resilience`. `PaystreamClientTests.cs` (new) covers the client against a fake message handler.

Marketplace back-office API on ASP.NET Core 10 minimal APIs, .NET 10 (C# 14, nullable reference types and implicit usings enabled), EF Core 10 with Npgsql, xUnit for tests (the test project, unchanged, has a global `using Xunit`). `Program.cs` is shown in full. Existing and unchanged: `MarketDbContext.Payouts` maps the `Payout` entity: `Guid Id`; `int SellerId`; `string DestinationAccount`, the seller's Paystream account id, checked when the seller onboards; `long AmountCents`, from 1 to 100,000,000 in the currency's minor unit (what Paystream's `amount` takes); `string Currency`, a lowercase ISO code Paystream accepts; `PayoutStatus Status` (`Pending`, `Sent`, `Expired`); `string? TransferId`; and the UTC `DateTime CreatedAt` and `DateTime? SentAt`. The weekly statement job (unchanged) creates `Pending` payouts and moves a payout still `Pending` after 7 days to `Expired` for finance's manual review; a payout becomes `Sent` only through `mark-sent` or this endpoint. A 2xx answer from Paystream carries the transfer as JSON with a non-empty `id`. The `Paystream` configuration section (`BaseUrl`, the API root ending in `/`, and `ApiKey`) is set through environment variables in every environment. The JWT bearer setup gives finance staff the `finance` role. `UseExceptionHandler` with `AddProblemDetails` logs an unhandled exception and answers a generic 500 problem body. If saving the payout fails after Paystream answered (a browser abort, a database error), the payout also stays `Pending` for another press. Finance sends at most a few hundred payouts a week, one press at a time. Microsoft.Extensions.Http.Resilience 10.11: `AddStandardResilienceHandler` chains a rate limiter, a total request timeout (30 s by default), the retry, a circuit breaker and the per-attempt timeout; the PR overrides only the attempt timeout and the retry count.

Requirements

Files touched

Review this PR

C# practice