How to handle LemonSqueezy Webhooks for non-auth users in Laravel
orders
table to store the orders for non-auth users.
lemon_squeezy_orders
table.
billable
model to store the orders in the database we need to create a new route for webhooks.
Create a new controller WebhookController
routes/web.php
file.
vendor/lemonsqueezy/laravel/src/Http/Controllers/WebhookController.php
file and copy the __construct(), __invoke() and handleOrderCreated() methods to your WebhookController
.
$billable->orders()
we will use LemonSqueezy::$orderModel
to create the order in our database
Remove 'customer_id' => $attributes['customer_id'],
from the $order
array as we are not using the billable
model.
Add user_email and user_name to the $order
array.
OrderCreated::dispatch($billable, $order, $payload)
as we are not using the billable
model.
WebhookHandled
event in your application.