AugusteVN.Mollie.Api
1.4.2
See the version list below for details.
dotnet add package AugusteVN.Mollie.Api --version 1.4.2
NuGet\Install-Package AugusteVN.Mollie.Api -Version 1.4.2
<PackageReference Include="AugusteVN.Mollie.Api" Version="1.4.2" />
paket add AugusteVN.Mollie.Api --version 1.4.2
#r "nuget: AugusteVN.Mollie.Api, 1.4.2"
// Install AugusteVN.Mollie.Api as a Cake Addin #addin nuget:?package=AugusteVN.Mollie.Api&version=1.4.2 // Install AugusteVN.Mollie.Api as a Cake Tool #tool nuget:?package=AugusteVN.Mollie.Api&version=1.4.2
Mollie Payment Processor API
This package contains wrapper- & helper methods for the Mollie API to process payments and refunds.
Configuration
Optional helper class to bind your API keys to the configuration.
This one is not directly used in this package but can be passed in a request's AccessToken
property.
In case of pasting your Mollie account's API key:
- Add your test API-key to your
appsettings.Development.json
. - Add your live API-key to your
appsettings.json
.
If you have an organizational access token, paste that one in since that has more access than your API key.
{
"MollieAuthConfig": {
"AccessToken": "<to-fill>",
"IsApiKey": true
}
}
Program.cs
builder.Services
.AddOptions<MollieAuthConfig>()
.BindConfiguration(nameof(MollieAuthConfig));
Payment API
Configuration
{
"MollieConfig": {
"ApiUrl": "https://api.mollie.com/v2/",
"PaymentsConfig": {
"WebhookUrl": "<to-fill>",
"IsTestMode": false
}
}
}
The WebhookUrl
should be set to the API endpoint you expose to handle the Mollie webhook's payment status notifications.
Read more: Mollie Docs
Program.cs
builder.Services.AddHttpClient(); // Adds the required IHttpClientFactory.
builder.Services
.AddOptions<MollieConfig>()
.BindConfiguration(nameof(MollieConfig));
builder.Services.AddSingleton<IMolliePaymentsClient, MolliePaymentsClient>();
// Or initialize an instance.
var paymentsClient = new MolliePaymentsClient(
new HttpClient(),
new MollieConfig {
ApiUrl = "https://api.mollie.com/v2/",
PaymentsConfig = new PaymentsConfig {
WebhookUrl = "https://your-api.net/payments/webhook"
}
});
Get Payment
Gets payment by id over API-key authorized HTTP call to Mollie API.
Read more: Get payment
Program.cs
app.MapGet("/", async (IMolliePaymentsClient paymentsClient) => {
var result = await paymentsClient.GetPaymentByIdAsync(new MollieGetPaymentByIdRequest {
Id = "<to-fill-payment-id>",
Testmode = true // Overwrites config value
}, new MollieAuthRequest {
AccessToken = "API key or organization / app / client / customer access token",
IsApiKey = true // default
});
if (result.IsFailure) {
return result.ToErrorResult();
}
Console.WriteLine(result.Value.Status); // paid
return result.Match(() => Results.Ok(result.Value));
});
Create Payment
Creates payment over API-key authorized HTTP call to Mollie API.
Read more: Create payment
Program.cs
app.MapPost("/", async (IMolliePaymentsClient paymentsClient) => {
var result = await paymentsClient.CreatePaymentAsync(new MollieCreatePaymentRequest {
Amount = new PaymentAmount { Amount = "5.00", Currency = "EUR" },
Description = "About this payment...",
RedirectUrl = "https://your-frontend.net/payment-confirmed",
Metadata = new { Foo = "bar" }
}, new MollieAuthRequest {
AccessToken = "API key",
IsApiKey = true // default
});
if (result.IsFailure || result.Value.Status != "open")
{
return result.ToErrorResult();
}
Console.WriteLine(result.Value.Status); // open
return result.Match(() => Results.Ok(result.Value.Links.Checkout!.Href));
});
Create Profile Payment
Creates profile payment over organization access token, authorized HTTP call to Mollie API.
Read more: Create payment for profile
Program.cs
app.MapPost("/", async (IMolliePaymentsClient paymentsClient) => {
var result = await paymentsClient.CreatePaymentForProfileAsync(new MollieCreatePaymentForProfileRequest {
Amount = new PaymentAmount { Amount = "5.00", Currency = "EUR" },
Description = "About this payment...",
RedirectUrl = "https://your-frontend.net/payment-confirmed",
Metadata = new { Foo = "bar" },
Testmode = true, // Overwrites config value
ProfileId = "pfl_<to-fill>"
}, new MollieAuthRequest {
AccessToken = "organization / app / client / customer access token",
IsApiKey = false
});
if (result.IsFailure || result.Value.Status != "open")
{
return result.ToErrorResult();
}
Console.WriteLine(result.Value.Status); // open
return result.Match(() => Results.Ok(result.Value.Links.Checkout!.Href));
});
Refund API
Configuration
{
"MollieConfig": {
"ApiUrl": "https://api.mollie.com/v2/",
"RefundsConfig": {
"IsTestMode": true
}
}
}
Program.cs
builder.Services.AddHttpClient(); // Adds the required IHttpClientFactory.
builder.Services
.AddOptions<MollieConfig>()
.BindConfiguration(nameof(MollieConfig));
builder.Services.AddSingleton<IMollieRefundsClient, MollieRefundsClient>();
Create Refund
Creates payment refund over API-key authorized HTTP call to Mollie API.
Read more: Create refund
Program.cs
app.MapPost("/", async (IMollieRefundsClient refundsClient) => {
var result = await refundsClient.CreateRefundAsync(new MollieCreateRefundRequest {
Amount = new PaymentAmount { Amount = "5.00", Currency = "EUR" },
Description = "About this refund...",
RedirectUrl = "https://your-frontend.net/refund-confirmed",
Metadata = new { Bar = "foo" }
}, new MollieAuthRequest {
AccessToken = "API key",
IsApiKey = true // default
});
if (result.IsFailure || new[] {"failed", "canceled"}.Contains(result.Value.Status)) {
return result.ToErrorResult();
}
return Results.NoContent();
});
Create Profile Refund
Creates profile payment refund over organization access token, authorized HTTP call to Mollie API.
Read more: Create profile refund
Program.cs
app.MapPost("/", async (IMollieRefundsClient refundsClient) => {
var result = await refundsClient.CreateRefundAsync(new MollieCreateRefundRequest {
Amount = new PaymentAmount { Amount = "5.00", Currency = "EUR" },
Description = "About this refund...",
RedirectUrl = "https://your-frontend.net/refund-confirmed",
Metadata = new { Bar = "foo" },
Testmode = false // Overwrites config value
}, new MollieAuthRequest {
AccessToken = "organization / app / client / customer access token",
IsApiKey = false
});
if (result.IsFailure || new[] {"failed", "canceled"}.Contains(result.Value.Status)) {
return result.ToErrorResult();
}
return Results.NoContent();
});
OAuth API
Configuration
{
"MollieConfig": {
"ApiUrl": "https://api.mollie.com/v2/",
"OAuthConfig": {
"ApiUrl": "https://api.mollie.com/oauth2/",
"MeUrl": "https://my.mollie.com/oauth2/",
"AppId": "app_<to-fill>",
"AppSecret": "<to-fill>",
"Scopes": ["<to-fill>.read", "<to-fill>.write"]
}
}
}
Program.cs
builder.Services.AddHttpClient(); // Adds the required IHttpClientFactory.
builder.Services
.AddOptions<MollieConfig>()
.BindConfiguration(nameof(MollieConfig));
builder.Services.AddSingleton<IMollieOAuthClient, MollieOAuthClient>();
Get Authorization Url
Program.cs
app.MapGet("/", async (IMollieOAuthClient mollieClient) =>
{
var result = await mollieClient.GetAuthorizationUrl();
return result.Match(() => Results.Ok(result.Value.AuthUrl));
});
Generate Tokens
routeGroup.MapPost("/", async (IMollieOAuthClient mollieClient) =>
{
var result = await mollieClient.GenerateTokensAsync(new MollieGenerateTokensRequest {
GrantType = "authorization_code",
Code = "auth_<to-fill_when-grant-type-is-authorization-code>",
RefreshToken = "<to-fill_when-grant-type-is-refresh-token>"
});
return result.Match(() => Results.Ok(new RefreshTokensResponse
{
AccessToken = tokensResult.Value.AccessToken,
RefreshToken = tokensResult.Value.RefreshToken,
ExpiresIn = tokensResult.Value.ExpiresIn,
Scope = tokensResult.Value.Scope,
TokenType = tokensResult.Value.TokenType
}));
});
Client Links API
Configuration
{
"MollieConfig": {
"ApiUrl": "https://api.mollie.com/v2/",
"ClientLinksConfig": {
"AppId": "app_<to-fill>",
"Scopes": ["<to-fill>.read", "<to-fill>.write"]
}
}
}
Program.cs
builder.Services.AddHttpClient(); // Adds the required IHttpClientFactory.
builder.Services
.AddOptions<MollieConfig>()
.BindConfiguration(nameof(MollieConfig));
builder.Services.AddSingleton<IMollieClientLinksClient, MollieClientLinksClient>();
Create Client Link
app.MapPost("/", async (IMollieClientLinksClient mollieClient) =>
{
var result = await mollieClient.CreateClientLink(new CreateClientLinkRequest {
Name = "Name of the organization.",
RegistrationNumber = "The Chamber of Commerce (or local equivalent) registration number of the organization.",
VatNumber = "The VAT number of the organization, if based in the European Union or the United Kingdom.",
Owner = new MollieClientLinkOwner
{
Email = "The email address of your customer.",
FamilyName = "The family name (surname) of your customer.",
GivenName = "The given name (first name) of your customer."
},
Address = new MollieClientLinkAddressRequest
{
StreetAndNumber = "The card holder's street and street number.",
City = "The card holder's city.",
PostalCode = "The card holder's postal code.",
Country = "The card holder's country in ISO 3166-1 alpha-2 format"
}
}, new MollieAuthRequest {
AccessToken = "organization / app / client / customer access token",
IsApiKey = false
});
return result.Match(() => Results.Ok(result.Value.ClientLink));
});
Profiles API
Configuration
{
"MollieConfig": {
"ApiUrl": "https://api.mollie.com/v2/",
"ProfilesConfig": {
"Mode": "live"
}
}
}
Program.cs
builder.Services.AddHttpClient(); // Adds the required IHttpClientFactory.
builder.Services
.AddOptions<MollieConfig>()
.BindConfiguration(nameof(MollieConfig));
builder.Services.AddSingleton<IMollieClientLinksClient, MollieClientLinksClient>();
Create Profile
app.MapPost("/", async (IMollieProfilesClient mollieClient) =>
{
var result = await mollieClient.CreateProfile(new MollieCreateProfileRequest {
Name = "Name of the organization.",
Email = "The email address of your customer.",
Website = "Must start with http:// or https://.",
Phone = "Prefixed by country code e.g. +32 for Belgium.",
BusinessCategory = "PET_SHOPS",
Mode = "live|test optional to override config variable, live by default",
Description = "optional",
CountriesOfActivity = {"NL", "BE"}
}, new MollieAuthRequest {
AccessToken = "organization / app / client / customer access token",
IsApiKey = false
});
return result.Match(() => Results.Ok(result.Value));
});
This was written for my own use cases before I discovered the official Mollie API client.
Get the original code of my package, here:
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. |
-
net8.0
- AugusteVN._Shared.Contracts (>= 1.0.3)
- AugusteVN._Shared.Extensions (>= 1.0.3)
- AugusteVN.ResultPattern.Contracts (>= 1.0.6)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
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.6.1 | 46 | 11/27/2024 | |
1.6.0 | 99 | 8/2/2024 | |
1.5.8 | 107 | 5/19/2024 | |
1.5.7 | 91 | 5/19/2024 | |
1.5.6 | 95 | 5/19/2024 | |
1.5.5 | 97 | 5/19/2024 | |
1.5.4 | 123 | 5/11/2024 | |
1.5.2 | 113 | 5/11/2024 | |
1.5.1 | 119 | 5/11/2024 | |
1.5.0 | 149 | 5/10/2024 | |
1.4.9 | 112 | 5/9/2024 | |
1.4.8 | 96 | 5/9/2024 | |
1.4.7 | 90 | 5/9/2024 | |
1.4.6 | 130 | 5/5/2024 | |
1.4.2 | 155 | 3/23/2024 | |
1.4.1 | 252 | 3/4/2024 |
Bugfix: use BooleanString as querystring param.