'array', 'status_history' => 'array', 'provider_metadata' => 'array', 'coupon_snapshot' => 'array', 'discount_breakdown' => 'array', 'expires_at' => 'datetime', 'completed_at' => 'datetime', 'accepted_terms_at' => 'datetime', 'accepted_privacy_at' => 'datetime', 'accepted_withdrawal_notice_at' => 'datetime', 'digital_content_waiver_at' => 'datetime', 'amount_subtotal' => 'decimal:2', 'amount_total' => 'decimal:2', 'amount_discount' => 'decimal:2', ]; /** * Default attributes. */ protected $attributes = [ 'status_history' => '[]', 'package_snapshot' => '[]', 'provider_metadata' => '[]', 'coupon_snapshot' => '[]', 'discount_breakdown' => '[]', ]; public function user(): BelongsTo { return $this->belongsTo(User::class); } public function tenant(): BelongsTo { return $this->belongsTo(Tenant::class); } public function package(): BelongsTo { return $this->belongsTo(Package::class)->withTrashed(); } public function coupon(): BelongsTo { return $this->belongsTo(Coupon::class); } public function scopeActive($query) { return $query->whereNotIn('status', [ self::STATUS_COMPLETED, self::STATUS_CANCELLED, ])->where(function ($inner) { $inner->whereNull('expires_at')->orWhere('expires_at', '>', now()); }); } public function scopeByProviderId($query, string $providerField, string $value) { return $query->where($providerField, $value); } public function isExpired(): bool { return (bool) $this->expires_at && $this->expires_at->isPast(); } public function requiresCustomerAction(): bool { return $this->status === self::STATUS_REQUIRES_CUSTOMER_ACTION; } }