Use this file to discover all available pages before exploring further.
SDK C# cung cấp quyền truy cập thuận tiện vào Dodo Payments REST API từ các ứng dụng viết bằng C#. Nó có API dựa trên async Task với kiểu dữ liệu mạnh, tự động thử lại và xử lý lỗi toàn diện.
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);
Luôn lưu trữ khóa API của bạn một cách an toàn bằng biến môi trường, user secrets hoặc Azure Key Vault. Không bao giờ viết cứng chúng vào mã nguồn hoặc cam kết chúng lên hệ thống điều khiển phiên bản.
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 yêu cầu tối thiểu mã ISO hai chữ cái Country. Sử dụng AttachExistingCustomer để đính kèm khách hàng hiện có, hoặc NewCustomer để tạo một khách hàng mới. ProductPrice là trong mệnh giá tiền tệ thấp nhất.