payOS 2.0.1

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

payOS .NET Library

NuGet

The payOS .NET library provides convenient access to the payOS Merchant API from applications written in C#.

To learn how to use payOS Merchant API, checkout our API Reference and Documentation. We also have some examples in the Examples directory.

Requirements

This library currently support .NET Standard 2.0+, .NET Core 5+.

Installation

Install the package via NuGet Package Manager:

dotnet add package payOS

Or via Package Manager Console:

Install-Package payOS

If update from v1, check Migration guide for detail migration.

Usage

Basic usage

First you need to initialize the client to interact with payOS Merchant API.

using PayOS;

// Initialize the client
var client = new PayOSClient("your-client-id", "your-api-key", "your-checksum-key");

// Or initialize with options
var client = new PayOSClient(new PayOSOptions
{
    ClientId = "your-client-id",
    ApiKey = "your-api-key",
    ChecksumKey = "your-checksum-key"
});

// Or use default value in environment variables (recommended)
// Set PAYOS_CLIENT_ID, PAYOS_API_KEY, PAYOS_CHECKSUM_KEY, PAYOS_PARTNER_CODE
var client = new PayOSClient();

Then you can interact with payOS Merchant API, for example create a payment link using PaymentRequests.CreateAsync().

using PayOS.Models;

var paymentRequest = new CreatePaymentLinkRequest
{
    OrderCode = 123,
    Amount = 2000,
    Description = "payment",
    ReturnUrl = "https://your-url.com",
    CancelUrl = "https://your-url.com"
};

var paymentLink = await client.PaymentRequests.CreateAsync(paymentRequest);

Webhook verification

You can register an endpoint to receive the payment webhook.

var confirmResult = await client.Webhooks.ConfirmAsync("https://your-url.com/payos-webhook");

Then use Webhooks.VerifyAsync() to verify and receive webhook data.

var webhookData = await client.Webhooks.VerifyAsync(new Webhook
{
    Code = "00",
    Description = "success",
    Success = true,
    Data = new WebhookData
    {
        OrderCode = 123,
        Amount = 3000,
        Description = "VQRIO123",
        AccountNumber = "12345678",
        Reference = "TF230204212323",
        TransactionDateTime = "2023-02-04 18:25:00",
        Currency = "VND",
        PaymentLinkId = "124c33293c43417ab7879e14c8d9eb18",
        Code = "00",
        Description2 = "Thành công",
        CounterAccountBankId = "",
        CounterAccountBankName = "",
        CounterAccountName = "",
        CounterAccountNumber = "",
        VirtualAccountName = "",
        VirtualAccountNumber = ""
    },
    Signature = "8d8640d802576397a1ce45ebda7f835055768ac7ad2e0bfb77f9b8f12cca4c7f"
});

For more information about webhooks, see the API doc.

Handling errors

The library throws custom exceptions for different error scenarios:

try
{
    var paymentLink = await client.PaymentRequests.CreateAsync(paymentData);
}
catch (ApiException ex)
{
    Console.WriteLine($"API Error: {ex.Message}");
    Console.WriteLine($"Status Code: {ex.StatusCode}");
    Console.WriteLine($"Error Code: {ex.ErrorCode}");
}
catch (PayOSException ex)
{
    Console.WriteLine($"PayOS Error: {ex.Message}");
}

Auto pagination

For endpoints that support pagination, you can use the built-in pagination:

var payouts = await client.Payouts.ListAsync(limit: 20, offset: 0);

Advanced usage

Custom configuration

You can customize the PayOS client with various options:

var client = new PayOSClient(new PayOSOptions
{
    ClientId = "your-client-id",
    ApiKey = "your-api-key",
    ChecksumKey = "your-checksum-key",
    PartnerCode = "your-partner-code", // Optional partner code
    BaseUrl = "https://api-merchant.client.vn", // Custom base URL
    TimeoutMs = 30000, // Request timeout in milliseconds (default: 60000)
    MaxRetries = 3, // Maximum retry attempts (default: 2)
    LogLevel = LogLevel.Information, // Log level
    Logger = logger, // Custom logger implementation
    HttpClient = httpClient, // Custom HttpClient instance
    DefaultHeaders = new Dictionary<string, string>
    {
        { "Custom-Header", "value" }
    }
});

Custom HttpClient

You can provide a custom HttpClient instance:

var httpClient = new HttpClient();
// Configure your HttpClient as needed

var client = new PayOSClient(new PayOSOptions
{
    ClientId = "your-client-id",
    ApiKey = "your-api-key",
    ChecksumKey = "your-checksum-key",
    HttpClient = httpClient
});

Request-level options

You can override client-level settings for individual requests using CancellationToken:

var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));

var paymentLink = await client.PaymentRequests.CreateAsync(
    paymentData,
    cts.Token // Custom timeout for this request
);

Logging and debugging

The SDK supports logging through Microsoft.Extensions.Logging:

var logger = LoggerFactory.Create(builder => builder.AddConsole()).CreateLogger<PayOS>();

var client = new PayOSClient(new PayOSOptions
{
    ClientId = "your-client-id",
    ApiKey = "your-api-key",
    ChecksumKey = "your-checksum-key",
    LogLevel = LogLevel.Debug, // Enable debug logging
    Logger = logger
});

Direct API access

For advanced use cases, you can make direct API calls:

// GET request
var response = await client.GetAsync<List<PaymentLink>>("/v2/payment-requests");

// POST request
var response = await client.PostAsync<CreatePaymentLinkResponse>("/v2/payment-requests", new
{
    orderCode = 123,
    amount = 2000,
    description = "payment",
    returnUrl = "https://your-url.com",
    cancelUrl = "https://your-url.com"
});

Signature

The signature can be manually created by PayOS.Crypto:

// for create-payment-link signature
var signature = await client.Crypto.CreateSignatureOfPaymentRequestAsync(data, client.ChecksumKey);

// for payment-requests and webhook signature
var signature = await client.Crypto.CreateSignatureFromObjectAsync(data, client.ChecksumKey);

// for payouts signature
var signature = await client.Crypto.CreateSignatureAsync(client.ChecksumKey, data);

Contributing

Please see our Contributing Guidelines for details.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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 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 is compatible.  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 is compatible.  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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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.1 4,527 10/29/2025
2.0.0 396 10/29/2025
1.0.9 39,492 11/11/2024
1.0.8 3,343 10/25/2024
1.0.7 4,310 9/27/2024
1.0.6 7,481 7/2/2024
1.0.5 2,795 5/9/2024
1.0.4 1,874 2/22/2024
1.0.2 7,707 12/5/2023
1.0.1 256 12/5/2023
1.0.0 403 12/5/2023