Skip to content

Commit

Permalink
qr code classe que gera
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardokum committed Jan 17, 2024
1 parent 4ee76f8 commit dc4060e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"ext-curl": "*",
"ext-json": "*",
"ext-openssl": "*",
"simplesoftwareio/simple-qrcode": "^4.2",
"eduardokum/laravel-mail-auto-embed": "dev-master"
"eduardokum/laravel-mail-auto-embed": "dev-master",
"chillerlan/php-qrcode": "^1.0|^2.0|^3.0|^4.0|^5.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0|^7.0|^8.0|^9.0|^10.0",
Expand Down
11 changes: 6 additions & 5 deletions exemplos/pix_boleto_qrcode_copia_cola_localizacao.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

require 'autoload.php';
$beneficiario = new \Eduardokum\LaravelBoleto\Pessoa([
$beneficiario = new Eduardokum\LaravelBoleto\Pessoa([
'nome' => 'ACME',
'endereco' => 'Rua um, 123',
'cep' => '99999-999',
Expand All @@ -10,7 +10,7 @@
'documento' => '99.999.999/9999-99',
]);

$pagador = new \Eduardokum\LaravelBoleto\Pessoa([
$pagador = new Eduardokum\LaravelBoleto\Pessoa([
'nome' => 'Cliente',
'endereco' => 'Rua um, 123',
'bairro' => 'Bairro',
Expand All @@ -22,7 +22,7 @@

$boleto = new Eduardokum\LaravelBoleto\Boleto\Banco\Itau([
'logo' => realpath(__DIR__ . '/../logos/') . DIRECTORY_SEPARATOR . '341.png',
'dataVencimento' => new \Carbon\Carbon(),
'dataVencimento' => new Carbon\Carbon(),
'valor' => 100,
'multa' => false,
'juros' => false,
Expand All @@ -38,10 +38,11 @@
'aceite' => 'S',
'especieDoc' => 'DM',
'pix_qrcode' => '00020104141234567890123426660014BR.GOV.BCB.PIX014466756C616E6F32303139406578616D706C652E636F6D27300012BR.COM.OUTRO011001234567895204000053039865406123.455802BR5915NOMEDORECEBEDOR6008BRASILIA61087007490062530515RP12345678-201950300017BR.GOV.BCB.BRCODE01051.0.080450014BR.GOV.BCB.PIX0123PADRAO.URL.PIX/0123ABCD81390012BR.COM.OUTRO01190123.ABCD.3456.WXYZ6304EB76',
'qr_code_style' => Eduardokum\LaravelBoleto\Boleto\Banco\Itau::QRCODE_ESTILO_PONTO,
]);

$pdf = new Eduardokum\LaravelBoleto\Boleto\Render\Pdf();
$pdf->addBoleto($boleto);
//$pdf->setLocalizacaoPix(Eduardokum\LaravelBoleto\Boleto\Render\Pdf::PIX_INSTRUCAO);
$pdf->setLocalizacaoPix(Eduardokum\LaravelBoleto\Boleto\Render\Pdf::PIX_COD_BARRAS);
$pdf->setLocalizacaoPix(Eduardokum\LaravelBoleto\Boleto\Render\Pdf::PIX_INSTRUCAO);
//$pdf->setLocalizacaoPix(Eduardokum\LaravelBoleto\Boleto\Render\Pdf::PIX_COD_BARRAS);
echo $pdf->gerarBoleto();
31 changes: 22 additions & 9 deletions src/Boleto/AbstractBoleto.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
use Throwable;
use Carbon\Carbon;
use Illuminate\Support\Str;
use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;
use Eduardokum\LaravelBoleto\Util;
use SimpleSoftwareIO\QrCode\Generator;
use chillerlan\QRCode\Data\QRMatrix;
use Eduardokum\LaravelBoleto\MagicTrait;
use chillerlan\QRCode\Output\QROutputInterface;
use Eduardokum\LaravelBoleto\Boleto\Render\Pdf;
use Eduardokum\LaravelBoleto\Boleto\Render\Html;
use Eduardokum\LaravelBoleto\Boleto\Render\PdfCaixa;
Expand Down Expand Up @@ -36,7 +39,6 @@ abstract class AbstractBoleto implements BoletoContract
const TIPO_CHAVEPIX_ALEATORIA = 'aleatoria';
const QRCODE_ESTILO_QUADRADO = 'square';
const QRCODE_ESTILO_PONTO = 'dot';
const QRCODE_ESTILO_ARREDONDADO = 'round';

/**
* Campos necessários para o boleto
Expand Down Expand Up @@ -1859,7 +1861,7 @@ public function getQrCodeStyle()
*/
public function setQrCodeStyle($qrCodeStyle)
{
if (! in_array($qrCodeStyle, [self::QRCODE_ESTILO_QUADRADO, self::QRCODE_ESTILO_PONTO, self::QRCODE_ESTILO_ARREDONDADO])) {
if (! in_array($qrCodeStyle, [self::QRCODE_ESTILO_QUADRADO, self::QRCODE_ESTILO_PONTO])) {
throw new ValidationException(sprintf('Estilo QRCODE %s não é válido', $qrCodeStyle));
}

Expand All @@ -1884,13 +1886,24 @@ public function getPixQrCodeBase64()
return $this->getPixQrCode();
}

$qrCode = new Generator();
$qrCode->format('png');
$qrCode->style($this->getQrCodeStyle());
$qrCode->eye('circle');
$qrCode->size(400);
$options = new QROptions;
$options->outputType = QROutputInterface::GDIMAGE_PNG;
$options->addQuietzone = true;
$options->scale = 20;
$options->quietzoneSize = 1;
$options->drawLightModules = false;

if ($this->getQrCodeStyle() == self::QRCODE_ESTILO_PONTO) {
$options->drawCircularModules = true;
$options->circleRadius = .5;
$options->keepAsSquare = [
QRMatrix::M_FINDER_DOT,
QRMatrix::M_FINDER_DARK,
];
}
$qrCode = new QRCode($options);

return 'data:image/png;base64,' . base64_encode($qrCode->generate($this->getPixQrCode()));
return $qrCode->render($this->getPixQrCode());
}

/**
Expand Down

0 comments on commit dc4060e

Please sign in to comment.