Integrate Dodo Payments into your .NET applications with modern async/await support
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.
Initialize the client and create a checkout session:
using System;using DodoPayments.Client;using DodoPayments.Client.Models.CheckoutSessions;// Configured using the DODO_PAYMENTS_API_KEY and DODO_PAYMENTS_BASE_URL environment variablesDodoPaymentsClient client = new();CheckoutSessionCreateParams parameters = new(){ ProductCart = [ new() { ProductID = "product_id", Quantity = 1, }, ],};var checkoutSessionResponse = await client.CheckoutSessions.Create(parameters);Console.WriteLine(checkoutSessionResponse.SessionId);
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.
using DodoPayments.Client.Models.Payments;using DodoPayments.Client.Models.Subscriptions;// Create a subscriptionvar subscription = await client.Subscriptions.Create(new SubscriptionCreateParams{ Billing = new BillingAddress { Country = "US", City = "San Francisco", State = "CA", Street = "1 Market St", Zipcode = "94105", }, Customer = new AttachExistingCustomer { CustomerID = "cus_123" }, ProductID = "pdt_456", Quantity = 1,});// Charge an on-demand subscription// ProductPrice is in the lowest currency denomination (e.g., 2500 = $25.00 USD)var charge = await client.Subscriptions.Charge( subscription.SubscriptionId, new SubscriptionChargeParams { ProductPrice = 2500 });
Billing erfordert mindestens den zwei Buchstaben ISO Country Code. Verwenden Sie AttachExistingCustomer, um einen bestehenden Kunden zu verknüpfen, oder NewCustomer, um einen neuen zu erstellen. ProductPrice ist in der kleinsten Währungseinheit.