koprogo_api/application/dto/
payment_method_dto.rs1use crate::domain::entities::payment_method::{PaymentMethod, PaymentMethodType};
2use chrono::{DateTime, Utc};
3use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct PaymentMethodResponse {
9 pub id: Uuid,
10 pub organization_id: Uuid,
11 pub owner_id: Uuid,
12 pub method_type: PaymentMethodType,
13 pub stripe_payment_method_id: String,
14 pub stripe_customer_id: String,
15 pub display_label: String,
16 pub is_default: bool,
17 pub is_active: bool,
18 pub metadata: Option<String>,
19 pub expires_at: Option<DateTime<Utc>>,
20 pub is_expired: bool, pub is_usable: bool, pub created_at: DateTime<Utc>,
23 pub updated_at: DateTime<Utc>,
24}
25
26impl From<PaymentMethod> for PaymentMethodResponse {
27 fn from(method: PaymentMethod) -> Self {
28 let is_expired = method.is_expired();
29 let is_usable = method.is_usable();
30
31 Self {
32 id: method.id,
33 organization_id: method.organization_id,
34 owner_id: method.owner_id,
35 method_type: method.method_type,
36 stripe_payment_method_id: method.stripe_payment_method_id,
37 stripe_customer_id: method.stripe_customer_id,
38 display_label: method.display_label,
39 is_default: method.is_default,
40 is_active: method.is_active,
41 metadata: method.metadata,
42 expires_at: method.expires_at,
43 is_expired,
44 is_usable,
45 created_at: method.created_at,
46 updated_at: method.updated_at,
47 }
48 }
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct CreatePaymentMethodRequest {
54 pub owner_id: Uuid,
55 pub method_type: PaymentMethodType,
56 pub stripe_payment_method_id: String,
57 pub stripe_customer_id: String,
58 pub display_label: String,
59 pub is_default: bool,
60 pub metadata: Option<String>,
61 pub expires_at: Option<DateTime<Utc>>,
62}
63
64#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct UpdatePaymentMethodRequest {
67 pub display_label: Option<String>,
68 pub is_default: Option<bool>,
69 pub metadata: Option<String>,
70}