Failed to sign request

5 views
Skip to first unread message

Nathan Raposo

unread,
Jun 6, 2025, 3:20:43 PMJun 6
to qz-p...@googlegroups.com

Hello everyone, I'm using the demo certificate and I'm getting this error below. I'll post all the information I can for you to help me:

Ambient Linux Ubuntu

r/qztray - Failed to sign requestr/qztray - Failed to sign request

Route sing PHP:

try {
        $dataToSign = $request->input('data');

        if (!$dataToSign) {
            abort(400, 'Dados ausentes para assinatura.');
        }

        $privateKeyPath = storage_path('app/keys/private-key.pem');

        if (!file_exists($privateKeyPath)) {
            abort(500, 'Chave privada não encontrada.');
        }

        $privateKeyContent = file_get_contents($privateKeyPath);

        // Carrega a chave de forma segura com openssl_get_privatekey
        $privateKey = openssl_get_privatekey($privateKeyContent);

        if (!$privateKey) {
            abort(500, 'Erro ao carregar a chave privada.');
        }

        $signature = null;

        $success = openssl_sign($dataToSign, $signature, $privateKey, OPENSSL_ALGO_SHA512);
        
        openssl_free_key($privateKey);

        if (!$success || !$signature) {
            abort(500, 'Erro ao assinar os dados.');
        }

        return base64_encode($signature);
    } catch (Throwable $exception) {
        throw new AppException(
            message: __('payment::exceptions.payment.error_found'),
            previous: $exception
        );
    }
}

JS:

 const handlePrint = async () => {
    qz.websocket
      .connect()
      .then(() => {
        console.log(qz.printers.find());
        return qz.printers.find("PDF");
      })
      .then((found) => {
        const config = qz.configs.create(found);

        const cliente = {
          nome: "João da Silva",
          cpf: "123.456.789-00",
          pagamento: "Cartão de crédito",
          valor: 150.75,
          data: new Date().toLocaleString("pt-BR"),
          pedido: "Pedido #12345",
        };

        const data = [
          {
            type: "pixel",
            format: "html",
            flavor: "plain",
            data: `
         <div style="width: 260px; margin: 0 auto; font-family: monospace; font-size: 12px; padding-left: 10px;">
          <center>
            <h2 style="margin: 0;">Cota Fácil</h2>
            <p style="margin: 0;">CNPJ: 12.345.678/0001-90</p>
            <p style="margin: 0;">Rua Exemplo, 123 - Cidade/UF</p>
            <hr style="margin: 5px 0;" />
            <strong>COMPROVANTE DE PAGAMENTO</strong>
            <hr style="margin: 5px 0;" />
          </center>
          <p><strong>Tipo de Fatura:</strong> Boleto Detran</p>
          <p><strong>Nome:</strong> João da Silva</p>
          <p><strong>CPF:</strong> 080.387.309-33</p>
          <p><strong>Valor:</strong> R$ 155,81</p>
          <p><strong>Tipo de Pagamento:</strong> Cartão de crédito</p>
          <p><strong>Data:</strong> 03/06/2025</p>
          <p><strong>Protocolo:</strong> 1234</p>
          <hr style="margin: 5px 0;" />
          <center>
            <p>Obrigado pela preferência!</p>
            <p>--- Cota Fácil ---</p>
          </center>
        </div>
        `,
          },
        ];

        return qz.print(config, data);
      })
      .catch((err) => {
        console.error("Erro ao imprimir", err);
      })
      .finally(() => {
        console.log("Impressão finalizada");
        return qz.websocket.disconnect();
      });
  };

 const signature = () => {
    qz.security.setCertificatePromise((resolve, reject) => {
      resolve(certificateDemo);
    });
    qz.security.setSignatureAlgorithm("SHA512");
    qz.security.setSignaturePromise((toSign: string) => {
      return api
        .post("/payments/sign", { data: toSign })
        .then((response: any) => {
          console.log("Resposta sign: ", response.data);
          return response.data;
        })
        .catch((error: any) => {
          console.error("Erro ao assinar:", error);
          throw new Error("Erro ao assinar a requisição.");
        });
    });

    console.log("Certificado e assinatura configurados.");
  };

Lite Finocchiaro

unread,
Jun 6, 2025, 4:40:15 PMJun 6
to Nathan Raposo, qz-p...@googlegroups.com
Nathan:

Can you send logs?

From the QZ Tray Icon:
Advanced, Troubleshooting, Zip Logs (To Desktop)

You can share them off-list if they contain sensitive information, but they will tell us what value QZ-Tray is getting for your signature.

Please compare your signing code to our PHP or JavaScript examples. We also offer a  TypeScript signing example if that works better for your project. 

If you could share your code for qz.security.setSignaturePromise() for the sign-message.php attempt, it may be helpful.

PHP and Javascript signing tutorials are also available on our YouTube channel.

I look forward to your reply.

Regards,

Lite Finocchiaro
VP, QZ Industries

--
You received this message because you are subscribed to the Google Groups "qz-print" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qz-print+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/qz-print/CAMvs40MTcJz7yJj53FU2FScw7808HAF2Zi6SZPOTmS%2B%2Bg_3X6Q%40mail.gmail.com.

Tres Finocchiaro

unread,
Jun 9, 2025, 10:21:44 AMJun 9
to Lite Finocchiaro, Nathan Raposo, qz-p...@googlegroups.com
Error:  Failed to sign request at http://terminal.cotafacil.local:5173/node_modules/...

You'll have to debug your controller.  The logs suggest something's wrong with the URL you're using for setSignaturePromise.



Reply all
Reply to author
Forward
0 new messages