mollie/mollie-api-php
Official Mollie API client for PHP. Create and manage payments, orders, customers, subscriptions, refunds, and settlements. Supports iDEAL, card, PayPal, Apple Pay, Google Pay, Bancontact, SEPA and more. Includes webhooks and OAuth support.
\Mollie\Api\MollieApiClient and bind it as a singleton or context-bound service.queue:listen for processing webhook payloads asynchronously). The package includes built-in signature validation for security.MockEvent, fake retain requests) and test-mode APIs, which align with Laravel’s testing tools (Pest, PHPUnit) and factories.CreatePaymentRequest, Payment resource), reducing boilerplate for HTTP clients, serialization, and error handling.AppServiceProvider to configure the client globally (e.g., API keys from .env).ValidateSignature) for security.id, status, amount) can be stored in Laravel’s database for reconciliation or reporting.| Risk Area | Mitigation Strategy |
|---|---|
| API Key Management | Store API keys in Laravel’s .env and use environment variables or Vault (e.g., Laravel Forge, HashiCorp Vault). Rotate keys via Mollie’s dashboard. |
| Webhook Reliability | Implement retry logic (exponential backoff) for failed webhook deliveries. Use Laravel’s queue:failed table to monitor and reprocess failed jobs. |
| Idempotency | Mollie supports idempotency keys; ensure Laravel’s HTTP client (Guzzle) respects these headers. |
| Currency/Regional Limits | Validate supported currencies/countries in Laravel’s validation rules (e.g., rule:in:EUR,USD). Mollie’s API will reject unsupported methods, but pre-validation reduces noise. |
| Rate Limiting | Mollie’s API has rate limits. Cache responses (e.g., Illuminate\Support\Facades\Cache) for frequent queries (e.g., payment status checks). |
| PHP Version Compatibility | The package supports PHP 7.4+, which aligns with Laravel’s LTS support (8.0+). Test with Laravel’s latest PHP version to catch deprecations (e.g., cURL changes in PHP 8.5). |
| Webhook Security | Use Laravel’s signed routes or middleware to validate Mollie’s webhook signatures. The package provides WebhookEventMapper for parsing payloads. |
| Data Migration | If migrating from another payment provider, use Laravel’s migrations to add Mollie-specific fields (e.g., mollie_payment_id, mollie_webhook_signature) to existing tables. |
Payment Flow Complexity:
scheduler to check for failed subscriptions and trigger retries.Webhook Handling:
queue:listen is recommended for scalability.MollieWebhookHandler service to process events like payment.authorized or subscription.cancelled.Error Recovery:
pending or failed statuses; Laravel can use observers or queued jobs to retry or notify users.laravel.log and send emails via Laravel Notifications.Testing Strategy:
MockEvent for unit tests; integration tests should use test API keys.mock() to simulate webhook payloads in feature tests.Multi-Tenant Support:
tenant()->mollieClient) can manage per-tenant API keys.Compliance:
| Laravel Component | Mollie Package Integration |
|---|---|
| Service Container | Bind MollieApiClient as a singleton in AppServiceProvider with API keys from .env. |
| HTTP Client | Use Laravel’s Guzzle HTTP client (default) or configure custom adapters (e.g., Mollie\Api\Http\Adapter\GuzzleAdapter). |
| Validation | Validate payment inputs using Laravel’s Form Requests (e.g., CreatePaymentRequest). Example: Ensure amount is numeric and currency is supported. |
| Routing | Create routes for webhooks (e.g., POST /mollie/webhook) and payment redirects (e.g., GET /payment/{id}/redirect). Use middleware to validate signatures. |
| Queues | Process webhooks asynchronously with Laravel Queues. Example: Dispatch a HandleMollieWebhook job when a webhook is received. |
| Events | Dispatch Laravel events (e.g., PaymentAuthorized) when Mollie webhooks trigger actions. Listen to these events in services or notifications. |
| Database | Store Mollie payment IDs and metadata in Laravel tables. Example: Add mollie_payment_id to orders table for reconciliation. |
| Testing | Use Mollie’s test mode and Laravel’s Pest/PHPUnit to mock API responses. Example: Stub MollieApiClient to return fake payments in unit tests. |
| Logging | Log Mollie API responses/errors to laravel.log using Laravel’s Log facade. Example: Log failed payment attempts with Log::error($payment->failureMessage). |
| Notifications | Send user notifications (e.g., payment failed) using Laravel Notifications (e.g., Mail, Slack). Example: Trigger PaymentFailedNotification when a webhook reports payment.failed. |
Phase 1: Setup and Configuration
composer require mollie/mollie-api-php..env:
MOLLIE_API_KEY=test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM
MOLLIE_WEBHOOK_SECRET=whsec_test_...
AppServiceProvider:
$this->app->singleton(MollieApiClient::class, function ($app) {
$client = new MollieApiClient();
$client->setToken(config('services.mollie.api_key'));
return $client;
});
Phase 2: Core Payment Integration
PaymentService to handle creation/refunds:
use Mollie\Api\Http\Requests\CreatePaymentRequest;
use Mollie\Api\Http\Data\Money;
class PaymentService {
public function createPayment(float $amount, string $currency, string $description) {
$payment = $this->mollieClient->send(new CreatePaymentRequest(
description: $description,
amount: new Money($currency, $amount),
redirectUrl: route('payment.redirect'),
webhookUrl: route
How can I help you explore Laravel packages today?