This LIB was built in order to make it flexible, so that everyone can use all features of all API versions.
You can access Iugu's official documentation by accessing this link.
Install the library using the command
composer require igorsamaral/iugu-php
To include the library in your project, just do the following:
<?php
require __DIR__ . " /vendor/autoload.php "
$ iugu = new IuguClient( " SUA_CHAVE_DE_API ");Client object: <?php
require __DIR__ . " /vendor/autoload.php "
$ iugu = new iuguClient(
" SUA_CHAVE_DE_API ",
[ " headers " => [ " MEU_HEADER_CUSTOMIZADO " => " VALOR HEADER CUSTOMIZADO " ]]
); And then, you can use the customer to make requests to yugu.com.br, as in the examples below.
Customers represent users of your store, or business. This object contains information about them, such as name, email and telephone, and other fields.
<?php
$ customer = $ iugu -> customers ()-> create ([
" email " => " [email protected] " ,
" name " => " João das Neves " ,
" notes " => " lorem... " ,
" phone " => " 999999999 " ,
" phone_prefix " => " 11 " ,
" cpf_cnpj " => " 11743685009 " ,
" zip_code " => " 76814112 " ,
" number " => " 100 " ,
" street " => " Rua Cabedelo " ,
" city " => " Porto Velho " ,
" state " => " RO " ,
" district " => " Marcos Freire " ,
" complement " => " complemento... " ,
" custom_variables " => [
" key " => " value "
]
]); <?php
$ customers = $ iugu -> customers ()-> getList (); <?php
$ customer = $ iugu -> customers ()-> get ([
" id " => " ID_DO_CLIENTE "
]);Token is a customer payment representation (eg your credit card), being fully safe, so that it is not possible for someone to get customer credit card information using this token. The token is generated for a specific transaction, making it even safer.
<?php
$ token = $ iugu -> paymentToken ()-> create ([
" account_id " => " ID_DA_SUA_CONTA_IUGU " ,
" customer_id " => " ID_DO_CUSTOMER " ,
" method " => " credit_card " ,
" data " => [
" number " => " 4242424242424242 " ,
" verification_value " => " 648 " ,
" first_name " => " João " ,
" last_name " => " das Neves " ,
" month " => " 01 " ,
" year " => " 2023 "
],
" test " => true ,
]);Simple charge via ticket or credit card.
<?php
$ charge = $ iugu -> charges ()-> create ([
" token " => " ID_DO_TOKEN_DE_PAGAMENTO_CRIADO " ,
" customer_id " => " ID_DO_CUSTOMER " ,
" total " => 10000 ,
" payer " => [
" cpf_cnpj " => " 84752882000 " ,
" name " => " João das Neves " ,
" address " => [
" zip_code " => " 72917210 " ,
" number " => " 100 "
]
],
" items " : [
[
" description " => " Descrição do item 1 " ,
" quantity " => 1 ,
" price_cents " => 10000
]
]
]);Creates an invoice for a customer.
<?php
$ invoice = $ iugu -> invoices ()-> create ([
" email " => " [email protected] " ,
" due_date " => " 2021-07-21 " ,
" items " => [
[
" description " => " Descrição do item 1 " ,
" quantity " => 1 ,
" price_cents " => 10000
]
],
" total " => 10000 ,
" payer " => [
" cpf_cnpj " => " 84752882000 " ,
" name " => " João das Neves " ,
" address " => [
" zip_code " => " 72917210 " ,
" number " => " 100 "
]
]
]); <?php
$ invoices = $ iugu -> invoices ()-> getList (); <?php
$ invoice = $ iugu -> invoices ()-> get ([
" id " => " ID_DA_FATURA "
]);