roundly-consulting / purchases-for-laravel
Handle payments and subscriptions from Payment Gateways and In-App Purchases.
Package info
github.com/roundly-consulting/purchases-for-laravel
pkg:composer/roundly-consulting/purchases-for-laravel
Fund package maintenance!
Requires
- php: ^8.4
- ext-bcmath: *
- illuminate/contracts: ^12.0|^13.0
- roundly-consulting/crypto-for-laravel: ^1.0
- roundly-consulting/enums-for-laravel: ^1.0
- roundly-consulting/money-for-laravel: ^1.0
- roundly-consulting/package-toolkit-for-laravel: ^1.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.18
- nunomaduro/collision: ^8.5
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- roundly-consulting/testing-for-laravel: ^1.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Purchases for Laravel
One API for Apple App Store, Google Play and Stripe purchases and subscriptions. It verifies every store's webhooks natively, records purchases, subscriptions and refunds as Eloquent models, and fires lifecycle events, with no third-party SDKs.
Installation
Requires PHP 8.4 (ext-bcmath) and Laravel 12 or 13.
composer require roundly-consulting/purchases-for-laravel
php artisan purchases:install --providers # publishes config + migrations, appends the providers' .env keys
php artisan migrate
If your owner models have UUID/ULID keys, set PURCHASES_KEY_TYPE before migrating. Fill in
each provider's credentials (for Stripe, PURCHASES_STRIPE_WEBHOOK_SECRET) and set
PURCHASES_ROUTES_ENABLED=true to receive webhooks at POST /purchases/webhooks/{provider}.
Usage
The bundled route verifies, records and fires events for you. From your own controller it is one call:
use RoundlyConsulting\Purchases\Facades\Purchases; $model = Purchases::handle('stripe', $request); // verify the signature, record, fire events
A store never says which of your users paid, so link the owner in a listener:
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(); });
Then gate features on it:
Purchases::for($user)->subscribedTo('pro'); // true Purchases::for($user)->activeSubscription('pro'); // ?Subscription
Documentation
The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/purchases-for-laravel
Release notes are in CHANGELOG.md. To contribute, see the contributing guide.
Support our work
This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.
License
The MIT License (MIT). Please see License File for more information.