AbacatePay.SDK 2.0.0

dotnet add package AbacatePay.SDK --version 2.0.0
                    
NuGet\Install-Package AbacatePay.SDK -Version 2.0.0
                    
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="AbacatePay.SDK" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AbacatePay.SDK" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AbacatePay.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 AbacatePay.SDK --version 2.0.0
                    
#r "nuget: AbacatePay.SDK, 2.0.0"
                    
#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 AbacatePay.SDK@2.0.0
                    
#: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=AbacatePay.SDK&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=AbacatePay.SDK&version=2.0.0
                    
Install as a Cake Tool

AbacatePay .NET SDK

NuGet Version License: MIT .NET Standard

A comprehensive .NET SDK for the AbacatePay API - a Brazilian payment solution that supports PIX payments, billing management, customer handling, and more.

Features

  • ๐Ÿš€ Easy Integration: Simple and intuitive API design
  • ๐Ÿ—๏ธ Modular Architecture: Domain-specific services for better organization
  • ๐Ÿ’ณ PIX Payments: Create and manage PIX QR codes for instant payments
  • ๐Ÿ‘ฅ Customer Management: Create and manage customer profiles
  • ๐Ÿ“„ Billing System: Handle recurring and one-time billings
  • ๐ŸŽซ Coupon System: Create and manage discount coupons
  • ๐Ÿช Store Management: Access store information and balance
  • ๐Ÿ’ฐ Withdrawals: Manage fund withdrawals
  • ๐Ÿ”’ Type Safety: Full .NET type safety with comprehensive models
  • โœ… Validation: Built-in request validation
  • ๐ŸŒ Async/Await: Modern async programming support
  • ๐Ÿ”ง Dependency Injection: Full support for DI containers
  • ๐Ÿงช Testability: Easy mocking and unit testing
  • ๐Ÿ“ฆ NuGet Package: Easy installation via NuGet

Installation

Package Manager

Install-Package AbacatePay.SDK

.NET CLI

dotnet add package AbacatePay.SDK

PackageReference

<PackageReference Include="AbacatePay.SDK" Version="1.0.0" />

Quick Start

1. Initialize the Client

using AbacatePay;

// Simple initialization with API key
var client = new AbacatePayClient("your-api-key-here");

// Or with full configuration
var config = new AbacatePayConfig
{
    ApiKey = "your-api-key-here",
    BaseUrl = "https://api.abacatepay.com",
    Sandbox = false, // Set to true for testing
    TimeoutSeconds = 30
};
var client = new AbacatePayClient(config);

2. Create a Customer

var customerRequest = new CustomerRequest
{
    Name = "Joรฃo Silva",
    Email = "joao@example.com",
    Cellphone = "+5511999999999",
    TaxId = "12345678901" // CPF or CNPJ
};

// Traditional way (still supported)
var customer = await client.CreateCustomerAsync(customerRequest);

// New modular way (recommended)
var customer = await client.Customers.CreateCustomerAsync(customerRequest);

Console.WriteLine($"Customer created with ID: {customer.Id}");

3. Create a PIX QR Code

var pixRequest = new PixQrCodeRequest
{
    Amount = 10000, // R$ 100.00 in cents
    Description = "Payment for services",
    ExpiresIn = 3600, // 1 hour
    Customer = new PixQrCodeCustomer
    {
        Name = "Joรฃo Silva",
        Email = "joao@example.com",
        Cellphone = "+5511999999999",
        TaxId = "12345678901"
    }
};

// Traditional way (still supported)
var pixQrCode = await client.CreatePixQrCodeAsync(pixRequest);

// New modular way (recommended)
var pixQrCode = await client.PixQrCodes.CreatePixQrCodeAsync(pixRequest);

Console.WriteLine($"PIX QR Code created: {pixQrCode.QrCode}");

4. Create a Billing

var billingRequest = new BillingRequest
{
    Frequency = "ONE_TIME",
    Methods = new List<string> { "PIX" },
    Products = new List<BillingProduct>
    {
        new BillingProduct
        {
            ExternalId = "prod-001",
            Name = "Premium Plan",
            Description = "Monthly subscription",
            Quantity = 1,
            Price = 5000 // R$ 50.00 in cents
        }
    },
    ReturnUrl = "https://yoursite.com/return",
    CompletionUrl = "https://yoursite.com/success",
    CustomerId = customer.Id,
    AllowCoupons = true
};

