amohamed / offline-cashier
A Laravel package for managing offline and online subscriptions with support for cash, check, bank transfer, and Stripe payments
Requires
- php: ^7.3|^8.0
- dompdf/dompdf: ^1.0|^2.0
- guzzlehttp/guzzle: ^6.0|^7.0
- laravel/cashier: ^12.0|^13.0|^14.0|^15.0
- laravel/framework: ^7.0|^8.0|^9.0|^10.0|^11.0
- nesbot/carbon: ^2.0
- spatie/laravel-permission: ^4.0|^5.0|^6.0
- stripe/stripe-php: ^7.0|^8.0|^9.0|^10.0|^13.0|^16.2
- symfony/mailer: ^5.0|^6.0|^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0|^3.0
- mockery/mockery: ^1.3|^1.4|^1.5
- nunomaduro/collision: ^4.0|^5.0|^6.0|^7.0
- orchestra/testbench: ^5.0|^6.0|^7.0|^8.0
- pestphp/pest: ^1.0|^2.0
- pestphp/pest-plugin-laravel: ^1.0|^2.0
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^8.0|^9.0|^10.0
Suggests
- ext-gd: Required for PDF generation
- ext-intl: Required for currency formatting
- league/omnipay: Required for additional payment gateways
This package is auto-updated.
Last update: 2025-02-27 22:40:49 UTC
README
OfflineCashier is a Laravel package that provides subscription and payment management with support for both offline and online payment methods.
Features
- Subscription Management (create, cancel, resume, change plans)
- Multiple Payment Methods (cash, check, bank transfer, Stripe)
- Invoice Generation
- PDF Generation
- Email Notifications
- Stripe Integration
- Customizable Views
- Event System
- Automatic Feature Assignment: Automatically assigns features to subscriptions based on the selected plan.
- Customizable Feature Assignment: Provides a hook for developers to customize or override the default feature assignment logic.
Table of Contents
- Installation
- Configuration
- Basic Usage
- Payment Methods
- Events & Notifications
- Stripe Integration
- Invoice Generation
- Testing
Example Usage
Here's an example of how to use the SubscriptionService
and InvoiceService
within a Livewire component to manage subscriptions and payments:
namespace App\Livewire\Subscription; use Livewire\Component; use AMohamed\OfflineCashier\Models\Plan; use AMohamed\OfflineCashier\Models\Subscription; use Illuminate\Support\Facades\Auth; use AMohamed\OfflineCashier\Services\InvoiceService; use Illuminate\Support\Facades\Log; use AMohamed\OfflineCashier\Services\SubscriptionService; class SubscriptionComponent extends Component { public $plans; public $selectedPlan; public $paymentMethod = 'cash'; public $referenceNumber; protected $invoiceService; protected $subscriptionService; public function __construct() { $this->invoiceService = new InvoiceService(); $this->subscriptionService = new SubscriptionService(); } public function mount() { $this->plans = Plan::with('features')->get(); } public function selectPlan($planId) { $this->selectedPlan = Plan::find($planId); } public function subscribe() { $this->validate([ 'selectedPlan' => 'required', 'paymentMethod' => 'required|in:cash,check,bank_transfer,stripe', 'referenceNumber' => 'required_if:paymentMethod,cash,check,bank_transfer' ]); $subscription = $this->subscriptionService->create(Auth::user(), $this->selectedPlan, $this->paymentMethod); $payment = $subscription->payments()->create([ 'amount' => $this->selectedPlan->price, 'payment_method' => $this->paymentMethod, 'status' => 'completed', 'reference_number' => $this->referenceNumber, 'paid_at' => now(), ]); $this->invoiceService->generate($payment); session()->flash('message', 'Successfully subscribed to ' . $this->selectedPlan->name); $this->reset(['selectedPlan', 'paymentMethod', 'referenceNumber']); } public function render() { return view('livewire.subscription.subscription-component'); } }
Visual Representation
This image illustrates the subscription creation process and feature assignment.
Project Example
For a practical example of how to use the OfflineCashier package, check out this GitHub repository. It demonstrates the implementation of the package in a real-world project.