misaf / vendra-subscription
Generic plans and polymorphic subscriptions for Vendra applications
Package info
github.com/misaf/vendra-subscription
Type:vendra-module
pkg:composer/misaf/vendra-subscription
Requires
- php: ^8.3
- cknow/laravel-money: ^8.5
- misaf/vendra-support: v1.10.0
- spatie/laravel-package-tools: ^1.93.1
Requires (Dev)
- fakerphp/faker: ^1.24.1
- larastan/larastan: ^3.10.0
- laravel/boost: ^2.4.12
- laravel/pint: ^1.29.3
- mockery/mockery: ^1.6.12
- nunomaduro/collision: ^8.9.4
- orchestra/testbench: ^11.1
- pestphp/pest: ^5.0
- pestphp/pest-plugin-arch: ^5.0
- pestphp/pest-plugin-laravel: ^5.0
- pestphp/pest-plugin-profanity: ^5.0
- pestphp/pest-plugin-type-coverage: ^5.0
- phpstan/extension-installer: ^1.4.3
README
Generic plans and polymorphic subscriptions for Vendra applications.
Features
- Defines plans with periods, pricing, trials, grace windows, feature entitlements, and usage limits
- Stores price and currency snapshots for each subscription period
- Persists provider-neutral subscription payment operations with stable idempotency keys and lifecycle states
- Supports any Eloquent subscriber through a polymorphic relationship and the
SubscriptionSubscribercontract - Enforces one active subscription per subscriber
- Provides pending-payment, active, past-due, lapsed, and expiry-reminder lifecycle primitives
- Runs a durable, retriable payment engine — queued collection (
ProcessSubscriptionPayment), idempotent charge/retrieve, and reconciliation - Emits lifecycle events (
SubscriptionPaymentPaid/Failed,SubscriptionActivated,SubscriptionExpiringSoon,SubscriptionGraceExpired) for host reactions
The engine is subscriber-agnostic: subscribe, activate, charge, and enforce all operate through the SubscriptionSubscriber contract and never reference a concrete subscriber. Subscriber-specific reactions — the concrete subscriber model, quota enforcement, provisioning, and owner notifications — belong to the host application, which implements the contract and subscribes to the engine's events. Provider adapters implement the SubscriptionCharger contract exposed by misaf/vendra-support; they must never collect more than once for the same idempotency key and financial payload.
Requirements
- PHP 8.3+
- Laravel 13
misaf/vendra-support
Installation
composer require misaf/vendra-subscription php artisan vendor:publish --tag=vendra-subscription-migrations php artisan migrate
The host application defines the inverse morphMany relationship and registers stable morph aliases for its subscriber models.
Requeue stale, interrupted, or reconciliation-ready payment operations after an outage with:
php artisan vendra-subscription:recover-payments
Inspect reconciliation, stalled-processing, and paid-but-not-activated backlog without mutating payments:
php artisan vendra-subscription:report-payment-backlog php artisan vendra-subscription:report-payment-backlog --stale-minutes=60
Testing
Run the package checks from the package directory:
composer test
composer analyse
License
MIT. See LICENSE.