Skip to content

Commit

Permalink
boleto email
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardokum committed Nov 28, 2023
1 parent f312c57 commit db0c7fa
Show file tree
Hide file tree
Showing 8 changed files with 435 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
/composer.lock
.phpunit.result.cache
.vs/
arquivos/*.txt
exemplos/arquivos/*.txt
exemplos/teste.php
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"ext-curl": "*",
"ext-json": "*",
"ext-openssl": "*",
"simplesoftwareio/simple-qrcode": "^4.2"
"simplesoftwareio/simple-qrcode": "^4.2",
"eduardokum/laravel-mail-auto-embed": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0",
Expand Down
3 changes: 2 additions & 1 deletion exemplos/arquivos/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*
!.gitignore
!*.ret
!*.ret
!template.blade.php
9 changes: 9 additions & 0 deletions exemplos/arquivos/template.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<img src="{{ $logo }}"/>
<h1>{{ $empresa }}</h1></body>
</html>
72 changes: 72 additions & 0 deletions exemplos/boleto_mail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

require 'autoload.php';
$beneficiario = new \Eduardokum\LaravelBoleto\Pessoa([
'nome' => 'ACME',
'endereco' => 'Rua um, 123',
'cep' => '99999-999',
'uf' => 'UF',
'cidade' => 'CIDADE',
'documento' => '99.999.999/9999-99',
]);

$pagador = new \Eduardokum\LaravelBoleto\Pessoa([
'nome' => 'Cliente',
'endereco' => 'Rua um, 123',
'bairro' => 'Bairro',
'cep' => '99999-999',
'uf' => 'UF',
'cidade' => 'CIDADE',
'documento' => '999.999.999-99',
]);

$boleto = new Eduardokum\LaravelBoleto\Boleto\Banco\Bancoob([
'logo' => realpath(__DIR__ . '/../logos/') . DIRECTORY_SEPARATOR . '756.png',
'dataVencimento' => new \Carbon\Carbon(),
'valor' => 100,
'multa' => false,
'juros' => false,
'numero' => 1,
'numeroDocumento' => 1,
'pagador' => $pagador,
'beneficiario' => $beneficiario,
'carteira' => 1,
'agencia' => 1111,
'convenio' => 123123,
'conta' => 22222,
'descricaoDemonstrativo' => ['demonstrativo 1', 'demonstrativo 2', 'demonstrativo 3'],
'instrucoes' => ['instrucao 1', 'instrucao 2', 'instrucao 3'],
'aceite' => 'S',
'especieDoc' => 'DM',
]);

$configsCasoNaoTenhaUmMailerConfiguradoNoSeuLaravel = [
'scheme' => 'smtp',
'port' => 'porta',
'host' => 'smtp.host.com',
'username' => 'usuario',
'password' => 'senha',
'from' => ['address' => 'empresa@empresa.com', 'name' => 'Empresa'],
];

$mail = new Eduardokum\LaravelBoleto\Boleto\Mail($boleto, 'email@cliente.com', $configsCasoNaoTenhaUmMailerConfiguradoNoSeuLaravel);

$data = [
'empresa' => 'Nome da empresa',
'logo' => 'full/path/logo.png',
];

$mail->send(['arquivos/template.blade.php', $data], 'assunto');

$mail->send(
[
'<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"></head><body><img src="{{ $logo }}"/><h1>{{ $empresa }}</h1></body></html>',
$data,
],
'assunto'
);

$mail->send(
'Email simples sem template',
'assunto'
);
41 changes: 41 additions & 0 deletions src/Boleto/LaravelBoletoMailer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Eduardokum\LaravelBoleto\Boleto;

use Exception;
use Illuminate\Mail\Mailer;
use Illuminate\Foundation\Application;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Container\ContainerExceptionInterface;
use Eduardokum\LaravelMailAutoEmbed\Listeners\SymfonyEmbedImages;
use Eduardokum\LaravelMailAutoEmbed\Contracts\Listeners\EmbedImages;

class LaravelBoletoMailer extends Mailer
{
/**
* @param $message
* @param $data
* @return bool
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
protected function shouldSendMessage($message, $data = [])
{
if (self::isLaravel9Plus() && ! app()->bound(EmbedImages::class)) {
try {
(new SymfonyEmbedImages(config()->get('mail-auto-embed')))->handle($message);
}
catch (Exception $e){}
}

return parent::shouldSendMessage($message, $data);
}

/**
* @return bool|int
*/
public static function isLaravel9Plus()
{
return version_compare(Application::VERSION, '9.0.0', '>=');
}
}
Loading

0 comments on commit db0c7fa

Please sign in to comment.