ソースを参照

feat(asaas): resolve a chave da matriz do banco com fallback para o .env

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ebagabee 4 週間 前
コミット
7809b7d511

+ 1 - 1
app/Jobs/SyncFranchiseeChargeJob.php

@@ -35,7 +35,7 @@ public function handle(AsaasClient $client, AsaasCustomerService $customerServic
     {
         // Asaas é opcional: se a matriz não tiver chave configurada, o recebível
         // segue como 'pending' para baixa manual — nenhuma cobrança é emitida.
-        if (empty(config('services.asaas.api_key'))) {
+        if (empty(\App\Models\CompanyPaymentAccount::resolveApiKey())) {
             Log::info("Asaas não configurado na matriz. Recebível #{$this->receive->id} seguirá para baixa manual.");
             return;
         }

+ 3 - 2
app/Services/Integrations/Asaas/AsaasClient.php

@@ -14,8 +14,9 @@ class AsaasClient
     public function __construct(?string $apiKey = null)
     {
         $this->baseUrl = config('services.asaas.base_url');
-        // Allows overriding the API key for subaccounts
-        $this->apiKey = $apiKey ?? config('services.asaas.api_key');
+        // Chave explícita (ex.: conta da unidade) tem prioridade. Sem ela, usa a
+        // chave da matriz resolvida do banco (UI) com fallback para o .env.
+        $this->apiKey = $apiKey ?? \App\Models\CompanyPaymentAccount::resolveApiKey();
     }
 
     protected function request(): PendingRequest