mercury_rust/resources/
recipient.rs

1use crate::client::Client;
2use crate::resources::transactions::{
3    DomesticWireRoutingInfo, InternationalWireRoutingInfo,
4};
5use crate::resources::{Address, List};
6use chrono::{DateTime, Utc};
7
8#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
9#[serde(rename_all = "camelCase")]
10pub struct Recipient {
11    pub id: String,
12    pub name: String,
13    pub email: Vec<String>,
14    pub date_last_paid: Option<DateTime<Utc>>,
15    pub electronic_routing_number: ElectronicRoutingInfo,
16    pub domestic_wire_routing_info: Option<DomesticWireRoutingInfo>,
17    pub international_wire_routing_info: Option<InternationalWireRoutingInfo>,
18    pub address: Option<Address>,
19}
20
21#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
22#[serde(rename_all = "camelCase")]
23pub struct ElectronicRoutingInfo {
24    pub account_number: String,
25    pub routing_number: String,
26    pub bank_name: Option<String>,
27    pub electronic_account_type: ElectronicAccountType,
28    pub address: Option<Address>,
29}
30
31#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
32#[serde(rename_all = "camelCase")]
33pub enum ElectronicAccountType {
34    BusinessChecking,
35    BusinessSavings,
36    PersonalChecking,
37    PersonalSavings,
38}
39
40#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
41#[serde(rename_all = "camelCase")]
42pub enum DefaultPaymentMethod {
43    ACH,
44    Check,
45    DomesticWire,
46    InternationalWire,
47}
48
49#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
50#[serde(rename_all = "lowercase")]
51pub enum RecipientStatus {
52    Active,
53    Deleted,
54}
55
56#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
57#[serde(rename_all = "camelCase")]
58pub enum RecipientPaymentMethod {
59    Check,
60    Electronic,
61    DomesticWire,
62    InternationalWire,
63}
64
65#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
66#[serde(rename_all = "camelCase")]
67pub struct RecipientParam<'a> {
68    pub name: &'a str,
69    pub address: Address,
70    pub emails: Vec<&'a str>,
71    pub payment_method: RecipientPaymentMethod,
72    pub electronic_routing_info: ElectronicRoutingInfo,
73    pub domestic_wire_routing_info: DomesticWireRoutingInfo,
74    pub international_wire_routing_info: InternationalWireRoutingInfo,
75}
76
77impl Recipient {
78    pub async fn list(client: &Client) -> crate::Result<List<Self>> {
79        client
80            .get("/recipients", vec![], serde_json::Map::new())
81            .await
82    }
83
84    pub async fn retrieve(client: &Client, id: &str) -> crate::Result<Self> {
85        client
86            .get("/recipients", vec![id], serde_json::Map::new())
87            .await
88    }
89
90    pub async fn create<B: serde::Serialize>(client: &Client, param: B) -> crate::Result<Self> {
91        client.get("/recipients", vec![], param).await
92    }
93
94    pub async fn update<B: serde::Serialize>(
95        client: &Client,
96        id: &str,
97        param: B,
98    ) -> crate::Result<Self> {
99        client.get("/recipients", vec![id], param).await
100    }
101}