add: stripe integration

This commit is contained in:
trisua 2025-05-05 19:38:01 -04:00
parent 2fa5a4dc1f
commit 1d120555a0
31 changed files with 1137 additions and 122 deletions

View file

@ -40,6 +40,9 @@ pub struct User {
/// External service connection details.
#[serde(default)]
pub connections: UserConnections,
/// The user's Stripe customer ID.
#[serde(default)]
pub stripe_id: String,
}
pub type UserConnections =
@ -245,6 +248,7 @@ impl User {
post_count: 0,
request_count: 0,
connections: HashMap::new(),
stripe_id: String::new(),
}
}

View file

@ -20,6 +20,7 @@ bitflags! {
const MANAGE_QUESTIONS = 1 << 9;
const MANAGE_CHANNELS = 1 << 10;
const MANAGE_MESSAGES = 1 << 11;
const MANAGE_EMOJIS = 1 << 12;
const _ = !0;
}

View file

@ -6,6 +6,7 @@ pub mod oauth;
pub mod permissions;
pub mod reactions;
pub mod requests;
pub mod uploads;
#[cfg(feature = "redis")]
pub mod channels;

View file

@ -32,6 +32,8 @@ bitflags! {
const MANAGE_QUESTIONS = 1 << 21;
const MANAGE_CHANNELS = 1 << 22;
const MANAGE_MESSAGES = 1 << 23;
const MANAGE_UPLOADS = 1 << 24;
const MANAGE_EMOJIS = 1 << 25;
const _ = !0;
}

View file

@ -0,0 +1,66 @@
use serde::{Serialize, Deserialize};
use tetratto_shared::{snow::AlmostSnowflake, unix_epoch_timestamp};
#[derive(Serialize, Deserialize)]
pub enum MediaType {
#[serde(alias = "image/webp")]
Webp,
#[serde(alias = "image/avif")]
Avif,
#[serde(alias = "image/png")]
Png,
#[serde(alias = "image/jpg")]
Jpg,
#[serde(alias = "image/gif")]
Gif,
}
#[derive(Serialize, Deserialize)]
pub struct MediaUpload {
pub id: usize,
pub created: usize,
pub owner: usize,
pub what: MediaType,
}
impl MediaUpload {
/// Create a new [`MediaUpload`].
pub fn new(what: MediaType, owner: usize) -> Self {
Self {
id: AlmostSnowflake::new(1234567890)
.to_string()
.parse::<usize>()
.unwrap(),
created: unix_epoch_timestamp() as usize,
owner,
what,
}
}
}
#[derive(Serialize, Deserialize)]
pub struct CustomEmoji {
pub id: usize,
pub created: usize,
pub owner: usize,
pub community: usize,
pub upload_id: usize,
pub name: String,
}
impl CustomEmoji {
/// Create a new [`CustomEmoji`].
pub fn new(owner: usize, community: usize, upload_id: usize, name: String) -> Self {
Self {
id: AlmostSnowflake::new(1234567890)
.to_string()
.parse::<usize>()
.unwrap(),
created: unix_epoch_timestamp() as usize,
owner,
community,
upload_id,
name,
}
}
}