From 6c0493ce8e8c3416c73b70b3b4af3de00db07614 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 11 Mar 2024 17:36:28 +0000 Subject: [PATCH] feat: Add Subscription model with Laravel Cashier --- app/Models/Subscription.php | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 app/Models/Subscription.php diff --git a/app/Models/Subscription.php b/app/Models/Subscription.php new file mode 100644 index 0000000..9210f94 --- /dev/null +++ b/app/Models/Subscription.php @@ -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 + } + } +}