stripe_client.rs

 1#[cfg(test)]
 2mod fake_stripe_client;
 3mod real_stripe_client;
 4
 5use std::sync::Arc;
 6
 7use anyhow::Result;
 8use async_trait::async_trait;
 9
10#[cfg(test)]
11pub use fake_stripe_client::*;
12pub use real_stripe_client::*;
13use serde::Deserialize;
14
15#[derive(Debug, PartialEq, Eq, Hash, Clone, derive_more::Display)]
16pub struct StripeCustomerId(pub Arc<str>);
17
18#[derive(Debug, Clone)]
19pub struct StripeCustomer {
20    pub id: StripeCustomerId,
21    pub email: Option<String>,
22}
23
24#[derive(Debug)]
25pub struct CreateCustomerParams<'a> {
26    pub email: Option<&'a str>,
27}
28
29#[derive(Debug, PartialEq, Eq, Hash, Clone, derive_more::Display)]
30pub struct StripePriceId(pub Arc<str>);
31
32#[derive(Debug, Clone)]
33pub struct StripePrice {
34    pub id: StripePriceId,
35    pub unit_amount: Option<i64>,
36    pub lookup_key: Option<String>,
37    pub recurring: Option<StripePriceRecurring>,
38}
39
40#[derive(Debug, Clone)]
41pub struct StripePriceRecurring {
42    pub meter: Option<String>,
43}
44
45#[derive(Debug, PartialEq, Eq, Hash, Clone, derive_more::Display, Deserialize)]
46pub struct StripeMeterId(pub Arc<str>);
47
48#[derive(Debug, Clone, Deserialize)]
49pub struct StripeMeter {
50    pub id: StripeMeterId,
51    pub event_name: String,
52}
53
54#[async_trait]
55pub trait StripeClient: Send + Sync {
56    async fn list_customers_by_email(&self, email: &str) -> Result<Vec<StripeCustomer>>;
57
58    async fn create_customer(&self, params: CreateCustomerParams<'_>) -> Result<StripeCustomer>;
59
60    async fn list_prices(&self) -> Result<Vec<StripePrice>>;
61
62    async fn list_meters(&self) -> Result<Vec<StripeMeter>>;
63}