Complete Guide to Integrate Mollie Payment Gateway into Your Custom Website

This guide explains how to integrate **Mollie** using their **Hosted Checkout** method (the simplest and most common approach).

#

Table of Contents

- [Prerequisites](#prerequisites)
- [1. Create and Verify Mollie Account](#1-create-and-verify-mollie-account)
- [2. Obtain API Keys](#2-obtain-api-keys)
- [3. Choose Your Integration Type](#3-choose-your-integration-type)
- [4. Install Official Mollie Client Library](#4-install-official-mollie-client-library)
- [5. Create a Payment](#5-create-a-payment)
- [6. Redirect Customer to Mollie Checkout](#6-redirect-customer-to-mollie-checkout)
- [7. Handle Customer Return (Redirect URL)](#7-handle-customer-return-redirect-url)
- [8. Set Up Webhook (Critical)](#8-set-up-webhook-critical)
- [9. Testing Your Integration](#9-testing-your-integration)
- [10. Going Live](#10-going-live)
- [11. Best Practices & Security](#11-best-practices--security)
- [12. Official Documentation Links](#12-official-documentation-links)

#

Prerequisites

- A live website (with products/prices visible) – required for Mollie approval
- Valid business bank account (IBAN)
- Server-side programming language (PHP, Node.js, Python, etc.)
- Publicly accessible HTTPS server for webhooks

#

1. Create and Verify Mollie Account

1. Sign up at [https://www.mollie.com](https://www.mollie.com)
2. Complete the **onboarding/verification**:
- Business details
- Website URL (must be live)
- Bank account
- ID documents for legal representatives
3. Wait for approval (usually 1–10 business days)

#

2. Obtain API Keys

1. Log in to your Mollie Dashboard
2. Go to **Developers → API keys**
3. Copy:
- **Test API key** (starts with `test_`)
- **Live API key** (starts with `live_`)
4. **Never expose these keys in frontend code.**

#

3. Choose Your Integration Type

| Type | Description | Recommended for beginners? |
|-----------------------|--------------------------------------------|----------------------------|
| Hosted Checkout | Redirect to Mollie’s payment page | Yes (this guide) |
| Mollie Components | Embed card form on your site (PCI) | Advanced |
| Orders API | Better refunds/shipping support | Medium |
| Subscriptions | Recurring payments | Advanced |

This guide covers **Hosted Checkout**.

#

4. Install Official Mollie Client Library

| Language | Installation Command | GitHub |
|----------|--------------------------------------------------------|--------|
| PHP | `composer require mollie/mollie-api-php` | [link](https://github.com/mollie/mollie-api-php) |
| Node.js | `npm install @mollie/api` | [link](https://github.com/mollie/mollie-api-node) |
| Python | `pip install mollie-api-python` | [link](https://github.com/mollie/mollie-api-python) |
| Ruby | `gem install mollie-api-ruby` | [link](https://github.com/mollie/mollie-api-ruby) |

#

5. Create a Payment

**Endpoint**: `POST https://api.mollie.com/v2/payments`

**Minimal payload** (JSON):

```json
{
"amount": {
"currency": "EUR",
"value": "25.00"
},
"description": "Order #12345",
"redirectUrl": "https://your-site.com/order/12345/return",
"webhookUrl": "https://your-site.com/webhook/mollie",
"locale": "en_US"
}
```

##

PHP Example (using official library)

```php
require 'vendor/autoload.php';

use Mollie\Api\MollieApiClient;

$mollie = new MollieApiClient();
$mollie->setApiKey("test_dH...your_test_key_here");

try {
$payment = $mollie->payments->create([
"amount" => [
"currency" => "EUR",
"value" => "25.00",
],
"description" => "Order #12345",
"redirectUrl" => "https://your-site.com/order/12345/return",
"webhookUrl" => "https://your-site.com/webhook/mollie",
"locale" => "en_US",
]);

// Redirect customer to Mollie checkout
header("Location: " . $payment->getCheckoutUrl());
exit;
} catch (\Mollie\Api\Exceptions\ApiException $e) {
echo "Error: " . htmlspecialchars($e->getMessage());
}
```

#

6. Redirect Customer to Mollie Checkout

After creating the payment, redirect the customer to:

```php
header("Location: " . $payment->getCheckoutUrl());
```

This takes them to Mollie’s secure hosted payment page.

#

7. Handle Customer Return (Redirect URL)

Mollie redirects back to your `redirectUrl` (e.g. `https://your-site.com/order/12345/return?payment_id=tr_abc123`).

##

PHP Example

```php
require 'vendor/autoload.php';

use Mollie\Api\MollieApiClient;

$mollie = new MollieApiClient();
$mollie->setApiKey("test_dH...your_key");

$paymentId = $_GET['payment_id'] ?? null;

if ($paymentId) {
$payment = $mollie->payments->get($paymentId);

if ($payment->isPaid()) {
echo "Payment successful! Order confirmed.";
// Update order status, send email, etc.
} elseif ($payment->isFailed() || $payment->isCancelled()) {
echo "Payment failed or cancelled.";
} else {
echo "Payment status: " . $payment->status;
}
}
```

**Important**: Do **not** rely solely on this redirect to confirm payment.

#

8. Set Up Webhook (Critical)

Mollie sends POST requests to your `webhookUrl` for every status change.

**Payload**:
```json
{ "id": "tr_abc123" }
```

##

PHP Webhook Example

```php
require 'vendor/autoload.php';

use Mollie\Api\MollieApiClient;

$mollie = new MollieApiClient();
$mollie->setApiKey("test_dH...your_key");

$paymentId = $_POST['id'] ?? null;

if ($paymentId) {
$payment = $mollie->payments->get($paymentId);

if ($payment->isPaid()) {
// Update order to "paid"
// Send confirmation email
} elseif ($payment->isRefunded()) {
// Handle refund
} elseif ($payment->isCancelled()) {
// Handle cancellation
}
}

// Always return 200 OK
http_response_code(200);
```

#

9. Testing Your Integration

- Use **test API key**
- Use Mollie’s test payment methods: [Testing Guide](https://docs.mollie.com/reference/testing)
- Test all outcomes: paid, failed, cancelled, refunded

#

10. Going Live

1. Switch to **live API key**
2. Perform a small real test transaction
3. Confirm webhook works in live mode

#

11. Best Practices & Security

- **Never expose API keys** on the frontend
- **Always use HTTPS**
- **Validate webhook origin** (optional: IP check)
- **Handle all API errors** and log them
- **Use Orders API** for complex flows (refunds, shipping)
- **Support multiple languages/currencies** via `locale`

#

12. Official Documentation Links

- [Getting Started](https://docs.mollie.com/docs/getting-started)
- [Payments API](https://docs.mollie.com/reference/v2/payments-api/create-payment)
- [Webhooks](https://docs.mollie.com/reference/v2/webhooks-api)
- [Testing](https://docs.mollie.com/reference/testing)
- [Client Libraries](https://docs.mollie.com/developers/packages)
- [Mollie Components (Advanced)](https://docs.mollie.com/components/overview)

Let me know your programming language/framework for more specific examples!