Datatrans.Net
0.1.0-preview.1
dotnet add package Datatrans.Net --version 0.1.0-preview.1
NuGet\Install-Package Datatrans.Net -Version 0.1.0-preview.1
<PackageReference Include="Datatrans.Net" Version="0.1.0-preview.1" />
<PackageVersion Include="Datatrans.Net" Version="0.1.0-preview.1" />
<PackageReference Include="Datatrans.Net" />
paket add Datatrans.Net --version 0.1.0-preview.1
#r "nuget: Datatrans.Net, 0.1.0-preview.1"
#:package Datatrans.Net@0.1.0-preview.1
#addin nuget:?package=Datatrans.Net&version=0.1.0-preview.1&prerelease
#tool nuget:?package=Datatrans.Net&version=0.1.0-preview.1&prerelease
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
| Product | Versions 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. |
-
net10.0
- Microsoft.Extensions.Http (>= 8.0.1)
- Microsoft.Extensions.Options (>= 8.0.2)
-
net8.0
- Microsoft.Extensions.Http (>= 8.0.1)
- Microsoft.Extensions.Options (>= 8.0.2)
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 |