koprogo_api/application/ports/
payment_repository.rs1use crate::domain::entities::{Payment, TransactionStatus};
2use async_trait::async_trait;
3use uuid::Uuid;
4
5#[async_trait]
6pub trait PaymentRepository: Send + Sync {
7 async fn create(&self, payment: &Payment) -> Result<Payment, String>;
9
10 async fn find_by_id(&self, id: Uuid) -> Result<Option<Payment>, String>;
12
13 async fn find_by_stripe_payment_intent_id(
15 &self,
16 stripe_payment_intent_id: &str,
17 ) -> Result<Option<Payment>, String>;
18
19 async fn find_by_idempotency_key(
21 &self,
22 organization_id: Uuid,
23 idempotency_key: &str,
24 ) -> Result<Option<Payment>, String>;
25
26 async fn find_by_owner(&self, owner_id: Uuid) -> Result<Vec<Payment>, String>;
28
29 async fn find_by_building(&self, building_id: Uuid) -> Result<Vec<Payment>, String>;
31
32 async fn find_by_expense(&self, expense_id: Uuid) -> Result<Vec<Payment>, String>;
34
35 async fn find_by_organization(&self, organization_id: Uuid) -> Result<Vec<Payment>, String>;
37
38 async fn find_by_status(
40 &self,
41 organization_id: Uuid,
42 status: TransactionStatus,
43 ) -> Result<Vec<Payment>, String>;
44
45 async fn find_by_building_and_status(
47 &self,
48 building_id: Uuid,
49 status: TransactionStatus,
50 ) -> Result<Vec<Payment>, String>;
51
52 async fn find_pending(&self, organization_id: Uuid) -> Result<Vec<Payment>, String>;
54
55 async fn find_failed(&self, organization_id: Uuid) -> Result<Vec<Payment>, String>;
57
58 async fn update(&self, payment: &Payment) -> Result<Payment, String>;
60
61 async fn delete(&self, id: Uuid) -> Result<bool, String>;
63
64 async fn get_total_paid_for_expense(&self, expense_id: Uuid) -> Result<i64, String>;
66
67 async fn get_total_paid_by_owner(&self, owner_id: Uuid) -> Result<i64, String>;
69
70 async fn get_total_paid_for_building(&self, building_id: Uuid) -> Result<i64, String>;
72
73 async fn get_owner_payment_stats(&self, owner_id: Uuid) -> Result<PaymentStats, String>;
75
76 async fn get_building_payment_stats(&self, building_id: Uuid) -> Result<PaymentStats, String>;
78}
79
80#[derive(Debug, Clone)]
82pub struct PaymentStats {
83 pub total_count: i64,
84 pub succeeded_count: i64,
85 pub failed_count: i64,
86 pub pending_count: i64,
87 pub total_amount_cents: i64,
88 pub total_succeeded_cents: i64,
89 pub total_refunded_cents: i64,
90 pub net_amount_cents: i64, }