Frameworks
Spring Boot — Intégration Scell.io
Pas de SDK Java — fetch HTTP via WebClient ou OkHttp
Scell.io ne publie PAS de SDK Java officiel. En Spring Boot, intégrer via `WebClient` (réactif, recommandé) ou `RestClient` (synchrone, Spring 6.1+). Encapsuler dans un `@Service` avec configuration `@Value("${scell.api.key}")`. Header `X-API-Key` injecté dans le builder. Utiliser `application.yml` pour la config.
À retenir
- Pas de SDK Java officiel — `WebClient` ou `RestClient`
- Configuration via `application.yml` + `@Value`
- `@Service` Spring autowired dans les controllers
- Compatible Spring Boot 3.x, JDK 17+
- Pour reactive : `Mono<Invoice>` retourné
Exemple de code
@Service
public class ScellService {
private final WebClient client;
public ScellService(@Value("${scell.api.key}") String apiKey) {
this.client = WebClient.builder()
.baseUrl("https://api.scell.io/api/v1")
.defaultHeader("X-API-Key", apiKey)
.build();
}
public Mono<Map> createInvoice(String buyer, double amount) {
Map<String, Object> body = Map.of(
"format", "factur-x",
"buyer", Map.of("name", buyer, "is_individual", true),
"lines", List.of(Map.of("description", "Service", "quantity", 1, "unit_price", amount, "vat_rate", 20.0))
);
return client.post().uri("/invoices").bodyValue(body).retrieve().bodyToMono(Map.class);
}
}