Expand description
The official Rust client for the Ha Tang (Hạ Tầng) API: transactional email, live chat and support CRM, plans and purchases on the customer’s profile, the AI chatbot’s knowledge, VietQR payments and webhook verification. Async (Tokio) and blocking.
use hatang::{Hatang, Platform, SubscriptionUpsert};
let hatang = Hatang::from_env()?; // reads HATANG_API_KEY; or Hatang::new("ht_…")
// What a customer pays for, from your backend (web sales included).
hatang.chat.subscriptions.upsert(Platform::Web, "sub_123", &SubscriptionUpsert {
status: "active".into(),
sku: Some("PRO-1M".into()), // finds the product in your catalog
external_user_id: Some("user-42".into()), // the id you pass to identify() in the chat
current_period_end: Some("2026-12-01T00:00:00Z".into()),
amount: Some(99000.0),
currency: Some("VND".into()),
..Default::default()
}).await?;Hatangis async (any runtime that drivesreqwest, Tokio in practice). With theblockingfeature,blocking::Hatanghas the same methods and returns results directly.- Bodies take
impl Serialize: the typed structs in this crate, orserde_json::json!for anything else. Responses areserde_json::Value, as the API sends them. - Errors are
Error;Error::retryabletells what can succeed later (unreachable, rate limits, a request still running with the same idempotency key, 5xx) from mistakes, withError::retry_after;Error::is_quota_exceededflags the daily email quota. verify_webhookandverify_ipncheck what Ha Tang sends to your endpoints.
Re-exports§
pub use resources::Contact;pub use webhooks::construct_ipn_event;pub use webhooks::construct_webhook_event;pub use webhooks::verify_ipn;pub use webhooks::verify_webhook;pub use webhooks::Headers;pub use types::*;
Modules§
- blocking
blocking - A synchronous client for code without an async runtime (scripts, CLIs, sync web frameworks).
- resources
- API namespaces, shared by the async and blocking clients.
- types
- Typed request bodies and query parameters, matching the REST API and the other SDKs.
- webhooks
- Checking what Ha Tang sends to your endpoints: webhook deliveries and payment IPN calls.
Structs§
- Async
- The async executor behind
crate::Hatang. - Blocking
blocking - The executor behind
blocking::Hatang. - Client
- A Ha Tang client. Use the aliases
Hatang(async) andblocking::Hatang. - Hatang
Builder - Settings for a client. Start from
Hatang::builder(orblocking::Hatang::builder).
Enums§
- Error
- Everything a call or a signature check can fail with.
Constants§
- DEFAULT_
BASE_ URL - The API’s address unless
HATANG_BASE_URLorHatangBuilder::base_urlsays otherwise. - DEFAULT_
TIMEOUT - How long one call may take unless
HatangBuilder::timeoutsays otherwise. - VERSION
- This crate’s version, sent in the User-Agent.
Traits§
- Executor
- How a client runs calls: the async client returns futures, the blocking client results.
Functions§
- identity_
hash - The signature that makes a chat identity trusted: hex HMAC-SHA256 of the user id with the site’s identity
secret (Ha Tang → Support → Channels → the site → Widget). Pass it as
hashwithuserIdtoidentifyin the widget or the app SDKs; never send the secret to the browser or the app. - purchase_
token - The app account token for one of your users: pass it as StoreKit
appAccountToken/ Google PlayobfuscatedAccountIdso the stores’ notifications reach that customer in Ha Tang. A UUID v5 of the user id in the site’s namespace; the app SDKs’purchaseTokengives the same value.