Official Rust SDK for the CryptoGate payment API.
[dependencies]
cryptogate = "1.0.0"use cryptogate::CryptoGateClient;
#[tokio::main]
async fn main() {
let cg = CryptoGateClient::new("sk_live_your_api_key");
let tx = cg.create_transaction("BTC", 50.0).await.unwrap();
println!("{}", tx.txid); // MTX-A1B2C3D4
println!("{}", tx.payment_url); // Redirect your customer here
}let tx = cg.create_transaction("BTC", 25.0).await?;
let tx = cg.get_transaction("MTX-A1B2C3D4").await?;
let result = cg.list_transactions(1, 20).await?;
let tx = cg.cancel_transaction("MTX-A1B2C3D4").await?;
let cryptos = cg.get_supported_cryptos().await?;
let rates = cg.get_exchange_rates().await?;use cryptogate::verify_webhook;
async fn webhook(
headers: HeaderMap,
body: Bytes,
) -> impl IntoResponse {
let signature = headers
.get("X-CryptoGate-Signature")
.and_then(|v| v.to_str().ok())
.unwrap_or("");
if !verify_webhook(&std::env::var("WEBHOOK_SECRET").unwrap(), &body, signature) {
return StatusCode::BAD_REQUEST;
}
// handle event
StatusCode::OK
}use cryptogate::CryptoGateError;
match cg.get_transaction("MTX-INVALID").await {
Ok(tx) => println!("{:?}", tx),
Err(CryptoGateError::NotFound(msg)) => eprintln!("Not found: {}", msg),
Err(CryptoGateError::Authentication(msg)) => eprintln!("Auth error: {}", msg),
Err(e) => eprintln!("Error: {}", e),
}MIT