1 unstable release
0.1.0 | Feb 13, 2025 |
---|
#709 in Magic Beans
125 downloads per month
215KB
4.5K
SLoC
Crypto Pay API Client for Rust ๐ฆ
A type-safe Rust client for the Crypto Bot API with async support.
Features โจ
- ๐ Complete type safety
- ๐ Async support
- ๐ก Comprehensive error handling
- ๐ Built-in parameter validation
- ๐ฆ Zero configuration
- ๐ Webhook support
- ๐ Full API coverage
- ๐งช Complete test coverage
Quick Start ๐
Add to your Cargo.toml
:
[dependencies]
crypto-pay-api = "0.1.0"
Basic Example with tokio
use crypto_pay_api::prelude::*;
#[tokio::main]
async fn main() -> Result<(), CryptoBotError> {
// Initialize client
let client = CryptoBot::builder().api_token("YOUR_API_TOKEN").build()?;
// Create an invoice
let params = CreateInvoiceParamsBuilder::new()
.asset(CryptoCurrencyCode::Ton)
.amount(dec!(10.5))
.description("Test payment".to_string())
.build(&client)
.await?;
let invoice = client.create_invoice(¶ms).await?;
println!("Payment URL: {}", invoice.pay_url);
Ok(())
}
API Coverage ๐
Invoices
- โ
Create invoice (
create_invoice
) - โ
Get invoices (
get_invoices
) - โ
Delete invoice (
delete_invoice
)
Transfers
- โ
Transfer (
transfer
) - โ
Get transfers (
get_transfers
)
Checks
- โ
Create check (
create_check
) - โ
Get checks (
get_checks
) - โ
Delete check (
delete_check
)
Other Features
- โ
Get balance (
get_balance
) - โ
Get exchange rates (
get_exchange_rates
) - โ
Get currencies (
get_currencies
) - โ
Get app info (
get_me
) - โ
Get statistics (
get_stats
)
Advanced Usage ๐ง
Webhook Handling
use crypto_pay_api::prelude::*;
#[tokio::main]
async fn main() -> Result<(), CryptoBotError> {
let client = CryptoBot::builder().api_token("YOUR_API_TOKEN").build()?;
let mut handler = client.webhook_handler(WebhookHandlerConfigBuilder::new().build());
// Register payment callback
handler.on_update(|update| async move {
println!("Invoice paid: {:?}", update.payload);
Ok(())
});
// Start webhook server
// ... integrate with your web framework
}
See examples/axum_webhook.rs for an example using axum.
Custom Configuration
let client = CryptoBot::builder()
.api_token("YOUR_API_TOKEN")
.base_url("https://pay.crypt.bot/api")
.timeout(Duration::from_secs(30))
.build();
Error Handling โ ๏ธ
The library provides detailed error types:
match client.get_balance().await {
Ok(balances) => {
for balance in balances {
println!("{}: {}", balance.currency_code, balance.available);
}
}
Err(CryptoBotError::ValidationError { kind, message, field }) => {
eprintln!("Validation error: {} (field: {:?})", message, field);
}
Err(e) => eprintln!("Other error: {}", e),
}
Documentation ๐
Contributing ๐ค
Contributions are welcome! Please check out our Contributing Guide.
License ๐
This project is licensed under the MIT License - see the LICENSE file for details.
Dependencies
~6โ18MB
~245K SLoC