Hoppa till huvudinnehåll
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

Billing kräver minst den tvåbokstavs ISO Country-koden. Använd AttachExistingCustomer för att bifoga en befintlig kund, eller NewCustomer för att skapa en. ProductPrice är i den lägsta valutabetäckningen.

Felhantering

SDK:n kastar specifika undantag baserat på HTTP-statuskoden. Alla 4xx-fel ärv från DodoPayments4xxException. Andra typer av undantag:
  • DodoPaymentsIOException: I/O-nätverksfel
  • DodoPaymentsInvalidDataException: Misslyckande att tolka analyserad data
  • DodoPaymentsException: Bas klass för alla undantag

Paginering

Automatisk paginering

Iterera genom alla resultat över alla sidor med hjälp av metoden Paginate, som returnerar en IAsyncEnumerable:

Manuell paginering

ASP.NET Core Integration

Registrera klienten i din DI container:
Program.cs
appsettings.json
För utveckling, använd user secrets istället för att lagra nycklar i appsettings.json:

Resurser

NuGet Package

Visa paket i NuGet Gallery

GitHub Repository

Visa källkod och bidra

API Reference

Komplett API-dokumentation

Discord Community

Få hjälp och anslut med utvecklare

Support

Behöver du hjälp med C# SDK?
Senast ändrad 28 maj 2026