Skip to main content

Crate upi_rs

Crate upi_rs 

Source
Expand description

§upi-rs: Type-Safe UPI Payment Integration Library

A production-ready, type-safe, asynchronous, and provider-agnostic Rust crate for integrating UPI payment processing into your applications.

§Philosophy

“Parse, don’t validate.” This crate enforces type safety at compile time, ensuring that illegal states (like negative amounts or invalid VPAs) are unrepresentable in the type system.

§Features

  • Type-Safe Domain Models: Invalid payment data cannot be constructed
  • Provider Agnostic: Swap payment providers without changing your code
  • Async-First: Built on tokio for modern async Rust
  • Cryptographic Verification: Constant-time HMAC-SHA256 signature verification
  • Zero-Cost Abstractions: Efficient implementations with minimal overhead

§Getting Started

§1. Create Domain Objects

use upi_rs::types::{Vpa, Amount};

// UPI address - validated at construction time
let vpa = Vpa::new("customer@upi")?;

// Monetary amount - stored in Paise (1 INR = 100 Paise)
let amount = Amount::from_inr(100.50)?;

§2. Initialize a Provider

use upi_rs::providers::RazorpayProvider;

let provider = RazorpayProvider::new(
    "your_key_id",
    "your_key_secret"
);

§3. Process Payments

use upi_rs::traits::PaymentRequest;

let request = PaymentRequest::new(vpa, amount, "TXN001".to_string());

match provider.create_payment(request).await {
    Ok(response) => println!("Payment ID: {}", response.id),
    Err(e) => eprintln!("Payment failed: {}", e),
}

§4. Verify Webhooks

if provider.verify_webhook(payload, signature) {
    println!("Webhook is authentic!");
}

§Modules

  • error: Unified error type for the entire crate
  • types: Domain types with strict validation (Vpa, Amount)
  • security: Cryptographic verification utilities
  • traits: Provider abstraction layer
  • providers: Concrete payment gateway implementations

Re-exports§

pub use error::UpiError;
pub use providers::RazorpayProvider;
pub use traits::PaymentRequest;
pub use traits::PaymentResponse;
pub use traits::PaymentStatus;
pub use traits::UpiProvider;
pub use types::Amount;
pub use types::Vpa;

Modules§

error
Error types for UPI payment operations.
providers
Razorpay UPI payment provider implementation.
security
Cryptographic verification utilities for UPI webhooks.
traits
Provider abstraction for UPI payment gateways.
types
Domain types for UPI payment operations.

Constants§

VERSION
The version of this crate.