1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* API Gateway: Cliente de API en PHP. |
7
|
|
|
* Copyright (C) API Gateway <https://www.apigateway.cl> |
8
|
|
|
* |
9
|
|
|
* Este programa es software libre: usted puede redistribuirlo y/o modificarlo |
10
|
|
|
* bajo los términos de la GNU Lesser General Public License (LGPL) publicada |
11
|
|
|
* por la Fundación para el Software Libre, ya sea la versión 3 de la Licencia, |
12
|
|
|
* o (a su elección) cualquier versión posterior de la misma. |
13
|
|
|
* |
14
|
|
|
* Este programa se distribuye con la esperanza de que sea útil, pero SIN |
15
|
|
|
* GARANTÍA ALGUNA; ni siquiera la garantía implícita MERCANTIL o de APTITUD |
16
|
|
|
* PARA UN PROPÓSITO DETERMINADO. Consulte los detalles de la GNU Lesser General |
17
|
|
|
* Public License (LGPL) para obtener una información más detallada. |
18
|
|
|
* |
19
|
|
|
* Debería haber recibido una copia de la GNU Lesser General Public License |
20
|
|
|
* (LGPL) junto a este programa. En caso contrario, consulte |
21
|
|
|
* <http://www.gnu.org/licenses/lgpl.html>. |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace apigatewaycl\api_client\sii; |
25
|
|
|
|
26
|
|
|
use Psr\Http\Message\ResponseInterface; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Módulo para consultas de DTEs emitidos al Portal MIPYME del SII. |
30
|
|
|
* |
31
|
|
|
* Para más información sobre la API, consulte la `documentación completa de DTEs |
32
|
|
|
* emitidos en el Portal MIPYME <https://developers.apigateway.cl/#c0d3d6f5-ae5e-47dc-891e-72f7beed93ca>`_. |
33
|
|
|
* |
34
|
|
|
* Cliente específico para gestionar DTE emitidos en el Portal Mipyme. |
35
|
|
|
*/ |
36
|
|
|
class PortalMipymeDteEmitidos extends PortalMiPymeDte |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* Obtiene documentos de DTE emitidos por un emisor. |
40
|
|
|
* |
41
|
|
|
* @param string $emisor RUT del emisor. |
42
|
|
|
* @param array $filtros Filtros adicionales para la consulta. |
43
|
|
|
* @return \Psr\Http\Message\ResponseInterface Documentos de DTE emitidos. |
44
|
|
|
*/ |
45
|
|
|
public function obtenerDtesEmitidos( |
46
|
|
|
string $emisor, |
47
|
|
|
array $filtros = [] |
48
|
|
|
): ResponseInterface { |
49
|
|
|
$url = sprintf( |
50
|
|
|
'/sii/mipyme/emitidos/documentos/%s', |
51
|
|
|
$emisor |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$body = [ |
55
|
|
|
'auth' => $this->getAuthPass(), |
56
|
|
|
'filtros' => $filtros, |
57
|
|
|
]; |
58
|
|
|
$response = $this->post(resource: $url, data: $body); |
59
|
|
|
return $response; |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Obtiene el PDF de un DTE emitido. |
64
|
|
|
* |
65
|
|
|
* @param string $emisor RUT del emisor. |
66
|
|
|
* @param string $dte Tipo de DTE o código del DTE emitido si no se pasa folio. |
67
|
|
|
* @param string $folio Número de folio del DTE (opcional). |
68
|
|
|
* @return \Psr\Http\Message\ResponseInterface Contenido del PDF del DTE emitido. |
69
|
|
|
*/ |
70
|
|
|
public function descargarPdfDteEmitido( |
71
|
|
|
string $emisor, |
72
|
|
|
string $dte, |
73
|
|
|
string $folio = null |
74
|
|
|
): ResponseInterface { |
75
|
|
|
$url = $folio != null ? sprintf( |
|
|
|
|
76
|
|
|
'/sii/mipyme/emitidos/pdf/%s/%s/%s', |
77
|
|
|
$emisor, |
78
|
|
|
$dte, |
79
|
|
|
$folio |
80
|
|
|
) : sprintf( |
81
|
|
|
'/sii/mipyme/emitidos/pdf/%s/%s', |
82
|
|
|
$emisor, |
83
|
|
|
$dte, |
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
$body = [ |
87
|
|
|
'auth' => $this->getAuthPass(), |
88
|
|
|
]; |
89
|
|
|
$response = $this->post(resource: $url, data: $body); |
90
|
|
|
return $response; |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Obtiene el XML de un DTE emitido. |
95
|
|
|
* |
96
|
|
|
* @param string $emisor RUT del emisor. |
97
|
|
|
* @param string $dte Tipo de DTE. |
98
|
|
|
* @param string $folio Número de folio del DTE. |
99
|
|
|
* @return \Psr\Http\Message\ResponseInterface Contenido del XML del DTE emitido. |
100
|
|
|
*/ |
101
|
|
|
public function descargarXmlDteEmitido( |
102
|
|
|
string $emisor, |
103
|
|
|
string $dte, |
104
|
|
|
string $folio |
105
|
|
|
): ResponseInterface { |
106
|
|
|
$url = sprintf( |
107
|
|
|
'/sii/mipyme/emitidos/xml/%s/%s/%s', |
108
|
|
|
$emisor, |
109
|
|
|
$dte, |
110
|
|
|
$folio |
111
|
|
|
); |
112
|
|
|
|
113
|
|
|
$body = [ |
114
|
|
|
'auth' => $this->getAuthPass(), |
115
|
|
|
]; |
116
|
|
|
$response = $this->post(resource: $url, data: $body); |
117
|
|
|
return $response; |
|
|
|
|
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|