Integre os pagamentos Dodo em suas aplicações .NET com suporte moderno a async/await
O SDK C# fornece acesso conveniente à API REST do Dodo Payments a partir de aplicativos escritos em C#. Ele possui uma API baseada em Tarefas assíncronas com forte tipagem, tentativas automáticas e tratamento de erros abrangente.
Inicialize o cliente e crie uma sessão de checkout:
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);
Sempre armazene suas chaves da API de forma segura usando variáveis de ambiente, segredos de usuário ou Azure Key Vault. Nunca os codifique diretamente no seu código-fonte ou os envie para o controle de versão.
O SDK tenta novamente automaticamente 2 vezes por padrão com recuo exponencial. Ele tenta novamente em erros de conexão e códigos de status 408, 409, 429 e 5xx.
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 requer, no mínimo, o código Country ISO de duas letras. Use AttachExistingCustomer para associar um cliente existente, ou NewCustomer para criar um. ProductPrice está na menor denominação de moeda.