Skip to main content

razorpay/
lib.rs

1//! # razorpay-rs
2//!
3//! An async, type-safe, idiomatic Rust SDK for the [Razorpay API](https://razorpay.com/docs/api/).
4//!
5//! ## Overview
6//!
7//! `razorpay-rs` provides access to Razorpay's payments platform including:
8//! - **Orders & Payments**: Create orders, capture payments, handle OTPs, and issue refunds.
9//! - **Payment Links & Invoices**: Generate hosted payment links and invoice line items.
10//! - **Subscriptions & Plans**: Set up recurring billing cycles, addons, and e-mandates.
11//! - **Smart Collect & Virtual Accounts**: Create virtual bank accounts and UPI VPAs.
12//! - **Route & Transfers**: Split payments and manage linked marketplace accounts.
13//! - **Disputes & Settlements**: Track chargebacks and on-demand instant settlements.
14//! - **Bills**: Manage retail and point-of-sale (POS) digital receipts.
15//! - **Webhooks & Security**: Constant-time signature verification for webhooks and checkouts.
16//!
17//! ## Creating a Client
18//!
19//! ### Basic Initialization
20//! ```no_run
21//! use razorpay::RazorpayClient;
22//!
23//! # #[tokio::main]
24//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
25//! let client = RazorpayClient::new("rzp_test_key", "test_secret")?;
26//! # Ok(())
27//! # }
28//! ```
29//!
30//! ### Custom Configuration with Builder
31//! ```no_run
32//! use razorpay::RazorpayClientBuilder;
33//! use std::time::Duration;
34//! use url::Url;
35//!
36//! # #[tokio::main]
37//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
38//! let client = RazorpayClientBuilder::new()
39//!     .key_id("rzp_test_key")
40//!     .key_secret("test_secret")
41//!     .timeout(Duration::from_secs(30))
42//!     .build()?;
43//! # Ok(())
44//! # }
45//! ```
46//!
47//! ## Usage Examples
48//!
49//! ### Creating an Order
50//! ```no_run
51//! use razorpay::{
52//!     Creatable, RazorpayClient,
53//!     models::CreateOrderRequest,
54//! };
55//!
56//! # #[tokio::main]
57//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
58//! let client = RazorpayClient::new("rzp_test_key", "test_secret")?;
59//!
60//! let req = CreateOrderRequest {
61//!     amount: 50000, // 500.00 INR in paise
62//!     currency: "INR".to_string(),
63//!     receipt: Some("rcpt_101".to_string()),
64//!     partial_payment: Some(false),
65//!     first_payment_min_amount: None,
66//!     transfers: None,
67//!     notes: None,
68//! };
69//!
70//! let order = client.orders().create(req, None).await?;
71//! println!("Created order ID: {}", order.id);
72//! # Ok(())
73//! # }
74//! ```
75//!
76//! ### Creating a Hosted Payment Link
77//! ```no_run
78//! use razorpay::{
79//!     Creatable, RazorpayClient,
80//!     models::CreatePaymentLinkRequest,
81//! };
82//!
83//! # #[tokio::main]
84//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
85//! let client = RazorpayClient::new("rzp_test_key", "test_secret")?;
86//!
87//! let req = CreatePaymentLinkRequest {
88//!     amount: 25000, // 250.00 INR in paise
89//!     currency: Some("INR".to_string()),
90//!     accept_partial: Some(false),
91//!     first_min_partial_amount: None,
92//!     expire_by: None,
93//!     reference_id: Some("tx_9981".to_string()),
94//!     description: Some("Product Purchase Link".to_string()),
95//!     customer: None,
96//!     notify: None,
97//!     reminder_enable: None,
98//!     notes: None,
99//!     callback_url: None,
100//!     callback_method: None,
101//! };
102//!
103//! let link = client.payment_links().create(req, None).await?;
104//! println!("Payment Link URL: {}", link.short_url);
105//! # Ok(())
106//! # }
107//! ```
108//!
109//! ### Verifying Checkout Payment Signature
110//! ```no_run
111//! use razorpay::webhooks::verify_payment_signature;
112//!
113//! let order_id = "order_EKwxwAgItmmXdp";
114//! let payment_id = "pay_29AeabbJyL3mAO";
115//! let signature = "9ef4dffbfd84f1318f6739a3ce19f9d85851857ae648f114332d840193e13ff1";
116//! let key_secret = "test_secret";
117//!
118//! match verify_payment_signature(order_id, payment_id, signature, key_secret) {
119//!     Ok(()) => println!("Payment verified successfully!"),
120//!     Err(err) => eprintln!("Invalid signature: {:?}", err),
121//! }
122//! ```
123//!
124//! ### Verifying Webhook Signature
125//! ```no_run
126//! use razorpay::webhooks::verify_webhook_signature;
127//!
128//! let raw_body = r#"{"entity":"event","event":"payment.captured"}"#;
129//! let signature_header = "25134763133642c26279f041c2c31e4e138a4d46f5de019e0cc0ab961a8a25c1";
130//! let webhook_secret = "my_webhook_secret";
131//!
132//! match verify_webhook_signature(raw_body, signature_header, webhook_secret) {
133//!     Ok(()) => println!("Webhook verified successfully!"),
134//!     Err(err) => eprintln!("Webhook signature mismatch: {:?}", err),
135//! }
136//! ```
137
138pub mod client;
139pub mod config;
140pub mod error;
141pub(crate) mod http;
142pub mod models;
143pub mod resources;
144pub mod traits;
145pub mod webhooks;
146
147// Convenient re-exports at root
148pub use client::{RazorpayClient, RazorpayClientBuilder};
149pub use config::RazorpayConfig;
150pub use error::{RazorpayError, RazorpayResult};
151pub use resources::{
152    Accounts, Addons, Bills, Cards, CustomerTokens, Customers, Disputes, Documents, FundAccounts,
153    Iins, Invoices, Items, Orders, PaymentLinks, Payments, Payouts, Plans, Products, QrCodes,
154    Refunds, Settlements, Stakeholders, Subscriptions, Tokens, Transfers, VirtualAccounts,
155    Webhooks,
156};
157pub use traits::{Creatable, Deletable, Fetchable, Listable, Updatable};