Skip to main content

zlicenser_server/payment/
mod.rs

1#[cfg(feature = "payment-stripe")]
2pub mod stripe;
3
4use crate::Result;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum PaymentTier {
8    Verified,
9    Pseudonymous,
10    Anonymous,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq)]
14pub enum IntentStatus {
15    RequiresCapture,
16    Pending,
17    RequiresAction,
18    Failed,
19    Cancelled,
20    Succeeded,
21}
22
23pub struct PaymentMetadata {
24    pub product_id: uuid::Uuid,
25    pub session_id: uuid::Uuid,
26    pub customer_email: Option<String>,
27}
28
29pub struct Money {
30    pub amount: i64,
31    pub currency: String,
32}
33
34pub struct PaymentIntent {
35    pub intent_id: String,
36    pub client_secret: String,
37}
38
39pub struct CaptureConfirmation {
40    pub transaction_id: String,
41    pub captured_at_ns: i64,
42}
43
44#[async_trait::async_trait]
45pub trait PaymentProvider: Send + Sync {
46    fn tier(&self) -> PaymentTier;
47    fn is_test_mode(&self) -> bool;
48
49    async fn create_intent(&self, money: Money, metadata: PaymentMetadata)
50    -> Result<PaymentIntent>;
51    async fn get_intent_status(&self, intent_id: &str) -> Result<IntentStatus>;
52    async fn capture_intent(&self, intent_id: &str) -> Result<CaptureConfirmation>;
53    async fn cancel_intent(&self, intent_id: &str) -> Result<()>;
54}