58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\SubscriptionPlan;
|
|
use Database\Factories\SubscriptionInvoiceFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
/**
|
|
* A snapshot of a Moneybird sales invoice tied to a subscription — one row
|
|
* per invoice we've seen, kept in sync via webhook (and the daily sync
|
|
* command as a fallback) so the billing page can show payment history
|
|
* without calling Moneybird on every page load.
|
|
*
|
|
* @property int $id
|
|
* @property int $subscription_id
|
|
* @property string $moneybird_invoice_id
|
|
* @property SubscriptionPlan $plan
|
|
* @property int $amount_cents
|
|
* @property string $state
|
|
* @property Carbon|null $invoice_date
|
|
* @property Carbon|null $due_date
|
|
* @property Carbon|null $paid_at
|
|
* @property string|null $payment_url
|
|
* @property Carbon|null $created_at
|
|
* @property Carbon|null $updated_at
|
|
*/
|
|
#[Fillable(['moneybird_invoice_id', 'plan', 'amount_cents', 'state', 'invoice_date', 'due_date', 'paid_at', 'payment_url'])]
|
|
class SubscriptionInvoice extends Model
|
|
{
|
|
/** @use HasFactory<SubscriptionInvoiceFactory> */
|
|
use HasFactory;
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'plan' => SubscriptionPlan::class,
|
|
'invoice_date' => 'date',
|
|
'due_date' => 'date',
|
|
'paid_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Subscription, $this>
|
|
*/
|
|
public function subscription(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Subscription::class);
|
|
}
|
|
}
|