1. Go to this page and download the library: Download igrejanet/gerencianet 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/ */
igrejanet / gerencianet example snippets
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();
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',
'[email protected]',
'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);
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);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.