lms/vendor/mollie/laravel-mollie/docs/webhook.md
2025-12-15 12:26:23 +01:00

61 lines
2.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

![Mollie](https://www.mollie.nl/files/Mollie-Logo-Style-Small.png)
# Process realtime status updates with a webhook
A webhook is a URL Mollie will call when an objects status changes, for example when a payment changes from `open` to `paid`. More specifics can be found in [the webhook guide](https://docs.mollie.com/guides/webhooks).
To implement the webhook in your Laravel application you need to provide a `webhookUrl` parameter when creating a payment (or subscription):
```php
$payment = Mollie::api()->payments->create([
'amount' => [
'currency' => 'EUR',
'value' => '10.00', // You must send the correct number of decimals, thus we enforce the use of strings
],
'description' => 'My first API payment',
'redirectUrl' => 'https://webshop.example.org/order/12345/',
'webhookUrl' => route('webhooks.mollie'),
]);
```
And create a matching route and controller for the webhook in your application:
```php
// routes/web.php
Route::name('webhooks.mollie')->post('webhooks/mollie', 'MollieWebhookController@handle');
```
```php
// App/Http/Controllers/MollieWebhookController.php
class MollieWebhookController extends Controller {
public function handle(Request $request) {
if (! $request->has('id')) {
return;
}
$payment = Mollie::api()->payments->get($request->id);
if ($payment->isPaid()) {
// do your thing...
}
}
}
```
Finally, it is _strongly advised_ to disable the `VerifyCsrfToken` middleware, which is included in the `web` middleware group by default. (Out of the box, Laravel applies the `web` middleware group to all routes in `routes/web.php`.)
You can exclude the route from the CSRF protection in your `bootstrap/app.php`:
```php
// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
$middleware->validateCsrfTokens(
except: ['webhooks/mollie']
);
})
```
If this solution does not work, open an [issue](https://github.com/mollie/laravel-mollie/issues) so we can assist you.