console.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. use App\Commands\ConfirmarPagamento;
  3. use App\Commands\CreateCrud;
  4. use App\Commands\RefreshPagarmeEntities;
  5. use App\Commands\RefreshPermissions;
  6. use App\Commands\TestWebsocketEvent;
  7. use App\Models\Provider;
  8. use App\Services\Pagarme\PagarmeTransferService;
  9. use App\Services\ProviderWithdrawalService;
  10. use Illuminate\Foundation\Inspiring;
  11. use Illuminate\Support\Facades\Artisan;
  12. use App\Jobs\InvalidateExpiredSchedules;
  13. use Illuminate\Support\Facades\Schedule;
  14. Artisan::command('inspire', function () {
  15. $this->comment(Inspiring::quote());
  16. })->purpose('Display an inspiring quote');
  17. Artisan::command('create:crud {name} {--m|model} {--s|service} {--c|controller} {--r|request} {--e|resource} {--t|route} {--g|migration} {--all}', function () {
  18. $this->call(CreateCrud::class, [
  19. 'name' => $this->argument('name'),
  20. '--model' => $this->option('model'),
  21. '--service' => $this->option('service'),
  22. '--controller' => $this->option('controller'),
  23. '--request' => $this->option('request'),
  24. '--resource' => $this->option('resource'),
  25. '--route' => $this->option('route'),
  26. '--migration' => $this->option('migration'),
  27. '--all' => $this->option('all'),
  28. ]);
  29. })->purpose('Create CRUD operations with typed Models');
  30. Artisan::command('permissions:refresh', function () {
  31. $this->call(RefreshPermissions::class);
  32. })->purpose('Refresh all permissions and user type permissions');
  33. Artisan::command('pagarme:refresh-entities', function () {
  34. $this->call(RefreshPagarmeEntities::class);
  35. })->purpose('Limpa os recipients e clients locais e os recria no Pagar.me');
  36. Artisan::command('websocket:test {room} {--event=test-event} {--data=}', function () {
  37. $this->call(TestWebsocketEvent::class, [
  38. 'room' => $this->argument('room'),
  39. '--event' => $this->option('event'),
  40. '--data' => $this->option('data'),
  41. ]);
  42. })->purpose('Test websocket broadcasting by emitting an event');
  43. Artisan::command('confirma_pagamento {payment_id?}', function () {
  44. $this->call(ConfirmarPagamento::class, [
  45. 'payment_id' => $this->argument('payment_id'),
  46. ]);
  47. })->purpose('[LOCAL] Simula a confirmacao de pagamento do ultimo agendamento solicitado');
  48. //
  49. Artisan::command('pagarme:recipient-balance {recipient_id} {--skip-local}', function (
  50. PagarmeTransferService $pagarmeTransfer,
  51. ProviderWithdrawalService $withdrawals,
  52. ) {
  53. $recipientId = $this->argument('recipient_id');
  54. if (! $this->option('skip-local')) {
  55. $provider = Provider::query()
  56. ->where('recipient_id', $recipientId)
  57. ->first();
  58. if ($provider) {
  59. $this->info('Saldo calculado localmente:');
  60. $this->line(sprintf(' available: R$ %s', number_format($withdrawals->getAvailableBalance($provider), 2, ',', '.')));
  61. $this->line(sprintf(' pending: R$ %s', number_format($withdrawals->getPendingBalance($provider), 2, ',', '.')));
  62. $this->newLine();
  63. } else {
  64. $this->warn('Nenhum provider local encontrado para esse recipient_id.');
  65. $this->newLine();
  66. }
  67. }
  68. $this->info('Saldo retornado pelo Pagar.me:');
  69. $this->line(json_encode($pagarmeTransfer->getRecipientBalance($recipientId), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
  70. })->purpose('Consult Pagar.me recipient balance and compare it with local withdrawal balance');
  71. Schedule::job(new InvalidateExpiredSchedules)->dailyAt('05:00');