#[cfg(feature = "stripe")]
pub mod stripe;
use chrono::{DateTime, Utc};
use uuid::Uuid;
use crate::{
db::{Collectable, Identifiable},
order::OrderId,
Result, UserId,
};
pub type PaymentId = uuid::Uuid;
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Payment {
pub id: PaymentId,
pub order: OrderId,
pub status: Status,
#[cfg(feature = "stripe")]
pub stripe_session_id: Option<String>,
}
impl Collectable for Payment {
fn get_collection_name() -> &'static str {
"payments"
}
}
impl Identifiable for Payment {
fn get_id(&self) -> uuid::Uuid {
self.id
}
}
impl Payment {
pub fn new(order: Uuid) -> Result<Self> {
Ok(Self {
id: Uuid::new_v4(),
order,
status: Status::Pending,
#[cfg(feature = "stripe")]
stripe_session_id: None,
})
}
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub enum Status {
Pending,
Canceled,
Error(String),
Successful { time: DateTime<Utc> },
}