### Install Purchases for Laravel with Composer and Artisan Source: https://github.com/roundly-consulting/purchases-for-laravel/blob/main/README.md Install the package via Composer, then run the artisan install command to publish config and migrations and append provider .env keys. Finally, run migrations. Requires PHP 8.4 with ext-bcmath and Laravel 12 or 13. ```bash composer require roundly-consulting/purchases-for-laravel php artisan purchases:install --providers # publishes config + migrations, appends the providers' .env keys php artisan migrate ``` -------------------------------- ### Link subscription owner in a listener Source: https://github.com/roundly-consulting/purchases-for-laravel/blob/main/README.md Listen for the SubscriptionStarted event to associate the subscription with the correct user. The example retrieves the Stripe customer id from the raw result and sets the subscription name to 'pro'. ```php use App\Models\User; use Illuminate\Support\Facades\Event; use RoundlyConsulting\Purchases\Events\SubscriptionStarted; Event::listen(function (SubscriptionStarted $event): void { $customer = $event->result->raw()['customer']; // the Stripe customer id $event->subscription->owner()->associate(User::firstWhere('stripe_id', $customer)); $event->subscription->name = 'pro'; // Stripe names no plan $event->subscription->save(); }); ``` -------------------------------- ### Handle a webhook with Purchases::handle Source: https://github.com/roundly-consulting/purchases-for-laravel/blob/main/README.md Use the Purchases facade to verify the webhook signature, record the purchase, and fire lifecycle events. This is the single call needed from your own controller. ```php use RoundlyConsulting\Purchases\Facades\Purchases; $model = Purchases::handle('stripe', $request); // verify the signature, record, fire events ``` -------------------------------- ### Check subscription status with Purchases::for Source: https://github.com/roundly-consulting/purchases-for-laravel/blob/main/README.md Gate features on a user's subscription using the Purchases facade. The subscribedTo method returns a boolean, while activeSubscription returns a Subscription instance or null. ```php Purchases::for($user)->subscribedTo('pro'); // true Purchases::for($user)->activeSubscription('pro'); // ?Subscription ```