| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace App\Jobs;
- use App\Models\Unit;
- use App\Services\Integrations\Asaas\AsaasAccountService;
- use Exception;
- use Illuminate\Bus\Queueable;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Queue\SerializesModels;
- use Illuminate\Support\Facades\Log;
- class CreateAsaasSubaccountJob implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- public int $unitId;
- public int $tries = 3;
- public function __construct(int $unitId)
- {
- $this->unitId = $unitId;
- }
- public function handle(AsaasAccountService $accountService): void
- {
- $unit = Unit::find($this->unitId);
- if (!$unit) {
- Log::warning("CreateAsaasSubaccountJob: Unidade {$this->unitId} não encontrada.");
- return;
- }
- try {
- $accountService->ensureSubaccount($unit);
- Log::info("CreateAsaasSubaccountJob: Subconta criada com sucesso para a Unidade {$unit->id}.");
- } catch (Exception $e) {
- Log::error("CreateAsaasSubaccountJob: Falha ao criar subconta para Unidade {$unit->id}.", [
- 'error' => $e->getMessage()
- ]);
- throw $e; // Throw to retry if needed
- }
- }
- }
|