PHP code example of egcservices / iugu-php-sdk
1. Go to this page and download the library: Download egcservices/iugu-php-sdk 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/ */
egcservices / iugu-php-sdk example snippets
use bubbstore\Iugu;
use bubbstore\Iugu\Exceptions\IuguException;
use bubbstore\Iugu\Exceptions\IuguValidationException;
$iugu = new Iugu('SEU_TOKEN');
$customer = $iugu->customer()->create([
'name' => 'User Test',
'email' => '[email protected] ',
]);
// Imprime o ID do cliente
echo $customer['id'];
$customer = $iugu->customer()->update('ID_CLIENTE', [
'name' => 'John'
]);
$customer = $iugu->customer()->find('ID_CLIENTE');
var_dump($customer);
$iugu->customer()->delete('ID_CLIENTE');
$charge = $iugu->charge()->create([
'method' => 'bank_slip',
'email' => '[email protected] ',
'order_id' => uniqid(),
'payer' => [
'cpf_cnpj' => '65634052076',
'name' => 'User Test',
'phone_prefix' => '11',
'phone' => '111111111',
'email' => '[email protected] ',
'address' => [
'street' => 'Foo Bar',
'number' => '123',
'district' => 'Foo',
'city' => 'Foo',
'state' => 'SP',
'zip_code' => '14940000',
],
],
'items' => [
[
'description' => 'Item 1',
'quantity' => 1,
'price_cents' => 1000
],
[
'description' => 'Item 2',
'quantity' => 2,
'price_cents' => 2000
],
],
]);
$charge = $iugu->charge()->create([
'invoice_id' => '12345678',
'token' => '0000000000000000' // Token gerado através da lib iugu.js
]);
$invoice = $iugu->invoice()->create([
'order_id' => uniqid(),
'email' => '[email protected] ',
'due_date' => '2018-07-14',
'notification_url' => 'https://webhook.site/08703bf2-d408-4f4c-b91c-0bc8e14352b2',
'fines' => false,
'per_day_interest' => false,
'discount_cents' => 500,
'ignore_due_email' => true,
'payable_with' => 'bank_slip',
'items' => [
[
'description' => 'Item 1',
'quantity' => 1,
'price_cents' => 1000
],
[
'description' => 'Item 2',
'quantity' => 2,
'price_cents' => 2000
],
[
'description' => 'Frete',
'quantity' => 1,
'price_cents' => 1000
],
],
'payer' => [
'cpf_cnpj' => '65634052076',
'name' => 'User Test',
'phone_prefix' => '11',
'phone' => '11111111',
'email' => '[email protected] ',
'address' => [
'street' => 'Foo Bar',
'number' => '123',
'district' => 'Foo',
'city' => 'Foo',
'state' => 'SP',
'zip_code' => '14940000',
],
],
]);
// Imprime o ID da fatura
echo $invoice['id'];
$iugu->invoice()->capture('ID_FATURA');
$iugu->invoice()->find('ID_FATURA');
$iugu->invoice()->refund('ID_FATURA');
$iugu->invoice()->cancel('ID_FATURA');
$payment = $iugu->paymentMethod()->create('ID_CLIENTE', [
'description' => 'Cartão de Crédito',
'token' => '123456',
]);
// Imprime o ID do pagamento
echo $payment['id'];
$iugu->paymentMethod()->update('ID_CLIENTE', 'ID_METODO_PAGAMENTO', [
'description' => 'Outra description',
]);
$iugu->paymentMethod()->find('ID_CLIENTE', 'ID_METODO_PAGAMENTO');
$iugu->paymentMethod()->delete('ID_CLIENTE', 'ID_METODO_PAGAMENTO');
bash
$ composer