From 3c05ce484436e70170531e23e1dc04ebd05205d9 Mon Sep 17 00:00:00 2001 From: FranBarro Date: Fri, 8 Sep 2023 08:29:17 +0200 Subject: [PATCH 1/6] Add namespaces for DocBlock. Add missing returns in some functions of PropertiesTrait. --- src/Extensions/FacturaeExtension.php | 1 + src/Face/SoapClient.php | 1 + src/Face/Traits/FaceTrait.php | 2 ++ src/Face/Traits/Faceb2bTrait.php | 2 ++ src/FacturaeTraits/PropertiesTrait.php | 5 +++++ 5 files changed, 11 insertions(+) diff --git a/src/Extensions/FacturaeExtension.php b/src/Extensions/FacturaeExtension.php index c50267b..9891242 100644 --- a/src/Extensions/FacturaeExtension.php +++ b/src/Extensions/FacturaeExtension.php @@ -1,5 +1,6 @@ $isPercentage ? $value : null, "amount" => $isPercentage ? null : $value ); + return $this; } @@ -622,6 +625,7 @@ public function clearCharges() { */ public function setRelatedInvoice($relatedInvoice) { $this->header['relatedInvoice'] = $relatedInvoice; + return $this; } @@ -671,6 +675,7 @@ public function addAttachment($file, $description=null) { "file" => $file, "description" => $description ); + return $this; } From ad7611ea01da0502f7f0c1a254c8c1b93f473766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Miguel=20Moreno?= Date: Sat, 9 Sep 2023 12:20:22 +0200 Subject: [PATCH 2/6] Mejoras en DocBlocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Añadidos tipos faltantes en DocBlocks - Corregidos typos en documentación --- src/Common/FacturaeSigner.php | 4 +-- src/Common/XmlTools.php | 2 +- src/CorrectiveDetails.php | 4 +-- src/Extensions/FacturaeExtension.php | 1 + src/Face/SoapClient.php | 5 ++-- src/Face/Traits/FaceTrait.php | 33 +++++++++++----------- src/Face/Traits/Faceb2bTrait.php | 12 ++++---- src/Facturae.php | 38 +++++++++++++------------- src/FacturaePayment.php | 2 +- src/FacturaeTraits/ExportableTrait.php | 7 +++-- src/FacturaeTraits/PropertiesTrait.php | 2 ++ src/FacturaeTraits/SignableTrait.php | 3 ++ src/FacturaeTraits/UtilsTrait.php | 11 ++++++-- src/ReimbursableExpense.php | 2 +- 14 files changed, 68 insertions(+), 58 deletions(-) diff --git a/src/Common/FacturaeSigner.php b/src/Common/FacturaeSigner.php index 4f1a18b..848fe0f 100644 --- a/src/Common/FacturaeSigner.php +++ b/src/Common/FacturaeSigner.php @@ -45,7 +45,7 @@ final class FacturaeSigner { public $timestampId; /** - * Class constuctor + * Class constructor */ public function __construct() { $this->regenerateIds(); @@ -72,7 +72,7 @@ public function regenerateIds() { /** * Set signing time - * @param int|string $time Time of the signature as UNIX timestamp or parseable date + * @param int|string $time Time of the signature as UNIX timestamp or parsable date * @return self This instance */ public function setSigningTime($time) { diff --git a/src/Common/XmlTools.php b/src/Common/XmlTools.php index 1782f20..d8f46e3 100644 --- a/src/Common/XmlTools.php +++ b/src/Common/XmlTools.php @@ -119,7 +119,7 @@ public static function toBase64($bytes, $pretty=false) { /** * Prettify * @param string $input Input string - * @return string Multi-line resposne + * @return string Multi-line response */ private static function prettify($input) { return chunk_split($input, 76, "\n"); diff --git a/src/CorrectiveDetails.php b/src/CorrectiveDetails.php index 3a38529..d5a99f5 100644 --- a/src/CorrectiveDetails.php +++ b/src/CorrectiveDetails.php @@ -35,13 +35,13 @@ class CorrectiveDetails { public $reasonDescription = null; /** - * Start of tax period (as UNIX timestamp or parseable date string) + * Start of tax period (as UNIX timestamp or parsable date string) * @var string|int|null */ public $taxPeriodStart = null; /** - * End of tax period (as UNIX timestamp or parseable date string) + * End of tax period (as UNIX timestamp or parsable date string) * @var string|int|null */ public $taxPeriodEnd = null; diff --git a/src/Extensions/FacturaeExtension.php b/src/Extensions/FacturaeExtension.php index 9891242..73ab121 100644 --- a/src/Extensions/FacturaeExtension.php +++ b/src/Extensions/FacturaeExtension.php @@ -1,5 +1,6 @@ request(''); @@ -26,8 +25,8 @@ public function getStatus() { /** * Get administrations - * @param boolean $onlyTopLevel Get only top level administrations - * @return SimpleXMLElement Response + * @param boolean $onlyTopLevel Get only top level administrations + * @return \SimpleXMLElement Response */ public function getAdministrations($onlyTopLevel=true) { $tag = "consultarAdministraciones"; @@ -38,8 +37,8 @@ public function getAdministrations($onlyTopLevel=true) { /** * Get units - * @param string|null $code Administration code - * @return SimpleXMLElement Response + * @param string|null $code Administration code + * @return \SimpleXMLElement Response */ public function getUnits($code=null) { if (is_null($code)) return $this->request(''); @@ -51,8 +50,8 @@ public function getUnits($code=null) { /** * Get NIFs - * @param string|null $code Administration code - * @return SimpleXMLElement Response + * @param string|null $code Administration code + * @return \SimpleXMLElement Response */ public function getNifs($code=null) { if (is_null($code)) return $this->request(''); @@ -64,8 +63,8 @@ public function getNifs($code=null) { /** * Get invoice - * @param string|string[] $regId Invoice register ID(s) - * @return SimpleXMLElement Response + * @param string|string[] $regId Invoice register ID(s) + * @return \SimpleXMLElement Response */ public function getInvoices($regId) { if (is_string($regId)) { @@ -82,10 +81,10 @@ public function getInvoices($regId) { /** * Send invoice - * @param string $email Email address - * @param FacturaeFile $invoice Invoice - * @param FacturaeFile[] $attachments Attachments - * @return SimpleXMLElement Response + * @param string $email Email address + * @param FacturaeFile $invoice Invoice + * @param FacturaeFile[] $attachments Attachments + * @return \SimpleXMLElement Response */ public function sendInvoice($email, $invoice, $attachments=array()) { $req = ''; @@ -111,9 +110,9 @@ public function sendInvoice($email, $invoice, $attachments=array()) { /** * Cancel invoice - * @param string $regId Invoice register ID - * @param string $reason Cancelation reason - * @return SimpleXMLElement Response + * @param string $regId Invoice register ID + * @param string $reason Cancellation reason + * @return \SimpleXMLElement Response */ public function cancelInvoice($regId, $reason) { return $this->request('' . diff --git a/src/Face/Traits/Faceb2bTrait.php b/src/Face/Traits/Faceb2bTrait.php index bec71f4..37084b5 100644 --- a/src/Face/Traits/Faceb2bTrait.php +++ b/src/Face/Traits/Faceb2bTrait.php @@ -118,8 +118,8 @@ public function downloadInvoice($regId, $validate=true) { /** * Confirm invoice download - * @param string $regId Registry number - * @return SimpleXMLElement Response + * @param string $regId Registry number + * @return SimpleXMLElement Response */ public function confirmInvoiceDownload($regId) { return $this->request('' . @@ -149,8 +149,8 @@ public function rejectInvoice($regId, $reason, $comment=null) { /** * Mark invoice as paid - * @param string $regId Registry number - * @return SimpleXMLElement Response + * @param string $regId Registry number + * @return SimpleXMLElement Response */ public function markInvoiceAsPaid($regId) { return $this->request('' . @@ -161,8 +161,8 @@ public function markInvoiceAsPaid($regId) { /** * Accept invoice cancellation - * @param string $regId Registry number - * @return SimpleXMLElement Response + * @param string $regId Registry number + * @return SimpleXMLElement Response */ public function acceptInvoiceCancellation($regId) { return $this->request('' . diff --git a/src/Facturae.php b/src/Facturae.php index d292831..72b76f9 100644 --- a/src/Facturae.php +++ b/src/Facturae.php @@ -33,43 +33,43 @@ class Facturae { const PRECISION_LINE = 1; const PRECISION_INVOICE = 2; - /** @deprecated 1.7.3 Use constants from @see{FacturaePayment} class instead. */ + /** @deprecated 1.7.3 Use constants from {@see FacturaePayment} class instead. */ const PAYMENT_CASH = "01"; - /** @deprecated 1.7.3 Use constants from @see{FacturaePayment} class instead. */ + /** @deprecated 1.7.3 Use constants from {@see FacturaePayment} class instead. */ const PAYMENT_DEBIT = "02"; - /** @deprecated 1.7.3 Use constants from @see{FacturaePayment} class instead. */ + /** @deprecated 1.7.3 Use constants from {@see FacturaePayment} class instead. */ const PAYMENT_RECEIPT = "03"; - /** @deprecated 1.7.3 Use constants from @see{FacturaePayment} class instead. */ + /** @deprecated 1.7.3 Use constants from {@see FacturaePayment} class instead. */ const PAYMENT_TRANSFER = "04"; - /** @deprecated 1.7.3 Use constants from @see{FacturaePayment} class instead. */ + /** @deprecated 1.7.3 Use constants from {@see FacturaePayment} class instead. */ const PAYMENT_ACCEPTED_BILL_OF_EXCHANGE = "05"; - /** @deprecated 1.7.3 Use constants from @see{FacturaePayment} class instead. */ + /** @deprecated 1.7.3 Use constants from {@see FacturaePayment} class instead. */ const PAYMENT_DOCUMENTARY_CREDIT = "06"; - /** @deprecated 1.7.3 Use constants from @see{FacturaePayment} class instead. */ + /** @deprecated 1.7.3 Use constants from {@see FacturaePayment} class instead. */ const PAYMENT_CONTRACT_AWARD = "07"; - /** @deprecated 1.7.3 Use constants from @see{FacturaePayment} class instead. */ + /** @deprecated 1.7.3 Use constants from {@see FacturaePayment} class instead. */ const PAYMENT_BILL_OF_EXCHANGE = "08"; - /** @deprecated 1.7.3 Use constants from @see{FacturaePayment} class instead. */ + /** @deprecated 1.7.3 Use constants from {@see FacturaePayment} class instead. */ const PAYMENT_TRANSFERABLE_IOU = "09"; - /** @deprecated 1.7.3 Use constants from @see{FacturaePayment} class instead. */ + /** @deprecated 1.7.3 Use constants from {@see FacturaePayment} class instead. */ const PAYMENT_IOU = "10"; - /** @deprecated 1.7.3 Use constants from @see{FacturaePayment} class instead. */ + /** @deprecated 1.7.3 Use constants from {@see FacturaePayment} class instead. */ const PAYMENT_CHEQUE = "11"; - /** @deprecated 1.7.3 Use constants from @see{FacturaePayment} class instead. */ + /** @deprecated 1.7.3 Use constants from {@see FacturaePayment} class instead. */ const PAYMENT_REIMBURSEMENT = "12"; - /** @deprecated 1.7.3 Use constants from @see{FacturaePayment} class instead. */ + /** @deprecated 1.7.3 Use constants from {@see FacturaePayment} class instead. */ const PAYMENT_SPECIAL = "13"; - /** @deprecated 1.7.3 Use constants from @see{FacturaePayment} class instead. */ + /** @deprecated 1.7.3 Use constants from {@see FacturaePayment} class instead. */ const PAYMENT_SETOFF = "14"; - /** @deprecated 1.7.3 Use constants from @see{FacturaePayment} class instead. */ + /** @deprecated 1.7.3 Use constants from {@see FacturaePayment} class instead. */ const PAYMENT_POSTGIRO = "15"; - /** @deprecated 1.7.3 Use constants from @see{FacturaePayment} class instead. */ + /** @deprecated 1.7.3 Use constants from {@see FacturaePayment} class instead. */ const PAYMENT_CERTIFIED_CHEQUE = "16"; - /** @deprecated 1.7.3 Use constants from @see{FacturaePayment} class instead. */ + /** @deprecated 1.7.3 Use constants from {@see FacturaePayment} class instead. */ const PAYMENT_BANKERS_DRAFT = "17"; - /** @deprecated 1.7.3 Use constants from @see{FacturaePayment} class instead. */ + /** @deprecated 1.7.3 Use constants from {@see FacturaePayment} class instead. */ const PAYMENT_CASH_ON_DELIVERY = "18"; - /** @deprecated 1.7.3 Use constants from @see{FacturaePayment} class instead. */ + /** @deprecated 1.7.3 Use constants from {@see FacturaePayment} class instead. */ const PAYMENT_CARD = "19"; const TAX_IVA = "01"; diff --git a/src/FacturaePayment.php b/src/FacturaePayment.php index a8ca0a4..ef4047a 100644 --- a/src/FacturaePayment.php +++ b/src/FacturaePayment.php @@ -34,7 +34,7 @@ class FacturaePayment { public $method = self::TYPE_CASH; /** - * Payment due date (as UNIX timestamp or parseable date string) + * Payment due date (as UNIX timestamp or parsable date string) * @var int|string|null */ public $dueDate = null; diff --git a/src/FacturaeTraits/ExportableTrait.php b/src/FacturaeTraits/ExportableTrait.php index 6b7c4d3..1f07184 100644 --- a/src/FacturaeTraits/ExportableTrait.php +++ b/src/FacturaeTraits/ExportableTrait.php @@ -2,18 +2,20 @@ namespace josemmo\Facturae\FacturaeTraits; use josemmo\Facturae\Common\XmlTools; -use josemmo\Facturae\CorrectiveDetails; +use josemmo\Facturae\Facturae; use josemmo\Facturae\FacturaePayment; use josemmo\Facturae\ReimbursableExpense; /** * Allows a Facturae instance to be exported to XML. + * + * @var Facturae $this */ trait ExportableTrait { /** * Add optional fields - * @param object $item Subject item + * @param array $item Subject item * @param string[] $fields Optional fields * @return string Output XML */ @@ -43,7 +45,6 @@ public function export($filePath=null) { // Prepare document $xml = ''; $totals = $this->getTotals(); - /** @var CorrectiveDetails|null */ $corrective = $this->getCorrective(); $paymentDetailsXML = $this->getPaymentDetailsXML($totals); diff --git a/src/FacturaeTraits/PropertiesTrait.php b/src/FacturaeTraits/PropertiesTrait.php index ad2cc25..5702480 100644 --- a/src/FacturaeTraits/PropertiesTrait.php +++ b/src/FacturaeTraits/PropertiesTrait.php @@ -13,6 +13,8 @@ * Implements all attributes and methods needed to make Facturae instantiable. * This includes all properties that define an electronic invoice, but without * additional functionalities such as signing or exporting. + * + * @var Facturae $this */ trait PropertiesTrait { protected $currency = "EUR"; diff --git a/src/FacturaeTraits/SignableTrait.php b/src/FacturaeTraits/SignableTrait.php index 65b1791..23a7032 100644 --- a/src/FacturaeTraits/SignableTrait.php +++ b/src/FacturaeTraits/SignableTrait.php @@ -2,10 +2,13 @@ namespace josemmo\Facturae\FacturaeTraits; use josemmo\Facturae\Common\FacturaeSigner; +use josemmo\Facturae\Facturae; /** * Implements all properties and methods needed for an instantiable * Facturae to be signed and time stamped. + * + * @var Facturae $this */ trait SignableTrait { /** @var FacturaeSigner|null */ diff --git a/src/FacturaeTraits/UtilsTrait.php b/src/FacturaeTraits/UtilsTrait.php index 858435c..02dea57 100644 --- a/src/FacturaeTraits/UtilsTrait.php +++ b/src/FacturaeTraits/UtilsTrait.php @@ -1,8 +1,13 @@ Date: Sat, 28 Oct 2023 18:43:28 +0200 Subject: [PATCH 3/6] Arreglo X509IssuerName - Actualizada clase FacturaeSigner > Fixes #142 --- src/Common/FacturaeSigner.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Common/FacturaeSigner.php b/src/Common/FacturaeSigner.php index 848fe0f..d802d52 100644 --- a/src/Common/FacturaeSigner.php +++ b/src/Common/FacturaeSigner.php @@ -154,8 +154,11 @@ public function sign($xml) { $signingTime = ($this->signingTime === null) ? time() : $this->signingTime; $certData = openssl_x509_parse($this->publicChain[0]); $certIssuer = []; - foreach ($certData['issuer'] as $item=>$value) { - $certIssuer[] = "$item=$value"; + foreach ($certData['issuer'] as $item=>$rawValues) { + $values = is_array($rawValues) ? $rawValues : [$rawValues]; + foreach ($values as $value) { + $certIssuer[] = "$item=$value"; + } } $certIssuer = implode(',', array_reverse($certIssuer)); $xadesSignedProperties = '' . From 96c5b830a349e97e0136407868c7d026adde6a1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Miguel=20Moreno?= Date: Sun, 12 Nov 2023 13:53:47 +0100 Subject: [PATCH 4/6] =?UTF-8?q?A=C3=B1adida=20correcci=C3=B3n=20de=20atrib?= =?UTF-8?q?utos=20OID=20al=20firmar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Actualizada clase FacturaeSigner > Related to #143 --- src/Common/FacturaeSigner.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Common/FacturaeSigner.php b/src/Common/FacturaeSigner.php index d802d52..b97ca04 100644 --- a/src/Common/FacturaeSigner.php +++ b/src/Common/FacturaeSigner.php @@ -13,6 +13,27 @@ final class FacturaeSigner { const SIGN_POLICY_NAME = 'Política de Firma FacturaE v3.1'; const SIGN_POLICY_URL = 'http://www.facturae.es/politica_de_firma_formato_facturae/politica_de_firma_formato_facturae_v3_1.pdf'; const SIGN_POLICY_DIGEST = 'Ohixl6upD6av8N7pEvDABhEL6hM='; + const ALLOWED_OID_TYPES = [ + // Mandatory fields in https://datatracker.ietf.org/doc/html/rfc4514#section-3 + 'CN' => 'CN', + 'L' => 'L', + 'ST' => 'ST', + 'O' => 'O', + 'OU' => 'OU', + 'C' => 'C', + 'STREET' => 'STREET', + 'DC' => 'DC', + 'UID' => 'UID', + + // Other fields with well-known names + 'GN' => 'GN', + 'SN' => 'SN', + + // Other fields with compatibility issues + 'organizationIdentifier' => 'OID.2.5.4.97', + 'serialNumber' => 'OID.2.5.4.5', + 'title' => 'OID.2.5.4.12', + ]; use KeyPairReaderTrait; @@ -155,12 +176,16 @@ public function sign($xml) { $certData = openssl_x509_parse($this->publicChain[0]); $certIssuer = []; foreach ($certData['issuer'] as $item=>$rawValues) { + if (!isset(self::ALLOWED_OID_TYPES[$item])) { + continue; + } + $item = self::ALLOWED_OID_TYPES[$item]; $values = is_array($rawValues) ? $rawValues : [$rawValues]; foreach ($values as $value) { $certIssuer[] = "$item=$value"; } } - $certIssuer = implode(',', array_reverse($certIssuer)); + $certIssuer = implode(', ', array_reverse($certIssuer)); $xadesSignedProperties = '' . '' . '' . date('c', $signingTime) . '' . From 69194142bf7e0d3b797341b3691dbbb9f629f230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Miguel=20Moreno?= Date: Sun, 12 Nov 2023 13:59:12 +0100 Subject: [PATCH 5/6] =?UTF-8?q?A=C3=B1adida=20correcci=C3=B3n=20de=20atrib?= =?UTF-8?q?utos=20OID=20al=20firmar=20(II)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Actualizada clase FacturaeSigner para añadir compatibilidad con PHP 5.6 > Related to #143 --- src/Common/FacturaeSigner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Common/FacturaeSigner.php b/src/Common/FacturaeSigner.php index b97ca04..9b69cde 100644 --- a/src/Common/FacturaeSigner.php +++ b/src/Common/FacturaeSigner.php @@ -176,7 +176,7 @@ public function sign($xml) { $certData = openssl_x509_parse($this->publicChain[0]); $certIssuer = []; foreach ($certData['issuer'] as $item=>$rawValues) { - if (!isset(self::ALLOWED_OID_TYPES[$item])) { + if (!array_key_exists($item, self::ALLOWED_OID_TYPES)) { continue; } $item = self::ALLOWED_OID_TYPES[$item]; From 40b66637f3f7b9c444522d56fc837daf9fb75b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Miguel=20Moreno?= Date: Sun, 19 Nov 2023 09:43:01 +0100 Subject: [PATCH 6/6] v1.7.9 --- src/Facturae.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Facturae.php b/src/Facturae.php index 72b76f9..10ec12d 100644 --- a/src/Facturae.php +++ b/src/Facturae.php @@ -10,7 +10,7 @@ * Class for creating electronic invoices that comply with the Spanish FacturaE format. */ class Facturae { - const VERSION = "1.7.8"; + const VERSION = "1.7.9"; const USER_AGENT = "FacturaePHP/" . self::VERSION; const SCHEMA_3_2 = "3.2";