crypto-pay-api 0.1.1

A Rust client library for Crypto Pay API provided by Telegram CryptoBot
Documentation
# Crypto Pay API Client for Rust ๐Ÿฆ€

[![Crates.io](https://img.shields.io/crates/v/crypto-pay-api.svg)](https://crates.io/crates/crypto-pay-api)
[![Documentation](https://docs.rs/crypto-pay-api/badge.svg)](https://docs.rs/crypto-pay-api)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![CI](https://github.com/escwxyz/crypto-pay-api/actions/workflows/test.yml/badge.svg)](https://github.com/escwxyz/crypto-pay-api/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/escwxyz/crypto-pay-api/graph/badge.svg?token=Ar6BnDUude)](https://codecov.io/gh/escwxyz/crypto-pay-api)

A type-safe Rust client for the [Crypto Bot](https://t.me/CryptoBot) 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`:

```toml
[dependencies]
crypto-pay-api = "0.1.1"
```

### Basic Example with tokio

```rust
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

```rust
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](examples/axum_webhook.rs) for an example using axum.

### Custom Configuration

```rust
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:

```rust
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 ๐Ÿ“š

- [API Documentation]https://docs.rs/crypto-pay-api
- [Crypto Bot API Documentation]https://help.crypt.bot/crypto-pay-api

## TODOs ๐Ÿงช

- Add more integration tests

## Contributing ๐Ÿค

Contributions are welcome! Please check out our [Contributing Guide](CONTRIBUTING.md).

## License ๐Ÿ“„

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.