laravel/cashier-mollie
Laravel Cashier integration for Mollie payments and subscriptions. This repository has moved to mollie/laravel-cashier-mollie (v1 and v2 continued) and will be closed Feb 1, 2022. Docs: cashiermollie.com.
Installation Replace this package with the official maintained version:
composer require mollie/laravel-cashier-mollie
Publish the config (if needed):
php artisan vendor:publish --provider="Mollie\LaravelCashierMollie\CashierMollieServiceProvider"
Configuration
Set your Mollie API key in .env:
MOLLIE_KEY=test_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Configure Cashier in config/cashier.php:
'driver' => 'mollie',
First Use Case: Create a Subscription
use App\Models\User;
use Mollie\LaravelCashierMollie\Facades\Cashier;
$user = User::find(1);
$user->newSubscription('main', 'price_123')->create($request->input('payment_method'));
Subscription Management
newSubscription() with a plan ID and payment method.subscription('main')->swap('price_456').subscription('main')->cancel() or subscription('main')->cancelNow().subscription('main')->resume().Webhooks
Handle Mollie events via Mollie_WebhookController:
use Mollie\LaravelCashierMollie\Webhook;
public function handleWebhook(Request $request)
{
return (new Webhook)->handle($request);
}
Register the route in routes/web.php:
Route::post('/mollie/webhook', [MollieWebhookController::class, 'handleWebhook']);
Invoices & Payments
$user->subscription('main')->invoice().$user->payments().Coupons & Trials
newSubscription('main')->withCoupon('SUMMER20')->create(...).newSubscription('main')->trialDays(7)->create(...).mollie:prices:sync to sync Mollie prices with Laravel models.EnsureUserHasSubscription.test_XXXX) and mock webhooks in tests.Webhook Verification
$webhook = new Webhook();
if (!$webhook->verify($request)) {
abort(403);
}
Plan ID Mismatches
price_* IDs in Laravel match Mollie’s API exactly (case-sensitive).mollie:prices:sync to avoid manual errors.Stale Subscriptions
subscription()->refresh() if needed.Currency & Taxes
EUR). Set this in your plan config..env:
MOLLIE_DEBUG=true
\Mollie\LaravelCashierMollie\Facades\Mollie::getClient()->setDebugMode(true);
Custom Webhook Logic
Extend Mollie\LaravelCashierMollie\Webhook to add custom handlers:
public function handlePaymentSucceeded($payload)
{
// Custom logic (e.g., send email)
}
Plan Validation
Override validatePlan() in a service provider to enforce custom rules:
Cashier::extend('mollie', function ($app) {
return new class extends \Mollie\LaravelCashierMollie\Cashier {
protected function validatePlan($plan)
{
// Custom validation
}
};
});
Payment Method Storage
Store additional payment method details in a payment_methods table:
$user->paymentMethods()->create([
'mollie_id' => $paymentMethod->id,
'brand' => $paymentMethod->brand,
]);
test_ keys in .env for development.MOLLIE_ (e.g., MOLLIE_KEY, MOLLIE_WEBHOOK_SECRET).MOLLIE_WEBHOOK_SECRET in .env for production security.Mollie\LaravelCashierMollie\Facades\Mollie directly for bulk API calls to avoid Cashier overhead.$subscription = Cache::remember("user_{$user->id}_subscription", now()->addHours(1), function () use ($user) {
return $user->subscription('main');
});
How can I help you explore Laravel packages today?