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
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
use serde::{Deserialize, Serialize};

use crate::currency::Currency;
use crate::invoice;

/// Charge is a charge resource.
#[derive(Debug, Serialize, Deserialize)]
pub struct Charge {
    pub id: String,
    /// Charge Description
    pub description: String,
    /// Charge price in satoshis
    pub amount: u64,
    /// Charge status
    /// unpaid/processing/paid
    pub status: Status,
    /// Charge fee in satoshis
    pub fee: Option<u64>,
    /// Charge value at issue time
    pub fiat_value: f64,
    /// Charge currency
    pub currency: Option<Currency>,
    /// timestamp
    pub created_at: u64,
    /// URL where user gets redirected after payment
    pub success_url: Option<String>,
    /// Charge notes
    pub notes: String,
    /// Charge requested instant exchange
    pub auto_settle: bool,
    /// External order ID
    pub order_id: Option<String>,
    /// Charge payment details
    pub chain_invoice: Option<invoice::Chain>,
    /// lightning_invoice
    pub lightning_invoice: Option<invoice::Lightning>,
    /// Hashed Order
    /// OpenNode signs all charge related events it sends
    /// to your endpoints by including a hashed_order field
    /// on the event payload. This allows you to validate that
    /// the events were sent by OpenNode and not by a third party.
    pub hashed_order: Option<String>,
}

#[derive(Debug, Serialize, Deserialize)]
pub enum Status {
    #[serde(rename = "unpaid")]
    Unpaid,
    #[serde(rename = "paid")]
    Paid,
    #[serde(rename = "processing")]
    Processing,
    #[serde(rename = "underpaid")]
    Underpaid,
    #[serde(rename = "refunded")]
    Refunded,
}

/// Payload is a charge payload.
#[derive(Debug, Serialize, Deserialize)]
pub struct Payload {
    /// Charge's price in satoshis, unless currency parameter is used.
    pub amount: u64,
    /// Charge's description
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    /// Charge's currency
    #[serde(skip_serializing_if = "Option::is_none")]
    pub currency: Option<Currency>,
    /// Customer's email
    #[serde(skip_serializing_if = "Option::is_none")]
    pub customer_email: Option<String>,
    /// Customer's name
    #[serde(skip_serializing_if = "Option::is_none")]
    pub customer_name: Option<String>,
    /// URL to receive webhooks
    #[serde(skip_serializing_if = "Option::is_none")]
    pub callback_url: Option<String>,
    /// URL to redirect user after payment
    #[serde(skip_serializing_if = "Option::is_none")]
    pub success_url: Option<String>,
    /// Convert to merchant's currency (needs Bank account enabled)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub auto_settle: Option<String>,
}

impl Payload {
    pub fn new(a: u64) -> Payload {
        Payload {
            amount: a,
            description: None,
            currency: None,
            customer_email: None,
            customer_name: None,
            callback_url: None,
            success_url: None,
            auto_settle: None,
        }
    }
}