1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpCfdi\Finkok; |
6
|
|
|
|
7
|
|
|
use DateTimeImmutable; |
8
|
|
|
use PhpCfdi\Credentials\Credential; |
9
|
|
|
use PhpCfdi\Finkok\Definitions\CancelAnswer; |
10
|
|
|
use PhpCfdi\Finkok\Definitions\ReceiptType; |
11
|
|
|
use PhpCfdi\Finkok\Definitions\RfcRole; |
12
|
|
|
use PhpCfdi\Finkok\Definitions\SignedDocumentFormat; |
13
|
|
|
use PhpCfdi\Finkok\Services\Cancel; |
14
|
|
|
use PhpCfdi\Finkok\Services\Manifest; |
15
|
|
|
use PhpCfdi\Finkok\Services\Registration; |
16
|
|
|
use PhpCfdi\Finkok\Services\Retentions; |
17
|
|
|
use PhpCfdi\Finkok\Services\Stamping; |
18
|
|
|
use PhpCfdi\Finkok\Services\Utilities; |
19
|
|
|
use PhpCfdi\XmlCancelacion\Models\CancelDocument; |
20
|
|
|
use PhpCfdi\XmlCancelacion\Models\CancelDocuments; |
21
|
|
|
|
22
|
|
|
class QuickFinkok |
23
|
|
|
{ |
24
|
|
|
/** @var FinkokSettings */ |
25
|
|
|
private $settings; |
26
|
|
|
|
27
|
34 |
|
public function __construct(FinkokSettings $factory) |
28
|
|
|
{ |
29
|
34 |
|
$this->settings = $factory; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Obtiene la configuración de conexión con la que será consumida la API de Finkok |
34
|
|
|
* |
35
|
|
|
* @return FinkokSettings |
36
|
|
|
*/ |
37
|
34 |
|
public function settings(): FinkokSettings |
38
|
|
|
{ |
39
|
34 |
|
return $this->settings; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Este método se encarga de realizar el timbrado de XML |
44
|
|
|
* |
45
|
|
|
* @param string $preCfdi |
46
|
|
|
* @return Stamping\StampingResult |
47
|
|
|
* @see https://wiki.finkok.com/doku.php?id=stamp |
48
|
|
|
*/ |
49
|
1 |
|
public function stamp(string $preCfdi): Stamping\StampingResult |
50
|
|
|
{ |
51
|
1 |
|
$command = new Stamping\StampingCommand($preCfdi); |
52
|
1 |
|
$service = new Stamping\StampService($this->settings()); |
53
|
1 |
|
return $service->stamp($command); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Este método se encarga de realizar el timbrado de XML, una vez que se timbra el XML se guarda en una cola de |
58
|
|
|
* espera para ser enviado en el mejor momento a los servicios del SAT, por lo que el servicio de timbrado es |
59
|
|
|
* mucho más rápido, y es de uso recomendado en timbrado de alto número de timbres por segundo. |
60
|
|
|
* |
61
|
|
|
* Nota: El CFDI generado puede no estar disponible en los servidores del SAT hasta varios minutos después |
62
|
|
|
* |
63
|
|
|
* @param string $preCfdi |
64
|
|
|
* @return Stamping\StampingResult |
65
|
|
|
* @see https://wiki.finkok.com/doku.php?id=metodo_quick_stamp |
66
|
|
|
*/ |
67
|
1 |
|
public function quickStamp(string $preCfdi): Stamping\StampingResult |
68
|
|
|
{ |
69
|
1 |
|
$command = new Stamping\StampingCommand($preCfdi); |
70
|
1 |
|
$service = new Stamping\QuickStampService($this->settings()); |
71
|
1 |
|
return $service->quickstamp($command); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Este método regresa la información de un XML ya timbrado previamente y que por algún motivo no se pudo recuperar |
76
|
|
|
* en la primera petición que se realizó, con este método se puede recuperar el UUID y el XML timbrado |
77
|
|
|
* |
78
|
|
|
* @param string $preCfdi |
79
|
|
|
* @return Stamping\StampingResult |
80
|
|
|
* @see https://wiki.finkok.com/doku.php?id=stamped |
81
|
|
|
*/ |
82
|
1 |
|
public function stamped(string $preCfdi): Stamping\StampingResult |
83
|
|
|
{ |
84
|
1 |
|
$command = new Stamping\StampingCommand($preCfdi); |
85
|
1 |
|
$service = new Stamping\StampedService($this->settings()); |
86
|
1 |
|
return $service->stamped($command); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Obtiene el XML de un UUID timbrado en Finkok de tipo CFDI 3.3 |
91
|
|
|
* solo es posible recuperar los timbrados en los últimos 3 meses. |
92
|
|
|
* |
93
|
|
|
* @param string $uuid |
94
|
|
|
* @param string $rfc |
95
|
|
|
* @return Utilities\DownloadXmlResult |
96
|
|
|
* @see https://wiki.finkok.com/doku.php?id=get_xml |
97
|
|
|
*/ |
98
|
1 |
|
public function cfdiDownload(string $uuid, string $rfc): Utilities\DownloadXmlResult |
99
|
|
|
{ |
100
|
1 |
|
$command = new Utilities\DownloadXmlCommand($uuid, $rfc, 'I'); |
101
|
1 |
|
$service = new Utilities\DownloadXmlService($this->settings()); |
102
|
1 |
|
return $service->downloadXml($command); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Este método se usa para consultar el estatus de una factura que se quedó pendiente de enviar al SAT debido a una |
107
|
|
|
* falla en el sistema del SAT o bien que se envió a través del método Quick_Stamp |
108
|
|
|
* |
109
|
|
|
* @param string $uuid |
110
|
|
|
* @return Stamping\QueryPendingResult |
111
|
|
|
* @see https://wiki.finkok.com/doku.php?id=query_pending |
112
|
|
|
*/ |
113
|
1 |
|
public function stampQueryPending(string $uuid): Stamping\QueryPendingResult |
114
|
|
|
{ |
115
|
1 |
|
$command = new Stamping\QueryPendingCommand($uuid); |
116
|
1 |
|
$service = new Stamping\QueryPendingService($this->settings()); |
117
|
1 |
|
return $service->queryPending($command); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Este método es el encargado de cancelar uno o varios CFDI emitidos por medio de los web services de Finkok |
122
|
|
|
* Durante el proceso no se envía ningún CSD a Finkok y la solicitud firmada es creada usando los datos del CSD |
123
|
|
|
* |
124
|
|
|
* @param Credential $credential |
125
|
|
|
* @param CancelDocument $document |
126
|
|
|
* @return Cancel\CancelSignatureResult |
127
|
|
|
* @see https://wiki.finkok.com/doku.php?id=cancelsigned_method |
128
|
|
|
* @see https://wiki.finkok.com/doku.php?id=cancel_method |
129
|
|
|
*/ |
130
|
1 |
|
public function cancel(Credential $credential, CancelDocument $document): Cancel\CancelSignatureResult |
131
|
|
|
{ |
132
|
1 |
|
$signer = new Helpers\CancelSigner(new CancelDocuments($document)); |
133
|
1 |
|
$signedRequest = $signer->sign($credential); |
134
|
1 |
|
$command = new Cancel\CancelSignatureCommand($signedRequest); |
135
|
1 |
|
$service = new Cancel\CancelSignatureService($this->settings()); |
136
|
1 |
|
return $service->cancelSignature($command); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Consulta el estatus del CFDI emitido con Finkok y la forma posible de cancelación a partir de todos sus datos. |
141
|
|
|
* También se puede consultar en modo producción utilizando la librería `phpcfdi/sat-estado-cfdi` |
142
|
|
|
* |
143
|
|
|
* @param string $rfcIssuer |
144
|
|
|
* @param string $rfcRecipient |
145
|
|
|
* @param string $uuid |
146
|
|
|
* @param string $total |
147
|
|
|
* @return Cancel\GetSatStatusResult |
148
|
|
|
* @see https://wiki.finkok.com/doku.php?id=get_sat_status |
149
|
|
|
* @see https://github.com/phpcfdi/sat-estado-cfdi |
150
|
|
|
*/ |
151
|
1 |
|
public function satStatus( |
152
|
|
|
string $rfcIssuer, |
153
|
|
|
string $rfcRecipient, |
154
|
|
|
string $uuid, |
155
|
|
|
string $total |
156
|
|
|
): Cancel\GetSatStatusResult { |
157
|
1 |
|
$command = new Cancel\GetSatStatusCommand($rfcIssuer, $rfcRecipient, $uuid, $total); |
158
|
1 |
|
$service = new Cancel\GetSatStatusService($this->settings()); |
159
|
1 |
|
return $service->query($command); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Consulta el estatus del CFDI emitido por Finkok y la forma posible de cancelación a partir del XML de un CFDI |
164
|
|
|
* |
165
|
|
|
* @param string $xmlCfdi |
166
|
|
|
* @return Cancel\GetSatStatusResult |
167
|
|
|
* @see https://wiki.finkok.com/doku.php?id=get_sat_status |
168
|
|
|
*/ |
169
|
2 |
|
public function satStatusXml(string $xmlCfdi): Cancel\GetSatStatusResult |
170
|
|
|
{ |
171
|
2 |
|
$extractor = Helpers\GetSatStatusExtractor::fromXmlString($xmlCfdi); |
172
|
2 |
|
$command = $extractor->buildCommand(); |
173
|
2 |
|
$service = new Cancel\GetSatStatusService($this->settings()); |
174
|
2 |
|
return $service->query($command); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Obtiene una lista de los UUID relacionados de un UUID |
179
|
|
|
* |
180
|
|
|
* @param Credential $credential |
181
|
|
|
* @param string $uuid |
182
|
|
|
* @param RfcRole|null $role Si es NULL entonces se usa el rol de emisor |
183
|
|
|
* @return Cancel\GetRelatedSignatureResult |
184
|
|
|
* @see https://wiki.finkok.com/doku.php?id=get_related_signature |
185
|
|
|
* @see https://wiki.finkok.com/doku.php?id=get_related |
186
|
|
|
*/ |
187
|
1 |
|
public function obtainRelated( |
188
|
|
|
Credential $credential, |
189
|
|
|
string $uuid, |
190
|
|
|
RfcRole $role = null |
191
|
|
|
): Cancel\GetRelatedSignatureResult { |
192
|
1 |
|
$signer = new Helpers\GetRelatedSigner($uuid, $role); |
193
|
1 |
|
$signedRequest = $signer->sign($credential); |
194
|
1 |
|
$command = new Cancel\GetRelatedSignatureCommand($signedRequest); |
195
|
1 |
|
$service = new Cancel\GetRelatedSignatureService($this->settings()); |
196
|
1 |
|
return $service->getRelatedSignature($command); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Consulta las solicitudes de cancelación tiene pendientes un receptor |
201
|
|
|
* Durante el proceso no se envía ningún CSD a Finkok y la solicitud firmada es creada usando los datos del CSD |
202
|
|
|
* |
203
|
|
|
* @param string $rfc |
204
|
|
|
* @return Cancel\GetPendingResult |
205
|
|
|
* @see https://wiki.finkok.com/doku.php?id=get_pending |
206
|
|
|
*/ |
207
|
1 |
|
public function obtainPendingToCancel(string $rfc): Cancel\GetPendingResult |
208
|
|
|
{ |
209
|
1 |
|
$command = new Cancel\GetPendingCommand($rfc); |
210
|
1 |
|
$service = new Cancel\GetPendingService($this->settings()); |
211
|
1 |
|
return $service->obtainPending($command); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Permite al receptor de una factura Aceptar o Rechazar una determinada cancelación que tenga pendiente |
216
|
|
|
* Durante el proceso no se envía ningún CSD a Finkok y la solicitud firmada es creada usando los datos del CSD |
217
|
|
|
* |
218
|
|
|
* @param Credential $credential |
219
|
|
|
* @param string $uuid |
220
|
|
|
* @param CancelAnswer $answer |
221
|
|
|
* @return Cancel\AcceptRejectSignatureResult |
222
|
|
|
* @see https://wiki.finkok.com/doku.php?id=accept_reject_signature |
223
|
|
|
* @see https://wiki.finkok.com/doku.php?id=accept_reject |
224
|
|
|
*/ |
225
|
1 |
|
public function answerAcceptRejectCancellation( |
226
|
|
|
Credential $credential, |
227
|
|
|
string $uuid, |
228
|
|
|
CancelAnswer $answer |
229
|
|
|
): Cancel\AcceptRejectSignatureResult { |
230
|
1 |
|
$signer = new Helpers\AcceptRejectSigner($uuid, $answer); |
231
|
1 |
|
$signedRequest = $signer->sign($credential); |
232
|
1 |
|
$command = new Cancel\AcceptRejectSignatureCommand($signedRequest); |
233
|
1 |
|
$service = new Cancel\AcceptRejectSignatureService($this->settings()); |
234
|
1 |
|
return $service->acceptRejectSignature($command); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Obtiene el acuse de recepción de la solicitud de cancelación |
239
|
|
|
* |
240
|
|
|
* @param string $rfcIssuer |
241
|
|
|
* @param string $uuid |
242
|
|
|
* @return Cancel\GetReceiptResult |
243
|
|
|
* @see https://wiki.finkok.com/doku.php?id=get_receipt |
244
|
|
|
*/ |
245
|
1 |
|
public function obtainCancelRequestReceipt(string $rfcIssuer, string $uuid): Cancel\GetReceiptResult |
246
|
|
|
{ |
247
|
1 |
|
$command = new Cancel\GetReceiptCommand($rfcIssuer, $uuid, ReceiptType::cancellation()); |
248
|
1 |
|
$service = new Cancel\GetReceiptService($this->settings()); |
249
|
1 |
|
return $service->download($command); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Obtener la fecha exacta de los servidores de timbrado para realizar el XML del CFDI |
254
|
|
|
* |
255
|
|
|
* @param string $postalCode Si está vacío se utiliza el horario de America/Mexico_City |
256
|
|
|
* @return Utilities\DatetimeResult |
257
|
|
|
* @see https://wiki.finkok.com/doku.php?id=datetime |
258
|
|
|
*/ |
259
|
2 |
|
public function serversDateTime(string $postalCode = ''): Utilities\DatetimeResult |
260
|
|
|
{ |
261
|
2 |
|
$command = new Utilities\DatetimeCommand($postalCode); |
262
|
2 |
|
$service = new Utilities\DatetimeService($this->settings()); |
263
|
2 |
|
return $service->datetime($command); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Reporte de los UUID timbrados con fecha, de un RFC entre un periodo de tiempo determinado |
268
|
|
|
* |
269
|
|
|
* @param string $rfc |
270
|
|
|
* @param DateTimeImmutable $since |
271
|
|
|
* @param DateTimeImmutable $until |
272
|
|
|
* @return Utilities\ReportUuidResult |
273
|
|
|
* @see https://wiki.finkok.com/doku.php?id=report_uuid |
274
|
|
|
*/ |
275
|
1 |
|
public function reportUuids( |
276
|
|
|
string $rfc, |
277
|
|
|
DateTimeImmutable $since, |
278
|
|
|
DateTimeImmutable $until |
279
|
|
|
): Utilities\ReportUuidResult { |
280
|
1 |
|
$command = new Utilities\ReportUuidCommand($rfc, 'I', $since, $until); |
281
|
1 |
|
$service = new Utilities\ReportUuidService($this->settings()); |
282
|
1 |
|
return $service->reportUuid($command); |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* Reporte de los créditos añadidos de un RFC |
287
|
|
|
* |
288
|
|
|
* @param string $rfc |
289
|
|
|
* @return Utilities\ReportCreditResult |
290
|
|
|
* @see https://wiki.finkok.com/doku.php?id=report_uuid |
291
|
|
|
*/ |
292
|
1 |
|
public function reportCredits(string $rfc): Utilities\ReportCreditResult |
293
|
|
|
{ |
294
|
1 |
|
$command = new Utilities\ReportCreditCommand($rfc); |
295
|
1 |
|
$service = new Utilities\ReportCreditService($this->settings()); |
296
|
1 |
|
return $service->reportCredit($command); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Reporte de los créditos añadidos de un RFC |
301
|
|
|
* |
302
|
|
|
* @param string $rfc |
303
|
|
|
* @param int $startYear |
304
|
|
|
* @param int $startMonth |
305
|
|
|
* @param int $endYear |
306
|
|
|
* @param int $endMonth |
307
|
|
|
* @return Utilities\ReportTotalResult |
308
|
|
|
* @see https://wiki.finkok.com/doku.php?id=report_uuid |
309
|
|
|
*/ |
310
|
1 |
|
public function reportTotals( |
311
|
|
|
string $rfc, |
312
|
|
|
int $startYear, |
313
|
|
|
int $startMonth, |
314
|
|
|
int $endYear = 0, |
315
|
|
|
int $endMonth = 0 |
316
|
|
|
): Utilities\ReportTotalResult { |
317
|
1 |
|
$command = new Utilities\ReportTotalCommand($rfc, 'I', $startYear, $startMonth, $endYear, $endMonth); |
318
|
1 |
|
$service = new Utilities\ReportTotalService($this->settings()); |
319
|
1 |
|
return $service->reportTotal($command); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* Agrega un cliente que va a timbrar bajo la cuenta de un socio de negocios de Finkok |
324
|
|
|
* |
325
|
|
|
* @param string $rfc |
326
|
|
|
* @param Registration\CustomerType|null $type Si es NULL entonces se utiliza OnDemand |
327
|
|
|
* @return Registration\AddResult |
328
|
|
|
* @see https://wiki.finkok.com/doku.php?id=add |
329
|
|
|
*/ |
330
|
1 |
|
public function customersAdd(string $rfc, ?Registration\CustomerType $type = null): Registration\AddResult |
331
|
|
|
{ |
332
|
1 |
|
$command = new Registration\AddCommand($rfc, $type); |
333
|
1 |
|
$service = new Registration\AddService($this->settings()); |
334
|
1 |
|
return $service->add($command); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* Edita el estatus de un cliente (suspender o activar) |
339
|
|
|
* |
340
|
|
|
* @param string $rfc |
341
|
|
|
* @param Registration\CustomerStatus $status |
342
|
|
|
* @return Registration\EditResult |
343
|
|
|
* @see https://wiki.finkok.com/doku.php?id=edit |
344
|
|
|
*/ |
345
|
1 |
|
public function customersEdit(string $rfc, Registration\CustomerStatus $status): Registration\EditResult |
346
|
|
|
{ |
347
|
1 |
|
$command = new Registration\EditCommand($rfc, $status); |
348
|
1 |
|
$service = new Registration\EditService($this->settings()); |
349
|
1 |
|
return $service->edit($command); |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* Edita el tipo de un cliente (prepago/Prepaid o ilimitado/Ondemand) |
354
|
|
|
* |
355
|
|
|
* @param string $rfc |
356
|
|
|
* @param Registration\CustomerType $type |
357
|
|
|
* @return Registration\SwitchResult |
358
|
|
|
* @see https://wiki.finkok.com/doku.php?id=switch |
359
|
|
|
*/ |
360
|
1 |
|
public function customersSwitch(string $rfc, Registration\CustomerType $type): Registration\SwitchResult |
361
|
|
|
{ |
362
|
1 |
|
$command = new Registration\SwitchCommand($rfc, $type); |
363
|
1 |
|
$service = new Registration\SwitchService($this->settings()); |
364
|
1 |
|
return $service->switch($command); |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* Obtiene los datos del RFC especificado |
369
|
|
|
* |
370
|
|
|
* @param string $filterByRfc |
371
|
|
|
* @return Registration\ObtainResult |
372
|
|
|
* @see https://wiki.finkok.com/doku.php?id=get |
373
|
|
|
*/ |
374
|
1 |
|
public function customersObtain(string $filterByRfc): Registration\ObtainResult |
375
|
|
|
{ |
376
|
1 |
|
$command = new Registration\ObtainCommand($filterByRfc); |
377
|
1 |
|
$service = new Registration\ObtainService($this->settings()); |
378
|
1 |
|
return $service->obtain($command); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* Obtiene el listado completo de clientes, consultando todas las páginas necesarias. |
383
|
|
|
* El resultado es solo la lista de clientes, sin acceso a los resultados de cada una de las consultas. |
384
|
|
|
* |
385
|
|
|
* @return Registration\Customers |
386
|
|
|
* @see https://wiki.finkok.com/doku.php?id=customers |
387
|
|
|
*/ |
388
|
1 |
|
public function customersObtainAll(): Registration\Customers |
389
|
|
|
{ |
390
|
1 |
|
$service = new Registration\ObtainCustomersService($this->settings()); |
391
|
1 |
|
return $service->obtainAll(); |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* Asignar créditos un cliente que va a timbrar |
396
|
|
|
* Si el crédito es un valor positivo y el cliente está como OnDemand se cambiará a PrePaid con los créditos |
397
|
|
|
* Si el crédito es un valor positivo y el cliente está como PrePaid sumarán los créditos a los actuales |
398
|
|
|
* Si el crédito es -1 el cliente se pondrá como OnDemand |
399
|
|
|
* |
400
|
|
|
* @param string $rfc |
401
|
|
|
* @param int $credits |
402
|
|
|
* @return Registration\AssignResult |
403
|
|
|
* @see https://wiki.finkok.com/doku.php?id=assign |
404
|
|
|
*/ |
405
|
1 |
|
public function customersAssign(string $rfc, int $credits): Registration\AssignResult |
406
|
|
|
{ |
407
|
1 |
|
$command = new Registration\AssignCommand($rfc, $credits); |
408
|
1 |
|
$service = new Registration\AssignService($this->settings()); |
409
|
1 |
|
return $service->assign($command); |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* Obtiene los textos del manifiesto de FINKOK (Aviso de Privacidad y Contrato de Servicio) |
414
|
|
|
* |
415
|
|
|
* @param string $rfc |
416
|
|
|
* @param string $name |
417
|
|
|
* @param string $address |
418
|
|
|
* @param string $email |
419
|
|
|
* @param string $snid |
420
|
|
|
* @return Manifest\GetContractsResult |
421
|
|
|
* @see https://wiki.finkok.com/doku.php?id=get_contracts_snid |
422
|
|
|
*/ |
423
|
2 |
|
public function customerGetContracts( |
424
|
|
|
string $rfc, |
425
|
|
|
string $name, |
426
|
|
|
string $address, |
427
|
|
|
string $email, |
428
|
|
|
string $snid |
429
|
|
|
): Manifest\GetContractsResult { |
430
|
2 |
|
$command = new Manifest\GetContractsCommand($rfc, $name, $address, $email, $snid); |
431
|
2 |
|
$service = new Manifest\GetContractsService($this->settings()); |
432
|
2 |
|
return $service->obtainContracts($command); |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
/** |
436
|
|
|
* Envía el aviso de privacidad y contratos firmados |
437
|
|
|
* |
438
|
|
|
* @param string $snid |
439
|
|
|
* @param string $signedPrivacy |
440
|
|
|
* @param string $signedContract |
441
|
|
|
* @return Manifest\SignContractsResult |
442
|
|
|
* @see https://wiki.finkok.com/doku.php?id=firmar |
443
|
|
|
*/ |
444
|
2 |
|
public function customerSendContracts( |
445
|
|
|
string $snid, |
446
|
|
|
string $signedPrivacy, |
447
|
|
|
string $signedContract |
448
|
|
|
): Manifest\SignContractsResult { |
449
|
2 |
|
$command = new Manifest\SignContractsCommand($snid, $signedPrivacy, $signedContract); |
450
|
2 |
|
$service = new Manifest\SignContractsService($this->settings()); |
451
|
2 |
|
return $service->sendSignedContracts($command); |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
/** |
455
|
|
|
* Obtiene los documentos legales (aviso de privacidad y contrato), los firma con la FIEL y envía |
456
|
|
|
* |
457
|
|
|
* @param Credential $fiel |
458
|
|
|
* @param string $snid |
459
|
|
|
* @param string $address |
460
|
|
|
* @param string $email |
461
|
|
|
* @param DateTimeImmutable|null $signedOn Si es NULL se utiliza la fecha y hora del sistema |
462
|
|
|
* @return Manifest\SignContractsResult |
463
|
|
|
*/ |
464
|
3 |
|
public function customerSignAndSendContracts( |
465
|
|
|
Credential $fiel, |
466
|
|
|
string $snid, |
467
|
|
|
string $address, |
468
|
|
|
string $email, |
469
|
|
|
?DateTimeImmutable $signedOn = null |
470
|
|
|
): Manifest\SignContractsResult { |
471
|
3 |
|
$rfc = $fiel->rfc(); |
472
|
3 |
|
$name = $fiel->legalName(); |
473
|
3 |
|
$signedOn = $signedOn ?? new DateTimeImmutable(); |
474
|
3 |
|
$documents = $this->customerGetContracts($rfc, $name, $address, $email, $snid); |
475
|
3 |
|
if (! $documents->success()) { |
476
|
1 |
|
return Manifest\SignContractsResult::createFromData( |
477
|
1 |
|
false, |
478
|
1 |
|
sprintf('Unable to get contracts: %s', $documents->error() ?: '(no error)') |
479
|
1 |
|
); |
480
|
|
|
} |
481
|
2 |
|
$privacy = (new Helpers\DocumentSigner($rfc, $signedOn, $documents->privacy()))->signUsingCredential($fiel); |
482
|
2 |
|
$contract = (new Helpers\DocumentSigner($rfc, $signedOn, $documents->contract()))->signUsingCredential($fiel); |
483
|
2 |
|
return $this->customerSendContracts($snid, $privacy, $contract); |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
/** |
487
|
|
|
* Obtiene los documentos legales (aviso de privacidad y contrato) previamente firmados con el SNID y RFC |
488
|
|
|
* |
489
|
|
|
* @param string $snid |
490
|
|
|
* @param string $rfc |
491
|
|
|
* @param SignedDocumentFormat|null $format |
492
|
|
|
* @return Manifest\GetSignedContractsResult |
493
|
|
|
*/ |
494
|
1 |
|
public function customerGetSignedContracts( |
495
|
|
|
string $snid, |
496
|
|
|
string $rfc, |
497
|
|
|
SignedDocumentFormat $format = null |
498
|
|
|
): Manifest\GetSignedContractsResult { |
499
|
1 |
|
$format = $format ?? SignedDocumentFormat::xml(); |
500
|
1 |
|
$command = new Manifest\GetSignedContractsCommand($snid, $rfc, $format); |
501
|
1 |
|
$service = new Manifest\GetSignedContractsService($this->settings()); |
502
|
1 |
|
return $service->getSignedContracts($command); |
503
|
|
|
} |
504
|
|
|
|
505
|
2 |
|
public function retentionStamp(string $xml): Retentions\StampResult |
506
|
|
|
{ |
507
|
2 |
|
$command = new Retentions\StampCommand($xml); |
508
|
2 |
|
$service = new Retentions\StampService($this->settings()); |
509
|
2 |
|
return $service->stamp($command); |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* Obtiene el XML de un UUID timbrado en Finkok de tipo CFDI de retenciones e información de pagos |
514
|
|
|
* solo es posible recuperar los timbrados en los últimos 3 meses. |
515
|
|
|
* |
516
|
|
|
* @param string $uuid |
517
|
|
|
* @param string $rfc |
518
|
|
|
* @return Utilities\DownloadXmlResult |
519
|
|
|
* @see https://wiki.finkok.com/doku.php?id=get_xml |
520
|
|
|
*/ |
521
|
2 |
|
public function retentionDownload(string $uuid, string $rfc): Utilities\DownloadXmlResult |
522
|
|
|
{ |
523
|
2 |
|
$command = new Utilities\DownloadXmlCommand($uuid, $rfc, 'R'); |
524
|
2 |
|
$service = new Utilities\DownloadXmlService($this->settings()); |
525
|
2 |
|
return $service->downloadXml($command); |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
/** |
529
|
|
|
* Este método regresa la información de un XML de retenciones e información de pagos ya timbrado previamente y |
530
|
|
|
* que por algún motivo no se pudo recuperar en la primera petición que se realizó, |
531
|
|
|
* con este método se puede recuperar el UUID y el XML timbrado |
532
|
|
|
* |
533
|
|
|
* Nota: el método no está documentado en Finkok |
534
|
|
|
* |
535
|
|
|
* @param string $preCfdi |
536
|
|
|
* @return Retentions\StampedResult |
537
|
|
|
* @see https://wiki.finkok.com/doku.php?id=retentions |
538
|
|
|
*/ |
539
|
2 |
|
public function retentionStamped(string $preCfdi): Retentions\StampedResult |
540
|
|
|
{ |
541
|
2 |
|
$command = new Retentions\StampedCommand($preCfdi); |
542
|
2 |
|
$service = new Retentions\StampedService($this->settings()); |
543
|
2 |
|
return $service->stamped($command); |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
/** |
547
|
|
|
* Este método es el encargado de cancelar un CFDI de retenciones emitido por medio de los web services de Finkok |
548
|
|
|
* Durante el proceso no se envía ningún CSD a Finkok y la solicitud firmada es creada usando los datos del CSD |
549
|
|
|
* |
550
|
|
|
* @param Credential $credential |
551
|
|
|
* @param CancelDocument $document |
552
|
|
|
* @return Retentions\CancelSignatureResult |
553
|
|
|
* @see https://wiki.finkok.com/doku.php?id=cancel_signature_method_retentions |
554
|
|
|
* @see https://wiki.finkok.com/doku.php?id=cancel_method_retentions |
555
|
|
|
*/ |
556
|
1 |
|
public function retentionCancel(Credential $credential, CancelDocument $document): Retentions\CancelSignatureResult |
557
|
|
|
{ |
558
|
1 |
|
$signer = new Helpers\CancelSigner(new CancelDocuments($document)); |
559
|
1 |
|
$signedRequest = $signer->signRetention($credential); |
560
|
1 |
|
$command = new Retentions\CancelSignatureCommand($signedRequest); |
561
|
1 |
|
$service = new Retentions\CancelSignatureService($this->settings()); |
562
|
1 |
|
return $service->cancelSignature($command); |
563
|
|
|
} |
564
|
|
|
} |
565
|
|
|
|