PHP code example of adaoex / zf2-phpbol

1. Go to this page and download the library: Download adaoex/zf2-phpbol library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

adaoex / zf2-phpbol example snippets


	 'modules' => array(
		...
		'PHPBol',
	)
     

'view_manager' => array(
   ...
   'template_map' => array(
	   ...
	   'boleto/layout' => __DIR__ . '/../../Application/view/layout/boletobb.phtml',
   ),
   'template_path_stack' => array(
	   ...
	   __DIR__ . '/../../Application/view',
   ),
),



namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use DOMPDFModule\View\Model\PdfModel;
use PHPBol\Boleto\Factory;

class BoletoController extends AbstractActionController
{
    public function boletoPdfAction()
    {
		/* seta layout para o boleto */
		$this->layout('layout/boletobb');
		
		$cedente = array(
            'nome'     => 'Nome da Empresa',
            'cpfcnpj'  => 'NUMERO CNPJ ou CPF',
            'endereco' => '',
            'bairro'   => '',
            'cidade'   => '',
            'uf'       => '',
            'cep'      => '',
        );

        $sacado = array(
            'logo'     => '',
            'nome'     => '',
            'cpfcnpj'  => '',
            'endereco' => '',
            'bairro'   => '',
            'cidade'   => '',
            'uf'       => '',
            'cep'      => '',
        );

        $avalista = array(
            'nome'     => '',
            'cpfcnpj'  => '',
        );
        
        $boletoData = array(
            'nossoNumero'          => $nossoNumero,
            'numeroDocumento'      => '',
            'dataVencimento'       => new \DateTime(),
            'dataEmissaoDocumento' => new \DateTime(),
            'dataProcessamento'    => new \DateTime(),
            'valorBoleto'          => 100.00,
            'quantidade'           => 1,
            'valorUnitario'        => null,
            'aceite'               => '',
            'especie'              => 'R$',
            'especieDoc'           => 'DM',
            'codigoBarra'          => '',
            'demonstrativo'        => '',
            'instrucoes'           => '<br />Senhor caixa,<br />'
                                    . '- Após o vencimento, cobrar multa de 2%<br />'
                                    . '- Após o vencimento, cobrar juros diário de 1%.<br />',
        );

        $img_logo = fread(fopen( realpath('./public/img/boleto/logobb.jpg'), "r"), filesize(realpath('./public/img/boleto/logobb.jpg')));
        
        $banco = array(
            'logo' => base64_encode($img_logo),
            'codigoCedente' => '0055',
            'codigo' => '001',
            'codigoDv' => '9',
            'agencia' => '0055',
            'agenciaDv' => '',
            'conta' => '0055',
            'contaDv' => 'X',
            'carteira' => '18',
            'variacao' =>  '027',
            'convenio' => '000555',
            'qtd_nosso_numero' => '17',
        );

        // Criando instância e definindo dados
        // Utilizando o recurso de chain
        $boleto = Factory::create('BB')
                ->setBanco($banco)
                ->setCedente($cedente)
                ->setSacado($sacado)
                ->setAvalista($avalista)
                ->setBoletoData($boletoData)
                ->setBarcodeImgBase64();
		
        $pdf = new PdfModel();
		/* Triggers PDF download, automatically appends ".pdf" */
        $pdf->setOption('filename', 'monthly-report');
        $pdf->setOption('paperSize', 'a4'); // Defaults to "8x11"
        $pdf->setOption('paperOrientation', 'landscape'); // Defaults to "portrait"
        
        // To set view variables
        $pdf->setVariables(array(
			'html' => $boleto->render('bb_boleto')'
        ));
        
        return $pdf;
    }
}

 
echo $this->html;