Skip to main content

Crate sagapay

Crate sagapay 

Source
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
CreateDepositParams
Parameters for creating a deposit
CreateWithdrawalParams
Parameters for creating a withdrawal
DepositResponse
Response from the create deposit endpoint
Token
Token information
Transaction
Transaction details
TransactionStatusResponse
Response from the transaction status endpoint
VerifyIpnParams
Parameters for confirming an IPN with the SagaPay API
VerifyIpnResponse
Response from the verify IPN endpoint
WalletBalanceResponse
Response from the wallet balance endpoint
WebhookHandler
Handler for SagaPay webhook notifications (IPN)
WebhookPayload
Webhook payload
WithdrawalResponse
Response from the create withdrawal endpoint

Enums§

AddressType
Address type enum
Error
SagaPay error types
IpnType
Transaction type as used by the IPN endpoints
NetworkType
Supported blockchain network types
TransactionStatus
Transaction status enum
TransactionType
Transaction type enum

Constants§

DEFAULT_MAX_AGE
A sensible limit for is_ipn_fresh and WebhookHandler::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.