koprogo_api/application/dto/
payment_dto.rs

1use crate::domain::entities::{Payment, PaymentMethodType, TransactionStatus};
2use chrono::{DateTime, Utc};
3use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6/// Payment response DTO
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct PaymentResponse {
9    pub id: Uuid,
10    pub organization_id: Uuid,
11    pub building_id: Uuid,
12    pub owner_id: Uuid,
13    pub expense_id: Option<Uuid>,
14    pub amount_cents: i64,
15    pub currency: String,
16    pub status: TransactionStatus,
17    pub payment_method_type: PaymentMethodType,
18    pub stripe_payment_intent_id: Option<String>,
19    pub stripe_customer_id: Option<String>,
20    pub payment_method_id: Option<Uuid>,
21    pub idempotency_key: String,
22    pub description: Option<String>,
23    pub metadata: Option<String>,
24    pub failure_reason: Option<String>,
25    pub refunded_amount_cents: i64,
26    pub net_amount_cents: i64, // amount_cents - refunded_amount_cents
27    pub succeeded_at: Option<DateTime<Utc>>,
28    pub failed_at: Option<DateTime<Utc>>,
29    pub cancelled_at: Option<DateTime<Utc>>,
30    pub created_at: DateTime<Utc>,
31    pub updated_at: DateTime<Utc>,
32}
33
34impl From<Payment> for PaymentResponse {
35    fn from(payment: Payment) -> Self {
36        let net_amount_cents = payment.get_net_amount_cents();
37
38        Self {
39            id: payment.id,
40            organization_id: payment.organization_id,
41            building_id: payment.building_id,
42            owner_id: payment.owner_id,
43            expense_id: payment.expense_id,
44            amount_cents: payment.amount_cents,
45            currency: payment.currency,
46            status: payment.status,
47            payment_method_type: payment.payment_method_type,
48            stripe_payment_intent_id: payment.stripe_payment_intent_id,
49            stripe_customer_id: payment.stripe_customer_id,
50            payment_method_id: payment.payment_method_id,
51            idempotency_key: payment.idempotency_key,
52            description: payment.description,
53            metadata: payment.metadata,
54            failure_reason: payment.failure_reason,
55            refunded_amount_cents: payment.refunded_amount_cents,
56            net_amount_cents,
57            succeeded_at: payment.succeeded_at,
58            failed_at: payment.failed_at,
59            cancelled_at: payment.cancelled_at,
60            created_at: payment.created_at,
61            updated_at: payment.updated_at,
62        }
63    }
64}
65
66/// Create payment request DTO
67#[derive(Debug, Clone, Serialize, Deserialize)]
68pub struct CreatePaymentRequest {
69    pub building_id: Uuid,
70    pub owner_id: Uuid,
71    pub expense_id: Option<Uuid>,
72    pub amount_cents: i64,
73    pub payment_method_type: PaymentMethodType,
74    pub payment_method_id: Option<Uuid>, // If using saved payment method
75    pub description: Option<String>,
76    pub metadata: Option<String>,
77}
78
79/// Refund payment request DTO
80#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct RefundPaymentRequest {
82    pub amount_cents: i64,
83    pub reason: Option<String>,
84}
85
86/// Payment statistics response DTO
87#[derive(Debug, Clone, Serialize, Deserialize)]
88pub struct PaymentStatsResponse {
89    pub total_count: i64,
90    pub succeeded_count: i64,
91    pub failed_count: i64,
92    pub pending_count: i64,
93    pub total_amount_cents: i64,
94    pub total_succeeded_cents: i64,
95    pub total_refunded_cents: i64,
96    pub net_amount_cents: i64,
97}