Skip to main content

Crate hatang

Crate hatang 

Source
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?;
  • Hatang is async (any runtime that drives reqwest, Tokio in practice). With the blocking feature, blocking::Hatang has the same methods and returns results directly.
  • Bodies take impl Serialize: the typed structs in this crate, or serde_json::json! for anything else. Responses are serde_json::Value, as the API sends them.
  • Errors are Error; Error::retryable tells what can succeed later (unreachable, rate limits, a request still running with the same idempotency key, 5xx) from mistakes, with Error::retry_after; Error::is_quota_exceeded flags the daily email quota.
  • verify_webhook and verify_ipn check 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§

blockingblocking
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.
Blockingblocking
The executor behind blocking::Hatang.
Client
A Ha Tang client. Use the aliases Hatang (async) and blocking::Hatang.
HatangBuilder
Settings for a client. Start from Hatang::builder (or blocking::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_URL or HatangBuilder::base_url says otherwise.
DEFAULT_TIMEOUT
How long one call may take unless HatangBuilder::timeout says 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 hash with userId to identify in 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 Play obfuscatedAccountId so the stores’ notifications reach that customer in Ha Tang. A UUID v5 of the user id in the site’s namespace; the app SDKs’ purchaseToken gives the same value.

Type Aliases§

BoxFuture
A future returned by the async client.
Hatang
The async client: every call returns a future.
Result
Result with this crate’s Error.