// Traditional way (still supported)
var billing = await client.CreateBillingAsync(billingRequest);

// New modular way (recommended)
var billing = await client.Billings.CreateBillingAsync(billingRequest);

Console.WriteLine($"Billing created: {billing.Id}");

Modular Architecture

The SDK now features a modular architecture with domain-specific services for better organization and testability.

Available Services

  • ICustomerService - Customer management operations
  • IBillingService - Billing and payment operations
  • IPixQrCodeService - PIX QR Code operations
  • ICouponService - Coupon management operations
  • IStoreService - Store information operations
  • IWithdrawService - Withdrawal operations

Using Domain Services

var client = new AbacatePayClient("your-api-key");

// Access domain-specific services
var customer = await client.Customers.CreateCustomerAsync(request);
var billing = await client.Billings.CreateBillingAsync(billingRequest);
var pix = await client.PixQrCodes.CreatePixQrCodeAsync(pixRequest);
var coupon = await client.Coupons.CreateCouponAsync(couponRequest);
var store = await client.Store.GetStoreAsync();
var withdraw = await client.Withdraws.CreateWithdrawAsync(withdrawRequest);

Dependency Injection Support

// Register services in your DI container
services.AddScoped<ICustomerService, CustomerService>();
services.AddScoped<IBillingService, BillingService>();
services.AddScoped<IPixQrCodeService, PixQrCodeService>();
services.AddScoped<ICouponService, CouponService>();
services.AddScoped<IStoreService, StoreService>();
services.AddScoped<IWithdrawService, WithdrawService>();

// Use in your controllers
public class PaymentController : ControllerBase
{
    private readonly ICustomerService _customerService;
    private readonly IBillingService _billingService;

    public PaymentController(ICustomerService customerService, IBillingService billingService)
    {
        _customerService = customerService;
        _billingService = billingService;
    }
}

Direct Service Usage

// Use services directly without the main client
var httpService = new HttpService(httpClient, config);
var customerService = new CustomerService(httpService);
var billingService = new BillingService(httpService);

var customer = await customerService.CreateCustomerAsync(request);
var billing = await billingService.CreateBillingAsync(billingRequest);

Testing with Mocks

[Test]
public async Task CreateCustomer_ShouldReturnCustomer()
{
    // Arrange
    var mockCustomerService = new Mock<ICustomerService>();
    mockCustomerService.Setup(x => x.CreateCustomerAsync(It.IsAny<CustomerRequest>(), It.IsAny<CancellationToken>()))
                       .ReturnsAsync(new CustomerResponseData());

    // Act
    var result = await mockCustomerService.Object.CreateCustomerAsync(request);

    // Assert
    Assert.IsNotNull(result);
}

API Reference

Customer Management

Create Customer
Task<CustomerResponseData> CreateCustomerAsync(CustomerRequest request, CancellationToken cancellationToken = default)
List Customers
Task<List<CustomerResponse>> ListCustomersAsync(CancellationToken cancellationToken = default)

PIX QR Code Management

Create PIX QR Code
Task<PixQrCodeData> CreatePixQrCodeAsync(PixQrCodeRequest request, CancellationToken cancellationToken = default)
Check PIX Status
Task<PixQrCodeStatusData> CheckPixQrCodeStatusAsync(string pixQrCodeId, CancellationToken cancellationToken = default)
Simulate Payment (Dev Mode)
Task<PixQrCodeData> SimulatePixQrCodePaymentAsync(string pixQrCodeId, CancellationToken cancellationToken = default)

Billing Management

Create Billing
Task<BillingData> CreateBillingAsync(BillingRequest request, CancellationToken cancellationToken = default)
Get Billing
Task<BillingData> GetBillingAsync(string billingId, CancellationToken cancellationToken = default)
List Billings
Task<List<BillingData>> ListBillingsAsync(CancellationToken cancellationToken = default)

Coupon Management

Create Coupon
Task<CouponData> CreateCouponAsync(CouponRequest request, CancellationToken cancellationToken = default)
List Coupons
Task<List<CouponData>> ListCouponsAsync(CancellationToken cancellationToken = default)

Store Management

Get Store Information
Task<StoreData> GetStoreAsync(CancellationToken cancellationToken = default)

Withdrawal Management

