libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

model.rs (3070B)


      1 /*
      2 * This file is part of LibEuFin.
      3 * Copyright (C) 2026 Taler Systems S.A.
      4 
      5 * LibEuFin is free software; you can redistribute it and/or modify
      6 * it under the terms of the GNU Affero General Public License as
      7 * published by the Free Software Foundation; either version 3, or
      8 * (at your option) any later version.
      9 
     10 * LibEuFin is distributed in the hope that it will be useful, but
     11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     12 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General
     13 * Public License for more details.
     14 
     15 * You should have received a copy of the GNU Affero General Public
     16 * License along with LibEuFin; see the file COPYING.  If not, see
     17 * <http://www.gnu.org/licenses/>
     18 */
     19 
     20 use compact_str::CompactString;
     21 use jiff::Timestamp;
     22 use taler_common::{
     23     api::wire::TransferState,
     24     types::{amount::Amount, payto::FullIbanPayto},
     25 };
     26 use taler_macros::EnumMeta;
     27 
     28 #[derive(Debug, Clone, Copy, PartialEq, Eq, sqlx::Type, EnumMeta)]
     29 #[allow(non_camel_case_types)]
     30 #[sqlx(type_name = "submission_state")]
     31 #[enum_meta(Str)]
     32 /** Outgoing transactions and batches submission status */
     33 pub enum SubmissionState {
     34     // Initiated but not yet submitted
     35     unsubmitted,
     36     // Submission failed, retry possible
     37     transient_failure,
     38     // Submission succeed, pending settltment
     39     pending,
     40     // Definitive failure, will never succeed
     41     permanent_failure,
     42     // Definitive success, booked and settled
     43     success,
     44     // Late failure after a success, happens when a payment is returned
     45     late_failure,
     46 }
     47 
     48 impl SubmissionState {
     49     pub fn to_transfer_status(self) -> TransferState {
     50         match self {
     51             SubmissionState::unsubmitted | SubmissionState::pending => TransferState::pending,
     52             SubmissionState::transient_failure => TransferState::transient_failure,
     53             SubmissionState::permanent_failure => TransferState::permanent_failure,
     54             SubmissionState::success | SubmissionState::late_failure => TransferState::success,
     55         }
     56     }
     57 }
     58 
     59 impl From<TransferState> for SubmissionState {
     60     fn from(value: TransferState) -> Self {
     61         match value {
     62             TransferState::pending => SubmissionState::pending,
     63             TransferState::transient_failure => SubmissionState::transient_failure,
     64             TransferState::permanent_failure => SubmissionState::permanent_failure,
     65             TransferState::late_failure => SubmissionState::late_failure,
     66             TransferState::success => SubmissionState::success,
     67         }
     68     }
     69 }
     70 
     71 /** Batch of initiated outgoing payment to sent together */
     72 #[derive(Debug, Clone, PartialEq, Eq)]
     73 pub struct PaymentBatch {
     74     pub id: u64,
     75     pub msg_id: CompactString,
     76     pub creation_date: Timestamp,
     77     pub sum: Amount,
     78     pub payments: Vec<Initiated>,
     79 }
     80 
     81 /** Initiated outgoing transaction */
     82 #[derive(Debug, Clone, PartialEq, Eq)]
     83 pub struct Initiated {
     84     pub id: u64,
     85     pub amount: Amount,
     86     pub subject: String,
     87     pub creditor: FullIbanPayto,
     88     pub initiation_time: Timestamp,
     89     pub e2e_id: CompactString,
     90 }