taler-rust

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

api_transfer.rs (3680B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 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 Transfer Gateway HTTP API <https://docs.taler.net/core/api-bank-wire-transfer.html#taler-wire-transfer-gateway-http-api>
     18 
     19 use compact_str::CompactString;
     20 use url::Url;
     21 
     22 use crate::{
     23     api_common::EddsaSignature,
     24     db::IncomingType,
     25     types::{amount::Amount, timestamp::TalerTimestamp},
     26 };
     27 
     28 use super::api_common::EddsaPublicKey;
     29 use serde::{Deserialize, Serialize};
     30 
     31 /// <https://docs.taler.net/core/api-bank-wire-transfer.html#tsref-type-SubjectFormat>
     32 #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
     33 #[allow(non_camel_case_types)]
     34 pub enum SubjectFormat {
     35     SIMPLE,
     36     URI,
     37     CH_QR_BILL,
     38 }
     39 
     40 /// <https://docs.taler.net/core/api-bank-wire-transfer.html#tsref-type-WireTransferConfig>
     41 #[derive(Debug, Clone, Serialize, Deserialize)]
     42 pub struct WireTransferConfig<'a> {
     43     pub name: &'a str,
     44     pub version: &'a str,
     45     pub currency: &'a str,
     46     pub implementation: Option<&'a str>,
     47     pub supported_formats: Vec<SubjectFormat>,
     48 }
     49 
     50 #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
     51 #[allow(non_camel_case_types)]
     52 pub enum TransferType {
     53     reserve,
     54     kyc,
     55 }
     56 
     57 impl From<TransferType> for IncomingType {
     58     fn from(value: TransferType) -> Self {
     59         match value {
     60             TransferType::reserve => IncomingType::reserve,
     61             TransferType::kyc => IncomingType::kyc,
     62         }
     63     }
     64 }
     65 
     66 #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
     67 pub enum PublicKeyAlg {
     68     EdDSA,
     69 }
     70 
     71 /// <https://docs.taler.net/core/api-bank-wire-transfer.html#tsref-type-RegistrationRequest>
     72 #[derive(Debug, Clone, Serialize, Deserialize)]
     73 pub struct RegistrationRequest {
     74     pub credit_amount: Amount,
     75     pub r#type: TransferType,
     76     pub alg: PublicKeyAlg,
     77     pub account_pub: EddsaPublicKey,
     78     pub authorization_pub: EddsaPublicKey,
     79     pub authorization_sig: EddsaSignature,
     80     pub recurrent: bool,
     81 }
     82 
     83 /// <https://docs.taler.net/core/api-bank-wire-transfer.html#tsref-type-TransferSubject>
     84 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
     85 #[serde(tag = "type")]
     86 pub enum TransferSubject {
     87     #[serde(rename = "SIMPLE")]
     88     Simple {
     89         credit_amount: Amount,
     90         subject: String,
     91     },
     92     #[serde(rename = "URI")]
     93     Uri { credit_amount: Amount, uri: Url },
     94     #[serde(rename = "CH_QR_BILL")]
     95     QrBill {
     96         credit_amount: Amount,
     97         qr_reference_number: String,
     98     },
     99 }
    100 
    101 /// <https://docs.taler.net/core/api-bank-wire-transfer.html#tsref-type-RegistrationResponse>
    102 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
    103 pub struct RegistrationResponse {
    104     pub subjects: Vec<TransferSubject>,
    105     pub expiration: TalerTimestamp,
    106 }
    107 
    108 /// <https://docs.taler.net/core/api-bank-wire-transfer.html#tsref-type-Unregistration>
    109 #[derive(Debug, Clone, Serialize, Deserialize)]
    110 pub struct Unregistration {
    111     pub timestamp: CompactString,
    112     pub authorization_pub: EddsaPublicKey,
    113     pub authorization_sig: EddsaSignature,
    114 }