for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace PhpLightning\Invoice\Infrastructure\Controller;
use Gacela\Framework\DocBlockResolverAwareTrait;
use Gacela\Router\Entities\Request;
use PhpLightning\Invoice\InvoiceFacade;
use Throwable;
/**
* @method InvoiceFacade getFacade()
*/
final class InvoiceController
{
use DocBlockResolverAwareTrait;
public function __construct(
private Request $request,
) {
}
* @psalm-suppress InternalMethod
public function __invoke(string $username = '', int $amount = 0): string
try {
if ($amount === 0) {
$amount = (int)$this->request->get('amount');
return $this->json(
$this->getFacade()->getCallbackUrl($username),
);
$this->getFacade()->generateInvoice($username, $amount),
} catch (Throwable $e) {
return $this->error($e);
private function json(array $json): string
return json_encode($json, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT);
private function error(Throwable $e): string
return $this->json([
'status' => 'ERROR',
'message' => $e->getMessage(),
]);