SDKs overview

Mollie provides Software Development Kits (SDKs) and client libraries designed to streamline the integration of its payment gateway services into various applications. These SDKs abstract much of the underlying HTTP request and response handling, authentication, and data serialization required to interact with the Mollie API. The primary objective of these libraries is to reduce development time and potential errors by offering language-specific wrappers around common API operations, such as creating payments, managing refunds, and handling subscriptions. Mollie's API follows a RESTful design philosophy, which is reflected in the structure and methods provided by its official SDKs.

The SDKs typically handle:

  • API Authentication: Managing API keys and secure token submission for requests.
  • Request Construction: Formatting requests according to Mollie's API specifications, including JSON payloads.
  • Response Parsing: Deserializing JSON responses into native language objects or data structures.
  • Error Handling: Providing structured error responses for API-specific issues.
  • Idempotency: Some SDKs may offer helpers for implementing idempotent requests to prevent duplicate actions.

Developers benefit from using SDKs as they can focus on application logic rather than the intricacies of HTTP communication. Mollie maintains official SDKs for several popular programming languages, ensuring compatibility and ongoing support with their API updates. Additionally, a community of developers contributes to unofficial libraries, expanding Mollie's reach into other languages and frameworks.

Official SDKs by language

Mollie offers maintained SDKs for a range of programming environments, ensuring that developers can integrate payment functionality with established coding practices. These official libraries are developed and supported by Mollie, providing the most reliable and up-to-date interface to their API. Each SDK typically includes comprehensive documentation, example code, and adherence to the latest API version. The table below outlines the key official SDKs available:

