alturacode / billing-laravel
AlturaCode Billing for Laravel
Installs: 3
Dependents: 0
Suggesters: 1
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/alturacode/billing-laravel
Requires
- php: >=8.4
- alturacode/billing-core: ^0.9.1
- illuminate/database: ^12.0
- illuminate/http: ^12.0
Suggests
- alturacode/billing-stripe: Stripe Billing Adapter for Altura Code Billing Package.
README
Altura Code Billing for Laravel gives you a clean, Eloquent‑friendly way to work with subscriptions, products, features, and billing providers in Laravel apps.
TL;DR
// Add the Billable trait to your billable model (e.g., User). use AlturaCode\Billing\Laravel\Billable; class User extends Model { use Billable; } // Create a subscription $result = $user->newSubscription('default') ->withPlanPriceId('price_basic_monthly') ->withTrialDays(14) ->create(); if ($result->requiresAction()) { return $result->redirect(); // e.g., off-site checkout or SCA } $subscription = $result->subscription; // AlturaCode\Billing\Laravel\Subscription
The default provider is a synchronous in-memory provider (great for demos and tests). Swap it for a real provider by
implementing BillingProvider from the core package and wiring it in the config.
Requirements
- PHP 8.4+
- Laravel 12.x
Installation
- Install the package
composer require alturacode/billing-laravel
The service provider is auto-discovered.
- Add the
Billabletrait to your billable model (usuallyApp\Models\User)
use AlturaCode\Billing\Laravel\Billable; class User extends Model { use Billable; }
- Publish the config file and migrations
php artisan vendor:publish --provider="AlturaCode\Billing\Laravel\BillingServiceProvider"
Quick start
Create a subscription for a user:
// In a controller action $result = $request->user()->newSubscription('default') ->withPlanPriceId('price_basic_monthly', quantity: 1) ->withTrialDays(14) ->create(); if ($result->requiresAction()) { return $result->redirect(); } $subscription = $result->subscription; // AlturaCode\Billing\Laravel\Subscription
Check a user’s subscription status:
if ($user->subscribed()) { // has an active default subscription } $sub = $user->subscription('default'); // Eloquent model or null
Query subscriptions:
use AlturaCode\Billing\Laravel\Subscription; $active = Subscription::query() ->provider('sync') ->active() ->get();
High-level API surface
-
Trait:
AlturaCode\Billing\Laravel\Billablesubscription(string $name = 'default'): ?Subscriptionsubscriptions()Eloquent relation (morphMany)subscribed(string $name = 'default'): boolnewSubscription(string $name): SubscriptionBuilder
-
Builder:
AlturaCode\Billing\Laravel\SubscriptionBuilder(delegates to CoreSubscriptionDraftBuilder)withName(string $name)withBillable(string $billableType, string $billableId)withProvider(string $provider)withPlanPriceId(string $priceId, int $quantity = 1)withTrialEndsAt(DateTimeImmutable|null $trialEndsAt)withTrialDays(int $days)withAddon(string $priceId, int $quantity = 1)create(array $providerOptions = []): AlturaCode\Billing\Laravel\BillingProviderResult
-
Models:
AlturaCode\Billing\Laravel\Subscription(Eloquent)- Relations:
items(),billable() - Helpers:
isActive(),isPaused(),isCanceled(),isIncomplete() - Scopes:
provider(),name(),active(),paused(),canceled(),incomplete() - Conversion:
toCore()-> CoreAlturaCode\Billing\Core\Subscriptions\Subscription
- Relations:
AlturaCode\Billing\Laravel\SubscriptionItem(Eloquent)- Conversion:
toCore()-> CoreAlturaCode\Billing\Core\Subscriptions\SubscriptionItem
- Conversion:
-
Result:
- Core
AlturaCode\Billing\Core\Provider\BillingProviderResult- Properties:
subscription,clientAction - Methods:
requiresAction()
- Properties:
- Laravel convenience wrapper
AlturaCode\Billing\Laravel\BillingProviderResultaddsredirect()(when used).
- Core
-
Service provider bindings:
BillingProviderRegistryis built fromconfig('billing.providers').- Repositories are bound from
config('billing.repositories.*').
Providers
The package ships with SynchronousBillingProvider (no external calls). To integrate with a real provider:
- Implement the Core interface
AlturaCode\Billing\Core\Provider\BillingProviderin your app (e.g.App\Billing\StripeProvider). - Add it to
config('billing.providers')and setconfig('billing.provider')to its key. - In your implementation, return a
BillingProviderResult::redirect(...)when a client action (e.g. checkout) is required, orBillingProviderResult::completed(...)when done.
License
MIT License. See LICENSE for details.