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