Create Withdrawal
Task<WithdrawData> CreateWithdrawAsync(WithdrawRequest request, CancellationToken cancellationToken = default)
Get Withdrawal
Task<WithdrawData> GetWithdrawAsync(string withdrawId, CancellationToken cancellationToken = default)
List Withdrawals
Task<WithdrawData> ListWithdrawsAsync(CancellationToken cancellationToken = default)

Migration Guide

From Version 1.x to 2.x

The new version is 100% backward compatible. Your existing code will continue to work without any changes.

Option 1: Keep Using Traditional API (No Changes Required)
// Your existing code continues to work
var client = new AbacatePayClient("api-key");
var customer = await client.CreateCustomerAsync(request);
var billing = await client.CreateBillingAsync(billingRequest);
// Old way
var customer = await client.CreateCustomerAsync(request);

// New way (recommended)
var customer = await client.Customers.CreateCustomerAsync(request);
Option 3: Use Dependency Injection
// Register services
services.AddScoped<ICustomerService, CustomerService>();
services.AddScoped<IBillingService, BillingService>();

// Use in controllers
public class PaymentController : ControllerBase
{
    private readonly ICustomerService _customerService;
    
    public PaymentController(ICustomerService customerService)
    {
        _customerService = customerService;
    }
    
    public async Task<IActionResult> CreateCustomer(CustomerRequest request)
    {
        var customer = await _customerService.CreateCustomerAsync(request);
        return Ok(customer);
    }
}

Benefits of Migration

  • Better Organization: Domain-specific services
  • Easier Testing: Mock individual services
  • Dependency Injection: Clean architecture support
  • Single Responsibility: Each service has one purpose
  • Future-Proof: Easy to extend and maintain

Configuration

AbacatePayConfig Properties

Property Type Description Default
ApiKey string Your Bearer token from AbacatePay dashboard Required
BaseUrl string Base URL for the API "https://api.abacatepay.com"
Sandbox bool Whether to use sandbox mode false
TimeoutSeconds int HTTP request timeout in seconds 30

Error Handling

The SDK throws AbacatePayException for API errors:

try
{
    var customer = await client.CreateCustomerAsync(customerRequest);
}
catch (AbacatePayException ex)
{
    Console.WriteLine($"API Error: {ex.Message}");
}
catch (ArgumentException ex)
{
    Console.WriteLine($"Validation Error: {ex.Message}");
}

Validation

The SDK includes built-in validation for all request models:

  • Required fields: Automatically validated
  • Data types: Type safety enforced
  • Custom validation: Business rules validated (e.g., frequency values, price minimums)
  • String length: Maximum length constraints enforced

Examples

Real-World Project Example

Check out a complete backend implementation using this SDK:

Complete Payment Flow

using AbacatePay;
using AbacatePay.Models;

// Initialize client
var client = new AbacatePayClient("your-api-key");

try
{
    // 1. Create PIX payment
    var pixPayment = await client.CreatePixQrCodeAsync(new PixQrCodeRequest
    {
        Amount = 9700, // R$ 25.00
        Description = "SDK Product",
        Customer = {
            Name = "Ismael Ash",
            Cellphone = "11967435133",
            Email = "contato@ismaelnascimento.com",
            TsxId = "01364181045"
        }
    });

    Console.WriteLine($"Payment created! Code: {pixPayment.BrCode}");

    // 2. Check payment status
    var status = await client.CheckPixQrCodeStatusAsync(pixPayment.Id);
    Console.WriteLine($"Payment status: {status.Status}");
}
catch (AbacatePayException ex)
{
    Console.WriteLine($"Payment failed: {ex.Message}");
}
finally
{
    client.Dispose();
}

Billing Flow Example

var billingRequest = new BillingRequest
{
    Frequency = "ONE_TIME",
    Methods = new List<string> { "PIX" },
    Products = new List<BillingProduct>
    {
        new BillingProduct
        {
            ExternalId = "subscription-001",
            Name = "Premium Subscription",
            Description = "Monthly premium access",
            Quantity = 1,
            Price = 9900 // R$ 99.00
        }
    },
    ReturnUrl = "https://yoursite.com/billing/return",
    CompletionUrl = "https://yoursite.com/billing/success",
    CustomerId = "customer-id-here", // The ID of a customer already registered in your store.
    AllowCoupons = true,
    Coupons = new List<string> { "WELCOME10" }
};

var billing = await client.CreateBillingAsync(billingRequest);
Console.WriteLine($"Billing link: {billing.Url}");

Development

Building the SDK

# Clone the repository
git clone https://github.com/oismaelash/abacatepay-dotnet-sdk.git
cd abacatepay-dotnet-sdk

