Skip to content

RIg410/yookassa-sdk-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YooKassa SDK for Rust

A Rust SDK for the YooKassa Payment Gateway API.

Features

  • 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

Installation

Add this to your Cargo.toml:

[dependencies]
yookassa = "0.1.0"

Quick Start

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(())
}

Authentication

Basic Auth

let client = YooKassa::with_credentials("account_id", "secret_key")?;

OAuth Token

let client = YooKassa::with_token("oauth_token")?;

API Coverage

  • ✅ 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

Examples

See the examples/ directory for more detailed examples:

  • create_payment.rs - Creating a payment
  • list_payments.rs - Listing payments

Run examples with:

YOOKASSA_ACCOUNT_ID=your_id YOOKASSA_SECRET_KEY=your_key cargo run --example create_payment

Error Handling

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),
}

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages