PluginProbe
Moloni / trunk
Moloni vtrunk
5.0.10 5.0.09 5.0.08 5.0.07 5.0.06 trunk 0.4.0.00 0.4.8.1 3.0.10 3.0.11 3.0.35 3.0.36 3.0.37 3.0.38 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.0.46 3.0.47 3.0.48 3.0.49 3.0.50 All 98 releases
moloni / src / Services / Documents / DownloadDocument.php

DownloadDocument.php in Moloni trunk, at src/Services/Documents/DownloadDocument.php

49 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Moloni\Services\Documents;
4
5 use Moloni\Curl;
6 use Moloni\Exceptions\APIException;
7
8 class DownloadDocument
9 {
10 private $documentId;
11
12 public function __construct($documentId)
13 {
14 $this->documentId = $documentId;
15
16 $this->run();
17 }
18
19 public function run(): void
20 {
21 try {
22 $result = Curl::simple('documents/getPDFLink', [
23 'document_id' => $this->documentId
24 ]);
25
26 if (isset($result['url'])) {
27 $downloadUrl = 'https://www.moloni.pt/downloads/index.php?action=getDownload&';
28 $downloadUrl .= substr($result['url'], strpos($result['url'], '?') + 1);
29 $downloadUrl .= '&e=wordpress.auto.download@moloni.pt';
30 $downloadUrl .= '&t=n';
31
32 header('Location: ' . $downloadUrl);
33 } else {
34 $this->showError(__('Documento não existe'));
35 }
36 } catch (APIException $e) {
37 $this->showError(__('Erro a obter documento'));
38 }
39 }
40
41 private function showError($message): void
42 {
43 echo "<script>";
44 echo " alert('" . esc_js($message) . "');";
45 echo " window.close();";
46 echo "</script>";
47 }
48 }
49