<!-- Parent: ../AGENTS.md -->
<!-- Generated: 2026-07-02 | Updated: 2026-07-02 -->

# Service

## Purpose
Application services. Currently a single service: PayPal REST integration.

## Key Files
| File | Description |
|------|-------------|
| `Facture/FactureBuilder.php` | **Single source of truth for an invoice.** Turns a `Commande` into the view model read by both the PDF and the web page: invoice number (`FA-<année>-<id>`), issuer identity, lines (one row per piece, one per paid option), totals and legal mentions. `commande.total` is authoritative — any gap with the lines shows up as an « Ajustement » row, never silently |
| `Facture/FacturePdfGenerator.php` | dompdf rendering of `templates/facture/pdf.html.twig`. Hardened options (no PHP/JS/remote), footer drawn on the canvas **after** `render()` (dompdf 3 runs `page_script` immediately, so calling it earlier prints « Page 1 / 1 » and skips later pages) |
| `Facture/FactureExemple.php` | Fictional order used to preview the layout without the DB (`app:facture:exemple`, `/facture/apercu-exemple` in dev) |
| `PayPalService.php` | Wraps the PayPal REST API: fetch OAuth access token, create order, capture payment. Configured via constructor args `$clientId`, `$clientSecret`, `$mode` (injected from `PAYPAL_CLIENT_ID` / `PAYPAL_CLIENT_SECRET` / `PAYPAL_MODE` env vars in `config/services.yaml`) |

## For AI Agents

### Working In This Directory
- **Fixed (2026-07-03): the PayPal `return_url`/`cancel_url`** are generated as absolute URLs via `UrlGeneratorInterface` — no more hardcoded localhost. Keep it that way when touching the checkout flow.
- `$mode` selects sandbox vs. live PayPal endpoints — verify the base URL switches with it.
- Credentials come from env vars (not hardcoded); keep it that way and do not log tokens/secrets.
- Called from `src/Controller/PaymentController.php` (order → capture flow).

### Common Patterns
- Auto-registered as a service; explicit argument binding in `config/services.yaml`.
- HTTP calls via Symfony/amphp HTTP client.

## Dependencies

### Internal
- Consumed by `PaymentController`; results persisted to the `Payment` entity.

### External
- PayPal REST API; `symfony/http-client` / `amphp/http-client`.

<!-- MANUAL: -->
