AugusteVN.Mollie.Api 1.5.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package AugusteVN.Mollie.Api --version 1.5.4                
NuGet\Install-Package AugusteVN.Mollie.Api -Version 1.5.4                
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="AugusteVN.Mollie.Api" Version="1.5.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AugusteVN.Mollie.Api --version 1.5.4                
#r "nuget: AugusteVN.Mollie.Api, 1.5.4"                
#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.
// Install AugusteVN.Mollie.Api as a Cake Addin
#addin nuget:?package=AugusteVN.Mollie.Api&version=1.5.4

// Install AugusteVN.Mollie.Api as a Cake Tool
#tool nuget:?package=AugusteVN.Mollie.Api&version=1.5.4                

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/",
    "IsTestMode": false,
    "PaymentsConfig": {
      "WebhookUrl": "<to-fill>"
    }
  }
}

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.AddScoped<IMolliePaymentsClient, MolliePaymentsClient>();

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));
});

Create First Payment For Customer

Creates a first payment for a customer to get consent as API-key authorized HTTP call to Mollie API.

Read more: Create first payment for customer

Program.cs

app.MapPost("/", async (IMolliePaymentsClient paymentsClient) => {
    
    var result = await paymentsClient.CreateFirstCustomerPaymentAsync(new MollieCreateFirstCustomerPaymentRequest {
        Amount = new PaymentAmount { Amount = "5.00", Currency = "EUR" },
        Description = "First payment for customer consent...",
        RedirectUrl = "https://your-frontend.net/payment-confirmed",
        Metadata = new { Foo = "bar" },
        Testmode = true, // Overwrites config value
        CustomerId = "cst_<to-fill>"
    }, new MollieAuthRequest {
        AccessToken = "organization / app / client / customer access token",
        IsApiKey = true
    });
    
    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 Recurring Payment For Customer

Creates a recurring payment for a customer as API-key authorized HTTP call to Mollie API.

Read more: Create recurring payment for customer

Program.cs

app.MapPost("/", async (IMolliePaymentsClient paymentsClient) => {
    
    var result = await paymentsClient.CreateFirstCustomerPaymentAsync(new MollieCreateFirstCustomerPaymentRequest {
        Amount = new PaymentAmount { Amount = "5.00", Currency = "EUR" },
        Description = "Recurring payment for customer...",
        RedirectUrl = "https://your-frontend.net/payment-confirmed",
        Metadata = new { Foo = "bar" },
        Testmode = true, // Overwrites config value
        CustomerId = "cst_<to-fill>"
    }, new MollieAuthRequest {
        AccessToken = "organization / app / client / customer access token",
        IsApiKey = true
    });
    
    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/",
    "IsTestMode": false
  }
}

Program.cs

builder.Services.AddHttpClient(); // Adds the required IHttpClientFactory.

builder.Services
    .AddOptions<MollieConfig>()
    .BindConfiguration(nameof(MollieConfig));

builder.Services.AddScoped<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

Mollie Connect

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.AddScoped<IMollieOAuthClient, MollieOAuthClient>();

Get Authorization Url

Authorize

Program.cs

app.MapGet("/", async (IMollieOAuthClient mollieClient) =>
{
    var result = await mollieClient.GetAuthorizationUrl();
    return result.Match(() => Results.Ok(result.Value.AuthUrl));
});

Generate Tokens

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
    }));
});

Mollie Onboarding

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.AddScoped<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

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.AddScoped<IMollieClientLinksClient, MollieClientLinksClient>();

Create Profile

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));
});

Customers API

Configuration

{
  "MollieConfig": {
    "ApiUrl": "https://api.mollie.com/v2/",
    "IsTestMode": false
  }
}

Read more: Mollie Docs

Program.cs

builder.Services.AddHttpClient(); // Adds the required IHttpClientFactory.

builder.Services
    .AddOptions<MollieConfig>()
    .BindConfiguration(nameof(MollieConfig));

builder.Services.AddScoped<IMollieCustomersClient, MollieCustomersClient>();

Get Customer

Gets customer by id over API-key authorized HTTP call to Mollie API.

Read more: Get customer

Program.cs

