Download the PHP package onaonbir/oo-subscription without Composer

On this page you can find all versions of the php package onaonbir/oo-subscription. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package oo-subscription

OO-Subscription

A backend-only subscription management package for Laravel. Built by OnaOnbir.

Supports polymorphic subscribables, immutable subscription rows, multi-language content, multi-currency pricing, feature usage tracking with overage billing, and a pluggable payment gateway contract.


Table of Contents


Installation

Publish the configuration and migrations:

The service provider (OnaOnbir\Subscription\SubscriptionServiceProvider) is auto-discovered.


Configuration

The config file is published to config/subscription.php.

Key Description Default
default_currency Default currency code for pricing 'TRY'
grace_period_days Default grace period after expiration 3
models Override any of the 7 model classes Base model classes
tables Override any of the 7 table names Default table names
gateway.driver Active gateway driver name null
gateway.handler PaymentGateway implementation class null

Models

The package provides 7 models. All use ULIDs as primary keys.

Plan

Represents a subscription plan with multi-language fields and multi-currency pricing.

Field Type Description
slug json Localized slugs ({"en": "pro", "tr": "pro"})
name json Localized names
description json Localized descriptions
prices json Currency-keyed prices in cents ({"USD": 1490, "TRY": 14900})
billing_interval enum monthly, yearly, or lifetime
trial_days int Number of trial days (0 for none)
grace_period_days int Grace period after expiration
sort_order int Display order
is_active bool Whether the plan is available
metadata json Arbitrary metadata

Relationships: features() (BelongsToMany), planFeatures() (HasMany), subscriptions() (HasMany)

Uses SoftDeletes.

Feature

Represents a capability that can be attached to plans or assigned directly.

Field Type Description
code string Unique identifier (e.g., api-requests)
slug json Localized slugs
name json Localized names
description json Localized descriptions
type enum boolean, quantity, or metered
resettable bool Whether usage resets each billing cycle
metadata json Arbitrary metadata

Uses SoftDeletes.

Subscription

An immutable record of a subscribable's subscription to a plan.

Field Type Description
subscribable morph Polymorphic owner (User, Team, etc.)
plan_id foreign key Associated plan
plan_snapshot json Immutable snapshot of plan at creation
gateway string Payment gateway identifier
gateway_subscription_id string External subscription ID
status enum active, trialing, past_due, canceled, expired
trial_ends_at datetime Trial end date
starts_at datetime Subscription start
ends_at datetime Subscription end / next renewal
cancels_at datetime Scheduled cancellation date
canceled_at datetime Actual cancellation timestamp
canceled_reason string Reason for cancellation
grace_ends_at datetime Grace period end
metadata json Arbitrary metadata

Methods: isActive(), isTrialing(), isPastDue(), isCanceled(), isExpired(), isValid(), onTrial(), onGracePeriod(), hasCancelScheduled(), isLifetime(), resolveCurrency(?string $override): string

PlanFeature (Pivot)

Pivot model connecting plans to features with plan-specific values.

Field Type Description
value string Limit value (e.g., '1000', 'true', null for unlimited)
overage_prices json Per-currency overage rates
metadata json Arbitrary metadata

SubscribableFeature

Direct feature assignment to a subscribable, independent of any plan.

Field Type Description
subscribable morph Polymorphic owner
feature_id foreign key Feature
value string Limit value
overage_prices json Per-currency overage rates
valid_from datetime Start of validity
valid_until datetime End of validity (null = indefinite)

Scopes: scopeCurrentlyValid() -- filters to features within their validity window.

FeatureUsage

Tracks current usage of a feature within a billing cycle.

UsageRecord

Immutable audit trail of individual usage events.


Enums

BillingInterval

Monthly, Yearly, Lifetime

Methods: addToDate(Carbon $date): ?Carbon -- calculates the next period end date.

SubscriptionStatus

Active, Trialing, PastDue, Canceled, Expired

Methods: activeStatuses(): array -- returns [Active, Trialing, PastDue].

FeatureType

Boolean, Quantity, Metered


HasSubscriptions Trait

Add to any Eloquent model to make it subscribable:

Subscription Methods

