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
use serde::{Deserialize, Serialize};

/// Refund is a refund resource.
#[derive(Debug, Serialize, Deserialize)]
pub struct Refund {
    pub id: String,
    /// Underpaid charge ID
    pub checkout_id: String,
    /// Bitcoin address to send the funds
    pub address: String,
    /// unpaid/processing/paid
    pub status: Status,
    /// Amount in satoshis
    pub amount: String,
    /// Refund fee in satoshis
    pub fee: Option<String>,
    /// Buyer email to get notified of the refund
    pub email: Option<String>,
    /// timestamp
    pub created_at: u64,
    /// timestamp
    pub processed_at: Option<u64>,
}

#[derive(Debug, Serialize, Deserialize)]
pub enum Status {
    #[serde(rename = "confirmed")]
    Confirmed,
    #[serde(rename = "pending")]
    Pending,
}

/// Payload is a refund payload.
#[derive(Debug, Serialize, Deserialize)]
pub struct Payload {
    /// Underpaid charge ID
    pub checkout_id: String,
    /// Bitcoin address to send the funds
    pub address: String,
    /// Refund's email
    #[serde(skip_serializing_if = "Option::is_none")]
    pub email: Option<String>,
}

impl Payload {
    pub fn new(id: impl Into<String>, address: impl Into<String>) -> Payload {
        Payload {
            checkout_id: id.into(),
            address: address.into(),
            email: None,
        }
    }
}