-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Subscription model with Laravel Cashier
- Loading branch information
1 parent
e42b7aa
commit 6c0493c
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Laravel\Cashier\Billable; | ||
|
||
class Subscription extends Model | ||
{ | ||
use Billable; | ||
|
||
protected $fillable = [ | ||
'name', 'stripe_id', 'stripe_status', 'stripe_plan', 'quantity', 'trial_ends_at', 'ends_at', | ||
]; | ||
|
||
public function user() | ||
{ | ||
return $this->belongsTo(User::class); | ||
} | ||
|
||
public function isActive() | ||
{ | ||
return $this->stripe_status === 'active'; | ||
} | ||
|
||
public function cancel() | ||
{ | ||
$this->subscription('default')->cancel(); | ||
} | ||
|
||
public function renew() | ||
{ | ||
if ($this->onGracePeriod()) { | ||
$this->subscription('default')->resume(); | ||
} else { | ||
// Handle logic for subscriptions that are not in grace period | ||
} | ||
} | ||
} |