openstamanager/plugins/receiptFE/src/Interaction.php

79 lines
1.8 KiB
PHP
Raw Normal View History

2018-12-14 12:50:44 +01:00
<?php
namespace Plugins\ReceiptFE;
2019-07-19 15:23:00 +02:00
use API\Services;
2018-12-14 12:50:44 +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-14 12:50:44 +01:00
{
public static function getReceiptList()
{
2019-07-10 15:02:09 +02:00
$directory = Ricevuta::getImportDirectory();
$list = [];
$files = glob($directory.'/*.xml*');
foreach ($files as $file) {
$list[] = basename($file);
}
// Ricerca da remoto
if (self::isEnabled()) {
$response = static::request('POST', 'notifiche_da_importare');
$body = static::responseBody($response);
if ($body['status'] == '200') {
$files = $body['results'];
foreach ($files as $file) {
$list[] = basename($file);
}
}
}
2018-12-14 12:50:44 +01:00
2019-07-24 17:17:54 +02:00
$list = array_clean($list);
// Aggiornamento cache hook
ReceiptHook::update($list);
return $list;
2018-12-14 12:50:44 +01:00
}
public static function getReceipt($name)
{
2019-02-20 16:07:42 +01:00
$directory = Ricevuta::getImportDirectory();
$file = $directory.'/'.$name;
if (!file_exists($file)) {
$response = static::request('POST', 'notifica_da_importare', [
'name' => $name,
]);
$body = static::responseBody($response);
Ricevuta::store($name, $body['content']);
}
2018-12-14 12:50:44 +01:00
2019-02-20 16:07:42 +01:00
return $name;
2019-02-20 12:39:28 +01:00
}
public static function processReceipt($filename)
{
$response = static::request('POST', 'notifica_xml_salvata', [
'filename' => $filename,
]);
$body = static::responseBody($response);
$result = true;
if ($body['status'] != '200') {
$result = $body['status'].' - '.$body['message'];
}
return $result;
2018-12-14 12:50:44 +01:00
}
}