Skip to content

Commit daaa8c4

Browse files
committed
feat: add get paginated messages
1 parent 2b11da8 commit daaa8c4

File tree

4 files changed

+174
-0
lines changed

4 files changed

+174
-0
lines changed

src/Resources/Efactura.php

+24
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Anaf\Contracts\FileContract;
88
use Anaf\Enums\Efactura\UploadStandard;
99
use Anaf\Responses\Efactura\CreateMessagesResponse;
10+
use Anaf\Responses\Efactura\CreatePaginatedMessagesResponse;
1011
use Anaf\Responses\Efactura\CreateUploadResponse;
1112
use Anaf\ValueObjects\Transporter\Payload;
1213
use Anaf\ValueObjects\Transporter\Xml;
@@ -66,6 +67,29 @@ public function messages(array $parameters): CreateMessagesResponse
6667
return CreateMessagesResponse::from($response);
6768
}
6869

70+
/**
71+
* Get the list of messages for a given taxpayer.
72+
*
73+
* @see https://mfinante.gov.ro/static/10/eFactura/listamesaje.html#/EFacturaListaMesaje/getPaginatie
74+
*
75+
* @param array<string, string> $parameters
76+
*/
77+
public function paginatedMessages(array $parameters): CreatePaginatedMessagesResponse
78+
{
79+
$payload = Payload::get('prod/FCTEL/rest/listaMesajePaginatieFactura', $parameters);
80+
81+
/**
82+
* @var array{eroare?: string, mesaje: array<int, array{data_creare: string, cif: string, id_solicitare: string, detalii: string, tip: string, id: string}>, numar_inregistrari_in_pagina: int, numar_total_inregistrari_per_pagina: int, numar_total_inregistrari: int, numar_total_pagini: int, index_pagina_curenta:int, serial: string, cui: string, titlu: string} $response
83+
*/
84+
$response = $this->transporter->requestObject($payload);
85+
86+
if (array_key_exists('eroare', $response)) {
87+
throw new RuntimeException($response['eroare']);
88+
}
89+
90+
return CreatePaginatedMessagesResponse::from($response);
91+
}
92+
6993
/**
7094
* Get the list of messages for a given taxpayer.
7195
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Anaf\Responses\Efactura;
6+
7+
use Anaf\Contracts\Response;
8+
use Anaf\Responses\Concerns\ArrayAccessible;
9+
10+
/**
11+
* @implements Response<array{messages: array<int, array{creation_date: string, tax_identification_number: string, solicitation_id: string, details: string, type: string, id: string}>, count_messages_current_page: int, per_page: int, total_messages: int, total_pages: int, current_page: int, serial: string, tax_identification_numbers: string, title: string}>
12+
*/
13+
class CreatePaginatedMessagesResponse implements Response
14+
{
15+
/**
16+
* @use ArrayAccessible<array{messages: array<int, Message>, count_messages_current_page: int, per_page: int, total_messages: int, total_pages: int, current_page: int, serial: string, tax_identification_numbers: string, title: string}>
17+
*/
18+
use ArrayAccessible;
19+
20+
/**
21+
* Creates a new CreateResponse instance.
22+
*
23+
* @param array<int, Message> $messages
24+
*/
25+
private function __construct(
26+
public readonly array $messages,
27+
public readonly string $serial,
28+
public readonly string $taxIdentificationNumbers,
29+
public readonly string $title,
30+
public readonly int $countMessagesCurrentPage,
31+
public readonly int $perPage,
32+
public readonly int $totalMessages,
33+
public readonly int $totalPages,
34+
public readonly int $currentPage,
35+
) {
36+
}
37+
38+
/**
39+
* Acts as static factory, and returns a new Response instance.
40+
*
41+
* @param array{mesaje: array<int, array{data_creare: string, cif: string, id_solicitare: string, detalii: string, tip: string, id: string}>, numar_inregistrari_in_pagina: int, numar_total_inregistrari_per_pagina: int, numar_total_inregistrari: int, numar_total_pagini: int, index_pagina_curenta:int, serial: string, cui: string, titlu: string} $attributes
42+
*/
43+
public static function from(array $attributes): self
44+
{
45+
$messages = array_map(
46+
static fn (array $result): Message => Message::from(
47+
$result
48+
),
49+
$attributes['mesaje'],
50+
);
51+
52+
return new self(
53+
$messages,
54+
$attributes['serial'],
55+
$attributes['cui'],
56+
$attributes['titlu'],
57+
$attributes['numar_inregistrari_in_pagina'],
58+
$attributes['numar_total_inregistrari_per_pagina'],
59+
$attributes['numar_total_inregistrari'],
60+
$attributes['numar_total_pagini'],
61+
$attributes['index_pagina_curenta'],
62+
);
63+
}
64+
65+
/**
66+
* {@inheritDoc}
67+
*/
68+
public function toArray(): array
69+
{
70+
return [
71+
'messages' => array_map(
72+
static fn (Message $result): array => $result->toArray(),
73+
$this->messages,
74+
),
75+
'count_messages_current_page' => $this->countMessagesCurrentPage,
76+
'per_page' => $this->perPage,
77+
'total_messages' => $this->totalMessages,
78+
'total_pages' => $this->totalPages,
79+
'current_page' => $this->currentPage,
80+
'serial' => $this->serial,
81+
'tax_identification_numbers' => $this->taxIdentificationNumbers,
82+
'title' => $this->title,
83+
];
84+
}
85+
}

