braspin-pagarme-dotnet-sdk 7.1.2

dotnet add package braspin-pagarme-dotnet-sdk --version 7.1.2
                    
NuGet\Install-Package braspin-pagarme-dotnet-sdk -Version 7.1.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="braspin-pagarme-dotnet-sdk" Version="7.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="braspin-pagarme-dotnet-sdk" Version="7.1.2" />
                    
Directory.Packages.props
<PackageReference Include="braspin-pagarme-dotnet-sdk" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add braspin-pagarme-dotnet-sdk --version 7.1.2
                    
#r "nuget: braspin-pagarme-dotnet-sdk, 7.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package braspin-pagarme-dotnet-sdk@7.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=braspin-pagarme-dotnet-sdk&version=7.1.2
                    
Install as a Cake Addin
#tool nuget:?package=braspin-pagarme-dotnet-sdk&version=7.1.2
                    
Install as a Cake Tool

Pagarme SDK para .NET 7

SDK .NET para integração com a API Core v5 da Pagar.me.

Instalação

Instale o pacote NuGet no seu projeto .NET 7:

dotnet add package braspin-pagarme-dotnet-sdk

Configuração com injeção de dependência

No Program.cs:

using PagarmeSDK;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddPagarMe(
    publicKey: builder.Configuration["Pagarme:PublicKey"],
    secretKey: builder.Configuration["Pagarme:SecretKey"]);

var app = builder.Build();
app.Run();

Com baseUrl e userAgent customizados:

builder.Services.AddPagarMe(options =>
{
    options.PublicKey = builder.Configuration["Pagarme:PublicKey"];
    options.SecretKey = builder.Configuration["Pagarme:SecretKey"];
    options.BaseUrl = "https://api.pagar.me/core/v5";
    options.UserAgent = "minha-aplicacao/1.0.0";
});

Se BaseUrl não for informado, o SDK usa https://api.pagar.me/core/v5. Se UserAgent não for informado, o SDK usa braspin-pagarme-dotnet-sdk 7.0.0.

Usando o client

Depois de registrar o SDK, injete PagarmeClient onde precisar:

using PagarmeSDK;
using PagarmeSDK.Models;

public class CustomerService
{
    private readonly PagarmeClient _pagarme;

    public CustomerService(PagarmeClient pagarme)
    {
        _pagarme = pagarme;
    }

    public GetCustomerResponse CreateCustomer()
    {
        var request = new CreateCustomerRequest
        {
            Name = "Tony Stark",
            Email = "tonystark@avengers.com",
            Type = "individual",
            Document = "93095135270",
            Code = "MY_CUSTOMER_001"
        };

        return _pagarme.Customers.CreateCustomer(request);
    }
}

Uso direto sem DI

using PagarmeSDK;

var client = new PagarmeClient(
    publicKey: "sua_public_key",
    secretKey: "sua_secret_key");

var charge = client.Charges.GetCharge("ch_exemplo");

Criar pedido com cartão de crédito

using PagarmeSDK;
using PagarmeSDK.Models;

var client = new PagarmeClient("sua_public_key", "sua_secret_key");

var request = new CreateOrderRequest
{
    Customer = new CreateCustomerRequest
    {
        Name = "Tony Stark",
        Email = "tonystark@avengers.com"
    },
    Items = new List<CreateOrderItemRequest>
    {
        new CreateOrderItemRequest
        {
            Amount = 2990,
            Description = "Chaveiro do Tesseract",
            Quantity = 1
        }
    },
    Payments = new List<CreatePaymentRequest>
    {
        new CreatePaymentRequest
        {
            PaymentMethod = "credit_card",
            CreditCard = new CreateCreditCardPaymentRequest
            {
                Card = new CreateCardRequest
                {
                    HolderName = "Tony Stark",
                    Number = "4000000000000010",
                    ExpMonth = 1,
                    ExpYear = 30,
                    Cvv = "123"
                }
            }
        }
    }
};

var response = client.Orders.CreateOrder(request);

Consultar cobrança

using PagarmeSDK;

var client = new PagarmeClient("sua_public_key", "sua_secret_key");

var charge = client.Charges.GetCharge("ch_exemplo");

CancellationToken

Todos os métodos assíncronos aceitam CancellationToken:

using PagarmeSDK;

var client = new PagarmeClient("sua_public_key", "sua_secret_key");

using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10));

var charge = await client.Charges.GetChargeAsync(
    "ch_exemplo",
    cancellationTokenSource.Token);

Tratamento de erros

O SDK lança exceptions específicas por tipo de erro retornado pela API:

using PagarmeSDK.Exceptions;

try
{
    var charge = client.Charges.GetCharge("ch_inexistente");
}
catch (PagarmeResourceNotFoundException ex)
{
    Console.WriteLine(ex.ResponseCode);
    Console.WriteLine(ex.Errors);
}
catch (PagarmeException ex)
{
    Console.WriteLine(ex.ResponseCode);
    Console.WriteLine(ex.Errors);
}

Principais exceptions:

  • PagarmeInvalidRequestException para HTTP 400
  • PagarmeInvalidApiKeyException para HTTP 401
  • PagarmeResourceNotFoundException para HTTP 404
  • PagarmeBusinessValidationException para HTTP 412
  • PagarmeContractValidationException para HTTP 422
  • PagarmeInternalServerErrorException para HTTP 500

Mais exemplos

A pasta examples contém exemplos para clientes, pedidos, cobranças, cartões, planos, assinaturas e marketplace.

Publicação no NuGet

O workflow .github/workflows/publish-nuget.yml publica versões por target framework:

  • net7.0 deve usar versões 7.0.x
  • net8.0 deve usar versões 8.0.x
  • net9.0 deve usar versões 9.0.x

Para publicar manualmente, execute o workflow no GitHub Actions e informe o target e a versão.

Também é possível publicar via tag:

git tag v7.0.1
git push origin v7.0.1

Uma tag v8.0.0 publica para net8.0, v9.0.0 publica para net9.0, e assim por diante.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
7.1.2 126 7/16/2026
7.1.1 128 6/18/2026
7.1.0 1,263 6/18/2026
7.0.3 133 5/25/2026
7.0.2 120 5/20/2026
7.0.1 105 5/20/2026
7.0.0 108 5/20/2026