koprogo_api/application/ports/
payment_method_repository.rs

1use crate::domain::entities::payment_method::{PaymentMethod, PaymentMethodType};
2use async_trait::async_trait;
3use uuid::Uuid;
4
5#[async_trait]
6pub trait PaymentMethodRepository: Send + Sync {
7    /// Create a new payment method
8    async fn create(&self, payment_method: &PaymentMethod) -> Result<PaymentMethod, String>;
9
10    /// Find payment method by ID
11    async fn find_by_id(&self, id: Uuid) -> Result<Option<PaymentMethod>, String>;
12
13    /// Find payment method by Stripe payment method ID
14    async fn find_by_stripe_payment_method_id(
15        &self,
16        stripe_payment_method_id: &str,
17    ) -> Result<Option<PaymentMethod>, String>;
18
19    /// Find all payment methods for an owner
20    async fn find_by_owner(&self, owner_id: Uuid) -> Result<Vec<PaymentMethod>, String>;
21
22    /// Find active payment methods for an owner
23    async fn find_active_by_owner(&self, owner_id: Uuid) -> Result<Vec<PaymentMethod>, String>;
24
25    /// Find default payment method for an owner
26    async fn find_default_by_owner(&self, owner_id: Uuid) -> Result<Option<PaymentMethod>, String>;
27
28    /// Find all payment methods for an organization
29    async fn find_by_organization(
30        &self,
31        organization_id: Uuid,
32    ) -> Result<Vec<PaymentMethod>, String>;
33
34    /// Find payment methods by type
35    async fn find_by_owner_and_type(
36        &self,
37        owner_id: Uuid,
38        method_type: PaymentMethodType,
39    ) -> Result<Vec<PaymentMethod>, String>;
40
41    /// Update payment method
42    async fn update(&self, payment_method: &PaymentMethod) -> Result<PaymentMethod, String>;
43
44    /// Delete payment method (soft delete recommended)
45    async fn delete(&self, id: Uuid) -> Result<bool, String>;
46
47    /// Set payment method as default (unsets other defaults for owner)
48    async fn set_as_default(&self, id: Uuid, owner_id: Uuid) -> Result<PaymentMethod, String>;
49
50    /// Count active payment methods for owner
51    async fn count_active_by_owner(&self, owner_id: Uuid) -> Result<i64, String>;
52
53    /// Check if owner has any active payment methods
54    async fn has_active_payment_methods(&self, owner_id: Uuid) -> Result<bool, String>;
55}