From 612bd209f0334c392dea8af4c88aa4db10378f6a Mon Sep 17 00:00:00 2001 From: Andrei Dumitrescu Date: Mon, 19 Jan 2026 20:38:56 +0200 Subject: [PATCH 1/4] dump --- .idea/copilot.data.migration.ask2agent.xml | 6 + .idea/inspectionProfiles/Project_Default.xml | 10 ++ .idea/laravel-idea.xml | 8 + .idea/php-test-framework.xml | 14 ++ .idea/php.xml | 110 +++++++++++++ .idea/vcs.xml | 6 + .idea/workspace.xml | 165 +++++++++++++++++++ 7 files changed, 319 insertions(+) create mode 100644 .idea/copilot.data.migration.ask2agent.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/laravel-idea.xml create mode 100644 .idea/php-test-framework.xml create mode 100644 .idea/php.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/copilot.data.migration.ask2agent.xml b/.idea/copilot.data.migration.ask2agent.xml new file mode 100644 index 0000000..1f2ea11 --- /dev/null +++ b/.idea/copilot.data.migration.ask2agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..e59f67b --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/.idea/laravel-idea.xml b/.idea/laravel-idea.xml new file mode 100644 index 0000000..bd941a4 --- /dev/null +++ b/.idea/laravel-idea.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/.idea/php-test-framework.xml b/.idea/php-test-framework.xml new file mode 100644 index 0000000..2554281 --- /dev/null +++ b/.idea/php-test-framework.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..bbe79ea --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..ea1a1ae --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,165 @@ + + + + + + + + + $PROJECT_DIR$/composer.json + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + "associatedIndex": 6 +} + + + + { + "keyToString": { + "ModuleVcsDetector.initialDetectionPerformed": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true", + "RunOnceActivity.git.unshallow": "true", + "git-widget-placeholder": "main", + "last_opened_file_path": "/Users/andumy/Documents/JrEnterprising/Projects/anaf-php", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "vue.rearranger.settings.migration": "true" + } +} + + + + + + + + + + + + + + + + + + + + 1768843701611 + + + + + + + + + + + + \ No newline at end of file From a15168c0651a669fc386381d0a722641849bfe98 Mon Sep 17 00:00:00 2001 From: Andrei Dumitrescu Date: Mon, 19 Jan 2026 20:11:40 +0200 Subject: [PATCH 2/4] added internal stage option --- .gitignore | 1 + src/Anaf.php | 26 +++++++--- src/Factory.php | 11 ++-- src/Transporters/HttpTransporter.php | 5 +- src/ValueObjects/Transporter/Payload.php | 8 +-- tests/Anaf.php | 64 +++++++++++++++++++++++- tests/Pest.php | 15 ++++++ 7 files changed, 107 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 24a3f07..49352e0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ *.swp *.swo reports/* +.idea diff --git a/src/Anaf.php b/src/Anaf.php index 5ebc46c..c423175 100644 --- a/src/Anaf.php +++ b/src/Anaf.php @@ -10,22 +10,32 @@ class Anaf /** * Creates a new Anaf Authorized Client with the given api key. */ - public static function authorizedClient(string $apiKey): Client + public static function authorizedClient(string $apiKey, bool $isStage = false): Client { - return self::factory() + $factory = self::factory() ->withApiKey($apiKey) - ->withBaseUri('api.anaf.ro') - ->make(); + ->withBaseUri('api.anaf.ro'); + + if (!$isStage) { + return $factory->make(); + } + + return $factory->staging()->make(); } /** * Creates a new Anaf Client for non-authorized requests. */ - public static function client(): Client + public static function client(bool $isStage = false): Client { - return self::factory() - ->withBaseUri('webservicesp.anaf.ro') - ->make(); + $factory = self::factory() + ->withBaseUri('webservicesp.anaf.ro'); + + if (!$isStage) { + return $factory->make(); + } + + return $factory->staging()->make(); } /** diff --git a/src/Factory.php b/src/Factory.php index 65019e3..1687425 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -23,7 +23,7 @@ class Factory */ private ?string $baseUri = null; - private static bool $staging = false; + private bool $staging = false; /** * The query parameters for the requests. @@ -58,16 +58,11 @@ public function withBaseUri(string $baseUri): self */ public function staging(): self { - self::$staging = true; + $this->staging = true; return $this; } - public static function isStaging(): bool - { - return self::$staging; - } - /** * Adds a custom query parameter to the request url. */ @@ -99,7 +94,7 @@ public function make(): Client $client = new GuzzleClient; - $transporter = new HttpTransporter($client, $baseUri, $headers, $queryParams); + $transporter = new HttpTransporter($client, $baseUri, $headers, $queryParams, $this->staging); return new Client($transporter); } diff --git a/src/Transporters/HttpTransporter.php b/src/Transporters/HttpTransporter.php index 9f2ee14..d068e52 100644 --- a/src/Transporters/HttpTransporter.php +++ b/src/Transporters/HttpTransporter.php @@ -30,6 +30,7 @@ public function __construct( private readonly BaseUri $baseUri, private readonly Headers $headers, private readonly QueryParams $queryParams, + private readonly bool $isStage = false, ) { // .. } @@ -41,7 +42,7 @@ public function __construct( */ public function requestObject(Payload $payload): array { - $request = $payload->toRequest($this->baseUri, $this->headers, $this->queryParams); + $request = $payload->toRequest($this->baseUri, $this->headers, $this->queryParams, $this->isStage); try { $response = $this->client->sendRequest($request); @@ -81,7 +82,7 @@ public function requestObject(Payload $payload): array public function requestFile(Payload $payload): FileHandler { - $request = $payload->toRequest($this->baseUri, $this->headers, $this->queryParams); + $request = $payload->toRequest($this->baseUri, $this->headers, $this->queryParams, $this->isStage); try { $response = $this->client->sendRequest($request); diff --git a/src/ValueObjects/Transporter/Payload.php b/src/ValueObjects/Transporter/Payload.php index d86830e..6960066 100644 --- a/src/ValueObjects/Transporter/Payload.php +++ b/src/ValueObjects/Transporter/Payload.php @@ -81,11 +81,11 @@ public static function get(string $resource, array $parameters): self /** * Creates a new Psr 7 Request instance. */ - public function toRequest(BaseUri $baseUri, Headers $headers, QueryParams $queryParams): RequestInterface + public function toRequest(BaseUri $baseUri, Headers $headers, QueryParams $queryParams, bool $isStage = false): RequestInterface { $psr17Factory = new Psr17Factory; - $uri = $this->buildUri($baseUri); + $uri = $this->buildUri($baseUri, $isStage); $queryParams = $queryParams->toArray(); @@ -123,11 +123,11 @@ public function toRequest(BaseUri $baseUri, Headers $headers, QueryParams $query return $request; } - private function buildUri(BaseUri $baseUri): string + private function buildUri(BaseUri $baseUri, bool $isStage = false): string { $uri = $baseUri->toString().$this->uri->toString(); - if (! Factory::isStaging()) { + if (! $isStage) { return $uri; } diff --git a/tests/Anaf.php b/tests/Anaf.php index c9a0d33..33e8d19 100644 --- a/tests/Anaf.php +++ b/tests/Anaf.php @@ -2,16 +2,77 @@ use Anaf\Client; +it('may create a client on stage and a client on prod', function () { + $anafClientStage = Anaf::client(isStage: true); + $anafClientProd = Anaf::client(); + + expect($anafClientStage)->toBeInstanceOf(Client::class) + ->and($anafClientProd)->toBeInstanceOf(Client::class); + + checkStageValue($anafClientStage, true); + checkStageValue($anafClientProd, false); + +}); + +it('may create an authorized client on stage and an authorized client on prod', function () { + $anafClientStage = Anaf::authorizedClient('dummy-api-key', isStage: true); + $anafClientProd = Anaf::authorizedClient('dummy-api-key'); + + expect($anafClientStage)->toBeInstanceOf(Client::class) + ->and($anafClientProd)->toBeInstanceOf(Client::class); + + checkStageValue($anafClientStage, true); + checkStageValue($anafClientProd, false); +}); + +it('may create an authorized on stage and a client on prod', function () { + $anafClientStage = Anaf::authorizedClient('dummy-api-key', isStage: true); + $anafClientProd = Anaf::client(); + + expect($anafClientStage)->toBeInstanceOf(Client::class) + ->and($anafClientProd)->toBeInstanceOf(Client::class); + + checkStageValue($anafClientStage, true); + checkStageValue($anafClientProd, false); +}); + +it('may create a client on stage and an authorized on prod', function () { + $anafClientStage = Anaf::client(isStage: true); + $anafClientProd = Anaf::authorizedClient('dummy-api-key'); + + expect($anafClientStage)->toBeInstanceOf(Client::class) + ->and($anafClientProd)->toBeInstanceOf(Client::class); + + checkStageValue($anafClientStage, true); + checkStageValue($anafClientProd, false); +}); + +it('may create a client on stage', function () { + $anafClient = Anaf::client(isStage: true); + + expect($anafClient)->toBeInstanceOf(Client::class); + checkStageValue($anafClient, true); +}); + +it('may create an authorized client on stage', function () { + $anafClient = Anaf::authorizedClient('dummy-api-key', isStage: true); + + expect($anafClient)->toBeInstanceOf(Client::class); + checkStageValue($anafClient, true); +}); + it('may create a client', function () { $anafClient = Anaf::client(); expect($anafClient)->toBeInstanceOf(Client::class); + checkStageValue($anafClient, false); }); -it('may create a authorized client', function () { +it('may create an authorized client', function () { $anafClient = Anaf::authorizedClient('dummy-api-key'); expect($anafClient)->toBeInstanceOf(Client::class); + checkStageValue($anafClient, false); }); it('may create a client via factory', function () { @@ -21,3 +82,4 @@ expect($anafClient)->toBeInstanceOf(Client::class); }); + diff --git a/tests/Pest.php b/tests/Pest.php index 3c6eb4b..a537e29 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -52,3 +52,18 @@ function mockAuthorizedClient(string $method, string $resource, Response|Respons return new Client($transporter); } + +function checkStageValue(Client $anafClient, bool $expectedValue): void +{ + $transporterReflection = new ReflectionClass($anafClient); + $transporterProperty = $transporterReflection->getProperty('transporter'); + $transporterProperty->setAccessible(true); + $transporter = $transporterProperty->getValue($anafClient); + + $stagingReflection = new ReflectionClass($transporter); + $stagingProperty = $stagingReflection->getProperty('isStage'); + $stagingProperty->setAccessible(true); + $staging = $stagingProperty->getValue($transporter); + + expect($staging)->toBe($expectedValue); +} From 6847ef2e35471bf0c6901b58931fea85a9b29c41 Mon Sep 17 00:00:00 2001 From: Andrei Dumitrescu Date: Fri, 23 Jan 2026 18:27:52 +0200 Subject: [PATCH 3/4] added isProdOnly --- .idea/workspace.xml | 50 +++++++++++++++-------- src/Anaf.php | 4 +- src/Resources/Efactura.php | 2 + src/ValueObjects/Transporter/Payload.php | 52 +++++++++++++++++++----- 4 files changed, 79 insertions(+), 29 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ea1a1ae..b981535 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,7 +4,10 @@