pub struct RazorpayClient { /* private fields */ }Expand description
The entry point to the API.
Construct one at startup and share it. reqwest::Client holds a connection
pool internally, so building a client per request discards pooling and TLS
session reuse and will exhaust sockets under load. Cloning is cheap — the
underlying HTTP client is reference-counted.
§Examples
use razorpay_api::RazorpayClient;
let client = RazorpayClient::new("rzp_test_key".into(), "secret".into());
assert_eq!(client.base_url().as_str(), "https://api.razorpay.com/v1/");Implementations§
Source§impl RazorpayClient
impl RazorpayClient
Sourcepub fn new(api_key: String, api_secret: String) -> Self
pub fn new(api_key: String, api_secret: String) -> Self
A client authenticating with an API key pair.
Get these from the Razorpay dashboard. Keep the secret out of source control — read it from the environment or a secret manager.
§Examples
use razorpay_api::RazorpayClient;
let client = RazorpayClient::new(
std::env::var("RAZORPAY_KEY_ID").unwrap(),
std::env::var("RAZORPAY_KEY_SECRET").unwrap(),
);Sourcepub fn new_with_bearer_token(token: String) -> Self
pub fn new_with_bearer_token(token: String) -> Self
A client authenticating with an OAuth access token.
Sourcepub fn auth_method(&self) -> &AuthMethod
pub fn auth_method(&self) -> &AuthMethod
The configured authentication method.
Note this exposes the key secret; avoid logging the result.
Sourcepub fn with_base_url(self, base_url: Url) -> Self
pub fn with_base_url(self, base_url: Url) -> Self
Point the client at a different host.
Exists so the crate is testable without network access: point it at a mock
server and every request goes there instead. Keep the trailing slash —
Url::join discards the last path segment without one.
§Examples
let client = RazorpayClient::new("k".into(), "s".into())
.with_base_url("http://127.0.0.1:8080/v1/".parse().unwrap());
assert_eq!(client.base_url().as_str(), "http://127.0.0.1:8080/v1/");Source§impl RazorpayClient
Resource accessors.
impl RazorpayClient
Resource accessors.
Each returns a zero-cost borrowing view rather than an owned client, so
client.orders().fetch(id) allocates nothing and the whole API does not
collapse into a hundred flat methods on RazorpayClient.
Sourcepub fn orders(&self) -> OrdersClient<'_>
pub fn orders(&self) -> OrdersClient<'_>
Orders — create these before opening Checkout.
Sourcepub fn payments(&self) -> PaymentsClient<'_>
pub fn payments(&self) -> PaymentsClient<'_>
Payments — fetch, capture, and refund.
Sourcepub fn refunds(&self) -> RefundsClient<'_>
pub fn refunds(&self) -> RefundsClient<'_>
Refunds — fetch and list issued refunds.
Sourcepub fn customers(&self) -> CustomersClient<'_>
pub fn customers(&self) -> CustomersClient<'_>
Customers — saved payer identities.
Sourcepub fn cards(&self) -> CardsClient<'_>
pub fn cards(&self) -> CardsClient<'_>
Cards — read card details behind a payment.
Sourcepub fn items(&self) -> ItemsClient<'_>
pub fn items(&self) -> ItemsClient<'_>
Items — reusable priced line items.
Sourcepub fn plans(&self) -> PlansClient<'_>
pub fn plans(&self) -> PlansClient<'_>
Plans — billing cadences for subscriptions.
Sourcepub fn subscriptions(&self) -> SubscriptionsClient<'_>
pub fn subscriptions(&self) -> SubscriptionsClient<'_>
Subscriptions — recurring billing.
Sourcepub fn invoices(&self) -> InvoicesClient<'_>
pub fn invoices(&self) -> InvoicesClient<'_>
Invoices — itemized requests for payment.
Sourcepub fn payment_links(&self) -> PaymentLinksClient<'_>
pub fn payment_links(&self) -> PaymentLinksClient<'_>
Payment links — shareable payment URLs.
Source§impl RazorpayClient
Public mirrors of the private wrappers, for integration tests only. Enabled by
the test-util feature so the real surface stays crate-private.
impl RazorpayClient
Public mirrors of the private wrappers, for integration tests only. Enabled by
the test-util feature so the real surface stays crate-private.
Sourcepub async fn get_public<Q, R>(
&self,
path: &str,
query: Option<&Q>,
) -> Result<R, RazorpayError>
pub async fn get_public<Q, R>( &self, path: &str, query: Option<&Q>, ) -> Result<R, RazorpayError>
Issue a raw GET. Test-only; use the resource accessors instead.
Sourcepub async fn post_public<B, R>(
&self,
path: &str,
body: Option<&B>,
) -> Result<R, RazorpayError>
pub async fn post_public<B, R>( &self, path: &str, body: Option<&B>, ) -> Result<R, RazorpayError>
Issue a raw POST. Test-only; use the resource accessors instead.
Sourcepub async fn patch_public<B, R>(
&self,
path: &str,
body: Option<&B>,
) -> Result<R, RazorpayError>
pub async fn patch_public<B, R>( &self, path: &str, body: Option<&B>, ) -> Result<R, RazorpayError>
Issue a raw PATCH. Test-only; use the resource accessors instead.
Sourcepub async fn put_public<B, R>(
&self,
path: &str,
body: Option<&B>,
) -> Result<R, RazorpayError>
pub async fn put_public<B, R>( &self, path: &str, body: Option<&B>, ) -> Result<R, RazorpayError>
Issue a raw PUT. Test-only; use the resource accessors instead.
Sourcepub async fn delete_public<R>(&self, path: &str) -> Result<R, RazorpayError>where
R: DeserializeOwned,
pub async fn delete_public<R>(&self, path: &str) -> Result<R, RazorpayError>where
R: DeserializeOwned,
Issue a raw DELETE. Test-only; use the resource accessors instead.