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\JsonResponse;
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 = ''): JsonResponse
try {
$amount = (int)$this->request->get('amount');
if ($amount === 0) {
return new JsonResponse(
$this->getFacade()->getCallbackUrl($username),
);
$this->getFacade()->generateInvoice($username, $amount),
} catch (Throwable $e) {
dump($e);
return new JsonResponse([
'status' => 'ERROR',
'message' => $e->getMessage(),
]);