Skip to main content

RazorpayClient

Struct RazorpayClient 

Source
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

Source

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(),
);
Source

pub fn new_with_bearer_token(token: String) -> Self

A client authenticating with an OAuth access token.

Source

pub fn base_url(&self) -> &Url

The base URL requests are sent to.

Source

pub fn auth_method(&self) -> &AuthMethod

The configured authentication method.

Note this exposes the key secret; avoid logging the result.

Source

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.

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.

Source

pub fn orders(&self) -> OrdersClient<'_>

Orders — create these before opening Checkout.

Source

pub fn payments(&self) -> PaymentsClient<'_>

Payments — fetch, capture, and refund.

Source

pub fn refunds(&self) -> RefundsClient<'_>

Refunds — fetch and list issued refunds.

Source

pub fn customers(&self) -> CustomersClient<'_>

Customers — saved payer identities.

Source

pub fn cards(&self) -> CardsClient<'_>

Cards — read card details behind a payment.

Source

pub fn items(&self) -> ItemsClient<'_>

Items — reusable priced line items.

Source

pub fn plans(&self) -> PlansClient<'_>

Plans — billing cadences for subscriptions.

Source

pub fn subscriptions(&self) -> SubscriptionsClient<'_>

Subscriptions — recurring billing.

Source

pub fn invoices(&self) -> InvoicesClient<'_>

Invoices — itemized requests for payment.

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn delete_public<R>(&self, path: &str) -> Result<R, RazorpayError>

Issue a raw DELETE. Test-only; use the resource accessors instead.

Trait Implementations§

Source§

impl Clone for RazorpayClient

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RazorpayClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more