|CompanyPaymentAccount newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|CompanyPaymentAccount newQuery() * @method static \Illuminate\Database\Eloquent\Builder|CompanyPaymentAccount query() * @method static \Illuminate\Database\Eloquent\Builder|CompanyPaymentAccount whereAsaasApiKey($value) * @method static \Illuminate\Database\Eloquent\Builder|CompanyPaymentAccount whereAsaasWebhookId($value) * @method static \Illuminate\Database\Eloquent\Builder|CompanyPaymentAccount whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|CompanyPaymentAccount whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|CompanyPaymentAccount whereOnboardedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|CompanyPaymentAccount whereStatus($value) * @method static \Illuminate\Database\Eloquent\Builder|CompanyPaymentAccount whereUpdatedAt($value) * @mixin \Eloquent */ 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'); } }