diff --git a/src/Common/FacturaeSigner.php b/src/Common/FacturaeSigner.php index 4f1a18b..9b69cde 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; @@ -45,7 +66,7 @@ final class FacturaeSigner { public $timestampId; /** - * Class constuctor + * Class constructor */ public function __construct() { $this->regenerateIds(); @@ -72,7 +93,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) { @@ -154,10 +175,17 @@ 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) { + if (!array_key_exists($item, self::ALLOWED_OID_TYPES)) { + 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) . '' . 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 c50267b..73ab121 100644 --- a/src/Extensions/FacturaeExtension.php +++ b/src/Extensions/FacturaeExtension.php @@ -1,6 +1,8 @@ request(''); @@ -24,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"; @@ -36,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(''); @@ -49,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(''); @@ -62,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)) { @@ -80,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 = ''; @@ -109,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 a4494d9..37084b5 100644 --- a/src/Face/Traits/Faceb2bTrait.php +++ b/src/Face/Traits/Faceb2bTrait.php @@ -2,6 +2,8 @@ namespace josemmo\Facturae\Face\Traits; use josemmo\Facturae\Common\XmlTools; +use josemmo\Facturae\FacturaeFile; +use SimpleXMLElement; trait Faceb2bTrait { /** @@ -116,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('' . @@ -147,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('' . @@ -159,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..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"; @@ -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 f62a1f2..5702480 100644 --- a/src/FacturaeTraits/PropertiesTrait.php +++ b/src/FacturaeTraits/PropertiesTrait.php @@ -2,8 +2,10 @@ namespace josemmo\Facturae\FacturaeTraits; use josemmo\Facturae\CorrectiveDetails; +use josemmo\Facturae\Facturae; use josemmo\Facturae\FacturaeFile; use josemmo\Facturae\FacturaeItem; +use josemmo\Facturae\FacturaeParty; use josemmo\Facturae\FacturaePayment; use josemmo\Facturae\ReimbursableExpense; @@ -11,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"; @@ -593,6 +597,7 @@ public function addCharge($reason, $value, $isPercentage=true) { "rate" => $isPercentage ? $value : null, "amount" => $isPercentage ? null : $value ); + return $this; } @@ -622,6 +627,7 @@ public function clearCharges() { */ public function setRelatedInvoice($relatedInvoice) { $this->header['relatedInvoice'] = $relatedInvoice; + return $this; } @@ -671,6 +677,7 @@ public function addAttachment($file, $description=null) { "file" => $file, "description" => $description ); + return $this; } 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 @@