Payments/subscriptions support (#943)

* [wip] Payments/subscriptions support

* finish

* working payment flow

* finish subscriptions, lint, clippy, etc

* docker compose
This commit is contained in:
Geometrically
2024-08-14 17:14:52 -07:00
committed by GitHub
parent 60edbcd5f0
commit 1d0d8d7fbe
71 changed files with 4009 additions and 1101 deletions

View File

@@ -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(),