ANAFBinHelper
extends ANAFAPIClient
in package
Table of Contents
Properties
- $Timeout : float
- $AccessToken : AccessToken|null
Methods
- __construct() : mixed
- CheckTVAStatus() : TVAResponse
- Check if a company is registered for TVA
- DoEntityFetch() : EntityResponse
- Base method for fetching company/institution data from ANAF
- DownloadAndExtractAnswer() : ExtractedAnswer
- Uses DownloadAnswer to get the zip file and then extracts it to check for errors, optionally verifies the signature of the answer)
- GetAccessToken() : AccessToken|null
- Gets the current access token (if it exists), tries to load it from the file if necessary
- GetAnswerPage() : InternalPagedAnswersResponse
- Call the paged answer list endpoint with a speicifc page number
- GetEntity() : EntityResponse
- Get company/institution data from ANAF
- GetLoginURL() : string
- Helper method for the initial OAuth2 login
- HasAccessToken() : bool
- Check if the client has a valid access token.
- HasSuggestedExtensionSupport() : bool
- Check if the client has support for answer extraction (libxml, openssl, dom)
- IsProduction() : bool
- ListAnswers() : ANAFAnswerListResponse
- Get answer list for a company (authenticated user must have access to the company!)
- ListAnswersWithPagination() : PagedAnswerListResponse
- Get answer list for a company (authenticated user must have access to the company!) Uses the paged API end point Answers will be returned in a unified list
- LoadAccessToken() : AccessToken|null
- Loads the access token from the file specified in TokenFilePath
- LogOutput() : void
- ProcessOAuthCallback() : AccessToken|null
- Gets the access token from ANAF, should be called from the OAuth callback script
- RefreshAccessToken() : bool
- Refresh the access token using the refresh token
- RemoveSchemaLocationAttribute() : string
- Removes the xsi:schemaLocation attribute from the root element of the UBL XML
- TokenWillExpireSoon() : bool|null
- Checks if the current access token will expire soon
- UBL2PDF() : string|false
- Convert UBL XML to PDF using the ANAF API
- UploadEFactura() : UBLUploadResponse
- ValidateCIF() : bool
- Verifies a CUI given the official checksum algorithm
- VerifyConfig() : void
- VerifyXML() : ANAFVerifyResponse
- ATTENTION DOES NOT FUNCTION RELIABLY. The API randomly returns "nok" for valid invoices.
Properties
$Timeout
public
float
$Timeout
= 5
Outgoing request timeout in seconds
$AccessToken
protected
AccessToken|null
$AccessToken
= null
Methods
__construct()
public
__construct(string $configFilePath) : mixed
Parameters
- $configFilePath : string
CheckTVAStatus()
Check if a company is registered for TVA
public
CheckTVAStatus(string $cui) : TVAResponse
Parameters
- $cui : string
Return values
TVAResponseDoEntityFetch()
Base method for fetching company/institution data from ANAF
public
DoEntityFetch(false|string $sanitizedCUI, EntityResponse $response) : EntityResponse
Parameters
- $sanitizedCUI : false|string
- $response : EntityResponse
Return values
EntityResponseDownloadAndExtractAnswer()
Uses DownloadAnswer to get the zip file and then extracts it to check for errors, optionally verifies the signature of the answer)
public
DownloadAndExtractAnswer(string $id, bool $verifySignature) : ExtractedAnswer
Parameters
- $id : string
- $verifySignature : bool
Return values
ExtractedAnswerGetAccessToken()
Gets the current access token (if it exists), tries to load it from the file if necessary
public
GetAccessToken() : AccessToken|null
Return values
AccessToken|nullGetAnswerPage()
Call the paged answer list endpoint with a speicifc page number
public
GetAnswerPage(int $startTime, int $endTime, int $cif, int $pageNumber[, AnswerFilter|null $filter = null ]) : InternalPagedAnswersResponse
Parameters
- $startTime : int
- $endTime : int
- $cif : int
- $pageNumber : int
- $filter : AnswerFilter|null = null
Return values
InternalPagedAnswersResponseGetEntity()
Get company/institution data from ANAF
public
GetEntity(string $cui) : EntityResponse
Parameters
- $cui : string
Return values
EntityResponseGetLoginURL()
Helper method for the initial OAuth2 login
public
GetLoginURL() : string
Return values
stringHasAccessToken()
Check if the client has a valid access token.
public
HasAccessToken() : bool
Return values
boolHasSuggestedExtensionSupport()
Check if the client has support for answer extraction (libxml, openssl, dom)
public
static HasSuggestedExtensionSupport() : bool
Return values
boolIsProduction()
public
IsProduction() : bool
Tags
Return values
boolListAnswers()
Get answer list for a company (authenticated user must have access to the company!)
public
ListAnswers(int $cif[, int $days = 60 ][, AnswerFilter|null $filter = null ][, bool $usePaginationIfNeeded = false ][, float|int $endDateOffsetForPagination = 5 * 60 ]) : ANAFAnswerListResponse
Parameters
- $cif : int
- $days : int = 60
-
Number of days to look back
- $filter : AnswerFilter|null = null
- $usePaginationIfNeeded : bool = false
-
If true and the answer has LastError code ANAFException::MESSAGE_LIST_TOO_LONG, the method will try to fetch the answers using pagination
- $endDateOffsetForPagination : float|int = 5 * 60
-
ANAF API gives an error if the end date is "in the future" based on their internal clock, so end date will be currentTime-$endDateOffsetForPagination. Default is 5 minutes
Tags
Return values
ANAFAnswerListResponseListAnswersWithPagination()
Get answer list for a company (authenticated user must have access to the company!) Uses the paged API end point Answers will be returned in a unified list
public
ListAnswersWithPagination(int $startTime, int $endTime, int $cif[, int|null $specificPage = null ][, AnswerFilter|null $filter = null ]) : PagedAnswerListResponse
Parameters
- $startTime : int
- $endTime : int
- $cif : int
- $specificPage : int|null = null
- $filter : AnswerFilter|null = null
Return values
PagedAnswerListResponseLoadAccessToken()
Loads the access token from the file specified in TokenFilePath
public
LoadAccessToken([bool $autoRefresh = true ]) : AccessToken|null
Parameters
- $autoRefresh : bool = true
-
if true, the token will be refreshed if it has expired
Tags
Return values
AccessToken|nullLogOutput()
public
LogOutput(string $message[, Throwable|null $ex = null ]) : void
Parameters
- $message : string
- $ex : Throwable|null = null
ProcessOAuthCallback()
Gets the access token from ANAF, should be called from the OAuth callback script
public
ProcessOAuthCallback(string $authCode) : AccessToken|null
Parameters
- $authCode : string
Tags
Return values
AccessToken|nullRefreshAccessToken()
Refresh the access token using the refresh token
public
RefreshAccessToken([AccessToken|null $token = null ]) : bool
Parameters
- $token : AccessToken|null = null
-
if null the current access token @see ANAFAPIClient::$AccessToken will be used.
Return values
boolRemoveSchemaLocationAttribute()
Removes the xsi:schemaLocation attribute from the root element of the UBL XML
public
static RemoveSchemaLocationAttribute(mixed $xmlString) : string
Parameters
- $xmlString : mixed
Return values
stringTokenWillExpireSoon()
Checks if the current access token will expire soon
public
TokenWillExpireSoon([int $soon = 3600 * 24 ]) : bool|null
Parameters
- $soon : int = 3600 * 24
-
Time in seconds to consider "soon" Default value is 24 hours
Return values
bool|null —Null if the token is not set or does not have an expiration date
UBL2PDF()
Convert UBL XML to PDF using the ANAF API
public
UBL2PDF(string $ubl, string $metadata[, bool $authenticated = true ][, float|null $timeoutOverride = null ]) : string|false
Parameters
- $ubl : string
- $metadata : string
- $authenticated : bool = true
-
if true the request will use the OAuth2 API endpoint
- $timeoutOverride : float|null = null
-
if set, will override the default timeout (ANAFAPIClient::$Timeout)
Return values
string|falseUploadEFactura()
public
UploadEFactura(string $ubl, string $sellerCIF[, bool $extern = false ][, bool $autoFactura = false ]) : UBLUploadResponse
Parameters
- $ubl : string
-
UBL XML content to upload
- $sellerCIF : string
-
CUI of the company which issued the invoice
- $extern : bool = false
-
If true, the invoice is marked as "extern" (not issued to a romanian company)
- $autoFactura : bool = false
-
If true, the invoice is marked as "autofactura" (issued by the buyer in the sellers name)
Return values
UBLUploadResponseValidateCIF()
Verifies a CUI given the official checksum algorithm
public
static ValidateCIF(string|false $cif) : bool
Parameters
- $cif : string|false
Return values
boolVerifyConfig()
public
VerifyConfig(array<string|int, mixed> $config) : void
Parameters
- $config : array<string|int, mixed>
VerifyXML()
ATTENTION DOES NOT FUNCTION RELIABLY. The API randomly returns "nok" for valid invoices.
public
VerifyXML(string $ubl[, bool $authenticated = true ]) : ANAFVerifyResponse
Use at your own risk. Read the comment above.
Parameters
- $ubl : string
- $authenticated : bool = true
-
If true, the request will use the OAuth2 API endpoint