diff --git a/src/RNEClient.php b/src/RNEClient.php index 104f440..1efbdf6 100644 --- a/src/RNEClient.php +++ b/src/RNEClient.php @@ -178,6 +178,18 @@ protected function requestApi(string $method, string $url, array $options = []): return $data; } + protected function requestFileApi(string $method, string $url, array $options = []): string + { + $data = []; + try { + $response = $this->client->request($method, $url, $options); + $data = $response->getBody()->getContents(); + } catch (GuzzleException $e) { + $this->catchResponseErrors($e); + } + return $data; + } + /** * Catch the response errors * diff --git a/src/SearchFinancialStatements.php b/src/SearchFinancialStatements.php new file mode 100644 index 0000000..36ea789 --- /dev/null +++ b/src/SearchFinancialStatements.php @@ -0,0 +1,75 @@ +requestApi("get", "api/companies/{$siren}/attachments", ['headers' => $this->getAuthorizationHeaderArray()]); + } + + /** + * Search balance sheet data by its id + * Exact search only + * + * @param string $id + * + * @throws GuzzleException + * @return array + */ + public function searchById(string $id): array + { + return $this->requestApi("get", "api/bilan-saisis/{$id}", ['headers' => $this->getAuthorizationHeaderArray()]); + } + + /** + * Get balance sheet metadata by its id + * Exact search only + * + * @param string $id + * + * @throws GuzzleException + * @return array + */ + public function getMetadataById(string $id): array + { + return $this->requestApi("get", "api/bilans/{$id}", ['headers' => $this->getAuthorizationHeaderArray()]); + } + + /** + * Get a balance sheet PDF file by its id + * Exact search only + * + * @param string $id + * + * @throws GuzzleException + * @return resource + */ + public function getFileById(string $id): string + { + return $this->requestFileApi("get", "api/bilans/{$id}/download", ['headers' => $this->getAuthorizationHeaderArray()]); + } +} \ No newline at end of file diff --git a/src/SearchFinancialStatementsInterface.php b/src/SearchFinancialStatementsInterface.php new file mode 100644 index 0000000..94e6692 --- /dev/null +++ b/src/SearchFinancialStatementsInterface.php @@ -0,0 +1,11 @@ +RNEClient = new SearchFinancialStatements(); + } + + public function testSearchBySiren(): void + { + // get from file + $fakeResponse = file_get_contents(__DIR__ . '/../../fixtures/SearchFinancialStatements/searchBySiren.json'); + + $mockHandler = new MockHandler([new Response(200, [], $fakeResponse)]); + $handlerStack = HandlerStack::create($mockHandler); + $mockedClient = new Client(['handler' => $handlerStack]); + + $this->RNEClient = new SearchFinancialStatements('fake_token', $mockedClient); + + $data = $this->RNEClient->searchBySiren('113277693'); + + $this->assertIsArray($data); + $this->assertIsArray($data['bilans']); + $this->assertIsArray($data['bilansSaisis']); + } + + public function testSearchBySirenWithBadSiren(): void + { + $mockHandler = new MockHandler([new Response(200, [], '[]')]); + $handlerStack = HandlerStack::create($mockHandler); + $mockedClient = new Client(['handler' => $handlerStack]); + + $this->RNEClient = new SearchFinancialStatements('fake_token', $mockedClient); + + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Invalid input siren, please use a 9 length number.'); + $this->RNEClient->searchBySiren('1234567890'); + } +} \ No newline at end of file diff --git a/tests/fixtures/SearchFinancialStatements/getMetadataById.json b/tests/fixtures/SearchFinancialStatements/getMetadataById.json new file mode 100644 index 0000000..52fa022 --- /dev/null +++ b/tests/fixtures/SearchFinancialStatements/getMetadataById.json @@ -0,0 +1,8 @@ +{ + "id": " idnumberxyz", + "siren": "NNNNNNNNN", + "denomination": "Nom Société", + "dateDepot": "2022-12-25", + "dateCloture": "2022-12-31", + "typeBilan": "C" +} \ No newline at end of file diff --git a/tests/fixtures/SearchFinancialStatements/searchById.json b/tests/fixtures/SearchFinancialStatements/searchById.json new file mode 100644 index 0000000..7543d38 --- /dev/null +++ b/tests/fixtures/SearchFinancialStatements/searchById.json @@ -0,0 +1,410 @@ +{ + "createdAt": "2023-01-11T17:32:25+01:00", + "updatedAt": "2023-01-11T17:32:25+01:00", + "id": " idnumberzzz", + "siren": "377708425", + "denomination": " DENOMINATION ", + "dateDepot": "2023-01-02", + "numChrono": "99", + "nomDocument": "CA_123456789_9201_2023B000001_2023_99", + "bilanSaisi": { + "bilan": { + "identite": { + "siren": "377708425", + "dateClotureExercice": "2021-12-31T00:00:00+01:00", + "codeGreffe": "9201", + "numDepot": "99", + "numGestion": "2023B000001", + "codeActivite": "6619B", + "dateClotureExerciceNMoins1": "2020-12-31T00:00:00+01:00", + "dureeExerciceN": "12", + "dureeExerciceNMoins1": "12", + "dateDepot": "2023-01-02T00:00:00+01:00", + "codeSaisie": "00", + "codeTypeBilan": "C", + "codeDevise": "EUR", + "codeOrigineDevise": "O", + "codeConfidentialite": "0", + "infoTraitement": "", + "denomination": "DENOMINATION", + "adresse": "92000 Nanterre" + }, + "detail": { + "pages": [ + { + "numero": 1, + "liasses": [ + { + "code": "AB", + "m1": "000000000001220", + "m2": "000000000001220", + "m3": "", + "m4": "" + }, + { + "code": "BJ", + "m1": "000000000001220", + "m2": "000000000001220", + "m3": "", + "m4": "" + }, + { + "code": "BZ", + "m1": "000000000001197", + "m2": "", + "m3": "000000000001197", + "m4": "" + }, + { + "code": "CF", + "m1": "000000000000180", + "m2": "", + "m3": "000000000000180", + "m4": "" + }, + { + "code": "CJ", + "m1": "000000000001376", + "m2": "", + "m3": "000000000001378", + "m4": "" + }, + { + "code": "CO", + "m1": "000000000002597", + "m2": "000000000001220", + "m3": "000000000001378", + "m4": "" + } + ] + }, + { + "numero": 2, + "liasses": [ + { + "code": "DA", + "m1": "000000000038113", + "m2": "", + "m3": "", + "m4": "" + }, + { + "code": "DH", + "m1": "-000000001127414", + "m2": "", + "m3": "", + "m4": "" + }, + { + "code": "DI", + "m1": "000000000026400", + "m2": "", + "m3": "", + "m4": "" + }, + { + "code": "DL", + "m1": "-000000001062901", + "m2": "", + "m3": "", + "m4": "" + }, + { + "code": "DV", + "m1": "000000001059959", + "m2": "", + "m3": "", + "m4": "" + }, + { + "code": "DX", + "m1": "000000000004320", + "m2": "", + "m3": "", + "m4": "" + }, + { + "code": "EC", + "m1": "000000001064279", + "m2": "", + "m3": "", + "m4": "" + }, + { + "code": "EE", + "m1": "000000000001378", + "m2": "", + "m3": "", + "m4": "" + }, + { + "code": "EG", + "m1": "000000001064279", + "m2": "", + "m3": "", + "m4": "" + } + ] + }, + { + "numero": 3, + "liasses": [ + { + "code": "FG", + "m1": "-000000000028700", + "m2": "", + "m3": "-000000000028700", + "m4": "" + }, + { + "code": "FJ", + "m1": "-000000000028700", + "m2": "", + "m3": "-000000000028700", + "m4": "" + }, + { + "code": "FR", + "m1": "", + "m2": "", + "m3": "-000000000028700", + "m4": "" + }, + { + "code": "FW", + "m1": "", + "m2": "", + "m3": "000000000000176", + "m4": "" + }, + { + "code": "GF", + "m1": "", + "m2": "", + "m3": "000000000000176", + "m4": "" + }, + { + "code": "GG", + "m1": "", + "m2": "", + "m3": "-000000000028876", + "m4": "" + }, + { + "code": "GI", + "m1": "", + "m2": "", + "m3": "000000000000001", + "m4": "" + }, + { + "code": "GK", + "m1": "", + "m2": "", + "m3": "000000000000081", + "m4": "" + }, + { + "code": "GR", + "m1": "", + "m2": "", + "m3": "000000000010962", + "m4": "" + }, + { + "code": "GU", + "m1": "", + "m2": "", + "m3": "000000000010962", + "m4": "" + }, + { + "code": "GV", + "m1": "", + "m2": "", + "m3": "-000000000010962", + "m4": "" + }, + { + "code": "GW", + "m1": "", + "m2": "", + "m3": "-000000000039837", + "m4": "" + } + ] + }, + { + "numero": 4, + "liasses": [ + { + "code": "HA", + "m1": "000000000066237", + "m2": "", + "m3": "", + "m4": "" + }, + { + "code": "HD", + "m1": "000000000066237", + "m2": "", + "m3": "", + "m4": "" + }, + { + "code": "HI", + "m1": "000000000066237", + "m2": "", + "m3": "", + "m4": "" + }, + { + "code": "HL", + "m1": "000000000037537", + "m2": "", + "m3": "", + "m4": "" + }, + { + "code": "HM", + "m1": "000000000011137", + "m2": "", + "m3": "", + "m4": "" + }, + { + "code": "HN", + "m1": "000000000026400", + "m2": "", + "m3": "", + "m4": "" + } + ] + }, + { + "numero": 5, + "liasses": [ + { + "code": "CZ", + "m1": "000000000001220", + "m2": "", + "m3": "", + "m4": "" + }, + { + "code": "0G", + "m1": "000000000001220", + "m2": "", + "m3": "", + "m4": "" + }, + { + "code": "IN", + "m1": "", + "m2": "", + "m3": "000000000001220", + "m4": "" + }, + { + "code": "I4", + "m1": "", + "m2": "", + "m3": "000000000001220", + "m4": "" + } + ] + }, + { + "numero": 6, + "liasses": [ + { + "code": "CY", + "m1": "000000000001220", + "m2": "", + "m3": "", + "m4": "000000000001220" + }, + { + "code": "0N", + "m1": "000000000001220", + "m2": "", + "m3": "", + "m4": "000000000001220" + } + ] + }, + { + "numero": 8, + "liasses": [ + { + "code": "VB", + "m1": "000000000001197", + "m2": "000000000001197", + "m3": "", + "m4": "" + }, + { + "code": "VT", + "m1": "000000000001197", + "m2": "000000000001197", + "m3": "", + "m4": "" + }, + { + "code": "8B", + "m1": "000000000004320", + "m2": "000000000004320", + "m3": "", + "m4": "" + }, + { + "code": "VI", + "m1": "000000001059959", + "m2": "000000001059959", + "m3": "", + "m4": "" + }, + { + "code": "VY", + "m1": "000000001064279", + "m2": "000000001064279", + "m3": "", + "m4": "" + } + ] + }, + { + "numero": 11, + "liasses": [ + { + "code": "SS", + "m1": "000000000000113", + "m2": "", + "m3": "", + "m4": "" + }, + { + "code": "ST", + "m1": "000000000000062", + "m2": "", + "m3": "", + "m4": "" + }, + { + "code": "ZJ", + "m1": "000000000000176", + "m2": "", + "m3": "", + "m4": "" + } + ] + } + ] + } + }, + "version": "1.0" + }, + "dateCloture": "2021-12-31", + "typeBilan": "C" +} \ No newline at end of file diff --git a/tests/fixtures/SearchFinancialStatements/searchBySiren.json b/tests/fixtures/SearchFinancialStatements/searchBySiren.json new file mode 100644 index 0000000..cdefae2 --- /dev/null +++ b/tests/fixtures/SearchFinancialStatements/searchBySiren.json @@ -0,0 +1,71 @@ +{ + "actes": [], + "bilans": [ + { + "createdAt": "2022-12-23T12:33:04+01:00", + "updatedAt": "2022-12-23T12:33:04+01:00", + "id": "idnumberxyz", + "siren": "123456789", + "denomination": "DENOMINATION", + "dateDepot": "2020-11-16", + "numChrono": "12345", + "nomDocument": " CA_123456789_7501_2222B1111_2019_123456", + "path": "", + "dateCloture": "2019-09-30", + "typeBilan": "C", + "version": "2.0" + } + ], + "bilansSaisis": [ + { + "createdAt": "2022-12-23T12:33:05+01:00", + "updatedAt": "2022-12-23T12:33:05+01:00", + "id": "idnumberzzz", + "siren": "123456789", + "denomination": "DENOMINATION", + "dateDepot": "2020-11-16", + "numChrono": "123456", + "nomDocument": "CA_123456789_7501_2222B1111_2019_123456", + "bilanSaisi": { + "bilan": { + "identite": { + "siren": "377708425", + "dateClotureExercice": "2021-12-31T00:00:00+01:00", + "codeGreffe": "9201", + "numDepot": "99", + "numGestion": "2023B000001", + "codeActivite": "6619B", + "dateClotureExerciceNMoins1": "2020-12-31T00:00:00+01:00", + "dureeExerciceN": "12", + "dureeExerciceNMoins1": "12", + "dateDepot": "2023-01-02T00:00:00+01:00", + "codeSaisie": "00", + "codeTypeBilan": "C", + "codeDevise": "EUR", + "codeOrigineDevise": "O", + "codeConfidentialite": "0", + "infoTraitement": "", + "denomination": "DENOMINATION", + "adresse": "92000 Nanterre" + }, + "detail": { + "pages": [ + { + "numero": 1, + "liasses": [ + { + "code": "AB", + "m1": "000000000001220", + "m2": "000000000001220", + "m3": "", + "m4": "" + } + ] + } + ] + } + } + } + } + ] + } \ No newline at end of file