LaravelPackages.net
Acme Inc.
Toggle sidebar
roundly-consulting/purchases-for-laravel

Handle payments and subscriptions from Payment Gateways and In-App Purchases.

22
6
1.1.9
About roundly-consulting/purchases-for-laravel

roundly-consulting/purchases-for-laravel is a Laravel package for handle payments and subscriptions from payment gateways and in-app purchases.. It currently has 6 GitHub stars and 22 downloads on Packagist (latest version 1.1.9). Install it with composer require roundly-consulting/purchases-for-laravel. Discover more Laravel packages by roundly-consulting or browse all Laravel packages to compare alternatives.

Last updated

Purchases for Laravel — Roundly open source

Latest release Tests Code style Donate Patreon Crypto

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 (Stripe needs both PURCHASES_STRIPE_SECRET and 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.

Donate to Roundly open source Become a patron on Patreon Donate crypto: BTC, ETH, BNB or SOL

License

The MIT License (MIT). Please see License File for more information.

Comments