api_wire.rs (6928B)
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 serde::{Deserialize, Serialize}; 21 use url::Url; 22 23 use super::api_common::{EddsaPublicKey, HashCode, SafeU64, ShortHashCode, WadId}; 24 use crate::{ 25 api_common::EddsaSignature, 26 types::{amount::Amount, payto::PaytoURI, timestamp::TalerTimestamp}, 27 }; 28 29 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-WireConfig> 30 #[derive(Debug, Clone, Serialize, Deserialize)] 31 pub struct WireConfig<'a> { 32 pub name: &'a str, 33 pub version: &'a str, 34 pub currency: &'a str, 35 pub implementation: Option<&'a str>, 36 pub support_account_check: bool, 37 } 38 39 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-TransferResponse> 40 #[derive(Debug, Clone, Serialize, Deserialize)] 41 pub struct TransferResponse { 42 pub timestamp: TalerTimestamp, 43 pub row_id: SafeU64, 44 } 45 46 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-TransferRequest> 47 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] 48 pub struct TransferRequest { 49 pub request_uid: HashCode, 50 pub amount: Amount, 51 pub exchange_base_url: Url, 52 pub metadata: Option<CompactString>, 53 pub wtid: ShortHashCode, 54 pub credit_account: PaytoURI, 55 } 56 57 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-TransferList> 58 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] 59 pub struct TransferList { 60 pub transfers: Vec<TransferListStatus>, 61 pub debit_account: PaytoURI, 62 } 63 64 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-TransferListStatus> 65 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] 66 pub struct TransferListStatus { 67 pub row_id: SafeU64, 68 pub status: TransferState, 69 pub amount: Amount, 70 pub credit_account: PaytoURI, 71 pub timestamp: TalerTimestamp, 72 } 73 74 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-TransfertSatus> 75 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] 76 pub struct TransferStatus { 77 pub status: TransferState, 78 pub status_msg: Option<String>, 79 pub amount: Amount, 80 pub origin_exchange_url: String, 81 pub metadata: Option<CompactString>, 82 pub wtid: ShortHashCode, 83 pub credit_account: PaytoURI, 84 pub timestamp: TalerTimestamp, 85 } 86 87 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-OutgoingHistory> 88 #[derive(Debug, Clone, Serialize, Deserialize)] 89 pub struct OutgoingHistory { 90 pub outgoing_transactions: Vec<OutgoingBankTransaction>, 91 pub debit_account: PaytoURI, 92 } 93 94 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-OutgoingBankTransaction> 95 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] 96 pub struct OutgoingBankTransaction { 97 pub row_id: SafeU64, 98 pub date: TalerTimestamp, 99 pub amount: Amount, 100 pub debit_fee: Option<Amount>, 101 pub credit_account: PaytoURI, 102 pub wtid: ShortHashCode, 103 pub exchange_base_url: Url, 104 pub metadata: Option<CompactString>, 105 } 106 107 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-IncomingHistory> 108 #[derive(Debug, Clone, Serialize, Deserialize)] 109 pub struct IncomingHistory { 110 pub credit_account: PaytoURI, 111 pub incoming_transactions: Vec<IncomingBankTransaction>, 112 } 113 114 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-IncomingBankTransaction> 115 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] 116 #[serde(tag = "type")] 117 pub enum IncomingBankTransaction { 118 #[serde(rename = "RESERVE")] 119 Reserve { 120 row_id: SafeU64, 121 date: TalerTimestamp, 122 amount: Amount, 123 credit_fee: Option<Amount>, 124 debit_account: PaytoURI, 125 reserve_pub: EddsaPublicKey, 126 authorization_pub: Option<EddsaPublicKey>, 127 authorization_sig: Option<EddsaSignature>, 128 }, 129 #[serde(rename = "WAD")] 130 Wad { 131 row_id: SafeU64, 132 date: TalerTimestamp, 133 amount: Amount, 134 debit_account: PaytoURI, 135 origin_exchange_url: Url, 136 wad_id: WadId, 137 }, 138 #[serde(rename = "KYCAUTH")] 139 Kyc { 140 row_id: SafeU64, 141 date: TalerTimestamp, 142 amount: Amount, 143 credit_fee: Option<Amount>, 144 debit_account: PaytoURI, 145 account_pub: EddsaPublicKey, 146 authorization_pub: Option<EddsaPublicKey>, 147 authorization_sig: Option<EddsaSignature>, 148 }, 149 } 150 151 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-AddIncomingRequest> 152 #[derive(Debug, Clone, Serialize, Deserialize)] 153 pub struct AddIncomingRequest { 154 pub amount: Amount, 155 pub reserve_pub: EddsaPublicKey, 156 pub debit_account: PaytoURI, 157 } 158 159 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-AddIncomingResponse> 160 #[derive(Debug, Clone, Serialize, Deserialize)] 161 pub struct AddIncomingResponse { 162 pub row_id: SafeU64, 163 pub timestamp: TalerTimestamp, 164 } 165 166 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-AddKycauthRequest> 167 #[derive(Debug, Clone, Serialize, Deserialize)] 168 pub struct AddKycauthRequest { 169 pub amount: Amount, 170 pub account_pub: EddsaPublicKey, 171 pub debit_account: PaytoURI, 172 } 173 174 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-AddMappedRequest> 175 #[derive(Debug, Clone, Serialize, Deserialize)] 176 pub struct AddMappedRequest { 177 pub amount: Amount, 178 pub authorization_pub: EddsaPublicKey, 179 pub debit_account: PaytoURI, 180 } 181 182 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-AccountInfo> 183 #[derive(Debug, Clone, Serialize, Deserialize)] 184 pub struct AccountInfo {} 185 186 #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, sqlx::Type)] 187 #[allow(non_camel_case_types)] 188 #[sqlx(type_name = "transfer_status")] 189 pub enum TransferState { 190 pending, 191 transient_failure, 192 permanent_failure, 193 late_failure, 194 success, 195 } 196 197 impl AsRef<str> for TransferState { 198 fn as_ref(&self) -> &str { 199 match self { 200 TransferState::pending => "pending", 201 TransferState::transient_failure => "transient_failure", 202 TransferState::permanent_failure => "permanent_failure", 203 TransferState::late_failure => "late_failure", 204 TransferState::success => "success", 205 } 206 } 207 }