bachs-sdk
An unofficial, fully-typed Rust SDK for the Bachs API — payments and billing for internet businesses.
This mirrors the resource layout of the unofficial Node.js SDK: one client, one method per resource, async all the way down.
Community project, not published or endorsed by Bachs.
Installation
Initialization
use Bachs;
// Infers sandbox (sk_sandbox_...) vs. production (sk_live_...) from the key prefix.
let bachs = new?;
Need to point at something else (a mock server in tests, an explicit environment)?
use ;
use Duration;
let bachs = builder
.environment // or Environment::Production / Environment::Custom(url)
.timeout
.build?;
Usage examples
Retrieve a customer
let customer = bachs.customers.get.await?;
println!;
Create a checkout session
use ;
let session = bachs
.checkout_sessions
.create
.await?;
println!;
For a recurring product, this same call is also how you create a subscription — there's no separate subscriptions.create.
Verify webhooks
Webhooks — not client-side checkout redirects — are the source of truth for fulfilment. Bachs signs each delivery with an HMAC-SHA256 signature and a whsec_... secret; pull the three relevant values from whatever your framework calls its webhook-id / webhook-timestamp / webhook-signature headers and pass them in:
use ;
async
raw_body must be the exact, unparsed request bytes — the signature is computed over them, so re-serializing a parsed body won't match.
Error handling
Every fallible call returns Result<T, BachsError>. API errors carry the same shape documented across the Bachs API: a detail, an error_code, and — for 400 VALIDATION_ERROR responses — a list of field-level errors.
use ;
match bachs.products.create.await
Idempotent retries
POST requests accept an Idempotency-Key:
use ;
let opts = new.idempotency_key;
let customer = bachs
.customers
.create_with_options
.await?;
Available resources
| Client method | Resource |
|---|---|
bachs.products() |
Manage products and pricing plans in your catalog. |
bachs.checkout_sessions() |
Create and retrieve hosted checkout sessions. |
bachs.subscriptions() |
Read, update, and cancel recurring billing subscriptions. |
bachs.customers() |
Store and manage customer details and billing information. |
bachs.customer_sessions() |
Create authenticated billing-portal sessions for customers. |
bachs.payments() |
Read and list one-time payments and transactions. |
bachs.refunds() |
Issue and track refunds for successful payments. |
bachs.accounts() |
Retrieve your account's balances and settlement details. |
bachs.connected_accounts() |
Manage sub-accounts for marketplace or platform routing. |
bachs.transfers() |
Route funds between your platform and connected accounts. |
bachs.media() |
Upload files and get an upload_id to attach to products. |
bachs.payment_rails() |
List supported payment methods and networks. |
bachs_sdk::webhooks |
Verify webhook signatures and parse events. |
A note on schema coverage
This SDK is built against Bachs' public documentation, not an internal schema dump. customers, products, and checkout_sessions follow fully-specified OpenAPI schemas and are typed strictly. A few other resources (subscriptions, payments, refunds, transfers, connected_accounts, ...) are typed against the fields the docs and examples confirm, with an extra: FlexObject catch-all on each response so additional fields your API version returns are preserved rather than causing a deserialization error.
If a response doesn't match what's modeled here, please open an issue — ideally with the (secret-redacted) response body.
Contributing
See CONTRIBUTING.md.
License
MIT