pauloak/nfse-lajeado

用于在Lajeado-RS上创建NFSE的包。

1.0.2 2023-02-16 21:45 UTC

This package is auto-updated.

Last update: 2024-09-17 01:11:41 UTC


README

此包目前支持在巴西Lajeado/RS城市的Web服务中创建、检索和取消NFS-e(RPS)。

您可以通过composer安装它

composer require pauloak/nfse-lajeado

观察

要使用此包,您需要有效的.pfx证书及其密码,用于在发送到城市Web服务之前对XML进行签名。

用法

您可以在示例文件夹中查看一些用法示例,但这里有一个简要概述。

创建NFS-e

需要.pfx证书

use PauloAK\NfseLajeado\EnviarLoteRpsEnvio;
use PauloAK\NfseLajeado\Common\Rps;
use PauloAK\NfseLajeado\Common\Rps\Endereco;
use PauloAK\NfseLajeado\Common\Rps\Prestador;
use PauloAK\NfseLajeado\Common\Rps\Servico;
use PauloAK\NfseLajeado\Common\Rps\Tomador;
use PauloAK\NfseLajeado\Helpers\Constants;

const CERTIFICATE_PATH = '/path/to/certificate.pfx';
const CERTIFICATE_PASS = 'rand_pass';

$tomador = (new Tomador)
    ->cpfCnpj('000.000.000-00')
    ->telefone('51 99999-9999')
    ->email('email@example.com')
    ->razaoSocial('Example')
    ->endereco(
        (new Endereco)
            ->rua('Av. Test')
            ->numero('0000')
            ->bairro('Centro')
            ->codigoMunicipio('4311403') // IBGE Code
            ->uf('RS')
            ->cep('95900-000')
            ->complemento('')
    );

$servico = (new Servico)
    ->codigoCnae('0000000')
    ->itemListaServico('000')
    ->discriminacao('Test RPS')
    ->issRetido(Constants::NAO)
    ->valorServicos(99.99);

$prestador = (new Prestador)
    ->cnpj('00.000.0000/0001-00')
    ->im('00000');

$rps = (new Rps)
    ->tomador($tomador)
    ->prestador($prestador)
    ->servico($servico)
    ->serie('00000')
    ->numero(1)
    ->naturezaOperacao(Constants::NATUREZA_OPERACAO_IMPOSTO_RECOLHIDO_PELO_REGIME_UNICO_TRIBUTACAO)
    ->optanteSimplesNacional(Constants::SIM);

$lote = (new EnviarLoteRpsEnvio(CERTIFICATE_PATH, CERTIFICATE_PASS))
    ->numeroLote(2)
    ->cnpj('00.000.000/0001-00')
    ->im('00000')
    ->rps($rps);

// Sends to Homologation
$response = $lote->sendHml();

// See Responses section
if ($response->success) {
    // ...
}

// Sends to Production
// $response = $lote->send();

检索NFS-e

不需要.pfx证书

创建NFS-e后,您将收到一个协议号,您可以用来检索NFS-e。目前,此包只返回NFS-e号码和验证码。

use PauloAK\NfseLajeado\Common\Rps\Prestador;
use PauloAK\NfseLajeado\ConsultarLoteRpsEnvio;

$consulta = (new ConsultarLoteRpsEnvio)
    ->prestador(
        (new Prestador)
            ->cnpj('00.000.000/0001-00')
            ->im('00000')
    )
    ->protocolo('00000'); // The protocol number returned in the creation call

// Sends to homologation
$response = $consulta->sendHml();

// See Responses section
if ($response->success) {
    // ...
}

取消NFS-e

需要.pfx证书

要取消NFS-e,您需要NFS-e号码和证书。

use PauloAK\NfseLajeado\CancelarRps;

const CERTIFICATE_PATH = '/path/to/certificate.pfx';
const CERTIFICATE_PASS = 'rand_pass';

$cancelamento = (new CancelarRps(CERTIFICATE_PATH, CERTIFICATE_PASS))
    ->cnpj('00.000.000/0001-00')
    ->im('00000')
    ->numero('00000');

// Sends to homologation
$response = $cancelamento->sendHml();

// See Responses section
if ($response->success) {
    // ...
}

响应

所有上述请求都返回一个 PauloAK\NfseLajeado\Helpers\Response::class 实例,对象如下所示

(object)[
    'success' => true, // bool - Boolean representing if the call was successfull
    'requestXml' => '...', // string - The XML that was sent to the WebService
    'responseXml' => '...', // string - The response XML returned from the WebService
    'data' => [], // array - Some quick access data parsed from the request
    'errorCode' => 'E...', // string - In case of failure, the error code returned
    'errorMessage' => '...', // string - The detailed error message in case of failure
    'isHml' => false // bool - Shows in which envioriment the call was made
];

创建响应

在成功的情况下,响应对象中的数据变量应如下所示

[
    'nextLoteNumber' => 999, // Last Lote number + 1, you can use it in the next create call
    'nextRpsNumber' => 999, // Last RPS number + 1, you can use it in the next create call
    'protocolNumber' => '123456' // Protocol number, you can use it to retrieve the NFS-e
]

检索响应

在成功的情况下,响应对象中的数据变量应如下所示

[
    'number' => '20231', // NFS-e number
    'verificationNumber' => '12346', // NFS-e verification code
    'pdfUrl' => 'https://...' // URL to the NFSE PDF document - Only works for production 
]

您可以在$response->responseXml中查看NFS-e XML中的所有其他信息;

取消响应

取消请求不返回数据信息,请使用$response->success变量来检查是否成功取消。