Skip to main content

razorpay_api/resources/
common.rs

1//! Types shared across more than one resource.
2
3use std::collections::HashMap;
4
5use serde::{Deserialize, Serialize};
6
7/// Free-form key/value metadata attached to most Razorpay entities.
8///
9/// Razorpay allows up to 15 keys, with string keys and values.
10pub type Notes = HashMap<String, String>;
11
12/// A request body carrying only `notes`, used by the several `edit` endpoints
13/// whose sole editable field is metadata.
14#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize)]
15pub struct NotesUpdate {
16    /// The replacement notes map.
17    pub notes: Notes,
18}
19
20impl NotesUpdate {
21    /// Wrap a notes map into an edit body.
22    pub fn new(notes: Notes) -> Self {
23        Self { notes }
24    }
25}
26
27impl From<Notes> for NotesUpdate {
28    fn from(notes: Notes) -> Self {
29        Self { notes }
30    }
31}
32
33/// How a payment was made.
34///
35/// Carries an [`Unknown`](PaymentMethod::Unknown) fallback: Razorpay adds methods
36/// without a version bump, and a strict enum would turn that into a decode failure
37/// on a previously working integration.
38#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
39#[serde(rename_all = "snake_case")]
40pub enum PaymentMethod {
41    /// Credit or debit card.
42    Card,
43    /// Netbanking.
44    Netbanking,
45    /// Wallet (Paytm, PhonePe, …).
46    Wallet,
47    /// UPI.
48    Upi,
49    /// EMI.
50    Emi,
51    /// Pay-later provider.
52    Paylater,
53    /// Cardless EMI.
54    Cardless,
55    /// A method this crate does not model yet.
56    #[serde(other)]
57    Unknown,
58}
59
60/// Whether an entity is in test or live mode — mirrors which API key was used.
61#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
62#[serde(rename_all = "snake_case")]
63pub enum EntityMode {
64    /// Created with test keys; no real money moved.
65    Test,
66    /// Created with live keys.
67    Live,
68    /// A mode this crate does not model yet.
69    #[serde(other)]
70    Unknown,
71}