Skip to main content

pain001_sdk/
lib.rs

1// SPDX-License-Identifier: Apache-2.0 OR MIT
2//! Typed blocking client for the pain001 REST API.
3//!
4//! [pain001](https://pain001.com) generates and validates ISO 20022
5//! `pain.001` (credit transfer) and `pain.008` (direct debit) payment
6//! files. Its engine is a Python server, `pain001 serve`; this crate is a
7//! thin typed client for it. Every request and response is JSON, sent with
8//! [`ureq`] on the calling thread, with no async runtime.
9//!
10//! ```no_run
11//! use pain001_sdk::{Client, MessageType};
12//! use std::time::Duration;
13//!
14//! # fn main() -> Result<(), pain001_sdk::Error> {
15//! let client = Client::new("http://127.0.0.1:8000").timeout(Duration::from_secs(10));
16//! let csv = std::fs::read_to_string("payments.csv").expect("read the CSV");
17//! let generated = client.generate(&csv, "payments.csv", MessageType::Pain00100109, None)?;
18//! assert!(generated.xml.is_some(), "an Ok always carries the XML");
19//! # Ok(())
20//! # }
21//! ```
22//!
23//! A generate call whose rows fail validation or a scheme rule becomes
24//! [`Error::Refused`] (HTTP `422`), carrying the typed findings; any other
25//! non-2xx response becomes [`Error::Api`], carrying the HTTP status and
26//! the server's `detail` (a string, or an array for a `422`). The client
27//! never logs request bodies, which hold payment data, and retries nothing
28//! unless given a [`RetryPolicy`], which retries `GET` calls only.
29#![forbid(unsafe_code)]
30#![warn(missing_docs)]
31
32mod client;
33mod error;
34mod retry;
35mod types;
36
37#[cfg(test)]
38mod stub;
39
40/// The encoding and decoding paths without the network, for `fuzz/` and
41/// `benches/`. Not public API: it exists only under `cfg(fuzzing)`, with
42/// the `internals` feature, and in unit tests.
43#[cfg(any(fuzzing, test, feature = "internals"))]
44#[doc(hidden)]
45pub mod fuzzing;
46
47pub use client::{Client, DEFAULT_TIMEOUT, USER_AGENT, VERSION};
48pub use error::Error;
49pub use retry::RetryPolicy;
50pub use types::{
51    CheckFinding, CheckResponse, FaceInfo, FaceResponse, GenerateResponse, HealthResponse,
52    LossReport, MessageType, RequestError, RowError, ValidationResponse,
53};
54
55/// Compiles the README's Rust snippets as doctests.
56#[cfg(doctest)]
57#[doc = include_str!("../README.md")]
58struct ReadmeDoctests;