1. Go to this page and download the library: Download tudorr89/fgo-php-api-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/ */
tudorr89 / fgo-php-api-sdk example snippets
use FgoApi\Client;
use FgoApi\Enums\Environment;
use FgoApi\Types\AddressClient;
use FgoApi\Types\InvoiceLine;
$client = new Client(
codUnic: 'YOUR_CUI',
privateKey: 'YOUR_PRIVATE_KEY',
platformUrl: 'https://your-app.com',
environment: Environment::Test,
);
// Create an invoice
$invoice = $client->invoices()->create(
series: 'BV',
currency: 'RON',
invoiceType: 'Factura',
clientData: new AddressClient(
name: 'Ionescu Popescu',
country: 'RO',
county: 'Bucuresti',
type: 'PF',
),
lines: [
new InvoiceLine(
name: 'Servicii Consultanta',
quantity: 2,
unit: 'ORE',
vatRate: 19,
unitPrice: 150.00,
),
],
);
echo "Invoice: {$invoice->series}{$invoice->number}\n";
echo "PDF: {$invoice->pdfLink}\n";
use FgoApi\Laravel\Fgo;
use FgoApi\Types\AddressClient;
use FgoApi\Types\InvoiceLine;
$invoice = Fgo::invoices()->create(
series: 'BV',
currency: 'RON',
invoiceType: 'Factura',
clientData: new AddressClient(name: 'Acme SRL'),
lines: [new InvoiceLine(name: 'Service', quantity: 1, unit: 'BUC', vatRate: 19, unitPrice: 100)],
);
use FgoApi\Client;
public function __construct(private readonly Client $fgo) {}
namespace App\Fgo;
use App\Models\Tenant;
use FgoApi\Laravel\Contracts\CredentialsResolver;
class TenantCredentialsResolver implements CredentialsResolver
{
public function resolve(?string $key = null): array
{
$tenant = $key
? Tenant::findOrFail($key)
: Tenant::current();
return [
'cod_unic' => $tenant->fgo_cod_unic,
'private_key' => decrypt($tenant->fgo_private_key),
'platform_url' => $tenant->platform_url,
'environment' => $tenant->fgo_environment, // "test" or "production"
];
}
}
use FgoApi\Laravel\Fgo;
// Current tenant — resolver is called with null
Fgo::invoices()->create(...);
// Specific tenant — resolver is called with the key, result cached for the request
Fgo::for($tenantId)->invoices()->create(...);
// Ad-hoc credentials (e.g. testing, one-off jobs)
Fgo::make([
'cod_unic' => '...',
'private_key' => '...',
'platform_url' => 'https://my-app.test',
'environment' => 'test',
])->invoices()->getStatus('001', 'BV');
// After rotating credentials
Fgo::forget($tenantId);
// in a service provider
config(['fgo.resolver' => fn (?string $key) => Tenant::resolve($key)->fgoConfig()]);
use FgoApi\Hash;
// Invoice creation — Y', 'Client Name');
// Invoice operations (print, cancel, etc.) — ata
Hash::forArticle('CUI', 'PRIVATE_KEY');
use FgoApi\Enums\Environment;
// Test (UAT)
new Client(..., environment: Environment::Test);
// Production
new Client(..., environment: Environment::Production);
// Custom URL
new Client(..., environment: 'https://custom-fgo.example.com/v1');
try {
$invoice = $client->invoices()->create(...);
} catch (ValidationException $e) {
// 400 / `Errors` map from API
print_r($e->getErrors());
} catch (AuthenticationException $e) {
// 401 / 403 — wrong CUI or private key
} catch (RateLimitException $e) {
sleep(max(1, $e->getRetryAfter()));
// ...retry
} catch (FgoApiException $e) {
// All other API errors
}
bash
php artisan vendor:publish --tag=fgo-config
bash
git clone https://github.com/tudorr89/fgo-php-api-sdk
cd fgo-php-api-sdk
composer install
# Static analysis
composer analyse
# Run tests
composer test
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.