Developer-friendly & type-safe Csharp SDK specifically catered to leverage Mollie API.
Important
This SDK is not yet ready for production use. To complete setup please follow the steps outlined in your workspace. Delete this section before > publishing to a package manager.
To add the NuGet package to a .NET project:
dotnet add package Mollie
To add a reference to a local instance of the SDK in a .NET project:
dotnet add reference src/Mollie/Mollie.csproj
using Mollie;
using Mollie.Models.Components;
using Mollie.Models.Requests;
var sdk = new Client(security: new Security() {
ApiKey = "<YOUR_BEARER_TOKEN_HERE>",
});
ListBalancesRequest req = new ListBalancesRequest() {
Currency = "EUR",
From = "bal_gVMhHKqSSRYJyPsuoPNFH",
Limit = 50,
Testmode = false,
IdempotencyKey = "123e4567-e89b-12d3-a456-426",
};
var res = await sdk.Balances.ListAsync(req);
// handle response
This SDK supports the following security schemes globally:
Name | Type | Scheme |
---|---|---|
ApiKey |
http | HTTP Bearer |
OAuth |
oauth2 | OAuth2 token |
You can set the security parameters through the security
optional parameter when initializing the SDK client instance. The selected scheme will be used by default to authenticate with the API for all operations that support it. For example:
using Mollie;
using Mollie.Models.Components;
using Mollie.Models.Requests;
var sdk = new Client(security: new Security() {
ApiKey = "<YOUR_BEARER_TOKEN_HERE>",
});
ListBalancesRequest req = new ListBalancesRequest() {
Currency = "EUR",
From = "bal_gVMhHKqSSRYJyPsuoPNFH",
Limit = 50,
Testmode = false,
IdempotencyKey = "123e4567-e89b-12d3-a456-426",
};
var res = await sdk.Balances.ListAsync(req);
// handle response
Available methods
- List - List balances
- Get - Get balance
- GetPrimary - Get primary balance
- GetReport - Get balance report
- ListTransactions - List balance transactions
- List - List capabilities
- Create - Create client link
- Create - Create customer
- List - List customers
- Get - Get customer
- Update - Update customer
- Delete - Delete customer
- CreatePayment - Create customer payment
- ListPayments - List customer payments
- Get - Get organization
- GetCurrent - Get current organization
- GetPartner - Get partner status
- Create - Create payment link
- List - List payment links
- Get - Get payment link
- Update - Update payment link
- Delete - Delete payment link
- ListPayments - Get payment link payments
- Create - Create payment
- List - List payments
- Get - Get payment
- Update - Update payment
- Cancel - Cancel payment
- ReleaseAuthorization - Release payment authorization
- Create - Create profile
- List - List profiles
- Get - Get profile
- Update - Update profile
- Delete - Delete profile
- GetCurrent - Get current profile
- Create - Create payment refund
- List - List payment refunds
- Get - Get payment refund
- Cancel - Cancel payment refund
- All - List all refunds
- Create - Create sales invoice
- List - List sales invoices
- Get - Get sales invoice
- Update - Update sales invoice
- Delete - Delete sales invoice
- List - List settlements
- Get - Get settlement
- GetOpen - Get open settlement
- GetNext - Get next settlement
- ListPayments - List settlement payments
- ListCaptures - List settlement captures
- ListRefunds - List settlement refunds
- ListChargebacks - List settlement chargebacks
- Create - Create subscription
- List - List customer subscriptions
- Get - Get subscription
- Update - Update subscription
- Cancel - Cancel subscription
- All - List all subscriptions
- ListPayments - List subscription payments
- RequestApplePaySession - Request Apple Pay payment session
- Get - Get a Webhook Event
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply pass a RetryConfig
to the call:
using Mollie;
using Mollie.Models.Components;
using Mollie.Models.Requests;
var sdk = new Client(security: new Security() {
ApiKey = "<YOUR_BEARER_TOKEN_HERE>",
});
ListBalancesRequest req = new ListBalancesRequest() {
Currency = "EUR",
From = "bal_gVMhHKqSSRYJyPsuoPNFH",
Limit = 50,
Testmode = false,
IdempotencyKey = "123e4567-e89b-12d3-a456-426",
};
var res = await sdk.Balances.ListAsync(
retryConfig: new RetryConfig(
strategy: RetryConfig.RetryStrategy.BACKOFF,
backoff: new BackoffStrategy(
initialIntervalMs: 1L,
maxIntervalMs: 50L,
maxElapsedTimeMs: 100L,
exponent: 1.1
),
retryConnectionErrors: false
),
request: req
);
// handle response
If you'd like to override the default retry strategy for all operations that support retries, you can use the RetryConfig
optional parameter when intitializing the SDK:
using Mollie;
using Mollie.Models.Components;
using Mollie.Models.Requests;
var sdk = new Client(
retryConfig: new RetryConfig(
strategy: RetryConfig.RetryStrategy.BACKOFF,
backoff: new BackoffStrategy(
initialIntervalMs: 1L,
maxIntervalMs: 50L,
maxElapsedTimeMs: 100L,
exponent: 1.1
),
retryConnectionErrors: false
),
security: new Security() {
ApiKey = "<YOUR_BEARER_TOKEN_HERE>",
}
);
ListBalancesRequest req = new ListBalancesRequest() {
Currency = "EUR",
From = "bal_gVMhHKqSSRYJyPsuoPNFH",
Limit = 50,
Testmode = false,
IdempotencyKey = "123e4567-e89b-12d3-a456-426",
};
var res = await sdk.Balances.ListAsync(req);
// handle response
BaseException
is the base exception class for all HTTP error responses. It has the following properties:
Property | Type | Description |
---|---|---|
Message |
string | Error message |
Request |
HttpRequestMessage | HTTP request object |
Response |
HttpResponseMessage | HTTP response object |
Some exceptions in this SDK include an additional Payload
field, which will contain deserialized custom error data when present. Possible exceptions are listed in the Error Classes section.
using Mollie;
using Mollie.Models.Components;
using Mollie.Models.Errors;
using Mollie.Models.Requests;
var sdk = new Client(security: new Security() {
ApiKey = "<YOUR_BEARER_TOKEN_HERE>",
});
try
{
ListBalancesRequest req = new ListBalancesRequest() {
Currency = "EUR",
From = "bal_gVMhHKqSSRYJyPsuoPNFH",
Limit = 50,
Testmode = false,
IdempotencyKey = "123e4567-e89b-12d3-a456-426",
};
var res = await sdk.Balances.ListAsync(req);
// handle response
}
catch (BaseException ex) // all SDK exceptions inherit from BaseException
{
// ex.ToString() provides a detailed error message
System.Console.WriteLine(ex);
// Base exception fields
HttpRequestMessage request = ex.Request;
HttpResponseMessage response = ex.Response;
var statusCode = (int)response.StatusCode;
var responseBody = ex.Body;
if (ex is ErrorResponse) // different exceptions may be thrown depending on the method
{
// Check error data fields
ErrorResponsePayload payload = ex.Payload;
long Status = payload.Status;
string Title = payload.Title;
// ...
}
// An underlying cause may be provided
if (ex.InnerException != null)
{
Exception cause = ex.InnerException;
}
}
catch (System.Net.Http.HttpRequestException ex)
{
// Check ex.InnerException for Network connectivity errors
}
Primary exceptions:
BaseException
: The base class for HTTP error responses.ErrorResponse
: An error response object. *
Less common exceptions (2)
-
System.Net.Http.HttpRequestException
: Network connectivity error. For more details about the underlying cause, inspect theex.InnerException
. -
Inheriting from
BaseException
:ResponseValidationError
: Thrown when the response data could not be deserialized into the expected type.
* Refer to the relevant documentation to determine whether an exception applies to a specific operation.
The default server can be overridden globally by passing a URL to the serverUrl: string
optional parameter when initializing the SDK client instance. For example:
using Mollie;
using Mollie.Models.Components;
using Mollie.Models.Requests;
var sdk = new Client(
serverUrl: "https://api.mollie.com/v2",
security: new Security() {
ApiKey = "<YOUR_BEARER_TOKEN_HERE>",
}
);
ListBalancesRequest req = new ListBalancesRequest() {
Currency = "EUR",
From = "bal_gVMhHKqSSRYJyPsuoPNFH",
Limit = 50,
Testmode = false,
IdempotencyKey = "123e4567-e89b-12d3-a456-426",
};
var res = await sdk.Balances.ListAsync(req);
// handle response
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.