juizmill/boleto-zend-framework

Zend Framework 的 boletos 模块

0.1.2 2017-08-11 20:24 UTC

This package is not auto-updated.

Last update: 2024-09-15 03:49:52 UTC


README

Packagist Build Status Packagist Code Climate Test Coverage Issue Count

Zend Framework 的 boletos 模块

本项目是基于 laravel-boleto 项目的 ZF3 版本。

配置

在文件 module.config.php 中添加 BoletoZendFramework

将文件 boleto-zendframework.golbal.php 复制到项目的 autoload 文件夹,此文件用于配置数据库的一些参数。

在控制器中,您可以这样做,其中 $this->boletoServiceboleto.zend.framework 服务

    public function boletoAction()
    {
        $pagador = [
            'nome' => 'Cliente',
            'endereco' => 'Rua um, 123',
            'bairro' => 'Bairro',
            'cep' => '99999-999',
            'uf' => 'UF',
            'cidade' => 'CIDADE',
            'documento' => '999.999.999-99',
        ];

        $dadosBoleto = [
            'dataVencimento' => new \Carbon\Carbon('1790-01-01'),
            'valor' => 100.00,
            'numero' => 1,
            'numeroDocumento' => 1,
            'codigoCliente' => 99999,
        ];

        $boleto = $this->boletoService->setDadosBoleto($dadosBoleto)
            ->setDadosPagador($pagador)
            ->getBoleto(BoletoServiceInterface::CAIXA);

        $response = new Response();
        $header = new Headers();
        $header->addHeaders([
            'Content-Type' => 'application/pdf',
            'Content-Disposition' => 'inline; boleto.pdf',
        ]);
        $response->setHeaders($header);
        $response->setStatusCode(200);
        $response->setContent($boleto->renderPDF());

        return $response;
    }

如果您希望使用策略,只需在 module.config.php 中添加即可

    'view_manager' => [
        'strategies' => [
            'ViewPdfStrategy'
        ],
    ]

在控制器中,您可以这样做

        $boleto = $this->boletoService->setDadosBoleto($dadosBoleto)
            ->setDadosPagador($pagador)
            ->getBoleto(BoletoServiceInterface::CAIXA);

        return new BoletoPdfModel(['data' => $boleto], ['name' => 'Nome do boleto para donwload']);