taler-rust

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

api_wire.rs (6640B)


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