AsaasSmokeTestCommand.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Services\Integrations\Asaas\AsaasClient;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Str;
  6. class AsaasSmokeTestCommand extends Command
  7. {
  8. protected $signature = 'asaas:smoke-test';
  9. protected $description = 'Executa um teste de fumaça criando um cliente e uma cobrança no Asaas Sandbox';
  10. public function handle()
  11. {
  12. $this->info('Iniciando teste de fumaça com o Asaas...');
  13. $client = new AsaasClient();
  14. try {
  15. $this->info('1. Criando Customer de teste...');
  16. $customer = $client->post('/customers', [
  17. 'name' => 'Teste Fumaça ' . Str::random(5),
  18. 'cpfCnpj' => '12345678909', // CPF matematicamente válido para testes
  19. 'email' => 'teste@ginasticacerebro.com.br',
  20. ]);
  21. $customerId = $customer['id'];
  22. $this->info("Customer criado com sucesso: $customerId");
  23. $this->info('2. Criando Cobrança (Payment) PIX...');
  24. $payment = $client->post('/payments', [
  25. 'customer' => $customerId,
  26. 'billingType' => 'PIX',
  27. 'value' => 10.50,
  28. 'dueDate' => now()->addDays(5)->format('Y-m-d'),
  29. 'description' => 'Cobrança Teste de Fumaça',
  30. ]);
  31. $this->info('Cobrança criada com sucesso: ' . $payment['id']);
  32. $this->info('Link de pagamento: ' . $payment['invoiceUrl']);
  33. $this->info('Teste finalizado com sucesso! 🎉');
  34. } catch (\Exception $e) {
  35. $this->error('Falha no teste: ' . $e->getMessage());
  36. return Command::FAILURE;
  37. }
  38. return Command::SUCCESS;
  39. }
  40. }