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