taler-rust

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

payto.rs (2134B)


      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 use taler_common::types::payto::{
     18     ACH, BankID, FullPayto, Payto, PaytoErr, PaytoImpl, PaytoURI, TransferPayto,
     19 };
     20 
     21 #[derive(Debug, Clone, PartialEq, Eq)]
     22 /// All kind of wise account we support
     23 pub enum WiseAccount {
     24     IBAN(BankID),
     25     ACH(ACH),
     26 }
     27 
     28 pub type WisePayto = Payto<WiseAccount>;
     29 pub type FullWisePayto = FullPayto<WiseAccount>;
     30 pub type TransferWisePayto = TransferPayto<WiseAccount>;
     31 
     32 impl PaytoImpl for WiseAccount {
     33     fn as_uri(&self) -> PaytoURI {
     34         match self {
     35             WiseAccount::IBAN(bank_id) => bank_id.as_uri(),
     36             WiseAccount::ACH(ach) => ach.as_uri(),
     37         }
     38     }
     39 
     40     fn parse(uri: &PaytoURI) -> Result<Self, PaytoErr> {
     41         Ok(if uri.as_ref().domain() == Some("ach") {
     42             Self::ACH(ACH::parse(uri)?)
     43         } else {
     44             Self::IBAN(BankID::parse(uri)?)
     45         })
     46     }
     47 }
     48 
     49 impl std::fmt::Display for WiseAccount {
     50     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
     51         match self {
     52             WiseAccount::IBAN(BankID { iban, bic }) => {
     53                 if let Some(bic) = bic {
     54                     write!(f, "iban {iban} {bic}")
     55                 } else {
     56                     write!(f, "iban {iban}")
     57                 }
     58             }
     59             WiseAccount::ACH(ACH {
     60                 routing_number,
     61                 account_number,
     62             }) => write!(f, "ach {routing_number} {account_number}"),
     63         }
     64     }
     65 }