Expand description
An async, typed Rust client for the Razorpay API.
This crate is a typed wrapper over Razorpay’s HTTP API: it turns
POST /v1/orders into client.orders().create(params)
without losing type safety or error detail.
§Quick start
use razorpay_api::{RazorpayClient, RazorpayError};
use razorpay_api::resources::CreateOrderParams;
// Construct once at startup and share it — the client pools connections.
let client = RazorpayClient::new(
std::env::var("RAZORPAY_KEY_ID").unwrap(),
std::env::var("RAZORPAY_KEY_SECRET").unwrap(),
);
// Amounts are in the smallest currency unit — 50_000 paise is ₹500.
let order = client
.orders()
.create(CreateOrderParams::new(50_000, "INR").receipt("rcpt#1"))
.await?;
println!("open Checkout with {}", order.id);§The payment flow
A complete integration has four steps, and step 3 is not optional:
- Create an order server-side with
orders().create(). - Open Checkout in the browser with that order id. The customer pays.
- Verify the signature Checkout posts back, with
verify_payment_signature. The browser is attacker-controlled; without this, anyone can claim a payment succeeded. - Handle the webhook for asynchronous updates, verifying it with
WebhookEvent::parse_verified.
use razorpay_api::signature::verify_payment_signature;
// These three values arrive from the browser after Checkout completes.
verify_payment_signature(order_id, payment_id, signature, secret)?;
// Only now is it safe to mark the order as paid.§Money is always an integer
Every amount in this crate is an i64 in the currency’s smallest unit —
paise for INR, so ₹1 is 100. Floating point is never used: 0.1 + 0.2 != 0.3
in binary floating point, and on money that is a reconciliation bug users cannot
work around.
§Forward compatibility
Razorpay adds enum values and event types without a version bump. Every enum
here carries an Unknown fallback and every optional field is #[serde(default)],
so a new status arriving in production degrades to Unknown instead of failing
to decode and breaking a working integration.
§Errors
Every call returns RazorpayError. The variants are deliberately distinct for
retry logic: Http means the request never landed and is
usually retryable, while Decode means Razorpay
answered with something unexpected and never is. See RazorpayError::is_retryable.
§Available resources
Orders, Payments, Refunds, Customers, Tokens, Cards, Items, Plans, Subscriptions, Invoices, Payment Links, and Webhooks.
Modules§
Structs§
- ApiError
- A structured error returned by Razorpay.
- Collection
- The envelope every list endpoint returns:
{"entity": "collection", "count": N, "items": [...]}. - List
Options - Filters accepted by every
all()/ list endpoint. - Razorpay
Client - The entry point to the API.
Enums§
- Auth
Method - How the client authenticates.
- Razorpay
Error - Everything that can go wrong in this crate.