openstamanager/plugins/exportFE/src/Interaction.php

52 lines
1.5 KiB
PHP
Raw Normal View History

2018-12-07 18:16:46 +01:00
<?php
namespace Plugins\ExportFE;
2019-07-19 15:23:00 +02:00
use API\Services;
2018-12-07 18:16:46 +01:00
/**
* Classe per l'interazione con API esterne.
*
* @since 2.4.3
*/
2019-07-19 15:23:00 +02:00
class Interaction extends Services
2018-12-07 18:16:46 +01:00
{
2019-07-24 17:17:54 +02:00
public static function sendInvoice($id_record)
2018-12-07 18:16:46 +01:00
{
try {
$fattura = new FatturaElettronica($id_record);
$file = DOCROOT.'/'.FatturaElettronica::getDirectory().'/'.$fattura->getFilename();
2019-02-19 15:59:27 +01:00
$response = static::request('POST', 'invio_fattura_xml', [
'xml' => file_get_contents($file),
'filename' => $fattura->getFilename(),
2018-12-07 18:16:46 +01:00
]);
2018-12-14 12:50:44 +01:00
$body = static::responseBody($response);
2018-12-07 18:16:46 +01:00
2019-08-29 16:01:49 +02:00
// Aggiornamento dello stato
if ($body['status'] == 200) {
database()->update('co_documenti', [
'codice_stato_fe' => 'WAIT',
'data_stato_fe' => date('Y-m-d H:i:s'),
], ['id' => $id_record]);
} elseif ($body['status'] == 405) {
database()->update('co_documenti', [
'codice_stato_fe' => 'ERR',
'data_stato_fe' => date('Y-m-d H:i:s'),
], ['id' => $id_record]);
}
2019-02-19 15:59:27 +01:00
return [
'code' => $body['status'],
'message' => $body['message'],
];
2018-12-07 18:16:46 +01:00
} catch (UnexpectedValueException $e) {
}
2019-02-19 15:59:27 +01:00
return [
'code' => 400,
'message' => tr('Fattura non generata correttamente'),
];
2018-12-07 18:16:46 +01:00
}
}