yaroslawww / laravel-cashier-subscription-pause
This package is abandoned and no longer maintained.
The author suggests using the think.studio/laravel-cashier-subscription-pause package instead.
Support of Pausing and Resuming a Subscription.
2.1.1
2023-12-06 12:47 UTC
Requires
- php: ^8.1
- laravel/cashier: ^14.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.16
- orchestra/testbench: ^8.5
- phpunit/phpunit: ^10.1
- psalm/plugin-laravel: ^2.8
- vimeo/psalm: ^5.11
README
Installation
Install the package via composer:
composer require think.studio/laravel-cashier-subscription-pause
You can publish the migrations files with:
php artisan vendor:publish --provider="CashierSubscriptionPause\ServiceProvider" --tag="migrations"
Usage
use CashierSubscriptionPause\Eloquent\UsesPauseCollection; use CashierSubscriptionPause\Eloquent\WithPauseCollection; class Subscription extends \Laravel\Cashier\Subscription implements WithPauseCollection { use UsesPauseCollection; protected $table = 'stripe_subscriptions'; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'quantity' => 'integer', 'pause_collection' => 'array', ]; }
$subscription = $user->subscription( 'main' ); $resumesAt = Carbon::now()->addWeek(); $subscription->pause(WithPauseCollection::BEHAVIOR_MARK_UNCOLLECTIBLE, $resumesAt); $subscription->unpause(); $subscription->pauseBehaviorMarkUncollectible($resumesAt); $subscription->pauseBehaviorKeepAsDraft($resumesAt); $subscription->pauseBehaviorVoid($resumesAt); $subscription->syncStripePauseCollection(); $subscription->paused()); $subscription->paused(WithPauseCollection::BEHAVIOR_MARK_UNCOLLECTIBLE); $subscription->paused(WithPauseCollection::BEHAVIOR_KEEP_AS_DRAFT); $subscription->paused(WithPauseCollection::BEHAVIOR_VOID); $subscription->pauseResumesAtTimestamp(); $subscription->pauseResumesAt();
Subscription::query()->paused()->count(); Subscription::query()->notPaused()->count(); Subscription::query()->paused(WithPauseCollection::BEHAVIOR_VOID)->count(); Subscription::query()->notPaused(WithPauseCollection::BEHAVIOR_VOID)->count(); Subscription::query()->paused(WithPauseCollection::BEHAVIOR_MARK_UNCOLLECTIBLE)->count(); Subscription::query()->notPaused(WithPauseCollection::BEHAVIOR_MARK_UNCOLLECTIBLE)->count(); Subscription::query()->paused(WithPauseCollection::BEHAVIOR_KEEP_AS_DRAFT)->count(); Subscription::query()->notPaused(WithPauseCollection::BEHAVIOR_KEEP_AS_DRAFT)->count();
Do not use default listener:
<?php namespace App\Providers; use CashierSubscriptionPause\Listeners\CashierWebhookHandledEventListener; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { public function boot() { // ... CashierWebhookHandledEventListener::deactivateListener(); } }