| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- /**
- * Conta Asaas da franqueadora (matriz). Linha única.
- *
- * @property int $id
- * @property string|null $asaas_api_key
- * @property string|null $asaas_webhook_id
- * @property string $status
- * @property \Illuminate\Support\Carbon|null $onboarded_at
- */
- class CompanyPaymentAccount extends Model
- {
- public const STATUS_PENDING = 'pending';
- public const STATUS_ACTIVE = 'active';
- protected $table = 'company_payment_accounts';
- protected $guarded = ['id'];
- protected $casts = [
- 'asaas_api_key' => 'encrypted',
- 'onboarded_at' => 'datetime',
- 'created_at' => 'datetime',
- 'updated_at' => 'datetime',
- ];
- /**
- * A (única) conta da matriz.
- */
- public static function current(): self
- {
- return static::query()->first() ?? new self();
- }
- /**
- * Chave efetiva da matriz: banco → fallback .env.
- */
- public static function resolveApiKey(): ?string
- {
- $key = static::query()->first()?->asaas_api_key;
- return filled($key) ? $key : config('services.asaas.api_key');
- }
- }
|