Language Package Name / Repository Installation Command Example Maturity / Status
PHP mollie/mollie-api-php composer require mollie/mollie-api-php Official, Actively Maintained
Node.js @mollie/api-client npm install @mollie/api-client Official, Actively Maintained
Ruby mollie-api-ruby gem install mollie-api-ruby Official, Actively Maintained
Python mollie-api-python pip install mollie-api-python Official, Actively Maintained
Java com.mollie.api:mollie-api-java Maven: Add dependency; Gradle: Add implementation Official, Actively Maintained
ASP.NET (C#) Mollie.Api Install-Package Mollie.Api Official, Actively Maintained

Each of these SDKs is designed to encapsulate the specific idioms and conventions of its respective programming language, making the integration process feel native to developers familiar with that ecosystem. For instance, the PHP SDK leverages Composer for dependency management, a standard practice in the PHP community. Similarly, the Node.js SDK integrates via npm, aligning with typical JavaScript project workflows. Developers can find detailed language-specific documentation and usage guides on the Mollie developer portal for each of these official offerings.

Installation

Installing a Mollie SDK typically involves using a language-specific package manager. The process is generally straightforward and follows standard practices for dependency management within each ecosystem. Below are common installation methods for the primary official Mollie SDKs:

PHP SDK Installation

The Mollie PHP API client is distributed via Composer, the dependency manager for PHP. Ensure Composer is installed on your system before proceeding.

composer require mollie/mollie-api-php

After installing, include the Composer autoloader in your project to use the SDK classes:

require_once 'vendor/autoload.php';

Node.js SDK Installation

The Node.js API client is available through npm, the package manager for JavaScript. Use the following command in your project directory:

npm install @mollie/api-client

Alternatively, if you use Yarn:

yarn add @mollie/api-client

Ruby SDK Installation

The Mollie Ruby API client is distributed as a RubyGems gem. Install it using the gem command:

gem install mollie-api-ruby

Then, require it in your Ruby application:

require 'mollie-api-ruby'

Python SDK Installation

The Mollie Python API client is installed using pip, Python's package installer. This command adds the package to your current Python environment:

pip install mollie-api-python

Java SDK Installation

For Java projects, the Mollie API client can be added as a dependency using Maven or Gradle.

Maven: Add the following to your pom.xml file:


    com.mollie.api
    mollie-api-java
    2.0.0 

Gradle: Add the following to your build.gradle file:

implementation 'com.mollie.api:mollie-api-java:2.0.0' // Check for the latest version

Ensure you replace 2.0.0 with the latest stable version available on the Mollie SDK documentation pages.

ASP.NET (C#) SDK Installation

For .NET projects, the Mollie API client is available via NuGet. Use the NuGet Package Manager Console in Visual Studio:

Install-Package Mollie.Api

Alternatively, you can use the .NET CLI:

dotnet add package Mollie.Api

These commands will download and configure the Mollie API client within your project, making its functionalities accessible for development. Developers should always refer to the official Mollie SDK documentation for the most up-to-date installation instructions and version information, as these can change over time.

Quickstart example

This quickstart example demonstrates how to create a simple payment using the Mollie PHP SDK. Similar logic applies to other SDKs, though syntax will differ. This example assumes you have installed the PHP SDK via Composer and have a Mollie API key (test or live).

PHP Payment Creation Example

First, ensure your Composer autoloader is included. Then, initialize the Mollie API client with your API key. This key can be found in your Mollie Dashboard under 'Developers' > 'API keys'. It is important to handle your API key securely, preferably by loading it from environment variables rather than hardcoding it.

<?php
require_once 'vendor/autoload.php';

try {
    /*
     * Initialize the Mollie API client
     *
     * See: https://docs.mollie.com/sdks/php
     */
    $mollie = new \Mollie\Api\MollieApiClient();
    $mollie->setApiKey('YOUR_API_KEY_HERE'); // Replace with your actual Mollie API key

    /*
     * Create a new payment
     *
     * See: https://docs.mollie.com/reference/v2/payments-api/create-payment
     */
    $payment = $mollie->payments->create([
        'amount' => [
            'currency' => 'EUR',
            'value' => '10.00', // Amount in EURO, formatted as a string with 2 decimals
        ],
        'description' => 'Order #12345',
        'redirectUrl' => 'https://example.org/return-from-mollie',
        'webhookUrl' => 'https://example.org/mollie-webhook',
        'metadata' => [
            'order_id' => '12345',
        ],
    ]);

    // Redirect the customer to the payment URL
    header('Location: ' . $payment->getCheckoutUrl());
    exit();

} catch (\Mollie\Api\Exceptions\ApiException $e) {
    echo 'API call failed: ' . htmlspecialchars($e->getMessage());
    // Log the full exception for debugging
    error_log('Mollie API Exception: ' . $e->getMessage() . '\n' . $e->getTraceAsString());
}
?>

This code snippet performs the following actions:

  1. Loads the Composer autoloader.
  2. Initializes the MollieApiClient with your API key.
  3. Creates a payment object with a specified amount, description, and critical URLs for redirection and webhook notifications. The redirectUrl is where your customer is sent after completing the payment on Mollie's hosted payment page. The webhookUrl is an endpoint on your server that Mollie calls to notify you of payment status changes (webhooks explained by Twilio).
  4. Redirects the user's browser to Mollie's hosted checkout page, where they can choose their preferred payment method and complete the transaction.
  5. Includes basic error handling to catch API-specific exceptions.

After the customer completes the payment, Mollie sends an asynchronous notification to the specified webhookUrl. Your application should listen for these webhooks to update the order status in your system. For detailed information on handling webhooks and securing them, refer to the Mollie webhook documentation.

Community libraries

Beyond Mollie's officially supported SDKs, the developer community contributes a variety of unofficial libraries and plugins. These community-driven projects can extend Mollie's reach into languages or frameworks not covered by official SDKs, or provide specialized integrations for popular e-commerce platforms. While not officially maintained or supported by Mollie, these resources can be valuable for specific use cases.

Examples of community contributions often include:

  • Framework Integrations: Libraries designed to work seamlessly with specific web frameworks like Laravel (PHP), Django (Python), or Ruby on Rails (Ruby).
  • CMS/E-commerce Platform Plugins: Modules for platforms such as WooCommerce, Magento, PrestaShop, and OpenCart, which provide direct payment gateway integration without extensive custom coding.
  • Additional Language Bindings: SDKs for languages where an official client might not exist, or alternative implementations offering different architectural approaches.
  • Specific Feature Enhancements: Libraries that focus on a particular aspect, such as enhanced webhook verification, advanced reporting, or simplified subscription management beyond the core SDK capabilities.

When considering a community library, it is important to evaluate its maintenance status, the last update date, community activity, and its compatibility with the latest Mollie API version. Developers should always review the source code and associated documentation to ensure security and functionality meet project requirements. The Mollie developer portal sometimes lists popular community contributions or provides links to resources where they can be discovered, such as GitHub repositories or package registries.

While official SDKs are recommended for production environments due to their direct support and maintenance, community libraries can offer flexible solutions for specialized needs or for developers working outside the officially supported language ecosystem. It's crucial to understand the distinction between official and community-supported resources in terms of reliability, security updates, and potential for breaking changes.