Skip to main content
The C# SDK provides convenient access to the Dodo Payments REST API from applications written in C#. It features an async Task-based API with strong typing, automatic retries, and comprehensive error handling.

Installation

Install the package from NuGet:
The SDK requires .NET 8.0 or later. It works with ASP.NET Core, Console applications, and other .NET project types.

Quick Start

Initialize the client and create a checkout session:
Always store your API keys securely using environment variables, user secrets, or Azure Key Vault. Never hardcode them in your source code or commit them to version control.

Core Features

Async/Await

Full async Task-based API for non-blocking operations

Strong Typing

Comprehensive type safety with nullable reference types

Smart Retries

Automatic retries with exponential backoff for transient errors

Error Handling

Built-in exception hierarchy for precise error management

Configuration

Environment Variables

.env

Manual Configuration

Environments

Switch between live and test mode:

Retries

The SDK automatically retries 2 times by default with exponential backoff. It retries on connection errors and status codes 408, 409, 429, and 5xx.

Timeouts

Requests time out after 1 minute by default.

Per-Request Overrides

Temporarily modify configuration for a single request using WithOptions:

Common Operations

Create a Checkout Session

Manage Customers

Handle Subscriptions

POST /subscriptions (SDK:ts subscriptions.create-metod) är föråldrad. Den fungerar fortfarande för befintliga integrationer, men nya integrationer bör skapa prenumerationer via en Checkout Session.
Billing kräver minst den tvåbokstaviga ISO-koden Country. Använd AttachExistingCustomer för att koppla en befintlig kund, eller NewCustomer för att skapa en. ProductPrice anges i den lägsta valutaenheten.

Felhantering

SDK:t kastar specifika undantag baserat på HTTP-statuskoden. Alla 4xx-fel ärver från DodoPayments4xxException. Andra undantagstyper:
  • DodoPaymentsIOException: I/O-nätverksfel
  • DodoPaymentsInvalidDataException: Kunde inte tolka parsade data
  • DodoPaymentsException: Basklass för alla undantag

Paginering

Automatisk paginering

Iterera genom alla resultat på alla sidor med Paginate-metoden, som returnerar en IAsyncEnumerable:

Manuell paginering

Integration med ASP.NET Core

Registrera klienten i din DI-container:
Program.cs
appsettings.json
För utveckling kan du använda user secrets i stället för att lagra nycklar i appsettings.json:

Resurser

NuGet Package

Visa paketet i NuGet Gallery

GitHub Repository

Visa källkoden och bidra

API Reference

Fullständig API-dokumentation

Discord Community

Få hjälp och kontakta utvecklare

Support

Behöver du hjälp med C# SDK:t?
Senast ändrad 17 augusti 2026