Tripay.NET 1.0.2

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

Tripay.NET

An unofficial, modern, and easy-to-use .NET SDK for integrating with the Tripay Payment Gateway. This library is designed for .NET developers, providing a strongly-typed client to interact with the Tripay API, including support for dependency injection, automatic signature generation, and robust error handling.

Features

  • .NET 9 Support: Built on the latest .NET platform.
  • Strongly-Typed: Provides clear and predictable models for all API requests and responses.
  • Dependency Injection Ready: Easily integrate into your ASP.NET Core application with a single line of code.
  • Automatic Signature Generation: Automatically handles HMAC-SHA256 signature creation for secure API calls.
  • Full API Coverage: Supports Closed and Open Payment transactions, payment channel inquiries, and transaction detail retrieval.
  • Async-First: All API calls are asynchronous, following modern .NET best practices.

Installation

Install the package via NuGet:

dotnet add package Tripay.NET

Getting Started

1. Configuration

First, register the TripayClient in your application's service container. In an ASP.NET Core application, you would do this in your Program.cs file.

// In Program.cs
using Tripay.NET;

var builder = WebApplication.CreateBuilder(args);

// Add Tripay SDK services
builder.Services.AddTripay(config =>
{
    config.ApiKey = builder.Configuration["Tripay:ApiKey"];
    config.PrivateKey = builder.Configuration["Tripay:PrivateKey"];
    config.MerchantCode = builder.Configuration["Tripay:MerchantCode"];
    config.IsProduction = false; // Set to true for production environment
});

// ... other services

It's recommended to store your credentials in appsettings.json or another secure configuration source:

// In appsettings.json
{
  "Tripay": {
    "ApiKey": "YOUR_API_KEY",
    "PrivateKey": "YOUR_PRIVATE_KEY",
    "MerchantCode": "YOUR_MERCHANT_CODE"
  }
}

2. Usage

Inject the ITripayClient interface into your controllers or services to start making API calls.

Get Payment Channels

Retrieve a list of all available payment channels.

public class PaymentController : ControllerBase
{
    private readonly ITripayClient _tripayClient;

    public PaymentController(ITripayClient tripayClient)
    {
        _tripayClient = tripayClient;
    }

    [HttpGet("channels")]
    public async Task<IActionResult> GetChannels()
    {
        var response = await _tripayClient.GetPaymentChannelsAsync();
        if (response.Success)
        {
            return Ok(response.Data);
        }
        return BadRequest(response.Message);
    }
}
Create a Closed Payment Transaction

Create a standard transaction where the amount is fixed.

[HttpPost("create-transaction")]
public async Task<IActionResult> CreateTransaction()
{
    var request = new TransactionRequest
    {
        Method = "BRIVA", // Example payment channel
        MerchantRef = "INV-" + Guid.NewGuid().ToString("N"),
        Amount = 50000,
        CustomerName = "John Doe",
        CustomerEmail = "john.doe@example.com",
        CustomerPhone = "081234567890",
        OrderItems = new List<OrderItem>
        {
            new OrderItem { Sku = "PRODUCT-01", Name = "My Awesome Product", Price = 50000, Quantity = 1 }
        },
        ReturnUrl = "https://your-domain.com/payment/success",
        ExpiredTime = new DateTimeOffset(DateTime.Now.AddHours(24)).ToUnixTimeSeconds()
    };

    // The signature will be generated automatically by the client.
    var response = await _tripayClient.CreateTransactionAsync(request);

    if (response.Success)
    {
        // Return the checkout URL or payment code to the user
        return Ok(response.Data);
    }

    return BadRequest(response.Message);
}
Create an Open Payment Transaction

Create a transaction where the customer can input the payment amount (e.g., for donations or top-ups).

[HttpPost("create-open-transaction")]
public async Task<IActionResult> CreateOpenTransaction()
{
    var request = new TransactionRequest
    {
        Method = "BCAVA", // An Open Payment channel
        MerchantRef = "TOPUP-" + Guid.NewGuid().ToString("N"),
        CustomerName = "Jane Doe"
        // Amount is not specified for open payments
    };

    // The signature is generated automatically using the correct formula for open payments.
    var response = await _tripayClient.CreateOpenTransactionAsync(request);

    if (response.Success)
    {
        // Return the payment code (VA number) to the user
        return Ok(response.Data);
    }

    return BadRequest(response.Message);
}
Get Transaction Details

Check the status of a transaction using its reference.

[HttpGet("transaction/{reference}")]
public async Task<IActionResult> GetTransactionDetail(string reference)
{
    var response = await _tripayClient.GetTransactionDetailAsync(reference);

    if (response.Success)
    {
        // response.Data contains the full transaction details, including status.
        return Ok(response.Data);
    }

    return NotFound(response.Message);
}

License

This project is licensed under the GNU General Public License v3.0.

Product Compatible and additional computed target framework versions.
.NET 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. 
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
1.0.2 141 3/16/2026
1.0.1 136 3/8/2026
1.0.0 106 3/8/2026