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