Altura Code Billing for Laravel gives you a clean, Eloquent‑friendly way to work with subscriptions, products, features, and billing providers in Laravel apps.
// 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\SubscriptionThe 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.
- PHP 8.4+
- Laravel 12.x
- 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"
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\SubscriptionCheck a user’s subscription status:
if ($user->subscribed()) {
// has an active default subscription
}
$sub = $user->subscription('default'); // Eloquent model or nullQuery subscriptions:
use AlturaCode\Billing\Laravel\Subscription;
$active = Subscription::query()
->provider('sync')
->active()
->get();-
Trait:
AlturaCode\Billing\Laravel\Billablesubscription(string $name = 'default'): ?Subscriptionsubscriptions()Eloquent relation (morphMany)subscribed(string $name = 'default'): boolnewSubscription(string $name = 'default'): 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) andsubscriptionproperty for retrieving the Eloquent subscription model.
- Core
-
Service provider bindings:
BillingProviderRegistryis built fromconfig('billing.providers').- Repositories are bound from
config('billing.repositories.*').
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.
MIT License. See LICENSE for details.