Skip to content

Commit

Permalink
feat: Add Subscription model with Laravel Cashier
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] committed Mar 11, 2024
1 parent e42b7aa commit 6c0493c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions app/Models/Subscription.php
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
}
}
}

0 comments on commit 6c0493c

Please sign in to comment.