developerlab/mollie-payment-bundle
## Getting Started
### Minimal Setup
1. **Installation**
```bash
composer require developerlab/mollie-payment-bundle
Note: Skip this package for now—it’s unstable (README explicitly warns against use). Instead, consider mollie/mollie-api-php (official, actively maintained) or spatie/laravel-mollie (Laravel-specific).
Configuration (if proceeding anyway)
Add to config/services.php (Laravel) or config.yml (Symfony):
mollie_payment:
testmode: true # Always start in test mode
api_key: "live_XXXX" # Replace with your live key
api_key_test: "test_XXXX" # Replace with your test key
Laravel users: Register the bundle in config/app.php under providers:
Developerlab\MolliePaymentBundle\MolliePaymentBundle::class,
First Use Case: Create a Payment Use the bundle’s service to create a payment (hypothetical example—check docs for actual methods):
$payment = $this->get('mollie_payment.service')->createPayment([
'amount' => 1000, // €10.00
'currency' => 'EUR',
'description' => 'Order #12345',
'redirectUrl' => route('mollie.redirect'),
]);
Redirect users to Mollie’s payment page:
return redirect($payment->getPaymentUrl());
Payment Creation & Redirect
paymentId in your DB (e.g., payments table) to track status later.// 1. Create payment
$payment = $this->mollieService->createPayment($data);
// 2. Store payment ID in DB
Payment::create(['mollie_id' => $payment->id]);
// 3. Redirect
return redirect($payment->getPaymentUrl());
Webhook Handling
/mollie/webhooks).X-Mollie-Signature header).public function handleWebhook(Request $request) {
$payload = $request->getContent();
$signature = $request->headers->get('X-Mollie-Signature');
if (!$this->mollieService->validateWebhook($payload, $signature)) {
abort(403);
}
$event = $this->mollieService->processWebhook($payload);
// Update your DB based on $event->type (e.g., 'payment.paid').
}
Customer Management
mollie:customers command:
php artisan mollie:customers # Laravel
php bin/console mollie:customers # Symfony
$customer = $this->mollieService->createCustomer([
'email' => 'user@example.com',
'name' => 'John Doe',
]);
Testing
mollie:testrun command to verify API connectivity:
php artisan mollie:testrun
mollie:customers command to sync additional fields (e.g., phone numbers) by modifying the bundle’s CustomerExporter class.Mollie\Api\Exceptions\ApiException). Catch these and log them:
try {
$payment = $this->mollieService->createPayment($data);
} catch (\Exception $e) {
Log::error('Mollie error: ' . $e->getMessage());
abort(500);
}
Unstable Package
spatie/laravel-mollie for Laravel or the official PHP SDK.Configuration Overrides
config.yml structure. In Laravel, you’ll need to:
config/services.php:
'mollie' => [
'testmode' => env('MOLLIE_TESTMODE', false),
'api_key' => env('MOLLIE_API_KEY'),
],
Webhook Validation
validateWebhook() method or implement manually:
use Mollie\Api\MollieApiClient;
$client = new MollieApiClient();
$client->setApiKey(env('MOLLIE_API_KEY'));
$isValid = $client->verifyWebhook($payload, $signature);
Route Conflicts
/mollie/redirect_url, /mollie/webhooks) may clash with existing routes.routes.php:
// Laravel
Route::prefix('payments')->group(function () {
Route::post('webhook', 'MollieWebhookController@handle');
});
Database Schema
mollie:customers command expects a mollie_customer table. Define migrations manually if missing:
Schema::create('mollie_customers', function (Blueprint $table) {
$table->id();
$table->string('mollie_id')->unique();
$table->string('email');
$table->string('name')->nullable();
$table->timestamps();
});
Enable API Logging
$client = new MollieApiClient();
$client->setApiKey(env('MOLLIE_API_KEY'));
$client->setLogger(new \Monolog\Logger('mollie'));
Test Mode Quirks
// Test card for successful payment
$data = ['amount' => 1000, 'currency' => 'EUR', 'method' => 'ideal'];
redirectUrl for some methods (e.g., iDEAL). Use sandbox testing tools instead.Command Output
mollie:testrun command may fail silently. Check logs or add verbose output:
php artisan mollie:testrun --verbose
Custom Webhook Handlers
WebhookController or creating a decorator.// app/Service/MollieWebhookHandler.php
class MollieWebhookHandler extends \Developerlab\MolliePaymentBundle\Controller\WebhookController {
public function handle(Request $request) {
$event = parent::processWebhook($request->getContent());
// Add custom logic (e.g., send Slack notification for 'payment.paid').
}
}
Additional Payment Methods
PaymentService:
public function createPayment(array $data) {
$data['method'] = $data['method'] ?? 'creditcard'; // Default
if ($data['method'] === 'custom_method') {
$data['customField'] = 'value';
}
return parent::createPayment($data);
}
Localization
$payment
How can I help you explore Laravel packages today?