bachs_sdk/lib.rs
1//! Unofficial Rust SDK for the [Bachs API](https://docs.bachs.io) — payments
2//! and billing for internet businesses.
3//!
4//! This is a community client, not published or endorsed by Bachs.
5//!
6//! # Quickstart
7//!
8//! ```no_run
9//! use bachs_sdk::{Bachs, customers::CreateCustomerRequest};
10//!
11//! # async fn run() -> Result<(), bachs_sdk::BachsError> {
12//! // Reads a sandbox (sk_sandbox_...) or live (sk_live_...) key and infers
13//! // the right base URL from the prefix.
14//! let bachs = Bachs::new(std::env::var("BACHS_API_KEY").unwrap())?;
15//!
16//! let customer = bachs
17//! .customers()
18//! .create(&CreateCustomerRequest::new("jane@example.com").name("Jane Doe"))
19//! .await?;
20//!
21//! println!("created {}", customer.customer_id);
22//! # Ok(())
23//! # }
24//! ```
25//!
26//! # Conventions carried over from the API
27//!
28//! - **Money** is always a decimal string at the currency's precision (e.g.
29//! `"29.00"`), paired with an ISO 4217 currency code — never minor units.
30//! - **Sandbox vs. production** are different hosts entirely
31//! (`sandbox-api.bachs.io` / `api.bachs.io`) with different key prefixes
32//! (`sk_sandbox_...` / `sk_live_...`). [`Bachs::new`] infers which one you
33//! mean from the key; going live is a key swap.
34//! - **Webhooks are the source of truth** for fulfilment — see the
35//! [`webhooks`] module — not client-side checkout redirects.
36//! - **Subscriptions** are created by completing a
37//! [checkout session](checkout_sessions::CheckoutSessions::create) against
38//! a recurring product. There's no direct create-subscription call.
39//! - Resource IDs carry type prefixes (`cust_`, `prod_`, `sub_`, `chk_`,
40//! `inv_`, `ref_`, ...).
41//!
42//! # A note on coverage
43//!
44//! This SDK is built from Bachs' public documentation, not an internal
45//! schema dump. The `customers` and `checkout_sessions` resources follow a
46//! fully-specified OpenAPI schema and are typed strictly. Several other
47//! resources (subscriptions, payments, refunds, transfers, connected
48//! accounts, ...) are typed against the fields the docs and examples confirm,
49//! with an `extra: FlexObject` catch-all on each response so additional
50//! fields your API version returns are preserved rather than causing a
51//! deserialization error. If you hit a mismatch, please open an issue.
52
53pub mod client;
54pub mod common;
55pub mod error;
56pub mod resources;
57pub mod webhooks;
58
59pub use client::{Bachs, BachsBuilder, Environment, RequestOptions};
60pub use common::{Address, ListParams, ListResponse, Metadata, Money, Pagination, Timestamp};
61pub use error::{ApiErrorBody, BachsError, BachsResult, FieldError};
62
63// Flat re-exports so callers can write `bachs_sdk::customers::...` as shown
64// in the README, matching the ergonomics of the Node SDK's `bachs.customers`.
65pub use resources::accounts;
66pub use resources::checkout_sessions;
67pub use resources::connected_accounts;
68pub use resources::customer_sessions;
69pub use resources::customers;
70pub use resources::media;
71pub use resources::payment_rails;
72pub use resources::payments;
73pub use resources::products;
74pub use resources::refunds;
75pub use resources::subscriptions;
76pub use resources::transfers;