Skip to content

escwxyz/crypto-pay-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

46 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Crypto Pay API Client for Rust πŸ¦€

Crates.io Documentation License CI codecov

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(&params).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.

About

Rust client for the Crypto Pay API by Telegram CryptoBot

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 2

  •  
  •  

Languages