Datatrans.Net 0.1.0-preview.1

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

Datatrans.Net

Unofficial .NET client for the Datatrans payment API (net8.0, net10.0).

Not affiliated with Datatrans AG.

Install

dotnet add package Datatrans.Net

Usage

builder.Services.AddDatatrans(options =>
{
    options.MerchantId = "...";
    options.Password = "...";
    options.Environment = DatatransEnvironment.Sandbox;
});
// Initialize and redirect the customer
var init = await client.Transactions.InitAsync(new InitRequest
{
    Amount = 1000, // CHF 10.00
    Currency = "CHF",
    Refno = "order-42"
});
return Redirect(init.PaymentPageUrl!.ToString());

// Check the result
var status = await client.Transactions.StatusAsync(transactionId);
if (status.IsPaid) { }

// Settle, cancel, refund
await client.Transactions.SettleAsync(transactionId, new SettleRequest { Amount = 1000, Currency = "CHF", Refno = "order-42" });
await client.Transactions.CancelAsync(transactionId);
await client.Transactions.CreditAsync(transactionId, new CreditRequest { Amount = 500, Currency = "CHF", Refno = "refund-42" });

// Saved cards: charge, check or delete an alias
await client.Transactions.AuthorizeAsync(new AuthorizeRequest { Amount = 1000, Currency = "CHF", Refno = "order-43", Card = new AliasCard { Alias = alias } });
await client.Aliases.GetAsync(alias);
await client.Aliases.DeleteAsync(alias);

Webhook, on the raw request body:

// The tolerance rejects an old request replayed with its valid signature
if (!DatatransWebhook.IsSignatureValid(signatureHeader, rawBody, hmacKey, tolerance: TimeSpan.FromMinutes(5)))
    return Results.Unauthorized();

var payload = DatatransWebhook.Parse(rawBody);

API errors throw a DatatransException. See the official API reference for the fields.

Payment methods

With the payment page (Redirect or Lightbox), Datatrans renders the payment methods itself: cards, Twint, Apple Pay and Google Pay need no specific code. PaymentMethods restricts the list, all methods enabled on the merchant account are offered when it is null.

PaymentMethods = [PaymentMethods.Visa, PaymentMethods.Mastercard, PaymentMethods.Twint, PaymentMethods.ApplePay, PaymentMethods.GooglePay]

The status tells which method was used: PaymentMethod, Card.WalletIndicator for a card coming from Apple Pay or Google Pay, Twint for Twint.

Properties without a typed model, for example the TWI options, go through AdditionalProperties and are sent as is.

License

MIT

Product Compatible and additional computed target framework versions.
.NET 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 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 is compatible.  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
0.1.0-preview.1 51 11/16/2026