bitmomo 0.1.0

BitMomo merchant SDK: accept crypto payments and verify webhooks in Rust
Documentation
//! BitMomo merchant SDK: accept crypto payments and verify BitMomo webhooks.
//!
//! > **Test money only.** BitMomo currently runs on test networks. Live API
//! > keys are disabled, so nothing you do with this SDK moves real money.
//!
//! ```no_run
//! use bitmomo::{Client, CreatePaymentParams, Decimal};
//!
//! # async fn run() -> Result<(), bitmomo::Error> {
//! let client = Client::new(std::env::var("BITMOMO_API_KEY").unwrap(), "https://api.dev.bitmomo.app")?;
//! let params = CreatePaymentParams::new(Decimal::new("150.00")?, "USDT_TRC20")
//!     .order_id("order-1001")
//!     .idempotency_key("order-1001"); // reuse the same key if you retry
//! let payment = client.create_payment(&params).await?;
//! println!("{} {} {}", payment.deposit_address, payment.crypto_amount, payment.qr_code_data);
//! # Ok(())
//! # }
//! ```
//!
//! Verify webhooks with [`webhooks::verify_event`]. Every failure is an
//! [`Error`] with the HTTP `status`, the API's `code`, a `message` and a
//! `retriable` hint. Money is [`Decimal`], an exact decimal string.
//!
//! The `client` feature (on by default) provides the async [`Client`]; turn
//! default features off to use only the webhook helpers. TLS uses rustls by
//! default (`rustls-tls`); enable `native-tls` instead if you prefer.
//!
//! Guides and the API reference: <https://docs.bitmomo.app>
#![forbid(unsafe_code)]

mod decimal;
mod error;
pub mod models;
pub mod webhooks;

#[cfg(feature = "client")]
mod client;

#[cfg(feature = "client")]
pub use client::{Client, ClientBuilder};
pub use decimal::Decimal;
pub use error::Error;
pub use models::*;

/// The SDK version, sent in the User-Agent header.
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

/// A random UUID (version 4) to use as an idempotency key. Keep it with the
/// business intent and reuse it when you retry.
pub fn new_idempotency_key() -> String {
    let mut b = [0u8; 16];
    getrandom::getrandom(&mut b).expect("bitmomo: the operating system random source failed");
    b[6] = (b[6] & 0x0f) | 0x40;
    b[8] = (b[8] & 0x3f) | 0x80;
    let h = hex::encode(b);
    format!(
        "{}-{}-{}-{}-{}",
        &h[0..8],
        &h[8..12],
        &h[12..16],
        &h[16..20],
        &h[20..32]
    )
}