Sfoglia il codice sorgente

feat(asaas): infra de webhook por unidade (coluna, config de URL e delete no client)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ebagabee 4 settimane fa
parent
commit
adf3825fdf

+ 11 - 0
app/Services/Integrations/Asaas/AsaasClient.php

@@ -46,4 +46,15 @@ public function post(string $endpoint, array $data = [])
 
         return $response->json();
     }
+
+    public function delete(string $endpoint)
+    {
+        $response = $this->request()->delete($endpoint);
+
+        if ($response->failed()) {
+            throw new AsaasException($response);
+        }
+
+        return $response->json();
+    }
 }

+ 2 - 0
config/services.php

@@ -39,6 +39,8 @@
         'base_url' => env('ASAAS_BASE_URL', 'https://sandbox.asaas.com/api/v3'),
         'api_key' => env('ASAAS_API_KEY'),
         'webhook_token' => env('ASAAS_WEBHOOK_TOKEN'),
+        // URL pública que a Asaas chama nos eventos. Fallback para APP_URL.
+        'webhook_url' => env('ASAAS_WEBHOOK_URL', rtrim(env('APP_URL', ''), '/') . '/api/webhooks/asaas'),
     ],
 
 ];

+ 26 - 0
database/migrations/2026_07_01_000002_add_webhook_id_to_unit_payment_accounts_table.php

@@ -0,0 +1,26 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Guarda o id do webhook criado na conta Asaas da unidade, para evitar
+     * duplicação e permitir remoção quando a chave é limpa.
+     */
+    public function up(): void
+    {
+        Schema::table('unit_payment_accounts', function (Blueprint $table) {
+            $table->string('asaas_webhook_id')->nullable()->after('asaas_api_key');
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::table('unit_payment_accounts', function (Blueprint $table) {
+            $table->dropColumn('asaas_webhook_id');
+        });
+    }
+};