mirror of
https://github.com/coollabsio/coolify.git
synced 2026-06-14 03:19:51 +00:00
1a603a10ed
Replace all uses of `forceFill`, `forceCreate`, and `forceFill` with their non-force equivalents across models, actions, controllers, and Livewire components. Add explicit `$fillable` arrays to all affected Eloquent models to enforce mass assignment protection. Add ModelFillableCreationTest and ModelFillableRegressionTest to verify that model creation respects fillable constraints and prevent regressions.
82 lines
2.2 KiB
PHP
82 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Subscription extends Model
|
|
{
|
|
protected $fillable = [
|
|
'team_id',
|
|
'stripe_invoice_paid',
|
|
'stripe_subscription_id',
|
|
'stripe_customer_id',
|
|
'stripe_cancel_at_period_end',
|
|
'stripe_plan_id',
|
|
'stripe_feedback',
|
|
'stripe_comment',
|
|
'stripe_trial_already_ended',
|
|
'stripe_past_due',
|
|
'stripe_refunded_at',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'stripe_refunded_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function team()
|
|
{
|
|
return $this->belongsTo(Team::class);
|
|
}
|
|
|
|
public function billingInterval(): string
|
|
{
|
|
if ($this->stripe_plan_id) {
|
|
$configKey = collect(config('subscription'))
|
|
->search($this->stripe_plan_id);
|
|
|
|
if ($configKey && str($configKey)->contains('yearly')) {
|
|
return 'yearly';
|
|
}
|
|
}
|
|
|
|
return 'monthly';
|
|
}
|
|
|
|
public function type()
|
|
{
|
|
if (isStripe()) {
|
|
if (! $this->stripe_plan_id) {
|
|
return 'zero';
|
|
}
|
|
$subscription = Subscription::where('id', $this->id)->first();
|
|
if (! $subscription) {
|
|
return null;
|
|
}
|
|
$subscriptionPlanId = data_get($subscription, 'stripe_plan_id');
|
|
if (! $subscriptionPlanId) {
|
|
return null;
|
|
}
|
|
$subscriptionInvoicePaid = data_get($subscription, 'stripe_invoice_paid');
|
|
if (! $subscriptionInvoicePaid) {
|
|
return null;
|
|
}
|
|
$subscriptionConfigs = collect(config('subscription'));
|
|
$stripePlanId = null;
|
|
$subscriptionConfigs->map(function ($value, $key) use ($subscriptionPlanId, &$stripePlanId) {
|
|
if ($value === $subscriptionPlanId) {
|
|
$stripePlanId = $key;
|
|
}
|
|
})->first();
|
|
if ($stripePlanId) {
|
|
return str($stripePlanId)->after('stripe_price_id_')->before('_')->lower();
|
|
}
|
|
}
|
|
|
|
return 'zero';
|
|
}
|
|
}
|