You've already forked AstralRinth
forked from didirus/AstralRinth
Payments/subscriptions support (#943)
* [wip] Payments/subscriptions support * finish * working payment flow * finish subscriptions, lint, clippy, etc * docker compose
This commit is contained in:
1314
src/routes/internal/billing.rs
Normal file
1314
src/routes/internal/billing.rs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -30,6 +30,7 @@ use rust_decimal::Decimal;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::postgres::PgPool;
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
use validator::Validate;
|
||||
@@ -217,6 +218,7 @@ impl TempUser {
|
||||
None
|
||||
},
|
||||
venmo_handle: None,
|
||||
stripe_customer_id: None,
|
||||
totp_secret: None,
|
||||
username,
|
||||
name: self.name,
|
||||
@@ -680,7 +682,6 @@ impl AuthProvider {
|
||||
pub id: String,
|
||||
pub email: String,
|
||||
pub name: Option<String>,
|
||||
pub bio: Option<String>,
|
||||
pub picture: Option<String>,
|
||||
}
|
||||
|
||||
@@ -1523,6 +1524,7 @@ pub async fn create_account_with_password(
|
||||
paypal_country: None,
|
||||
paypal_email: None,
|
||||
venmo_handle: None,
|
||||
stripe_customer_id: None,
|
||||
totp_secret: None,
|
||||
username: new_account.username.clone(),
|
||||
name: Some(new_account.username),
|
||||
@@ -2157,6 +2159,7 @@ pub async fn set_email(
|
||||
redis: Data<RedisPool>,
|
||||
email: web::Json<SetEmail>,
|
||||
session_queue: Data<AuthQueue>,
|
||||
stripe_client: Data<stripe::Client>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
email
|
||||
.0
|
||||
@@ -2197,6 +2200,22 @@ pub async fn set_email(
|
||||
)?;
|
||||
}
|
||||
|
||||
if let Some(customer_id) = user
|
||||
.stripe_customer_id
|
||||
.as_ref()
|
||||
.and_then(|x| stripe::CustomerId::from_str(x).ok())
|
||||
{
|
||||
stripe::Customer::update(
|
||||
&stripe_client,
|
||||
&customer_id,
|
||||
stripe::UpdateCustomer {
|
||||
email: Some(&email.email),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
let flow = Flow::ConfirmEmail {
|
||||
user_id: user.id.into(),
|
||||
confirm_email: email.email.clone(),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
pub(crate) mod admin;
|
||||
pub mod billing;
|
||||
pub mod flows;
|
||||
pub mod moderation;
|
||||
pub mod pats;
|
||||
@@ -17,6 +18,7 @@ pub fn config(cfg: &mut actix_web::web::ServiceConfig) {
|
||||
.configure(session::config)
|
||||
.configure(flows::config)
|
||||
.configure(pats::config)
|
||||
.configure(moderation::config),
|
||||
.configure(moderation::config)
|
||||
.configure(billing::config),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -55,8 +55,8 @@ pub async fn get_projects(
|
||||
ProjectStatus::Processing.as_str(),
|
||||
count.count as i64
|
||||
)
|
||||
.fetch_many(&**pool)
|
||||
.try_filter_map(|e| async { Ok(e.right().map(|m| database::models::ProjectId(m.id))) })
|
||||
.fetch(&**pool)
|
||||
.map_ok(|m| database::models::ProjectId(m.id))
|
||||
.try_collect::<Vec<database::models::ProjectId>>()
|
||||
.await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user