1use serde::Deserialize;
2use serde::Serialize;
3use tofuri_core::*;
4use tofuri_key::Key;
5#[derive(Serialize, Deserialize, Debug, Clone)]
6pub enum ChargeStatus {
7 New,
8 Pending,
9 Expired,
10 Completed,
11 Cancelled,
12}
13pub fn status(status: &ChargeStatus) -> String {
14 match *status {
15 ChargeStatus::New => "NEW".to_string(),
16 ChargeStatus::Pending => "PENDING".to_string(),
17 ChargeStatus::Expired => "EXPIRED".to_string(),
18 ChargeStatus::Completed => "COMPLETED".to_string(),
19 ChargeStatus::Cancelled => "CANCELLED".to_string(),
20 }
21}
22#[derive(Serialize, Deserialize, Debug, Clone)]
23pub struct Charge {
24 pub amount: u128,
25 pub timestamp: u32,
26 pub status: ChargeStatus,
27 pub subkey_n: u128,
28}
29impl Charge {
30 pub fn address_bytes(&self, key: &Key) -> AddressBytes {
31 key.subkey(self.subkey_n).unwrap().address_bytes()
32 }
33 pub fn payment(&self, key: &Key) -> Payment {
34 let address = tofuri_address::address::encode(&self.address_bytes(key));
35 let status = status(&self.status);
36 Payment {
37 address,
38 amount: self.amount,
39 timestamp: self.timestamp,
40 status,
41 }
42 }
43}
44#[derive(Serialize, Deserialize, Debug, Clone)]
45pub struct Payment {
46 pub address: String,
47 pub amount: u128,
48 pub timestamp: u32,
49 pub status: String,
50}