.NET SDK

The Buckaroo .NET SDK is an open source library that connects a .NET application to the Buckaroo API. It gives you typed requests and responses and takes care of authentication, request signing and verifying push messages, so you can start payments and refunds without building the requests yourself.
Running a store on an e-commerce platform? Use one of our ready-made plugins and apps instead. This SDK is for custom applications.
Requirements
| Requirement | Details |
|---|---|
| Buckaroo account | Create an account if you do not have one yet |
| .NET | .NET Standard 2.0 or higher. This covers current .NET versions, .NET Core and .NET Framework 4.6.1 and higher |
| Dependencies | Newtonsoft.Json, installed with the package |
Installation
Install the BuckarooSdk package from NuGet. This is the easiest way to stay up to date.
dotnet add package BuckarooSdkInstall-Package BuckarooSdkThe source code is on GitHub.
Quick start
Every request is one chain: create a request, authenticate, set the basic fields, choose the payment method and action, and execute.
using System.Globalization;
using BuckarooSdk;
using BuckarooSdk.DataTypes.RequestBases;
using BuckarooSdk.Services.Ideal.TransactionRequest;
var client = new SdkClient();
var response = client.CreateRequest()
.Authenticate("STORE_KEY", "SECRET_KEY", isLive: false, new CultureInfo("nl-NL"))
.TransactionRequest()
.SetBasicFields(new TransactionBase
{
Currency = "EUR",
AmountDebit = 10.00m,
Invoice = "INV-1001", // must be unique per payment
Description = "Order #1001",
ReturnUrl = "https://example.com/buckaroo/return",
PushUrl = "https://example.com/buckaroo/push",
})
.Ideal()
.Pay(new IdealPayRequest())
.Execute();
if (response.RequiredAction?.RedirectURL != null)
{
// send the customer to response.RequiredAction.RedirectURL
}That starts an iDEAL | Wero payment in the test environment. The result of the payment arrives on your push URL. See Handle push messages.
Create the client
var client = new SdkClient();SdkClient holds no credentials. You pass your keys with every request in Authenticate, so you can create one client and reuse it for all requests, for example as a singleton.
Where to find your credentials
Both keys are in Plaza under Settings → API keys.
| Key | What it is |
|---|---|
| Store key | Identifies the Buckaroo store that the transaction belongs to. It is the first argument of Authenticate, which the SDK calls websiteKey |
| Secret key | Signs your requests and verifies push messages. It is the second argument, which the SDK calls apiKey |
Keep your secret key out of version control. Load both keys from your application's configuration or a secrets manager instead of writing them in your code.
Test and live mode
The isLive argument of Authenticate decides which Buckaroo environment receives the request. In the test environment, no real money is moved.
isLive | Environment |
|---|---|
false | Test |
true | Live |
The fourth argument is the culture, such as nl-NL or en-US. It sets the language of the payment page.
Start a payment
Set the fields that every payment has with SetBasicFields, then choose the payment method and the action:
| Field | Description |
|---|---|
Currency | ISO currency code, such as EUR |
AmountDebit | The amount to charge |
Invoice | Your unique invoice number |
Order | Your order number |
Description | Shown to the customer and in Plaza |
ReturnUrl | Where the customer is sent after paying |
ReturnUrlCancel, ReturnUrlError, ReturnUrlReject | Alternative return pages |
PushUrl | Where Buckaroo sends the push message. Falls back to the push settings in Plaza |
ClientIp | The customer's IP address. Required by some methods |
Each payment method has its own method on the request, such as .Ideal(), .Visa(), .MasterCard(), .Bancontact() and .PayPal(), and its own actions, such as .Pay(...), .Refund(...) and .Authorize(...). Your editor shows what is available at each step.
- The Services folder in the repository has every payment method and service
- Payment methods describes the parameters each method accepts
Use async
Every action also has an awaitable variant. Use it in asynchronous code:
var response = await client.CreateRequest()
.Authenticate(storeKey, secretKey, isLive: false, new CultureInfo("nl-NL"))
.TransactionRequest()
.SetBasicFields(basicFields)
.Ideal()
.Pay(new IdealPayRequest())
.ExecuteAsync();Read the response
Execute returns a RequestResponse:
var transactionKey = response.Key; // store this: you need it for refunds
var statusCode = response.Status.Code.Code;
if (statusCode == BuckarooSdk.Constants.Status.Success)
{
// paid
}
else if (response.RequiredAction?.RedirectURL != null)
{
// send the customer to response.RequiredAction.RedirectURL
}The status codes are constants in BuckarooSdk.Constants.Status:
| Constant | Code |
|---|---|
Success | 190 |
Failed | 490 |
FailedValidation | 491 |
TechnicalError | 492 |
Declined | 690 |
PendingInput | 790 |
PendingProcessing | 791 |
WaitingForConsumer | 792 |
OnHold | 793 |
CanceledByUser | 890 |
CanceledByMerchant | 891 |
For the fields that belong to one payment method, use response.GetActionResponse<T>() with the response type of that method, such as IdealPayResponse.
See Status and Substatus for what each code means.
Handle push messages
A push message is how Buckaroo tells your application that a payment succeeded, failed or changed status. It is sent from server to server, independently of the customer's browser.
Update orders from the push message, never from the return page. A customer returning to your return URL only proves that their browser came back, not that the payment completed.
The push handler verifies the signature and turns the message into an object. It throws an AuthenticationException when the signature is invalid, so an unverified message never reaches your code.
using BuckarooSdk.DataTypes.Push;
var pushHandler = client.GetPushHandler("SECRET_KEY");
// body: the raw request body as bytes
// requestUri: the full URL that Buckaroo called
// authorizationHeader: the value of the Authorization header
Push push = pushHandler.DeserializePush(body, requestUri, authorizationHeader);
if (push is TransactionPush transaction)
{
if (transaction.Status.Code.Code == BuckarooSdk.Constants.Status.Success)
{
// MarkOrderAsPaid(transaction.Invoice, transaction.Key);
}
}- Pass the raw body, not a body that was parsed and serialised again
- Buckaroo can send the same push message more than once, so check whether you have already handled that transaction key and status
- Return HTTP
200once you have stored the message. Buckaroo retries a push message that does not get a200
See Push messages for the Plaza settings and the IP addresses to allow.
Refund a payment
A refund goes through the same payment method as the original payment, and refers to it with OriginalTransactionKey:
var refund = client.CreateRequest()
.Authenticate("STORE_KEY", "SECRET_KEY", isLive: false, new CultureInfo("nl-NL"))
.TransactionRequest()
.SetBasicFields(new TransactionBase
{
Currency = "EUR",
AmountCredit = 10.00m, // full or partial amount
Invoice = "INV-1001", // invoice of the original payment
OriginalTransactionKey = "ORIGINAL_TX_KEY",
})
.Ideal()
.Refund(new IdealRefundRequest())
.Execute();Whether and how long a payment can be refunded differs per payment method. See Refunds.
Logging
The SDK keeps a log of every request, which helps when a request does not do what you expect. You choose the logger when you create the client or a request.
| Logger | Use |
|---|---|
StandardLogger | The default |
ExtensiveLogger | More detail, for debugging |
| Your own | A class that implements the ILogger interface |
using BuckarooSdk.Logging;
// For every request from this client
var client = new SdkClient(() => new ExtensiveLogger());
// Or for one request
var request = client.CreateRequest(new ExtensiveLogger());The log of a request is available on the response, in response.BuckarooSdkLogger.
Treat the log as confidential. It contains details of the request, so do not write it to a shared location and remove sensitive values before you send it to anyone.
Test and go live
Test with isLive: false first.
Test card numbers and test accounts are listed per payment method on the Test transactions page.
Before you switch to isLive: true:
- A failed and a cancelled payment leave the order unpaid
- The order is updated when the customer closes the browser before returning
- The same push message twice does not process the order twice
- Your push URL is reachable from the internet over HTTPS and returns HTTP
200 - Buckaroo's push IP addresses and ports are on your allow list. See Push messages
- The payment methods you need are active for your store in Plaza
Support and contributing
Check Buckaroo Status first when something stops working.
For bugs and feature requests, open an issue on GitHub. Pull requests are welcome.
For questions about your account or the API, see Contact us.
Updated 13 days ago