A Rust SDK for the YooKassa Payment Gateway API.
- Full support for YooKassa API v3
- Async/await support using Tokio
- Strong typing with serde
- Comprehensive error handling
- Support for all major payment methods
- Webhook support
- Receipt and refund management
Add this to your Cargo.toml
:
[dependencies]
yookassa = "0.1.0"
use yookassa::{YooKassa, Amount, Currency, models::payment::CreatePaymentRequest};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create client with credentials
let client = YooKassa::with_credentials("your_account_id", "your_secret_key")?;
// Create a payment
let payment_request = CreatePaymentRequest::new(Amount::new("100.00", Currency::Rub))
.with_description("Order #12345")
.with_capture(true);
let payment = client.payments().create(payment_request).await?;
println!("Payment ID: {}", payment.id);
Ok(())
}
let client = YooKassa::with_credentials("account_id", "secret_key")?;
let client = YooKassa::with_token("oauth_token")?;
- ✅ Payments API
- Create payment
- Get payment info
- Capture payment
- Cancel payment
- List payments
- ✅ Refunds API
- Create refund
- Get refund info
- List refunds
- ✅ Receipts API
- Create receipt
- Get receipt info
- List receipts
- ✅ Webhooks API
- Create webhook
- List webhooks
- Delete webhook
- ✅ Settings API
- Get account settings
See the examples/
directory for more detailed examples:
create_payment.rs
- Creating a paymentlist_payments.rs
- Listing payments
Run examples with:
YOOKASSA_ACCOUNT_ID=your_id YOOKASSA_SECRET_KEY=your_key cargo run --example create_payment
The SDK provides comprehensive error handling:
use yookassa::Error;
match client.payments().create(request).await {
Ok(payment) => println!("Success: {}", payment.id),
Err(Error::Api(e)) => eprintln!("API error: {} - {}", e.code, e.description),
Err(Error::Unauthorized) => eprintln!("Invalid credentials"),
Err(e) => eprintln!("Other error: {}", e),
}
MIT