41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* One Stripe Price a priced catalogue row has had, live or superseded.
|
|
*
|
|
* `plan_prices.stripe_price_id` points at the one that is on sale; this is the
|
|
* history behind it, and it exists because a Stripe Price cannot be edited. When
|
|
* the amount a row is charged at changes — the move from net to gross, or a
|
|
* change to the VAT rate — a new Price is minted, this row is archived, and the
|
|
* old Price stays live in Stripe for as long as a contract is still billing on
|
|
* it. See the migration for why that history has to be readable.
|
|
*/
|
|
class StripePlanPrice extends Model
|
|
{
|
|
protected $guarded = [];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'charged_cents' => 'integer',
|
|
'archived_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function planPrice(): BelongsTo
|
|
{
|
|
return $this->belongsTo(PlanPrice::class);
|
|
}
|
|
|
|
/** Is this the Price the catalogue is selling on right now? */
|
|
public function isLive(): bool
|
|
{
|
|
return $this->archived_at === null;
|
|
}
|
|
}
|