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

Il metodo POST /subscriptions dell’SDK (il metodo subscriptions.create) è deprecato. Continua a funzionare per le integrazioni esistenti, ma per le nuove integrazioni è consigliabile creare le sottoscrizioni tramite una Checkout Session.
Billing richiede almeno il codice ISO a due lettere Country. Usa AttachExistingCustomer per associare un cliente esistente oppure NewCustomer per crearne uno. ProductPrice è espresso nella denominazione più bassa della valuta.

Gestione degli errori

L’SDK genera eccezioni specifiche in base al codice di stato HTTP. Tutti gli errori 4xx ereditano da DodoPayments4xxException. Altri tipi di eccezione:
  • DodoPaymentsIOException: errori di rete I/O
  • DodoPaymentsInvalidDataException: impossibilità di interpretare i dati analizzati
  • DodoPaymentsException: classe base per tutte le eccezioni

Paginazione

Paginazione automatica

Itera su tutti i risultati di tutte le pagine usando il metodo Paginate, che restituisce un IAsyncEnumerable:

Paginazione manuale

Integrazione con ASP.NET Core

Registra il client nel container DI:
Program.cs
appsettings.json
Per lo sviluppo, usa i segreti utente invece di archiviare le chiavi in appsettings.json:

Risorse

NuGet Package

Visualizza il pacchetto nella NuGet Gallery

GitHub Repository

Visualizza il codice sorgente e contribuisci

API Reference

Documentazione completa dell’API

Discord Community

Ricevi assistenza e connettiti con gli sviluppatori

Assistenza

Hai bisogno di assistenza con l’SDK C#?
Ultima modifica il 17 agosto 2026