gildonei / unicred
Unicred PHP API
1.0.1
2019-09-18 20:09 UTC
Requires
- php: >=5.6
This package is auto-updated.
Last update: 2024-09-05 21:23:42 UTC
README
Unicred API
PHP 版本,用于消费 Unicred 银行服务 API(Cobweb - UBR - Unicred 巴西)。用于认证、发票和账单查询。
官方网站 - https://portal-api.e-unicred.com.br/api-portal/
依赖项
- PHP >= 5.6
安装 SDK
如果您已经有一个 composer.json
文件,只需将以下依赖项添加到您的项目中
"require": { "gildonei/unicred": "dev-master" }
添加依赖项到 composer.json
后,只需执行
composer install
或者,您可以直接在终端执行
composer require gildonei/unicred:dev-master
使用示例
账单登记
<?php use \Unicred\Environment; use \Unicred\UnicredApi; use \Unicred\Entity\Assignor; use \Unicred\Entity\Payer; use \Unicred\Entity\Address; use \Unicred\Entity\BankSlip; use \Unicred\Request\AuthenticationRequest; use \Unicred\Exception\UnicredRequestException; try { #Preparando o ambiente $ambiente = Environment::sandbox(); #Dados do Cedente (Cliente Unicred) $cedente = new Assignor(); $cedente->setBankAgency('BANK AGENCY NUMBER') ->setApiKey('SUA API KEY') ->setUser('SEU LOGIN') ->setPassword('SUA SENHA') ->setPayeeCode('SEU CÓDIGO DE BENEFICIÁRIO') ->setPortifolio('CÓDIGO VARIAÇÃO DA CARTEIRA'); #Obter o Token de Acesso $autenticacao = new AuthenticationRequest($cedente, $ambiente); $autenticacao->execute(); #Dados do boleto $parcelaId = 12304; $boleto = new BankSlip(); $boleto->setDueDate(new DateTime()) ->setValue(10.45) ->setYourNumber($parcelaId) ->setBankSlipNumber($parcelaId) ->getPayer() ->setName('Fulano de Tal') ->setPayerType(PAYER::PERSON) ->setDocument('44675831141') ->setEmail('Test@test.com') ->setCorporateName('Fulano de Tal') ->getAddress() ->setState('SC') ->setDistrict('Bairro') ->setCity('Cidade') ->setAddress('Logradouro com Número') ->setZip('99999-999'); $boleto->getDiscount() ->setIndicator(0) // Opções válidas no manual da Unicred ->setDateLimit(new DateTime()) ->setValue(0.00); $boleto->getFine() ->setIndicator(0) ->setDateLimit(new DateTime()) ->setValue(0.00); $boleto->getInterest() ->setIndicator(0) ->setDateLimit(new DateTime()) ->setValue(0.00); #Instancia a API $unicred = new UnicredApi($cedente, $ambiente); #Obtém o ID do boleto gerado $boletoId = $unicred->createBankSlip($boleto); #Atribui o ID do boleto Unicred ao objeto boleto $boleto->setBankSlipId($boletoId); # Consulta o objeto boleto na API - obtém código de barras e linha digitável $boleto = $unicred->consultBankSlip($boleto); #Output do objeto boleto (BankSlip) print_r($boleto); } catch (UnicredRequestException $e) { echo $e->getUnicredError()->getMessage(); } catch (Exception $e) { echo $e->getMessage(); }
账单查询
<?php use \Unicred\Environment; use \Unicred\UnicredApi; use \Unicred\Entity\Assignor; use \Unicred\Entity\BankSlip; use \Unicred\Request\AuthenticationRequest; use \Unicred\Exception\UnicredRequestException; try { #Preparando o ambiente $ambiente = Environment::sandbox(); #Dados do Cedente (Cliente Unicred) $cedente = new Assignor(); $cedente->setBankAgency('BANK AGENCY NUMBER') ->setApiKey('SUA API KEY') ->setUser('SEU LOGIN') ->setPassword('SUA SENHA') ->setPayeeCode('SEU CÓDIGO DE BENEFICIÁRIO') ->setPortifolio('CÓDIGO VARIAÇÃO DA CARTEIRA'); #Obter o Token de Acesso $autenticacao = new AuthenticationRequest($cedente, $ambiente); $autenticacao->execute(); #Dados do boleto $boleto = new BankSlip(); $boleto->setBankSlipId('TOKEN DO BOLETO'); # Consulta o objeto boleto na API - obtém código de barras e linha digitável $boleto = $unicred->consultBankSlip($boleto); #Output do objeto boleto (BankSlip) print_r($boleto); } catch (UnicredRequestException $e) { echo $e->getUnicredError()->getMessage(); } catch (Exception $e) { echo $e->getMessage(); }
感谢和参考文献
本 API 的实现和参考部分灵感来源于由 @netojoaobatista 开发的 Cielo API-3.0 项目 - https://github.com/DeveloperCielo/API-3.0-PHP
任何额外的贡献,如测试、改进、修复和进化都将非常受欢迎。