Mollie.Api .NET Client Library

repository·development·Indexed 41 days ago

https://github.com/viincenttt/mollieapi

A comprehensive .NET client library for integrating the Mollie payment provider. It supports various payment methods, webhooks, and API services, providing interfaces such as IPaymentClient, ICustomerClient, and ISubscriptionClient. Includes the Mollie.Api.AspNet package for automatic parsing and validation of incoming webhooks using the [FromMollieWebhook] attribute.

Tokens
1.9K
Snippets
11
Records
11
Agent score
1%

What's inside Mollie.Api

  1. Handle Mollie Webhooks in ASP.NET

    development

    The Mollie.Api.AspNet package provides built-in attributes to automatically parse and validate incoming webhooks (supporting both Classic and Next-gen beta systems). Use the [FromMollieWebhook] attribute on your controller action parameters and the [ServiceFilter(typeof(MollieSignatureFilter))] attribute to ensure the request is authentic.

    [HttpPost("full/specific")]
    [ServiceFilter(typeof(MollieSignatureFilter))]
    public Task<ActionResult> WebhookWithSpecificType([FromMollieWebhook] FullWebhookEventResponse<PaymentLinkResponse> data) {
        return Task.FromResult<ActionResult>(Ok());
    }
  2. Manually instantiate a Mollie API client

    development

    If you are not using Dependency Injection, you can manually create a client instance. It is recommended to provide your own HttpClient instance. If you do not provide one, the client will create one automatically, in which case you must ensure the client is properly disposed.

    using IPaymentClient paymentClient = new PaymentClient("{yourApiKey}", new HttpClient());
  3. Use Open Iconic's SVG Sprite

    development

    The SVG sprite allows you to load all icons in a single request. To use it, reference the sprite file and the specific icon ID within a <use> tag.

    Styling Tips:

    • Add a general class to the <svg> tag for shared properties.
    • Add a unique class to the <use> tag for icon-specific styling (like color).
    • To size icons, set equal width and height on the <svg> tag.
    • To color icons, use the CSS fill property on the <use> tag.
    <svg class="icon">
      <use xlink:href="open-iconic.svg#account-login" class="icon-account-login"></use>
    </svg>
  4. Configure Mollie.Api with Dependency Injection

    development

    You can register all API client interfaces using the built-in DI extension. This allows you to inject specific clients like IPaymentClient, ICustomerClient, or ISubscriptionClient into your services or controllers. You can also configure a RetryPolicy using MollieHttpRetryPolicies.

    builder.Services.AddMollieApi(options => {
        options.ApiKey = builder.Configuration["Mollie:ApiKey"];
        options.RetryPolicy = MollieHttpRetryPolicies.TransientHttpErrorRetryPolicy();
    });
  5. Create a payment using IPaymentClient

    development

    To create a payment, instantiate a PaymentRequest with the required details (Amount, Description, RedirectUrl, and Method) and call CreatePaymentAsync on the IPaymentClient. The response contains the checkout URL used to redirect the user.

    using IPaymentClient paymentClient = new PaymentClient("{yourApiKey}", new HttpClient());
    
    var paymentRequest = new PaymentRequest {
        Amount = new Amount(Currency.EUR, 100.00m),
        Description = "The .NET library makes creating payments so easy!",
        RedirectUrl = "https://github.com/Viincenttt/MollieApi",
        Method = PaymentMethod.Ideal
    };
    
    PaymentResponse paymentResponse = await paymentClient.CreatePaymentAsync(paymentRequest);
    // Redirect your user to the checkout URL
    string checkoutUrl = paymentResponse.Links.Checkout.Href;
  6. Supported APIs in Mollie.Api

    development

    The library provides coverage for a wide range of Mollie APIs. Note that some APIs are currently marked as 'documentation coming soon'.

    - Payment API
    - PaymentMethod API
    - PaymentLink API
    - Customer API
    - Mandate API
    - Subscription API
    - Refund API
    - Connect API
    - Chargeback API (documentation coming soon)
    - Invoice API (documentation coming soon)
    - Permissions API (documentation coming soon)
    - Profile API
    - Organizations API
    - Order API
    - Capture API
    - Onboarding API
    - ClientLink API (documentation coming soon)
    - Wallet API (documentation coming soon)
    - Client API (documentation coming soon)
    - Capability API (documentation coming soon)
    - Terminal API (documentation coming soon)
    - Webhooks API
    - WebhooksEvents API
    - Balance transfer API
    - Payout API
    - Balances API
    - Order API