1. Go to this page and download the library: Download andalisolutions/anaf-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/ */
andalisolutions / anaf-php example snippets
/*
* Client used for unauthenticated requests
*/
$client = Anaf::client();
/*
* Client used for authenticated requests
*/
$authorizedClient = Anaf::authorizedClient($apiKey);
/*
* Build a client with a specific base URI, staging and more. Example:
*/
$factoryClient = Anaf::factory()
->withApiKey($apiKey)
->staging()
->withBaseUri('https://webservicesp.anaf.ro')
->make();
$companyInfo = $client->info()->create([
[
'cui' => '12345678',
'data' => '2021-01-01',
],
[
'cui' => '222222',
'data' => '2021-01-01',
]
]);
/*
* If you send one array, for one company, you will receive a CreateResponse object with the structure below.
* If you send multiple arrays, for multiple companies, you will receive a CreateResponses object with an array
* with CreateResponse objects.
*/
$companyInfo->generalData;
/* Accessible information in general data */
$companyInfo->generalData->companyName;
$companyInfo->generalData->address;
$companyInfo->generalData->registrationNumber;
$companyInfo->generalData->phone;
$companyInfo->generalData->fax;
$companyInfo->generalData->postalCode;
$companyInfo->generalData->document;
$companyInfo->generalData->registrationStatus;
$companyInfo->generalData->registrationDate;
$companyInfo->generalData->activityCode;
$companyInfo->generalData->bankAccount;
$companyInfo->generalData->roInvoiceStatus;
$companyInfo->generalData->authorityName;
$companyInfo->generalData->formOfOwnership;
$companyInfo->generalData->organizationalForm;
$companyInfo->generalData->legalForm;
$companyInfo->vatRegistration;
/* Accessible information in vat registration */
$companyInfo->vatRegistration->status;
//vatPeriods is an array from ANAF v8
$companyInfo->vatRegistration->vatPeriods[0]->startDate
$companyInfo->vatRegistration->vatPeriods[0]->stopDate;
$companyInfo->vatRegistration->vatPeriods[0]->stopEffectiveDate;
$companyInfo->vatRegistration->vatPeriods[0]->message;
$companyInfo->vatAtCheckout;
/* Accessible information in vat at checkout */
$companyInfo->vatAtCheckout->startDate;
$companyInfo->vatAtCheckout->stopDate;
$companyInfo->vatAtCheckout->updateDate;
$companyInfo->vatAtCheckout->publishDate;
$companyInfo->vatAtCheckout->updatedType;
$companyInfo->vatAtCheckout->status;
$companyInfo->inactiveState;
/* Accessible information in inactive state */
$companyInfo->inactiveState->inactivationDate;
$companyInfo->inactiveState->reactivationDate;
$companyInfo->inactiveState->publishDate;
$companyInfo->inactiveState->deletionDate;
$companyInfo->inactiveState->status;
$companyInfo->splitVat;
/* Accessible information in split tva */
$companyInfo->splitVat->startDate;
$companyInfo->splitVat->stopDate;
$companyInfo->splitVat->status;
$companyInfo->hqAddress;
/* Accessible information in hq address */
$companyInfo->hqAddress->street;
$companyInfo->hqAddress->no;
$companyInfo->hqAddress->city;
$companyInfo->hqAddress->cityCode;
$companyInfo->hqAddress->county;
$companyInfo->hqAddress->countyCode;
$companyInfo->hqAddress->countyShort;
$companyInfo->hqAddress->country;
$companyInfo->hqAddress->details;
$companyInfo->hqAddress->postalCode;
$companyInfo->fiscalAddress;
/* Accessible information in fiscal address */
$companyInfo->fiscalAddress->street;
$companyInfo->fiscalAddress->no;
$companyInfo->fiscalAddress->city;
$companyInfo->fiscalAddress->cityCode;
$companyInfo->fiscalAddress->county;
$companyInfo->fiscalAddress->countyCode;
$companyInfo->fiscalAddress->countyShort;
$companyInfo->fiscalAddress->country;
$companyInfo->fiscalAddress->details;
$companyInfo->fiscalAddress->postalCode;
// You can use all resources as array
$companyInfo->toArray(); // ["general_data" => ["tax_identification_number" => '', "company_name" => ''...]..]
// or
$companyInfo->generalData->toArray(); // ['tax_identification_number' => '', 'company_name' => ''...]
$entityInfo = $client->ngo()->create([
[
'cui' => '12345678',
'data' => '2021-01-01',
]
]);
$entityInfo->taxIdentificationNumber;
$entityInfo->searchDate;
$entityInfo->entityName;
$entityInfo->address;
$entityInfo->phone;
$entityInfo->postalCode;
$entityInfo->document;
$entityInfo->registrationStatus;
$entityInfo->startDate;
$entityInfo->endDate;
$entityInfo->status;
// You can use all resources as array
$entityInfo->toArray(); // ["tax_identification_number" => '', "entity_name" => ''...]
$upload = $authorizedClient->efactura()->upload(
xml_path: $pathToXmlFile,
taxIdentificationNumber: '12345678',
//standard: UploadStandard::UBL, // default value is UBL
//extern: false, // default value is false
//selfInvoice: false, // default value is false
);
$upload->responseDate, // 202401011640
$upload->executionStatus,
$upload->uploadIndex,
$file = $authorizedClient->efactura()->download([
'id' => '12345678',
]);
$file->getContent(); // string - You can save/download the content to a file
/*
* $xmlStandard can be one of the following: 'FACT1', 'FCN'.
* The default value is 'FACT1'
*/
$file = $client->efactura()->xmlToPdf($pathToXmlFile, $xmlStandard);
$file->getContent(); // string - You can save the pdf content to a file
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.