|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Squareetlabs\VeriFactu\Helpers; |
|
6
|
|
|
|
|
7
|
|
|
use Squareetlabs\VeriFactu\Contracts\VeriFactuInvoice; |
|
8
|
|
|
|
|
9
|
|
|
class QrUrlHelper |
|
10
|
|
|
{ |
|
11
|
|
|
public const PRE_URL_VF = 'https://prewww2.aeat.es/wlpl/TIKE-CONT/ValidarQR'; |
|
12
|
|
|
public const PROD_URL_VF = 'https://www2.agenciatributaria.gob.es/wlpl/TIKE-CONT/ValidarQR'; |
|
13
|
|
|
public const PRE_URL_NOVF = 'https://prewww2.aeat.es/wlpl/TIKE-CONT/ValidarQRNoVerifactu'; |
|
14
|
|
|
public const PROD_URL_NOVF = 'https://www2.agenciatributaria.gob.es/wlpl/TIKE-CONT/ValidarQRNoVerifactu'; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Build QR URL for an invoice |
|
18
|
|
|
* |
|
19
|
|
|
* @param VeriFactuInvoice $invoice |
|
20
|
|
|
* @param string $issuerVat NIF of the issuer |
|
21
|
|
|
* @param bool $production Whether to use production or test environment |
|
22
|
|
|
* @param bool|null $verifactuMode Whether to use VERIFACTU mode (true) or NO VERIFACTU mode (false) |
|
23
|
|
|
* @return string |
|
24
|
|
|
*/ |
|
25
|
|
|
public static function build( |
|
26
|
|
|
VeriFactuInvoice $invoice, |
|
27
|
|
|
string $issuerVat, |
|
28
|
|
|
bool $production = false, |
|
29
|
|
|
?bool $verifactuMode = null |
|
30
|
|
|
): string { |
|
31
|
|
|
$verifactuMode = $verifactuMode ?? config('verifactu.verifactu_mode', true); |
|
32
|
|
|
|
|
33
|
|
|
$base = self::getBaseUrl($production, $verifactuMode); |
|
34
|
|
|
|
|
35
|
|
|
$nif = $issuerVat; |
|
36
|
|
|
$numserie = (string) $invoice->getInvoiceNumber(); |
|
37
|
|
|
$fecha = $invoice->getIssueDate()->format('d-m-Y'); |
|
38
|
|
|
$importe = number_format((float) $invoice->getTotalAmount(), 2, '.', ''); |
|
39
|
|
|
|
|
40
|
|
|
$query = http_build_query([ |
|
41
|
|
|
'nif' => $nif, |
|
42
|
|
|
'numserie' => $numserie, |
|
43
|
|
|
'fecha' => $fecha, |
|
44
|
|
|
'importe' => $importe, |
|
45
|
|
|
], '', '&', PHP_QUERY_RFC3986); |
|
46
|
|
|
|
|
47
|
|
|
return $base . '?' . $query; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Get the base URL for QR validation |
|
52
|
|
|
* |
|
53
|
|
|
* @param bool $production |
|
54
|
|
|
* @param bool $verifactuMode |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
|
|
protected static function getBaseUrl(bool $production, bool $verifactuMode): string |
|
58
|
|
|
{ |
|
59
|
|
|
if ($verifactuMode) { |
|
60
|
|
|
return $production ? self::PROD_URL_VF : self::PRE_URL_VF; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return $production ? self::PROD_URL_NOVF : self::PRE_URL_NOVF; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|