1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::StdResp;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

pub type FetchChargesResponse = StdResp<Option<Vec<ChargesData>>>;
pub type FetchOneChargeResponse = StdResp<Option<ChargesData>>;

#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct InvoiceData {
    pub request: String,
    pub uri: String,
}

#[derive(Debug, Serialize, Deserialize, Default)]
pub struct ChargesData {
    pub id: String,
    pub unit: String,
    pub amount: String,
    #[serde(rename = "createdAt")]
    pub created_at: Option<DateTime<Utc>>,
    #[serde(rename = "internalId")]
    pub internal_id: String,
    #[serde(rename = "callbackUrl")]
    pub callback_url: String,
    pub description: String,
    #[serde(rename = "expiresAt")]
    pub expires_at: Option<DateTime<Utc>>,
    #[serde(rename = "confirmedAt")]
    pub confirmed_at: Option<DateTime<Utc>>,
    pub status: String,
    pub invoice: Option<InvoiceData>,
}

/// Use this struct to create a well crafted json body for your charge requests
#[derive(Debug, Serialize, Deserialize)]
pub struct Charge {
    #[serde(rename = "expiresIn")]
    pub expires_in: u32,
    pub amount: String,
    pub description: String,
    #[serde(rename = "internalId")]
    pub internal_id: String,
    #[serde(rename = "callbackUrl")]
    pub callback_url: String,
}

impl Default for Charge {
    fn default() -> Self {
        Charge {
            expires_in: 300,
            amount: String::from("0"),
            description: String::from("using zebedee rust sdk"),
            internal_id: String::from(""),
            callback_url: String::from(""),
        }
    }
}