openstamanager/plugins/importFE/src/Interaction.php

48 lines
1.1 KiB
PHP
Raw Normal View History

2018-11-30 15:33:25 +01:00
<?php
namespace Plugins\ImportFE;
2018-12-14 12:50:44 +01:00
use Plugins\ExportFE\Connection;
2018-11-30 15:33:25 +01:00
/**
* Classe per l'interazione con API esterne.
*
* @since 2.4.3
*/
2018-12-14 12:50:44 +01:00
class Interaction extends Connection
2018-11-30 15:33:25 +01:00
{
public static function listToImport()
{
$directory = FatturaElettronica::getImportDirectory();
2018-12-14 12:50:44 +01:00
$response = static::request('POST', 'get_fatture_da_importare');
$body = static::responseBody($response);
2018-11-30 15:33:25 +01:00
2018-12-14 12:50:44 +01:00
$list = $body['results'];
2018-11-30 15:33:25 +01:00
$files = glob($directory.'/*.xml');
foreach ($files as $file) {
$list[] = basename($file);
}
return array_clean($list);
}
public static function getImportXML($name)
{
$directory = FatturaElettronica::getImportDirectory();
$file = $directory.'/'.$name;
if (!file_exists($file)) {
2018-12-14 12:50:44 +01:00
$response = static::request('POST', 'get_fattura_da_importare', [
2018-11-30 15:33:25 +01:00
'name' => $name,
]);
2018-12-14 12:50:44 +01:00
$body = static::responseBody($response);
2018-11-30 15:33:25 +01:00
2018-12-14 12:50:44 +01:00
FatturaElettronica::store($name, $body['content']);
2018-11-30 15:33:25 +01:00
}
return $name;
}
}