comptine 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
comptine/__init__.py ADDED
@@ -0,0 +1,15 @@
1
+ """Unofficial Python client for the Urssaf Tierce Déclaration Pajemploi API."""
2
+
3
+ from comptine.client import ApiClient, ApiError, OAuthTokenCache
4
+ from comptine.config import Config, Environment, load_config
5
+
6
+ __all__ = [
7
+ "ApiClient",
8
+ "ApiError",
9
+ "Config",
10
+ "Environment",
11
+ "OAuthTokenCache",
12
+ "load_config",
13
+ ]
14
+
15
+ __version__ = "0.1.0"
@@ -0,0 +1,21 @@
1
+ """API category modules — one per OpenAPI operation group of TDPAJE 1.5.1."""
2
+
3
+ from comptine.api.associer import Associer
4
+ from comptine.api.declarer import Declarer
5
+ from comptine.api.employeurs import Employeurs
6
+ from comptine.api.enfants import Enfants
7
+ from comptine.api.estimer import Estimer
8
+ from comptine.api.mandats import Mandats
9
+ from comptine.api.predeclarer import Predeclarer
10
+ from comptine.api.salaries import Salaries
11
+
12
+ __all__ = [
13
+ "Associer",
14
+ "Declarer",
15
+ "Employeurs",
16
+ "Enfants",
17
+ "Estimer",
18
+ "Mandats",
19
+ "Predeclarer",
20
+ "Salaries",
21
+ ]
comptine/api/_base.py ADDED
@@ -0,0 +1,20 @@
1
+ """Shared base class for API category modules."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from comptine.client import ApiClient
8
+
9
+
10
+ class ApiCategory:
11
+ """Holds a reference to the :class:`ApiClient` and surfaces small helpers."""
12
+
13
+ def __init__(self, client: ApiClient) -> None:
14
+ self._client = client
15
+
16
+ def _json(self, response: Any) -> Any:
17
+ """Decode a JSON response; returns ``None`` for empty bodies."""
18
+ if not response.content:
19
+ return None
20
+ return response.json()
@@ -0,0 +1,39 @@
1
+ """Associate a worker to a private employer (API PAJE023)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from datetime import date
6
+ from typing import Any
7
+
8
+ from comptine.api._base import ApiCategory
9
+
10
+
11
+ class Associer(ApiCategory):
12
+ def link(
13
+ self,
14
+ *,
15
+ employer_pajemploi_number: str,
16
+ employer_date_of_birth: date,
17
+ employee_date_of_birth: date,
18
+ employee_pajemploi_number: str | None = None,
19
+ employee_nir: str | None = None,
20
+ creation_body: dict[str, Any] | None = None,
21
+ ) -> dict[str, Any]:
22
+ """API PAJE023 — Associer un salarie a un particulier employeur."""
23
+ params: dict[str, str] = {
24
+ "dtNaissanceEmployeur": employer_date_of_birth.isoformat(),
25
+ "dtNaissanceSalarie": employee_date_of_birth.isoformat(),
26
+ }
27
+ if employee_pajemploi_number is not None:
28
+ params["numeroPajeSalarie"] = employee_pajemploi_number
29
+ if employee_nir is not None:
30
+ params["nirSalarie"] = employee_nir
31
+ # Spring rejects a body-less POST with 415 before any business rule runs,
32
+ # so always send an object — empty when the worker already exists.
33
+ body = {"inputCreationSalarie": creation_body} if creation_body else {}
34
+ resp = self._client.post(
35
+ f"/tiersdecl/v1/paje/employeurs/{employer_pajemploi_number}/salarie/associer",
36
+ params=params,
37
+ json=body,
38
+ )
39
+ return self._json(resp) or {}
@@ -0,0 +1,47 @@
1
+ """Submit a final declaration (cotisations are billed).
2
+
3
+ * ``POST /employeurs/{n}/ama/declarer`` — Assistante maternelle.
4
+ * ``POST /employeurs/{n}/ged/declarer`` — Garde d'enfants à domicile.
5
+
6
+ The response (``OutputDeclaration``) carries ``referenceDocumentaire`` — the
7
+ "volet social n°" printed on the official pay slip.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from datetime import date
13
+ from typing import Any
14
+
15
+ from comptine.api._base import ApiCategory
16
+
17
+
18
+ class Declarer(ApiCategory):
19
+ def ged(
20
+ self,
21
+ *,
22
+ employer_pajemploi_number: str,
23
+ employer_date_of_birth: date,
24
+ body: dict[str, Any],
25
+ ) -> dict[str, Any]:
26
+ """API PAJE051 — Déclarer le salaire d'une garde à domicile (GED)."""
27
+ resp = self._client.post(
28
+ f"/tiersdecl/v1/paje/employeurs/{employer_pajemploi_number}/ged/declarer",
29
+ params={"dtNaissanceEmployeur": employer_date_of_birth.isoformat()},
30
+ json=body,
31
+ )
32
+ return self._json(resp) or {}
33
+
34
+ def ama(
35
+ self,
36
+ *,
37
+ employer_pajemploi_number: str,
38
+ employer_date_of_birth: date,
39
+ body: dict[str, Any],
40
+ ) -> dict[str, Any]:
41
+ """API PAJE050 — Déclarer le salaire d'une assistante maternelle (AMA)."""
42
+ resp = self._client.post(
43
+ f"/tiersdecl/v1/paje/employeurs/{employer_pajemploi_number}/ama/declarer",
44
+ params={"dtNaissanceEmployeur": employer_date_of_birth.isoformat()},
45
+ json=body,
46
+ )
47
+ return self._json(resp) or {}
@@ -0,0 +1,40 @@
1
+ """Private-employer verification (API PAJE020).
2
+
3
+ The only employer-scoped GET in the spec: verify that a particulier-employeur
4
+ is registered with Pajemploi.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from datetime import date
10
+ from typing import Any
11
+
12
+ from comptine.api._base import ApiCategory
13
+
14
+
15
+ class Employeurs(ApiCategory):
16
+ def verify(self, *, pajemploi_number: str, date_of_birth: date) -> dict[str, Any]:
17
+ """API PAJE020 — Verifier un compte Pajemploi pour un particulier employeur.
18
+
19
+ Returns the ``OutputVerificationPe`` payload (status, identity, account state).
20
+ """
21
+ resp = self._client.get(
22
+ f"/tiersdecl/v1/paje/employeurs/{pajemploi_number}/verifier",
23
+ params={"dtNaissanceEmployeur": date_of_birth.isoformat()},
24
+ )
25
+ return self._json(resp) or {}
26
+
27
+ def verify_children(
28
+ self,
29
+ *,
30
+ pajemploi_number: str,
31
+ date_of_birth: date,
32
+ children: list[dict[str, Any]],
33
+ ) -> dict[str, Any]:
34
+ """API PAJE022 — Verification des enfants ouvrant droit d'un particulier employeur."""
35
+ resp = self._client.post(
36
+ f"/tiersdecl/v1/paje/employeurs/{pajemploi_number}/enfants/verifier",
37
+ params={"dtNaissanceEmployeur": date_of_birth.isoformat()},
38
+ json={"inputEnfantPe": children},
39
+ )
40
+ return self._json(resp) or {}
@@ -0,0 +1,69 @@
1
+ """Children verification (API PAJE022).
2
+
3
+ Answers the question the declaration itself cannot: *which* children open the
4
+ right (``enfant ouvrant droit``) for a given private employer. Only those belong
5
+ in ``inputDeclEnfant`` — the CMG is granted per opening child, not per child in
6
+ the household.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from datetime import date
12
+ from typing import Any
13
+
14
+ from comptine.api._base import ApiCategory
15
+ from comptine.config import Enfant
16
+ from comptine.mapper import children_to_wire
17
+
18
+ OPENS_THE_RIGHT = (1, 2)
19
+ """``reponseStatutEnfant``: 1 = found, 2 = found through a partial search."""
20
+
21
+
22
+ class Enfants(ApiCategory):
23
+ def verify(
24
+ self,
25
+ *,
26
+ employer_pajemploi_number: str,
27
+ employer_date_of_birth: date,
28
+ enfants: list[Enfant],
29
+ ) -> dict[str, Any]:
30
+ """API PAJE022 — Vérification des enfants ouvrant droit d'un particulier employeur."""
31
+ resp = self._client.post(
32
+ f"/tiersdecl/v1/paje/employeurs/{employer_pajemploi_number}/enfants/verifier",
33
+ params={"dtNaissanceEmployeur": employer_date_of_birth.isoformat()},
34
+ json={"inputEnfantPe": children_to_wire(enfants)},
35
+ )
36
+ return self._json(resp) or {}
37
+
38
+ def opening_the_right(
39
+ self,
40
+ *,
41
+ employer_pajemploi_number: str,
42
+ employer_date_of_birth: date,
43
+ enfants: list[Enfant],
44
+ ) -> list[Enfant]:
45
+ """Return only the children the SI Pajemploi recognises as opening the right.
46
+
47
+ The API echoes each submitted child back with a status, so we match on the
48
+ wire payload rather than trusting the response order.
49
+ """
50
+ out = self.verify(
51
+ employer_pajemploi_number=employer_pajemploi_number,
52
+ employer_date_of_birth=employer_date_of_birth,
53
+ enfants=enfants,
54
+ )
55
+ results: list[dict[str, Any]] = out.get("verificationEnfantPe") or []
56
+ opening_wire = {
57
+ (
58
+ r.get("inputEnfantPe", {}).get("nomEnfant"),
59
+ r.get("inputEnfantPe", {}).get("prenomEnfant"),
60
+ r.get("inputEnfantPe", {}).get("dtNaissanceEnfant"),
61
+ )
62
+ for r in results
63
+ if r.get("reponseStatutEnfant") in OPENS_THE_RIGHT
64
+ }
65
+ return [
66
+ enfant
67
+ for enfant, wire in zip(enfants, children_to_wire(enfants), strict=True)
68
+ if (wire["nomEnfant"], wire["prenomEnfant"], wire["dtNaissanceEnfant"]) in opening_wire
69
+ ]
@@ -0,0 +1,29 @@
1
+ """Estimate social contributions (no side effects).
2
+
3
+ Two endpoints, one per regime:
4
+
5
+ * ``POST /ama/estimer`` — Assistante maternelle agréée.
6
+ * ``POST /ged/estimer`` — Garde d'enfants à domicile.
7
+
8
+ The bodies (``InputEstimationAma`` / ``InputEstimationGed``) differ slightly,
9
+ but both produce an :class:`OutputEstimation` whose key field is
10
+ ``mntCotiEmplAcharge`` (the employer's net cost).
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from typing import Any
16
+
17
+ from comptine.api._base import ApiCategory
18
+
19
+
20
+ class Estimer(ApiCategory):
21
+ def ged(self, body: dict[str, Any]) -> dict[str, Any]:
22
+ """API PAJE041 — Estimer pour une activité de garde d'enfant à domicile (GED)."""
23
+ resp = self._client.post("/tiersdecl/v1/paje/ged/estimer", json=body)
24
+ return self._json(resp) or {}
25
+
26
+ def ama(self, body: dict[str, Any]) -> dict[str, Any]:
27
+ """API PAJE040 — Estimer pour une activité d'assistante maternelle agréée (AMA)."""
28
+ resp = self._client.post("/tiersdecl/v1/paje/ama/estimer", json=body)
29
+ return self._json(resp) or {}
@@ -0,0 +1,54 @@
1
+ """Mandate operations.
2
+
3
+ Per the official OpenAPI spec (TDPAJE 1.5.1), only two operations exist on
4
+ ``/mandats``:
5
+
6
+ * ``POST /mandats?numeroPaje=...&dateNaissance=...`` registers a mandate.
7
+ * ``DELETE /mandats?numeroPaje=...&dateNaissance=...`` cancels one.
8
+
9
+ There is no list/get endpoint: a third-party declarant cannot enumerate the
10
+ employers it can declare for.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from datetime import date
16
+
17
+ from comptine.api._base import ApiCategory
18
+
19
+ PATH = "/tiersdecl/v1/paje/mandats"
20
+
21
+
22
+ class Mandats(ApiCategory):
23
+ def register(
24
+ self, *, employer_pajemploi_number: str, employer_date_of_birth: date
25
+ ) -> dict[str, object]:
26
+ """API PAJE030 — Enregistrement de mandat.
27
+
28
+ Args:
29
+ employer_pajemploi_number: ``numeroPaje`` of the private employer.
30
+ employer_date_of_birth: ``dateNaissance`` (yyyy-MM-dd), used as a second-factor check.
31
+ """
32
+ resp = self._client.post(
33
+ PATH,
34
+ params={
35
+ "numeroPaje": employer_pajemploi_number,
36
+ "dateNaissance": employer_date_of_birth.isoformat(),
37
+ },
38
+ json={},
39
+ headers={"Content-Type": "application/json"},
40
+ )
41
+ return self._json(resp) or {}
42
+
43
+ def cancel(
44
+ self, *, employer_pajemploi_number: str, employer_date_of_birth: date
45
+ ) -> dict[str, object]:
46
+ """API PAJE031 — Annulation de mandat."""
47
+ resp = self._client.delete(
48
+ PATH,
49
+ params={
50
+ "numeroPaje": employer_pajemploi_number,
51
+ "dateNaissance": employer_date_of_birth.isoformat(),
52
+ },
53
+ )
54
+ return self._json(resp) or {}
@@ -0,0 +1,44 @@
1
+ """Pre-declare a Pajemploi activity (draft state, not yet billed).
2
+
3
+ * ``POST /employeurs/{n}/ama/predeclarer`` — Assistante maternelle.
4
+ * ``POST /employeurs/{n}/ged/predeclarer`` — Garde d'enfants à domicile.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from datetime import date
10
+ from typing import Any
11
+
12
+ from comptine.api._base import ApiCategory
13
+
14
+
15
+ class Predeclarer(ApiCategory):
16
+ def ged(
17
+ self,
18
+ *,
19
+ employer_pajemploi_number: str,
20
+ employer_date_of_birth: date,
21
+ body: dict[str, Any],
22
+ ) -> dict[str, Any]:
23
+ """API PAJE046 — Pré-déclarer le salaire pour une garde à domicile (GED)."""
24
+ resp = self._client.post(
25
+ f"/tiersdecl/v1/paje/employeurs/{employer_pajemploi_number}/ged/predeclarer",
26
+ params={"dtNaissanceEmployeur": employer_date_of_birth.isoformat()},
27
+ json=body,
28
+ )
29
+ return self._json(resp) or {}
30
+
31
+ def ama(
32
+ self,
33
+ *,
34
+ employer_pajemploi_number: str,
35
+ employer_date_of_birth: date,
36
+ body: dict[str, Any],
37
+ ) -> dict[str, Any]:
38
+ """API PAJE045 — Pré-déclarer le salaire d'une assistante maternelle (AMA)."""
39
+ resp = self._client.post(
40
+ f"/tiersdecl/v1/paje/employeurs/{employer_pajemploi_number}/ama/predeclarer",
41
+ params={"dtNaissanceEmployeur": employer_date_of_birth.isoformat()},
42
+ json=body,
43
+ )
44
+ return self._json(resp) or {}
@@ -0,0 +1,35 @@
1
+ """Domestic-worker verification (API PAJE021)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from datetime import date
6
+ from typing import Any
7
+
8
+ from comptine.api._base import ApiCategory
9
+
10
+
11
+ class Salaries(ApiCategory):
12
+ def verify(
13
+ self,
14
+ *,
15
+ pajemploi_number: str | None = None,
16
+ nir: str | None = None,
17
+ date_of_birth: date | None = None,
18
+ identification: dict[str, Any] | None = None,
19
+ ) -> dict[str, Any]:
20
+ """API PAJE021 — Verifier un compte Pajemploi pour un salarie particulier.
21
+
22
+ Needs one of: Pajemploi number, NIR + DOB, or a full identification body.
23
+ """
24
+ params: dict[str, str] = {}
25
+ if pajemploi_number is not None:
26
+ params["numeroPajeSalarie"] = pajemploi_number
27
+ if nir is not None:
28
+ params["nirSalarie"] = nir
29
+ if date_of_birth is not None:
30
+ params["dtNaissanceSalarie"] = date_of_birth.isoformat()
31
+ # Spring rejects a body-less POST with 400 "Required request body is missing",
32
+ # so always send an object — empty when the query params carry the identity.
33
+ body = {"inputIdentificationSalarie": identification} if identification else {}
34
+ resp = self._client.post("/tiersdecl/v1/paje/salaries/verifier", params=params, json=body)
35
+ return self._json(resp) or {}