Method Returns Description
subscribe(Plan, ?currency, ?gateway, ?gatewayId) Subscription Create a new subscription
subscriptions() MorphMany All subscriptions
activeSubscriptions() Collection Active + Trialing + PastDue (cached per request)
clearSubscriptionCache() void Clear the cached active subscriptions
subscription(?Plan) ?Subscription Latest active subscription
subscribed() bool Has any active subscription
subscribedTo(Plan) bool Subscribed to a specific plan
onTrial() bool Currently on a trial
onGracePeriod() bool Currently in a grace period
subscriptionHistory() Collection All subscriptions ordered by date

Feature Methods

Method Returns Description
hasFeature(string $code) bool Has feature via plan or direct assignment
canUseFeature(string $code) bool Has feature and has remaining quota
remainingUsage(string $code) ?int Remaining usage (null = unlimited)
recordUsage(string $code, int $amount, ?array $metadata) FeatureUsage Record feature usage
subscribableFeatures() MorphMany Direct feature assignments
featureUsages() MorphMany All feature usage records

Actions

All actions are resolved from the container and follow an immutable pattern.

CreateSubscription

CancelSubscription

RenewSubscription

ChangePlan

RecordFeatureUsage


State Guards

Actions validate subscription state before executing. Invalid operations throw typed exceptions:

Action Allowed States Exception
CreateSubscription (new) DuplicateSubscriptionException if same plan already active
CancelSubscription Active, Trialing, PastDue InvalidSubscriptionStateException
RenewSubscription Active, Trialing, PastDue InvalidSubscriptionStateException
ChangePlan Active, Trialing, PastDue InvalidSubscriptionStateException
RecordFeatureUsage (any) InvalidArgumentException for bad input, FeatureLimitExceededException for limits

Events

Event Dispatched When
SubscriptionCreated New subscription created
SubscriptionActivated Subscription becomes active
SubscriptionCanceled Subscription canceled
SubscriptionExpired Subscription expired
SubscriptionRenewed Subscription renewed
PlanChanged Plan changed
FeatureLimitReached Usage limit reached
UsageRecorded Usage recorded
BillingCycleCompleted Billing cycle reset

Feature Types

Boolean

The subscribable either has the feature or does not. No usage tracking.

Quantity

A limited number of items per billing cycle.

Metered

Pay-as-you-go with an optional included amount.

Modeling Protocols (Boolean + Quantity Pattern)

For capabilities with both an on/off toggle and a numeric limit, use two features:

Then in your plan:

Check in your application:


Plan Snapshots

Each subscription stores an immutable snapshot of the plan at creation time. Plan changes never retroactively affect existing subscriptions.


Overage Pricing


Direct Feature Assignments

Assign features directly to a subscribable without requiring a plan:

Direct feature limits are additive with plan limits.


Usage Cycle Reset

For resettable features, the used counter resets to 0 when the billing period expires. A BillingCycleCompleted event is dispatched on reset.


Payment Gateway Integration

This package manages subscription state -- it does not process payments. Implement the PaymentGateway contract in your application:

Register in config/subscription.php:

Webhook handling is your responsibility. Create your own webhook controller and call the package's Actions directly.


Model Customization

Swap any model by extending the base class and updating the config:


Table Customization

Override table names in the config:


Scheduled Commands

subscription:process

Processes all pending lifecycle transitions:

Operation Result Event
Expire active status -> expired SubscriptionExpired
Activate trials status -> active SubscriptionActivated
Expire grace status -> expired SubscriptionExpired
Execute cancels status -> canceled SubscriptionCanceled
Reset usage used = 0 BillingCycleCompleted

Supports --expired, --trials, --grace, --cancellations, --usage-reset, and --dry-run flags.

subscription:status

Displays a status report with subscription counts and pending warnings.


Authorization

This package does not include authorization policies. You are responsible for implementing gates, policies, or middleware to control who can subscribe, cancel, change plans, etc.


Testing


Quick Start


License

MIT - See LICENSE for details.

Built with care by OnaOnbir.


All versions of oo-subscription with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/database Version ^11.0 || ^12.0
illuminate/support Version ^11.0 || ^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package onaonbir/oo-subscription contains the following files

Loading the files please wait ...