api_wire.rs (6802B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2024, 2025, 2026 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Affero General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. 12 13 You should have received a copy of the GNU Affero General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 17 //! Type for the Taler Wire Gateway HTTP API <https://docs.taler.net/core/api-bank-wire.html#taler-wire-gateway-http-api> 18 19 use compact_str::CompactString; 20 use url::Url; 21 22 use crate::{ 23 api_common::EddsaSignature, 24 types::{amount::Amount, payto::PaytoURI, timestamp::TalerTimestamp}, 25 }; 26 27 use super::api_common::{EddsaPublicKey, HashCode, SafeU64, ShortHashCode, WadId}; 28 use serde::{Deserialize, Serialize}; 29 30 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-WireConfig> 31 #[derive(Debug, Clone, Serialize, Deserialize)] 32 pub struct WireConfig<'a> { 33 pub name: &'a str, 34 pub version: &'a str, 35 pub currency: &'a str, 36 pub implementation: Option<&'a str>, 37 pub support_account_check: bool, 38 } 39 40 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-TransferResponse> 41 #[derive(Debug, Clone, Serialize, Deserialize)] 42 pub struct TransferResponse { 43 pub timestamp: TalerTimestamp, 44 pub row_id: SafeU64, 45 } 46 47 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-TransferRequest> 48 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] 49 pub struct TransferRequest { 50 pub request_uid: HashCode, 51 pub amount: Amount, 52 pub exchange_base_url: Url, 53 pub metadata: Option<CompactString>, 54 pub wtid: ShortHashCode, 55 pub credit_account: PaytoURI, 56 } 57 58 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-TransferList> 59 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] 60 pub struct TransferList { 61 pub transfers: Vec<TransferListStatus>, 62 pub debit_account: PaytoURI, 63 } 64 65 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-TransferListStatus> 66 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] 67 pub struct TransferListStatus { 68 pub row_id: SafeU64, 69 pub status: TransferState, 70 pub amount: Amount, 71 pub credit_account: PaytoURI, 72 pub timestamp: TalerTimestamp, 73 } 74 75 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-TransfertSatus> 76 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] 77 pub struct TransferStatus { 78 pub status: TransferState, 79 pub status_msg: Option<String>, 80 pub amount: Amount, 81 pub origin_exchange_url: String, 82 pub metadata: Option<CompactString>, 83 pub wtid: ShortHashCode, 84 pub credit_account: PaytoURI, 85 pub timestamp: TalerTimestamp, 86 } 87 88 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-OutgoingHistory> 89 #[derive(Debug, Clone, Serialize, Deserialize)] 90 pub struct OutgoingHistory { 91 pub outgoing_transactions: Vec<OutgoingBankTransaction>, 92 pub debit_account: PaytoURI, 93 } 94 95 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-OutgoingBankTransaction> 96 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] 97 pub struct OutgoingBankTransaction { 98 pub row_id: SafeU64, 99 pub date: TalerTimestamp, 100 pub amount: Amount, 101 pub debit_fee: Option<Amount>, 102 pub credit_account: PaytoURI, 103 pub wtid: ShortHashCode, 104 pub exchange_base_url: Url, 105 pub metadata: Option<CompactString>, 106 } 107 108 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-IncomingHistory> 109 #[derive(Debug, Clone, Serialize, Deserialize)] 110 pub struct IncomingHistory { 111 pub credit_account: PaytoURI, 112 pub incoming_transactions: Vec<IncomingBankTransaction>, 113 } 114 115 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-IncomingBankTransaction> 116 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] 117 #[serde(tag = "type")] 118 pub enum IncomingBankTransaction { 119 #[serde(rename = "RESERVE")] 120 Reserve { 121 row_id: SafeU64, 122 date: TalerTimestamp, 123 amount: Amount, 124 credit_fee: Option<Amount>, 125 debit_account: PaytoURI, 126 reserve_pub: EddsaPublicKey, 127 authorization_pub: Option<EddsaPublicKey>, 128 authorization_sig: Option<EddsaSignature>, 129 }, 130 #[serde(rename = "WAD")] 131 Wad { 132 row_id: SafeU64, 133 date: TalerTimestamp, 134 amount: Amount, 135 debit_account: PaytoURI, 136 origin_exchange_url: Url, 137 wad_id: WadId, 138 }, 139 #[serde(rename = "KYCAUTH")] 140 Kyc { 141 row_id: SafeU64, 142 date: TalerTimestamp, 143 amount: Amount, 144 credit_fee: Option<Amount>, 145 debit_account: PaytoURI, 146 account_pub: EddsaPublicKey, 147 authorization_pub: Option<EddsaPublicKey>, 148 authorization_sig: Option<EddsaSignature>, 149 }, 150 } 151 152 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-AddIncomingRequest> 153 #[derive(Debug, Clone, Serialize, Deserialize)] 154 pub struct AddIncomingRequest { 155 pub amount: Amount, 156 pub reserve_pub: EddsaPublicKey, 157 pub debit_account: PaytoURI, 158 } 159 160 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-AddIncomingResponse> 161 #[derive(Debug, Clone, Serialize, Deserialize)] 162 pub struct AddIncomingResponse { 163 pub row_id: SafeU64, 164 pub timestamp: TalerTimestamp, 165 } 166 167 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-AddKycauthRequest> 168 #[derive(Debug, Clone, Serialize, Deserialize)] 169 pub struct AddKycauthRequest { 170 pub amount: Amount, 171 pub account_pub: EddsaPublicKey, 172 pub debit_account: PaytoURI, 173 } 174 175 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-AccountInfo> 176 #[derive(Debug, Clone, Serialize, Deserialize)] 177 pub struct AccountInfo {} 178 179 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-AddKycauthResponse> 180 pub type AddKycauthResponse = AddIncomingResponse; 181 182 #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, sqlx::Type)] 183 #[allow(non_camel_case_types)] 184 #[sqlx(type_name = "transfer_status")] 185 pub enum TransferState { 186 pending, 187 transient_failure, 188 permanent_failure, 189 late_failure, 190 success, 191 } 192 193 impl AsRef<str> for TransferState { 194 fn as_ref(&self) -> &str { 195 match self { 196 TransferState::pending => "pending", 197 TransferState::transient_failure => "transient_failure", 198 TransferState::permanent_failure => "permanent_failure", 199 TransferState::late_failure => "late_failure", 200 TransferState::success => "success", 201 } 202 } 203 }