tests/Fixtures/Efactura.php

+36
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,42 @@ function getEfacturaMessages(): array
3333

3434
}
3535

36+
/**
37+
* @return array<string, mixed>
38+
*/
39+
function getEfacturaPaginatedMessages(): array
40+
{
41+
return [
42+
'mesaje' => [
43+
[
44+
'data_creare' => '202211011415',
45+
'cif' => '8000000000',
46+
'id_solicitare' => '5001130147',
47+
'detalii' => 'Erori de validare identificate la factura primita cu id_incarcare=5001130147',
48+
'tip' => 'ERORI FACTURA',
49+
'id' => '3001293434',
50+
],
51+
[
52+
'data_creare' => '202211011336',
53+
'cif' => '8000000000',
54+
'id_solicitare' => '5001131297',
55+
'detalii' => 'Factura cu id_incarcare=5001131297 emisa de cif_emitent=8000000000 pentru cif_beneficiar=3',
56+
'tip' => 'FACTURA TRIMISA',
57+
'id' => '3001503294',
58+
],
59+
],
60+
'numar_inregistrari_in_pagina' => 2,
61+
'numar_total_inregistrari_per_pagina' => 500,
62+
'numar_total_inregistrari' => 14130,
63+
'numar_total_pagini' => 29,
64+
'index_pagina_curenta' => 29,
65+
'serial' => '1234AA456',
66+
'cui' => '8000000000',
67+
'titlu' => 'Lista Mesaje disponibile din intervalul 06-09-2022 09:48:20 - 02-11-2022 11:49:24',
68+
];
69+
70+
}
71+
3672
function getUploadMessage(): array
3773
{
3874
return [

tests/Resources/Efactura.php

+29
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use Anaf\Contracts\FileContract;
44
use Anaf\Responses\Efactura\CreateMessagesResponse;
5+
use Anaf\Responses\Efactura\CreatePaginatedMessagesResponse;
56
use Anaf\Responses\Efactura\CreateUploadResponse;
67
use Anaf\Responses\Efactura\Message;
78

@@ -40,6 +41,34 @@
4041

4142
});
4243

44+
test('get paginated messages', function () {
45+
$authorizedClient = mockAuthorizedClient('GET', '/prod/FCTEL/rest/listaMesajePaginatieFactura', getEfacturaPaginatedMessages());
46+
47+
$response = $authorizedClient->efactura()->paginatedMessages(
48+
[
49+
'startTime' => 1706738400000,
50+
'endTime' => 1707343800000,
51+
'cif' => 8000000000,
52+
'pagina' => 2,
53+
],
54+
);
55+
56+
expect($response)
57+
->toBeInstanceOf(CreatePaginatedMessagesResponse::class)
58+
->toHaveProperty('messages')
59+
->and($response->serial)
60+
->toBe('1234AA456')
61+
->and($response->taxIdentificationNumbers)
62+
->toBe('8000000000')
63+
->and($response->currentPage)
64+
->toBe(29)
65+
->and($response->messages)
66+
->toBeArray()
67+
->and($response->messages[0])
68+
->toBeInstanceOf(Message::class);
69+
70+
});
71+
4372
test('download efactura', function () {
4473
$authorizedClient = mockAuthorizedClient('GET', '/prod/FCTEL/rest/descarcare', getFakeFile('dummy content'), 'requestFile');
4574

0 commit comments

Comments
 (0)