taler-rust

GNU Taler code in Rust. Largely core banking integrations.
Log | Files | Refs | Submodules | README | LICENSE

api_wire.rs (6211B)


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