- How do I install and configure mollie/mollie-api-php in Laravel?
- Install it with Composer using composer require mollie/mollie-api-php. Because it is a plain PHP package that relies on Composer autoloading, Laravel picks it up automatically. The recommended setup is to bind \Mollie\Api\MollieApiClient as a singleton in AppServiceProvider and inject your API key from the .env file. Resolve the client through the container in your controllers, jobs, and services instead of instantiating it in every class.
- Does mollie/mollie-api-php work with Laravel 10 and Laravel 11?
- Yes. The package is framework agnostic and only requires PHP and Composer, so it runs fine on Laravel 10, 11, and any other modern Laravel release that supports your chosen PHP version. Laravel's service container can hold the MollieApiClient as a singleton, and Laravel's queue, event, and HTTP layers integrate cleanly with Mollie webhooks and API calls. The main constraint to check is the PHP floor of the package version you install, since the v3 line requires PHP 8.x.
- How do I create a payment with the Mollie API client in Laravel?
- Resolve the MollieApiClient, then call $client->payments->create() with an amount (value and currency), a description, a redirectUrl, a webhookUrl, and optional metadata for your order reference. Mollie returns a Payment resource with a checkout URL that you redirect the customer to. The package handles the HTTP request, JSON serialization, and error handling for you through request and response objects such as CreatePaymentRequest and Payment. Always persist the payment id before redirecting so you can reconcile it later.
- How do I handle Mollie webhooks in a Laravel application?
- Create a dedicated route for Mollie's webhook and exclude it from CSRF protection. Never trust the posted payload for status; use the payment id from the request to fetch the payment from Mollie's API and act on the authoritative status. Offload the work to a queued job so slow processing never blocks Mollie's webhook call, and validate the request using middleware such as a signature validator where applicable. Idempotency matters, so guard against processing the same payment id twice.
- What is the difference between the Mollie Payments API and Checkout Sessions?
- The classic Payments API flow is server-side: you create a payment, redirect the customer to the checkout URL, and confirm the result via webhook. Checkout Sessions, first-class in v2.80.0, is a newer path where the server creates a session and hands a clientAccessToken to the frontend, which drives the checkout UI. The Session resource exposes fields like clientAccessToken, profile ID, and lifecycle timestamps, plus STATUS_OPEN, STATUS_EXPIRED, isOpen(), and isExpired() helpers. The change is additive, so existing Payments API integrations keep working.
- Do I still need Mollie webhooks if I use Checkout Sessions?
- Yes. Session status is a UI-state signal, not a settlement signal, so isOpen() and isExpired() tell you about the checkout experience rather than whether money actually moved. You should still listen to Mollie webhooks on the underlying payment to confirm the final paid or failed state. A common pattern is to store session data locally in a mollie_sessions table so UI decisions can be made from local state while webhooks remain the source of truth for settlement.
- How do I test Mollie payments in Laravel without real transactions?
- Use a Mollie test API key in your testing and staging environments and keep it out of your production .env. The package ships mocking utilities such as MockEvent and fake request handling, which pair well with Pest and PHPUnit so you can assert on request and response behavior without hitting the network. If your tests cover Checkout Sessions, update your session fixtures with the new fields like clientAccessToken and lifecycle timestamps. Combine this with Laravel factories to simulate orders and payments in your test database.
- How do I process refunds and recurring subscriptions with mollie-api-php?
- Refunds are issued against a payment resource and can be partial or full, and you should persist the refund id and status just like a payment. For recurring billing, create a Mollie customer, attach a mandate through a first payment, then create a subscription against that customer so Mollie handles the recurring charges. Handle the resulting webhooks for both subscription payments and refund status changes, and use metadata to map every Mollie object back to your internal order or subscription record.
- Is the Mollie clientAccessToken safe to send to the frontend?
- The clientAccessToken is a bearer credential for the checkout UI, so it should only ever be served through a short-lived, authenticated endpoint scoped to a single order or session. Never embed it in server-rendered HTML, and exclude it from logs, error trackers, and session dumps. Scope it to one session so a leaked token cannot be reused elsewhere, and rotate your API keys through the Mollie dashboard if you suspect any exposure.
- Which version of mollie/mollie-api-php should I pin and which PHP version is required?
- Pin an explicit constraint in composer.json rather than using a wildcard, because the published release metadata references a v3.11.0 line while the notes describe v2.80.0, and these appear to be two separately maintained lines. Confirm which line your production code actually runs and verify its PHP floor, since the v3 line requires PHP 8.x while earlier assumptions of 7.4+ may not hold. Checkout Sessions require v2.80.0 or later, so your pin needs to be at least that version if you plan to use the new session API.