Expand description
§SagaPay Rust SDK
This crate provides a Rust interface to the SagaPay blockchain payment gateway API. SagaPay is the world’s first free, non-custodial blockchain payment gateway service provider.
§Example
use sagapay::{AddressType, Client, Config, CreateDepositParams, NetworkType};
#[tokio::main]
async fn main() -> Result<(), sagapay::Error> {
// Initialize the SagaPay client
let client = Client::new(Config {
api_key: "your-api-key".to_string(),
api_secret: "your-api-secret".to_string(),
..Config::default()
});
// Create a deposit address
let deposit = client.create_deposit(CreateDepositParams {
network_type: NetworkType::BEP20,
contract_address: "0".to_string(), // '0' for native tokens (BNB)
amount: "1.5".to_string(),
ipn_url: "https://example.com/webhook".to_string(),
udf: Some("order-123".to_string()),
address_type: Some(AddressType::Temporary),
transfer_balance: None, // defaults to true server side
}).await?;
println!("Deposit address: {}", deposit.address);
println!("Expires at: {:?}", deposit.expires_at);
Ok(())
}§Notifications (IPN)
WebhookHandler verifies each notification’s X-Sagapay-Merchant-Signature
header with your signing secret (dashboard: Webhooks → Signing secret), then
parses it. Notifications are delivered at least once, and a replayed request
carries a valid signature too, so act on each id only once.
is_ipn_fresh optionally rejects old notifications.
Structs§
- Balance
- Balance information
- Client
- SagaPay API client
- Config
- Configuration for the SagaPay client
- Create
Deposit Params - Parameters for creating a deposit
- Create
Withdrawal Params - Parameters for creating a withdrawal
- Deposit
Response - Response from the create deposit endpoint
- Token
- Token information
- Transaction
- Transaction details
- Transaction
Status Response - Response from the transaction status endpoint
- Verify
IpnParams - Parameters for confirming an IPN with the SagaPay API
- Verify
IpnResponse - Response from the verify IPN endpoint
- Wallet
Balance Response - Response from the wallet balance endpoint
- Webhook
Handler - Handler for SagaPay webhook notifications (IPN)
- Webhook
Payload - Webhook payload
- Withdrawal
Response - Response from the create withdrawal endpoint
Enums§
- Address
Type - Address type enum
- Error
- SagaPay error types
- IpnType
- Transaction type as used by the IPN endpoints
- Network
Type - Supported blockchain network types
- Transaction
Status - Transaction status enum
- Transaction
Type - Transaction type enum
Constants§
- DEFAULT_
MAX_ AGE - A sensible limit for
is_ipn_freshandWebhookHandler::with_max_age: 24 hours, well above the IPN retry schedule (about 7.5 hours). - SIGNATURE_
HEADER - Header carrying the IPN signature, formatted as
sha256=<hex>
Functions§
- is_
ipn_ fresh - Whether a notification’s timestamp is recent enough to act on, as a guard against an old, validly signed notification being replayed.