index.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. declare(strict_types=1);
  3. // Exiba erros durante o desenvolvimento
  4. ini_set('display_errors', '1');
  5. ini_set('display_startup_errors', '1');
  6. error_reporting(E_ALL);
  7. require __DIR__ . '/../vendor/autoload.php';
  8. use FrameworkX\App;
  9. use React\Http\Message\Response;
  10. function writeLog(string $event, string $body): void
  11. {
  12. $logLine = date('Y-m-d H:i:s') . " - [{$event}] - " . $body . PHP_EOL;
  13. file_put_contents(__DIR__ . '/../webhook.log', $logLine, FILE_APPEND);
  14. }
  15. $app = new App();
  16. $app->get('/', function () {
  17. return new Response(
  18. 200,
  19. ['Content-Type' => 'application/json'],
  20. json_encode(['message' => 'Webhook Service is up'])
  21. );
  22. });
  23. $app->post('/genial/cashin', function ($request) {
  24. $body = (string) $request->getBody();
  25. writeLog('/genial/cashin', $body);
  26. return new Response(200, ['Content-Type' => 'application/json'], json_encode(['status' => 'success']));
  27. });
  28. $app->post('/genial/cashout', function ($request) {
  29. $body = (string) $request->getBody();
  30. writeLog('/genial/cashout', $body);
  31. return new Response(200, ['Content-Type' => 'application/json'], json_encode(['status' => 'success']));
  32. });
  33. $app->post('/{webhook}', function ($request, string $webhook) {
  34. $body = (string) $request->getBody();
  35. writeLog($webhook, $body);
  36. return new Response(200, ['Content-Type' => 'application/json'], json_encode(['status' => 'success']));
  37. });
  38. $app->run();