-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f690c98
commit 0cdbbbb
Showing
13 changed files
with
467 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Anaf\Enums\Efactura; | ||
|
||
enum ConvertXmlStandard: string | ||
{ | ||
case INVOICE = 'FACT1'; | ||
case CREDIT_NOTE = 'FCN'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Anaf\Enums\Efactura; | ||
|
||
enum MessagesFilter: string | ||
{ | ||
case ERROR = 'E'; | ||
case RECEIVED = 'P'; | ||
case SENT = 'T'; | ||
case MESSAGE_RESPONSE = 'R'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,6 @@ | |
|
||
namespace Anaf\Enums\Efactura; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
enum UploadStandard: string | ||
{ | ||
case UBL = 'UBL'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace Anaf\Requests\Efactura; | ||
|
||
use Anaf\Enums\Efactura\MessagesFilter; | ||
use InvalidArgumentException; | ||
|
||
class MessagesRequest | ||
{ | ||
/** | ||
* @param array<string, string> $parameters | ||
*/ | ||
public function __construct( | ||
private readonly array $parameters, | ||
) { | ||
// .. | ||
} | ||
|
||
/** | ||
* Creates a new Messages value object | ||
*/ | ||
public static function withTaxIdetificationNumber(string $taxIdentificationNumber): self | ||
{ | ||
return new self( | ||
parameters: [ | ||
'cif' => $taxIdentificationNumber, | ||
], | ||
); | ||
} | ||
|
||
/** | ||
* Creates a new Message value object with the zile parameter | ||
*/ | ||
public function withDays(int $days): self | ||
{ | ||
if ($days < 1 || $days > 60) { | ||
throw new InvalidArgumentException('Days must be between 1 and 60'); | ||
} | ||
|
||
return new self( | ||
parameters: [ | ||
...$this->parameters, | ||
'zile' => (string) $days, | ||
], | ||
); | ||
} | ||
|
||
/** | ||
* Creates a new Message value object with the filtru parameter | ||
*/ | ||
public function withFilter(MessagesFilter $filter): self | ||
{ | ||
return new self( | ||
parameters: [ | ||
...$this->parameters, | ||
'filtru' => $filter->value, | ||
], | ||
); | ||
} | ||
|
||
/** | ||
* @return array<string, string> $parameters | ||
*/ | ||
public function toArray(): array | ||
{ | ||
$requiredKeys = ['zile', 'cif']; | ||
|
||
$missingKeys = array_diff($requiredKeys, array_keys($this->parameters)); | ||
|
||
if ($missingKeys !== []) { | ||
throw new InvalidArgumentException('Missing required parameters: '.implode(', ', $missingKeys)); | ||
} | ||
|
||
return $this->parameters; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
namespace Anaf\Requests\Efactura; | ||
|
||
use Anaf\Enums\Efactura\UploadStandard; | ||
use InvalidArgumentException; | ||
|
||
class UploadRequest | ||
{ | ||
/** | ||
* @param array<string, string> $parameters | ||
*/ | ||
public function __construct( | ||
private readonly string $xml_path, | ||
private readonly array $parameters, | ||
) { | ||
// .. | ||
} | ||
|
||
/** | ||
* Creates a new UploadParameters value object with the xml_path parameter | ||
*/ | ||
public static function withXmlPath(string $xml_path): self | ||
{ | ||
return new self(xml_path: $xml_path, parameters: []); | ||
} | ||
|
||
/** | ||
* Creates a new UploadParameters value object with the tax_identification_number parameter | ||
*/ | ||
public function withTaxIdentificationNumber(string|int $tax_identification_number): self | ||
{ | ||
return new self( | ||
xml_path: $this->xml_path, | ||
parameters: [ | ||
...$this->parameters, | ||
'cif' => (string) $tax_identification_number, | ||
], | ||
); | ||
} | ||
|
||
/** | ||
* Creates a new UploadParameters value object with the standard parameter | ||
*/ | ||
public function withStandard(UploadStandard $standard): self | ||
{ | ||
return new self( | ||
xml_path: $this->xml_path, | ||
parameters: [ | ||
...$this->parameters, | ||
'standard' => $standard->value, | ||
], | ||
); | ||
} | ||
|
||
/** | ||
* Creates a new UploadParameters value object with the extern parameter | ||
*/ | ||
public function extern(): self | ||
{ | ||
return new self( | ||
xml_path: $this->xml_path, | ||
parameters: [ | ||
...$this->parameters, | ||
'extern' => 'DA', | ||
], | ||
); | ||
} | ||
|
||
/** | ||
* Creates a new UploadParameters value object with the selfInvoice parameter | ||
*/ | ||
public function selfInvoice(): self | ||
{ | ||
return new self( | ||
xml_path: $this->xml_path, | ||
parameters: [ | ||
...$this->parameters, | ||
'autofactura' => 'DA', | ||
], | ||
); | ||
} | ||
|
||
/** | ||
* @return array<string, string> $parameters | ||
*/ | ||
public function toArray(): array | ||
{ | ||
$requiredKeys = ['cif', 'standard']; | ||
|
||
$missingKeys = array_diff($requiredKeys, array_keys($this->parameters)); | ||
|
||
if ($missingKeys !== []) { | ||
throw new InvalidArgumentException('Missing required parameters: '.implode(', ', $missingKeys)); | ||
} | ||
|
||
return $this->parameters; | ||
} | ||
|
||
/** | ||
* Xml path getter | ||
*/ | ||
public function getXmlPath(): string | ||
{ | ||
if ($this->xml_path === '' || $this->xml_path === '0') { | ||
throw new InvalidArgumentException('Xml path is required'); | ||
} | ||
|
||
return $this->xml_path; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Anaf\Requests\Efactura; | ||
|
||
use Anaf\Enums\Efactura\ConvertXmlStandard; | ||
use InvalidArgumentException; | ||
|
||
class XmlToPdfRequest | ||
{ | ||
public function __construct( | ||
private readonly string $xml_path, | ||
public readonly ConvertXmlStandard $standard = ConvertXmlStandard::INVOICE, | ||
public readonly bool $validate = true, | ||
) { | ||
// .. | ||
} | ||
|
||
/** | ||
* Creates a new UploadParameters value object with the xml_path parameter | ||
*/ | ||
public static function withXmlPath(string $xml_path): self | ||
{ | ||
return new self(xml_path: $xml_path); | ||
} | ||
|
||
/** | ||
* Creates XML to PDF request with the standard parameter | ||
*/ | ||
public function withStandard(ConvertXmlStandard $standard): self | ||
{ | ||
return new self( | ||
xml_path: $this->xml_path, | ||
standard: $standard, | ||
validate: $this->validate, | ||
); | ||
} | ||
|
||
/** | ||
* Creates a new UploadParameters value object with the selfInvoice parameter | ||
*/ | ||
public function withoutValidation(): self | ||
{ | ||
return new self( | ||
xml_path: $this->xml_path, | ||
standard: $this->standard, | ||
validate: false, | ||
); | ||
} | ||
|
||
/** | ||
* Xml path getter | ||
*/ | ||
public function getXmlPath(): string | ||
{ | ||
if ($this->xml_path === '' || $this->xml_path === '0') { | ||
throw new InvalidArgumentException('Xml path is required'); | ||
} | ||
|
||
return $this->xml_path; | ||
} | ||
} |
Oops, something went wrong.