Move charges to DB + fix subscription recurring payments (#971)

* Move charges to DB + fix subscription recurring payments

* Finish most + pyro integration

* Finish billing

* Run prepare

* Fix intervals

* Fix clippy

* Remove unused test
This commit is contained in:
Geometrically
2024-10-09 21:11:30 -07:00
committed by GitHub
parent 28b6bf8603
commit c88bfbb5f0
33 changed files with 1692 additions and 816 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -510,7 +510,7 @@ impl AuthProvider {
map.insert("grant_type", "authorization_code");
let token: AccessToken = reqwest::Client::new()
.post(&format!("{api_url}oauth2/token"))
.post(format!("{api_url}oauth2/token"))
.header(reqwest::header::ACCEPT, "application/json")
.header(
AUTHORIZATION,
@@ -766,7 +766,7 @@ impl AuthProvider {
let api_url = dotenvy::var("PAYPAL_API_URL")?;
let paypal_user: PayPalUser = reqwest::Client::new()
.get(&format!(
.get(format!(
"{api_url}identity/openidconnect/userinfo?schema=openid"
))
.header(reqwest::header::USER_AGENT, "Modrinth")
@@ -1393,7 +1393,7 @@ pub async fn sign_up_beehiiv(email: &str) -> Result<(), AuthenticationError> {
let client = reqwest::Client::new();
client
.post(&format!(
.post(format!(
"https://api.beehiiv.com/v2/publications/{id}/subscriptions"
))
.header(AUTHORIZATION, format!("Bearer {}", api_key))

View File

@@ -21,7 +21,7 @@ pub async fn export(
&req,
&**pool,
&redis,
&*session_queue,
&session_queue,
Some(&[Scopes::SESSION_ACCESS]),
)
.await?
@@ -34,19 +34,19 @@ pub async fn export(
crate::database::models::Collection::get_many(&collection_ids, &**pool, &redis)
.await?
.into_iter()
.map(|x| crate::models::collections::Collection::from(x))
.map(crate::models::collections::Collection::from)
.collect::<Vec<_>>();
let follows = crate::database::models::User::get_follows(user_id, &**pool)
.await?
.into_iter()
.map(|x| crate::models::ids::ProjectId::from(x))
.map(crate::models::ids::ProjectId::from)
.collect::<Vec<_>>();
let projects = crate::database::models::User::get_projects(user_id, &**pool, &redis)
.await?
.into_iter()
.map(|x| crate::models::ids::ProjectId::from(x))
.map(crate::models::ids::ProjectId::from)
.collect::<Vec<_>>();
let org_ids = crate::database::models::User::get_organizations(user_id, &**pool).await?;
@@ -64,7 +64,7 @@ pub async fn export(
)
.await?
.into_iter()
.map(|x| crate::models::notifications::Notification::from(x))
.map(crate::models::notifications::Notification::from)
.collect::<Vec<_>>();
let oauth_clients =
@@ -73,7 +73,7 @@ pub async fn export(
)
.await?
.into_iter()
.map(|x| crate::models::oauth_clients::OAuthClient::from(x))
.map(crate::models::oauth_clients::OAuthClient::from)
.collect::<Vec<_>>();
let oauth_authorizations = crate::database::models::oauth_client_authorization_item::OAuthClientAuthorization::get_all_for_user(
@@ -81,7 +81,7 @@ pub async fn export(
)
.await?
.into_iter()
.map(|x| crate::models::oauth_clients::OAuthClientAuthorization::from(x))
.map(crate::models::oauth_clients::OAuthClientAuthorization::from)
.collect::<Vec<_>>();
let pat_ids = crate::database::models::pat_item::PersonalAccessToken::get_user_pats(
@@ -102,7 +102,7 @@ pub async fn export(
let payouts = crate::database::models::payout_item::Payout::get_many(&payout_ids, &**pool)
.await?
.into_iter()
.map(|x| crate::models::payouts::Payout::from(x))
.map(crate::models::payouts::Payout::from)
.collect::<Vec<_>>();
let report_ids =
@@ -110,7 +110,7 @@ pub async fn export(
let reports = crate::database::models::report_item::Report::get_many(&report_ids, &**pool)
.await?
.into_iter()
.map(|x| crate::models::reports::Report::from(x))
.map(crate::models::reports::Report::from)
.collect::<Vec<_>>();
let message_ids = sqlx::query!(
@@ -146,7 +146,7 @@ pub async fn export(
crate::database::models::image_item::Image::get_many(&uploaded_images_ids, &**pool, &redis)
.await?
.into_iter()
.map(|x| crate::models::images::Image::from(x))
.map(crate::models::images::Image::from)
.collect::<Vec<_>>();
let subscriptions =
@@ -155,7 +155,7 @@ pub async fn export(
)
.await?
.into_iter()
.map(|x| crate::models::billing::UserSubscription::from(x))
.map(crate::models::billing::UserSubscription::from)
.collect::<Vec<_>>();
Ok(HttpResponse::Ok().json(serde_json::json!({

View File

@@ -106,14 +106,11 @@ pub async fn version_create(
// Get all possible side-types for loaders given- we will use these to check if we need to convert/apply singleplayer, etc.
let loaders = match v3::tags::loader_list(client.clone(), redis.clone()).await {
Ok(loader_response) => match v2_reroute::extract_ok_json::<
Vec<v3::tags::LoaderData>,
>(loader_response)
.await
{
Ok(loaders) => loaders,
Err(_) => vec![],
},
Ok(loader_response) => {
(v2_reroute::extract_ok_json::<Vec<v3::tags::LoaderData>>(loader_response)
.await)
.unwrap_or_default()
}
Err(_) => vec![],
};

View File

@@ -352,7 +352,7 @@ pub async fn create_payout(
.fetch_optional(&mut *transaction)
.await?;
let balance = get_user_balance(user.id.into(), &**pool).await?;
let balance = get_user_balance(user.id, &pool).await?;
if balance.available < body.amount || body.amount < Decimal::ZERO {
return Err(ApiError::InvalidInput(
"You do not have enough funds to make this payout!".to_string(),
@@ -734,7 +734,7 @@ pub async fn get_balance(
.await?
.1;
let balance = get_user_balance(user.id.into(), &**pool).await?;
let balance = get_user_balance(user.id.into(), &pool).await?;
Ok(HttpResponse::Ok().json(balance))
}