PHP code example of wagnermontanini / apinfefasa
1. Go to this page and download the library: Download wagnermontanini/apinfefasa 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/ */
wagnermontanini / apinfefasa example snippets
WagnerMontanini\ApiNfeFasa\ProductInvoices;
$invoices = new ProductInvoices(
"http://fasa_nfe.test/v1",
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvbmZlLmZhc2FpbmZvcm1hdGljYS5jb20uYnJcL3YxXC9hdXRoXC90b2tlbiIsImlhdCI6MTYyNTQ5MTQyOSwiZXhwIjoxNjI1NTc3ODI5LCJuYmYiOjE2MjU0OTE0MjksImp0aSI6InJPbXVORU5JUk1BSUkzb20iLCJzdWIiOiJkYzU4ZGMwNS00MDUyLTQ4ZjgtYTU4OS01ZTIwMjllMzRmYzkiLCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.58K2S3ApGsgpgX56Ldto3pTKg9V2Mo2tEVkZd1jIuh0",
"71b1be22-68f9-4887-8597-914c035aa4ea"
);
/**
* READ
*/
echo "<h1>READ</h1>";
$invoice = $invoices->read("35123456789123456789123456789123456789123456");
if ($invoice->error()) {
echo "<p class='error'>{$invoice->error()->message}</p>";
} else {
$invoiceData = $invoice->response()->data;
var_dump(
$invoiceData
);
}
WagnerMontanini\ApiNfeFasa\Me;
$me = new Me(
"http://fasa_nfe.test/v1"
);
/**
* register
*/
echo "<h1>Register</h1>";
$user = $me->register(array(
"name"=> "Fasa Informatica LTDA",
"email"=> "[email protected] ",
"cnpj"=> "18349966000102",
"tax_regime"=> "none",
"password"=> "123456789",
"address"=> [
"postal_code"=> "18520000",
"street"=> "Rua Teste",
"number"=> "120",
"district"=> "centro",
"city_code"=> "3511508"
]
));
var_dump($user->response());
/**
* login
*/
echo "<h1>Login</h1>";
$user = $me->auth("[email protected] ","123456789");
var_dump($user->response());
var_dump($user->error());
/**
* me
*/
echo "<h1>ME</h1>";
$user = $me->me();
var_dump($user->response());
/**
* logout
*/
echo "<h1>Logout</h1>";
$user = $me->logout();
var_dump($user->response());
WagnerMontanini\ApiNfeFasa\Companies;
$companies = new Companies(
"http://fasa_nfe.test/v1",
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvbmZlLmZhc2FpbmZvcm1hdGljYS5jb20uYnJcL3YxXC9hdXRoXC90b2tlbiIsImlhdCI6MTYyNTQ5MTQyOSwiZXhwIjoxNjI1NTc3ODI5LCJuYmYiOjE2MjU0OTE0MjksImp0aSI6InJPbXVORU5JUk1BSUkzb20iLCJzdWIiOiJkYzU4ZGMwNS00MDUyLTQ4ZjgtYTU4OS01ZTIwMjllMzRmYzkiLCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.58K2S3ApGsgpgX56Ldto3pTKg9V2Mo2tEVkZd1jIuh0"
);
/**
* index
*/
echo "<h1>INDEX</h1>";
$index = $companies->index(null);
if ($index->error()) {
var_dump($index->error());
} else {
var_dump($index->response());
}
/**
* create
*/
echo "<h1>CREATE</h1>";
$create = $companies->create([
"name"=> "Fasa Informatica LTDA",
"trade_name"=> "Fasa Informatica",
"email"=> "[email protected] ",
"cnpj"=> "18349966000102",
"tax_regime"=> "none",
"address"=> [
"postal_code"=> "18520000",
"street"=> "Rua Teste",
"number"=> "120",
"district"=> "centro",
"city_code"=> "3511508" ]
]);
if ($create->error()) {
echo "<p class='error'>{$create->error()->message}</p>";
} else {
var_dump($create->response());
}
/**
* READ
*/
echo "<h1>READ</h1>";
$read = $companies->read("71b1be22-68f9-4887-8597-914c035aa4ea");
if ($read->error()) {
echo "<p class='error'>{$read->error()->message}</p>";
} else {
var_dump($read->response());
}
/**
* UPDATE
*/
echo "<h1>UPDATE</h1>";
$update = $companies->update("71b1be22-68f9-4887-8597-914c035aa4ea", [
"name"=> "Fasa Informatica LTDA",
"trade_name"=> "Fasa Informatica",
"email"=> "[email protected] ",
"cnpj"=> "18349966000102",
"tax_regime"=> "none",
"address"=> [
"postal_code"=> "18520000",
"street"=> "Rua Teste",
"number"=> "120",
"district"=> "centro",
"city_code"=> "3511508" ]
]);
if ($update->error()) {
echo "<p class='error'>{$update->error()->message}</p>";
} else {
var_dump($update->response());
}
/**
* DELETE
*/
echo "<h1>DELETE</h1>";
$delete = $companies->delete("71b1be22-68f9-4887-8597-914c035aa4ea");
if ($delete->error()) {
echo "<p class='error'>{$delete->error()->message}</p>";
} else {
var_dump($delete->response());
}