2017 © Pedro Peláez
 

library gerencianet

Wrapper for use GerenciaNet on Laravel FrameWork

image

igrejanet/gerencianet

Wrapper for use GerenciaNet on Laravel FrameWork

  • Wednesday, March 28, 2018
  • by devLopez
  • Repository
  • 1 Watchers
  • 1 Stars
  • 109 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 21 % Grown

The README.md

Igrejanet/GerenciaNet

Build Status, (*1)

O Pacote GerênciaNet é um wrapper desenvolvido para facilitar a integração com o Gateway de pagamentos GerênciaNet, (*2)

Instalação

Realize a Instalação do Pacote Via composer:, (*3)

$ composer require igrejanet/gerencianet

PS.: O pacote já vem com package auto-discovery para utilização com Laravel. A Classe Gerencianet é instanciada automaticamente em Singleton, (*4)

Utilização

Para utilizar o pacote, vamos separar o processo em 2: Criação da cobrança e Checkout da cobrança, (*5)

Criação da Cobrança

Esta etapa, em geral, é executada antes que o formulário de pagamento seja exibido., (*6)


<?php use Gerencianet\Gerencianet; use Igrejanet\GerenciaNet\ChargeCreator; use Igrejanet\GerenciaNet\Products; $gerencianet = new Gerencianet([ 'client_id' => 'meu_client_id', 'client_secret' => 'meu_client_secret', 'sandbox' => true // Ou false, caso em produção ]); $products = new Products(); $products->add('Carrinho Hot Wheels', 1500, 3); $products->add('Bolacha Maizena', 185, 2); $charge = new ChargeCreator($gerencianet); $charge->setInvoiceId(1); // Gerado pelo seu sistema $charge->setNotificationUrl('http://minhaloja.com'); $charge->setProducts($products); // Guarde bem este valor, vamos precisar dele na segunda etapa $charge_id = $charge->generateCharge();

Processo de Checkout

<?php

use Gerencianet\Gerencianet;
use Igrejanet\GerenciaNet\ChargeSender;
use Igrejanet\GerenciaNet\Customer\BillingAddress;
use Igrejanet\GerenciaNet\Customer\Customer;
use Igrejanet\GerenciaNet\Methods\BankingBillet;
use Igrejanet\GerenciaNet\Methods\CreditCard;
use Igrejanet\GerenciaNet\Methods\DiscountManager;

$gerencianet = new Gerencianet([
    'client_id'     => 'meu_client_id',
    'client_secret' => 'meu_client_secret',
    'sandbox'       => true // Ou false, caso em produção
]);

$customer = new Customer(
    'João Lopes',
    '32214653783',
    'joao@company.com',
    '3895281420',
    '1990-01-01'
);

$billingAddress = new BillingAddress(
    'Rua do Cachorro Toco',
    12,
    'São Pedo da Garça',
    '39400000',
    'Montes Claros',
    'MG'
);

// O desconto pode ser aplicado em centavos ou porcentagem.
//No caso de porcentagem, multiplicar o valor por 100
$discount = new DiscountManager(1000);

// Se o cliente pagar com boleto...
if($isBoleto) {
    $method = new BankingBillet();
    $method->setExpirationDate(7); // Em quantos dias o boleto deve vencer?
    $method->setCustomer($customer);

} else if($isCartao) {
    // Estas variáveis são repassadas pela tela de checkout
    $method = new CreditCard($paymentToken, $installments);

    $method->setCustomer($customer);

    // O End. de cobrança deve ser aplicado em pagamentos via CC
    $method->setBillingAddress($billingAddress);

    // O desconto pode ser aplicado em ambos os métodos
    $method->setDiscount($discount);
}

$chargeSender = new ChargeSender($gerencianet);

// A variável charge ID contém o valor definido na geração da cobrança
// Sem o charge_id, a cobrança não será enviada
// A variável response recebe um array contendo todos os dados da transação
$response = $chargeSender->sendPaymentRequest($method, $charge_id);

Notifications

O sistema do GerenciaNet envia uma notificação ao seu sistema sempre que o status da transação é alterado. Para receber estas notificações e os novos status da cobrança, faça:, (*7)

<?php

use Gerencianet\Gerencianet;
use Igrejanet\GerenciaNet\Notifications;

$gerencianet = new Gerencianet([
    'client_id'     => 'meu_client_id',
    'client_secret' => 'meu_client_secret',
    'sandbox'       => true // Ou false, caso em produção
]);

$notifications = new Notifications($gerencianet);

// O token é repassado via POST pelo sistema de notificações do GerenciaNet
$status = $notifications->receiveNotification($token);

Testes

Existem dois testes que devem ser executados separadamente, pois, antes de executá-los você deve setar o seu client_id e client_secret no arquivo phpunit.xml. Somente assim é possível testar a criação e o envio de cobranças para seu sandbox no GerênciaNet, (*8)

  • ChargeCreatorTest.php
  • ChargeSenderTest.php
  • IgrejanetTest.php

Ao executar o PHPUnit, somente os testes que não utilizam acesso à API são executados., (*9)

Para testar os arquivos acima, é necessário testá-los separadamente., (*10)

Futuro

Atualmente o package aceita somente os pagamentos via boleto e cartão. Existem planos de expansão para as demais formas ofereciadas pelo GerênciaNet. Contribuições são extremamente bem vindas, (*11)

The Versions

28/03 2018

dev-master

9999999-dev

Wrapper for use GerenciaNet on Laravel FrameWork

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matheus Lopes Santos

28/03 2018

1.4.0

1.4.0.0

Wrapper for use GerenciaNet on Laravel FrameWork

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matheus Lopes Santos

27/02 2018

1.3.0

1.3.0.0

Wrapper for use GerenciaNet on Laravel FrameWork

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matheus Lopes Santos

08/01 2018

1.2.1

1.2.1.0

Wrapper for use GerenciaNet on Laravel FrameWork

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matheus Lopes Santos

04/01 2018

1.2.0

1.2.0.0

Wrapper for use GerenciaNet on Laravel FrameWork

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matheus Lopes Santos

07/12 2017

1.1.4

1.1.4.0

Wrapper for use GerenciaNet on Laravel FrameWork

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matheus Lopes Santos

06/12 2017

1.1.3

1.1.3.0

Wrapper for use GerenciaNet on Laravel FrameWork

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matheus Lopes Santos

06/12 2017

1.1.2

1.1.2.0

Wrapper for use GerenciaNet on Laravel FrameWork

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matheus Lopes Santos

04/12 2017

1.1.1

1.1.1.0

Wrapper for use GerenciaNet on Laravel FrameWork

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matheus Lopes Santos

04/12 2017

1.1.0

1.1.0.0

Wrapper for use GerenciaNet on Laravel FrameWork

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matheus Lopes Santos

01/12 2017

1.0.0

1.0.0.0

Wrapper for use GerenciaNet on Laravel FrameWork

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matheus Lopes Santos