How mercadopago/sdk-dotnet works
Project Type and Purpose
• This is an open-source, language-specific SDK (a .NET client library) for interacting with Mercado Pago’s payment APIs.
• Primary consumers are .NET applications (console apps, web back-ends, desktop apps) that need to call Mercado Pago endpoints.
High-Level Components
a. SDK Core (in src/MercadoPago)
• Config: MercadoPagoConfig (holds AccessToken, RetryStrategy, custom HttpClient)
• Client: one Client class per API surface (OrderClient, PaymentClient, etc.)
• Http: DefaultHttpClient, IHttpClient, DefaultRetryStrategy, IRequestOptions
• Serialization: DefaultSerializer, ISerializer, converters
• Error Handling: ApiError, MercadoPagoException
b. Unit Tests (src/MercadoPago.Tests)
• Client unit tests (using mock HttpClient)
• Serialization tests
c. Documentation (docfx configuration + docs/ folder)
• Auto-generated API reference via DocFX
• Static HTML output
d. Examples (examples/ folder)
• Sample .NET console programs demonstrating common flows (Order Create, Capture, Refund, etc.)
e. CI/CD (GitHub workflows)
• CI.yml: runs tests on push/PR
• CD.yml: builds/publishes NuGet package
Relationships and Data Flows
• Developer App → references NuGet package → instantiates Client classes
• Client uses Config (AccessToken, HttpClient, RetryStrategy)
• Client calls IHttpClient.SendAsync → HTTP/JSON REST call to Mercado Pago API (external service)
• Response JSON → Serialization layer → Resource models → returned to caller
• Error HTTP codes → mapped to ApiError/MercadoPagoException
• Unit tests mock IHttpClient to verify client logic without real network
Architectural Patterns and Principles
• Modular layering: Config → Client → Http → Serialization → Resource
• Dependency inversion: Client depends on IHttpClient & ISerializer interfaces
• Single Responsibility: each Client handles one API domain; Serializer handles only JSON mapping
• Idempotency & retry built into Http layer
• Extensibility: per-request RequestOptions, custom HttpClient injection