PHP code example of enlivy / enlivy-php
1. Go to this page and download the library: Download enlivy/enlivy-php 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/ */
enlivy / enlivy-php example snippets
$client = new \Enlivy\EnlivyClient([
'api_key' => '1|your_api_token',
'organization_id' => 'org_xxx',
]);
// List invoices
$invoices = $client->invoices->list(['per_page' => 25]);
foreach ($invoices as $invoice) {
echo $invoice->id . "\n";
}
// Create
$invoice = $client->invoices->create([
'organization_receiver_user_id' => 'org_user_xxx',
'status' => 'draft',
'currency' => 'EUR',
'payment_method' => 'bank_transfer',
'delivery_method' => 'email',
'line_items' => [
[
'name_lang_map' => ['en' => 'Consulting Services'],
'quantity' => 10,
'price' => 100.00,
'type' => 'service',
],
],
]);
// Retrieve with related data
$invoice = $client->invoices->retrieve('org_inv_xxx', [
'
// Per-client configuration
$client = new \Enlivy\EnlivyClient([
'api_key' => '1|your_token',
'organization_id' => 'org_xxx',
'api_base' => 'https://api.enlivy.com',
'timeout' => 30,
]);
// Or global configuration
\Enlivy\Enlivy::setApiKey('1|your_token');
\Enlivy\Enlivy::setOrganizationId('org_xxx');
$client = new \Enlivy\EnlivyClient();
use Enlivy\Exception\{
ValidationException,
NotFoundException,
AuthenticationException,
RateLimitException,
};
try {
$invoice = $client->invoices->retrieve('org_inv_xxx');
} catch (ValidationException $e) {
$errors = $e->errors(); // ['field' => ['error message']]
} catch (NotFoundException $e) {
// 404
} catch (AuthenticationException $e) {
// 401
} catch (RateLimitException $e) {
$retryAfter = $e->retryAfter(); // seconds
}
$invoices = $client->invoices->list(['page' => 1, 'per_page' => 25]);
echo "Page " . $invoices->getCurrentPage() . " of " . $invoices->getTotalPages();
foreach ($invoices as $invoice) {
echo $invoice->id;
}
// List all available API resources
$resources = $client->discovery->list();
// Get detailed metadata for a specific resource
$invoiceSpec = $client->discovery->resource('organization_invoices');
'name_lang_map' => [
'en' => 'Consulting Services',
'ro' => 'Servicii de Consultanta',
],
bash
composer