Skip to content

Commit

Permalink
Merge pull request #144 from josemmo/develop
Browse files Browse the repository at this point in the history
v1.7.9
  • Loading branch information
josemmo authored Nov 19, 2023
2 parents 3c490fa + 40b6663 commit 6d5fb5f
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 60 deletions.
38 changes: 33 additions & 5 deletions src/Common/FacturaeSigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -45,7 +66,7 @@ final class FacturaeSigner {
public $timestampId;

/**
* Class constuctor
* Class constructor
*/
public function __construct() {
$this->regenerateIds();
Expand All @@ -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) {
Expand Down Expand Up @@ -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 = '<xades:SignedProperties Id="'. $this->signatureSignedPropertiesId . '">' .
'<xades:SignedSignatureProperties>' .
'<xades:SigningTime>' . date('c', $signingTime) . '</xades:SigningTime>' .
Expand Down
2 changes: 1 addition & 1 deletion src/Common/XmlTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/CorrectiveDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/Extensions/FacturaeExtension.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace josemmo\Facturae\Extensions;

use josemmo\Facturae\Facturae;

abstract class FacturaeExtension {
private $fac;

Expand Down
4 changes: 2 additions & 2 deletions src/Face/SoapClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ protected abstract function getWebNamespace();

/**
* Send SOAP request
* @param string $body Request body
* @return SimpleXMLElement Response
* @param string $body Request body
* @return \SimpleXMLElement Response
*/
protected function request($body) {
// Generate random IDs for this request
Expand Down
33 changes: 17 additions & 16 deletions src/Face/Traits/FaceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace josemmo\Facturae\Face\Traits;

use josemmo\Facturae\Common\XmlTools;
use josemmo\Facturae\FacturaeFile;

trait FaceTrait {
/**
Expand All @@ -15,7 +16,7 @@ protected function getWebNamespace() {

/**
* Get invoice status codes
* @return SimpleXMLElement Response
* @return \SimpleXMLElement Response
*/
public function getStatus() {
return $this->request('<web:consultarEstados></web:consultarEstados>');
Expand All @@ -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";
Expand All @@ -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('<web:consultarUnidades></web:consultarUnidades>');
Expand All @@ -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('<web:consultarNIFs></web:consultarNIFs>');
Expand All @@ -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)) {
Expand All @@ -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 = '<web:enviarFactura><request>';
Expand All @@ -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('<web:anularFactura>' .
Expand Down
14 changes: 8 additions & 6 deletions src/Face/Traits/Faceb2bTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
namespace josemmo\Facturae\Face\Traits;

use josemmo\Facturae\Common\XmlTools;
use josemmo\Facturae\FacturaeFile;
use SimpleXMLElement;

trait Faceb2bTrait {
/**
Expand Down Expand Up @@ -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('<web:ConfirmInvoiceDownload><request>' .
Expand Down Expand Up @@ -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('<web:MarkInvoiceAsPaid><request>' .
Expand All @@ -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('<web:AcceptInvoiceCancellation><request>' .
Expand Down
40 changes: 20 additions & 20 deletions src/Facturae.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/FacturaePayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/FacturaeTraits/ExportableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -43,7 +45,6 @@ public function export($filePath=null) {
// Prepare document
$xml = '<fe:Facturae xmlns:fe="' . self::$SCHEMA_NS[$this->version] . '">';
$totals = $this->getTotals();
/** @var CorrectiveDetails|null */
$corrective = $this->getCorrective();
$paymentDetailsXML = $this->getPaymentDetailsXML($totals);

Expand Down
7 changes: 7 additions & 0 deletions src/FacturaeTraits/PropertiesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
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;

/**
* 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";
Expand Down Expand Up @@ -593,6 +597,7 @@ public function addCharge($reason, $value, $isPercentage=true) {
"rate" => $isPercentage ? $value : null,
"amount" => $isPercentage ? null : $value
);
return $this;
}


Expand Down Expand Up @@ -622,6 +627,7 @@ public function clearCharges() {
*/
public function setRelatedInvoice($relatedInvoice) {
$this->header['relatedInvoice'] = $relatedInvoice;
return $this;
}


Expand Down Expand Up @@ -671,6 +677,7 @@ public function addAttachment($file, $description=null) {
"file" => $file,
"description" => $description
);
return $this;
}


Expand Down
Loading

0 comments on commit 6d5fb5f

Please sign in to comment.