Skip to main content

Processing Invoice Agent Response

Basics

After sending the request, the server's response includes the result of the requested operation (success or failure), as well as the data according to the response schema (see the constants starting with SzamlaAgentRequest::XML_SCHEMA_CREATE_ in the package).

// Checking the success of the request as follows:
$agent = SzamlaAgentAPI::create('agentApiKey');
...
...
if ($result->isSuccess()) {
...
}

// Retrieving the document number from the response:
echo $result->getDocumentNumber();

// Getting all the data as follows:
$data = $result->getData();

// The response object for invoice requests contains the following class: `InvoiceResponse`,
// for receipt, it is `ReceiptResponse`.

// If you want to use the object containing the data received in the response:
$data = $result->getDataObj();

// If you need the PDF document received in the response:
$pdfFile = $result->toPdf();

// If you want to receive and process the response in XML format:
$xmlData = $result->toXML();

// If you want to receive and process the response in JSON format:
$jsonData = $result->toJson();

During the request generation process, the provided data is converted into an XML document according to the expected schema of the Invoice Agent and saved in the package's xml folder using the following naming conventions: {request|response}-{xml-schema}-{text|xml}-{object-name}-{current-timestamp}.xml

For example: response-xmlszamla-text-invoice-2021031012301712345.xml

Handling Custom Errors

It is possible that an invoice is successfully issued, but for some reason, the invoice notification cannot be delivered to the Számlázz.hu system.

The success of issuing the invoice can still be checked with the $result->isSuccess() method. In this case, we can check the failure of the invoice notification delivery with the $result->hasInvoiceNotificationSendError() method. The failure of the notification delivery is logged by the API, so it can be found in the log file as well.

Let's look at a specific example of handling the response:

if ($result->isSuccess()) {
echo 'The invoice has been successfully created. Invoice number: ' . $result->getDocumentNumber();
}
// if the delivery of the invoice notification fails
if ($result->hasInvoiceNotificationSendError()) {
var_dump($result->getDataObj());
}