app.MapGet("/", async (IMollieCustomersClient customersClient) => {
    
    var result = await customersClient.GetCustomerByIdAsync(new MollieGetCustomerByIdRequest {
        Id = "<to-fill-customer-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();
    }
    
    return result.Match(() => Results.Ok(result.Value));
});

Create Customer

Creates customer over API-key authorized HTTP call to Mollie API.

Read more: Create customer

Program.cs

app.MapPost("/", async (IMollieCustomersClient customersClient) => {
    
    var result = await customersClient.CreateCustomerAsync(new MollieCreateCustomerRequest {
        
        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 Organization Customer

Creates customer organization over organization access token, authorized HTTP call to Mollie API.

Read more: Create customer for profile

Program.cs

app.MapPost("/", async (IMollieCustomersClient customersClient) => {
    
    var result = await paymentsClient.CreateOrganizationCustomerAsync(new MollieCreateOrganizationCustomerRequest {
        
        Metadata = new { Foo = "bar" },
        Testmode = true, // Overwrites config value
    }, 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));
});

Mandates API

Configuration

{
  "MollieConfig": {
    "ApiUrl": "https://api.mollie.com/v2/",
    "IsTestMode": false
  }
}

Read more: Mollie Docs

Program.cs

builder.Services.AddHttpClient(); // Adds the required IHttpClientFactory.

builder.Services
    .AddOptions<MollieConfig>()
    .BindConfiguration(nameof(MollieConfig));

builder.Services.AddScoped<IMollieMandatesClient, MollieMandatesClient>();

Get Mandate

Gets mandate by id over API-key authorized HTTP call to Mollie API.

Read more: Get mandate

Program.cs

app.MapGet("/", async (IMollieMandatesClient mandatesClient) => {
    
    var result = await mandatesClient.GetMandateByIdAsync(new MollieGetMandateByIdRequest {
        CustomerId = "<cst_to-fill>",
        MandateId = "<mnd_to-fill>",
        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();
    }
    
    return result.Match(() => Results.Ok(result.Value));
});

Create Mandate

Creates mandate over API-key authorized HTTP call to Mollie API.

Read more: Create mandate

Program.cs

app.MapPost("/", async (IMollieMandatesClient mandatesClient) => {
    
    var result = await mandatesClient.CreateMandateAsync(new MollieCreateMandateRequest {
        ...
        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 Organization Mandate

Creates mandate over organization access token, authorized HTTP call to Mollie API.

Read more: Create mandate for organization

Program.cs

app.MapPost("/", async (IMollieMandatesClient mandatesClient) => {
    
    var result = await mandatesClient.CreateOrganizationMandateAsync(new MollieCreateOrganizationMandateRequest {
        ...
        Metadata = new { Foo = "bar" },
        Testmode = true, // Overwrites config value
    }, 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));
});

Subscriptions API

Configuration

{
  "MollieConfig": {
    "ApiUrl": "https://api.mollie.com/v2/",
    "IsTestMode": false,
    "SubscriptionsConfig": {}
  }
}

Read more: Mollie Docs

Program.cs

builder.Services.AddHttpClient(); // Adds the required IHttpClientFactory.

builder.Services
    .AddOptions<MollieConfig>()
    .BindConfiguration(nameof(MollieConfig));

builder.Services.AddScoped<IMollieSubscriptionsClient, MollieSubscriptionsClient>();

Get Subscription

Gets subscription by id over API-key authorized HTTP call to Mollie API.

Read more: Get subscription

Program.cs

app.MapGet("/", async (IMollieSubscriptionsClient subscriptionsClient) => {
    
    var result = await subscriptionsClient.GetSubscriptionByIdAsync(new MollieGetSubscriptionByIdRequest {
        CustomerId = "<cst_to-fill>",
        SubscriptionId = "<sbs_to-fill>",
        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();
    }
    
    return result.Match(() => Results.Ok(result.Value));
});

Create Subscription

Creates subscription over API-key authorized HTTP call to Mollie API.

Read more: Create subscription

Program.cs

app.MapPost("/", async (IMollieSubscriptionsClient subscriptionsClient) => {
    
    var result = await subscriptionsClient.CreateSubscriptionAsync(new MollieCreateSubscriptionRequest {
        ...
        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 Organization Subscription

Creates subscription over organization access token, authorized HTTP call to Mollie API.

Read more: Create subscription for profile

Program.cs

app.MapPost("/", async (IMollieSubscriptionsClient subscriptionsClient) => {
    
    var result = await subscriptionsClient.CreateOrganizationSubscriptionAsync(new MollieCreateOrganizationSubscriptionRequest {
        ...
        Metadata = new { Foo = "bar" },
        Testmode = true, // Overwrites config value
    }, 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));
});

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 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. 
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
1.6.0 87 8/2/2024
1.5.8 89 5/19/2024
1.5.7 74 5/19/2024
1.5.6 76 5/19/2024
1.5.5 79 5/19/2024
1.5.4 105 5/11/2024
1.5.2 93 5/11/2024
1.5.1 97 5/11/2024
1.5.0 131 5/10/2024
1.4.9 110 5/9/2024
1.4.8 94 5/9/2024
1.4.7 88 5/9/2024
1.4.6 128 5/5/2024
1.4.2 153 3/23/2024
1.4.1 250 3/4/2024

Added 'CancelSubscriptionAsync'.