### Install yoomoney dependency Source: https://github.com/amnesiaof/yoomoney/blob/master/README.md Add the yoomoney crate to your Cargo.toml file. ```toml [dependencies] yoomoney = "0.1" ``` -------------------------------- ### Build Quickpay link Source: https://github.com/amnesiaof/yoomoney/blob/master/README.md Generate a payment link for Quickpay without requiring an access token. ```rust use yoomoney::Quickpay; let url = Quickpay::new("4100123456789", "button", 100.0) .payment_type("AC") .label("order-123") .base_url()?; println!("{url}"); ``` -------------------------------- ### Fetch account information Source: https://github.com/amnesiaof/yoomoney/blob/master/README.md Retrieve account details and balance using a valid token. ```rust use yoomoney::Client; #[tokio::main] async fn main() -> yoomoney::Result<()> { let client = Client::new("your-token"); let account = client.account_info().await?; println!("{}: {} {}", account.account, account.balance, account.currency); Ok(()) } ``` -------------------------------- ### Authorize with OAuth Source: https://github.com/amnesiaof/yoomoney/blob/master/README.md Perform OAuth authorization by generating an authorization URL and handling the redirect to exchange the code for a token. ```rust use yoomoney::{Authorize, Scope}; #[tokio::main] async fn main() -> yoomoney::Result<()> { let auth = Authorize::new("your-client-id", "localhost", None); // 1. Show this URL to the user, they confirm access. let url = auth.authorize_url(&[Scope::AccountInfo, Scope::OperationHistory])?; println!("Open and confirm: {url}"); // 2. Get the URL the user was redirected to and exchange the code. let redirected = "http://localhost/?code=XXXXXXXX"; let token = auth.handle_redirect(redirected).await?; println!("token: {token}"); Ok(()) } ``` -------------------------------- ### Perform P2P transfer Source: https://github.com/amnesiaof/yoomoney/blob/master/README.md Request a P2P transfer and confirm the payment using the wallet as the money source. ```rust use yoomoney::{Client, MoneySource, P2pTransfer, ProcessPaymentQuery}; #[tokio::main] async fn main() -> yoomoney::Result<()> { let client = Client::new("your-token"); // 1. Create the transfer (requires the payment-p2p scope). let request = client .request_p2p(&P2pTransfer { to: "4100123456789".into(), amount: 10.0, message: Some("For coffee".into()), ..Default::default() }) .await?; if !request.is_success() { eprintln!("refused: {:?}", request.error); return Ok(()); } // 2. Confirm it from the wallet. let payment = client .process_payment(&ProcessPaymentQuery { request_id: request.request_id.clone().unwrap(), money_source: Some(MoneySource::Wallet), ..Default::default() }) .await?; println!("success: {:?}", payment.payment_id); Ok(()) } ``` -------------------------------- ### Retrieve operation history Source: https://github.com/amnesiaof/yoomoney/blob/master/README.md Fetch a list of recent operations using HistoryQuery. ```rust use yoomoney::{Client, HistoryQuery}; #[tokio::main] async fn main() -> yoomoney::Result<()> { let client = Client::new("your-token"); let history = client .operation_history(&HistoryQuery { records: Some(30), ..Default::default() }) .await?; for op in history.operations { println!("{:?} {:?} {:?}", op.datetime, op.amount, op.title); } Ok(()) } ``` -------------------------------- ### Verify incoming transfer notification Source: https://github.com/amnesiaof/yoomoney/blob/master/README.md Parse and verify the HMAC-SHA256 signature of an incoming HTTP notification. ```rust use yoomoney::IncomingTransfer; let transfer = IncomingTransfer::parse( "notification_type=p2p-incoming&operation_id=123&amount=0.99¤cy=643\ &datetime=2014-04-28T16:31:28Z&codepro=false&label=&sign=ABCD", ) .unwrap(); if transfer.verify("my-notification-secret") { println!("got {} RUB from {}", transfer.amount, transfer.sender); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.