# Run the build script
sh ./build.sh

Project Structure

src/
โ”œโ”€โ”€ AbacatePay/
โ”‚   โ”œโ”€โ”€ AbacatePayClient.cs          # Main client class (facade)
โ”‚   โ”œโ”€โ”€ Models/                      # Data models
โ”‚   โ”‚   โ”œโ”€โ”€ Common/                  # Common models
โ”‚   โ”‚   โ”œโ”€โ”€ Customer/                # Customer models
โ”‚   โ”‚   โ”œโ”€โ”€ Billing/                 # Billing models
โ”‚   โ”‚   โ”œโ”€โ”€ PixQrCode/               # PIX QR Code models
โ”‚   โ”‚   โ”œโ”€โ”€ Coupon/                  # Coupon models
โ”‚   โ”‚   โ”œโ”€โ”€ Store/                   # Store models
โ”‚   โ”‚   โ””โ”€โ”€ Withdraw/                # Withdrawal models
โ”‚   โ”œโ”€โ”€ Enums/                       # Enumerations
โ”‚   โ”œโ”€โ”€ Services/                    # Domain services
โ”‚   โ”‚   โ”œโ”€โ”€ BaseService.cs           # Base service with common logic
โ”‚   โ”‚   โ”œโ”€โ”€ CustomerService.cs       # Customer operations
โ”‚   โ”‚   โ”œโ”€โ”€ BillingService.cs        # Billing operations
โ”‚   โ”‚   โ”œโ”€โ”€ PixQrCodeService.cs     # PIX operations
โ”‚   โ”‚   โ”œโ”€โ”€ CouponService.cs         # Coupon operations
โ”‚   โ”‚   โ”œโ”€โ”€ StoreService.cs          # Store operations
โ”‚   โ”‚   โ”œโ”€โ”€ WithdrawService.cs       # Withdrawal operations
โ”‚   โ”‚   โ”œโ”€โ”€ HttpService.cs           # HTTP communication
โ”‚   โ”‚   โ””โ”€โ”€ Interfaces/              # Service interfaces
โ”‚   โ”‚       โ”œโ”€โ”€ ICustomerService.cs
โ”‚   โ”‚       โ”œโ”€โ”€ IBillingService.cs
โ”‚   โ”‚       โ”œโ”€โ”€ IPixQrCodeService.cs
โ”‚   โ”‚       โ”œโ”€โ”€ ICouponService.cs
โ”‚   โ”‚       โ”œโ”€โ”€ IStoreService.cs
โ”‚   โ”‚       โ”œโ”€โ”€ IWithdrawService.cs
โ”‚   โ”‚       โ””โ”€โ”€ IHttpService.cs
โ”‚   โ”œโ”€โ”€ Validators/                  # Request validators
โ”‚   โ””โ”€โ”€ Attributes/                  # Custom validation attributes

Requirements

  • .NET Standard 2.1 or higher
  • .NET 5.0 or higher
  • .NET Core 3.1 or higher
  • .NET Framework 4.8 or higher

Dependencies

  • Newtonsoft.Json (13.0.3)
  • System.ComponentModel.Annotations (5.0.0)

License

This project is licensed under the MIT License - see the LICENSE file for details.

Learn More

Support

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Changelog

Version 2.0.0

  • ๐Ÿ—๏ธ Modular Architecture: Domain-specific services for better organization
  • ๐Ÿ”ง Dependency Injection: Full support for DI containers
  • ๐Ÿงช Enhanced Testability: Easy mocking and unit testing
  • ๐Ÿ”„ Backward Compatibility: All existing code continues to work
  • ๐Ÿ“ฆ Service Interfaces: Clean abstractions for all domain operations
  • ๐ŸŽฏ Single Responsibility: Each service handles one domain
  • โšก Performance: Optimized service layer with common base class

Version 1.0.0

  • Initial release
  • Customer management
  • PIX QR Code payments
  • Billing system
  • Coupon management
  • Store information
  • Withdrawal management
  • Comprehensive validation
  • Async/await support

Made with โค๏ธ by Ismael Ash for the Brazilian fintech ecosystem.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
2.0.0 71 10/25/2025
1.0.0 85 10/25/2025

- Added modular architecture
     - Added domain-specific services
     - Added request validation
     - Added async/await support
     - Added dependency injection support
     - Added testability
     - Added performance optimization