forked from didirus/AstralRinth
Use auto payments with paypal (#472)
* Use auto payments with paypal * Remove sandbox key
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use super::ids::*;
|
||||
use crate::database::models::User;
|
||||
use crate::models::teams::Permissions;
|
||||
use crate::models::users::Badges;
|
||||
use crate::models::users::{Badges, RecipientType, RecipientWallet};
|
||||
use rust_decimal::Decimal;
|
||||
|
||||
pub struct TeamBuilder {
|
||||
@@ -158,7 +158,9 @@ impl TeamMember {
|
||||
SELECT tm.id id, tm.role member_role, tm.permissions permissions, tm.accepted accepted, tm.payouts_split payouts_split,
|
||||
u.id user_id, u.github_id github_id, u.name user_name, u.email email,
|
||||
u.avatar_url avatar_url, u.username username, u.bio bio,
|
||||
u.created created, u.role user_role, u.badges badges, u.paypal_email paypal_email
|
||||
u.created created, u.role user_role, u.badges badges, u.balance balance,
|
||||
u.payout_wallet payout_wallet, u.payout_wallet_type payout_wallet_type,
|
||||
u.payout_address payout_address
|
||||
FROM team_members tm
|
||||
INNER JOIN users u ON u.id = tm.user_id
|
||||
WHERE tm.team_id = $1
|
||||
@@ -186,7 +188,10 @@ impl TeamMember {
|
||||
created: m.created,
|
||||
role: m.user_role,
|
||||
badges: Badges::from_bits(m.badges as u64).unwrap_or_default(),
|
||||
paypal_email: m.paypal_email
|
||||
balance: m.balance,
|
||||
payout_wallet: m.payout_wallet.map(|x| RecipientWallet::from_string(&*x)),
|
||||
payout_wallet_type: m.payout_wallet_type.map(|x| RecipientType::from_string(&*x)),
|
||||
payout_address: m.payout_address
|
||||
},
|
||||
payouts_split: m.payouts_split
|
||||
})))
|
||||
@@ -221,7 +226,9 @@ impl TeamMember {
|
||||
SELECT tm.id id, tm.team_id team_id, tm.role member_role, tm.permissions permissions, tm.accepted accepted, tm.payouts_split payouts_split,
|
||||
u.id user_id, u.github_id github_id, u.name user_name, u.email email,
|
||||
u.avatar_url avatar_url, u.username username, u.bio bio,
|
||||
u.created created, u.role user_role, u.badges badges, u.paypal_email paypal_email
|
||||
u.created created, u.role user_role, u.badges badges, u.balance balance,
|
||||
u.payout_wallet payout_wallet, u.payout_wallet_type payout_wallet_type,
|
||||
u.payout_address payout_address
|
||||
FROM team_members tm
|
||||
INNER JOIN users u ON u.id = tm.user_id
|
||||
WHERE tm.team_id = ANY($1)
|
||||
@@ -250,7 +257,10 @@ impl TeamMember {
|
||||
created: m.created,
|
||||
role: m.user_role,
|
||||
badges: Badges::from_bits(m.badges as u64).unwrap_or_default(),
|
||||
paypal_email: m.paypal_email
|
||||
balance: m.balance,
|
||||
payout_wallet: m.payout_wallet.map(|x| RecipientWallet::from_string(&*x)),
|
||||
payout_wallet_type: m.payout_wallet_type.map(|x| RecipientType::from_string(&*x)),
|
||||
payout_address: m.payout_address
|
||||
},
|
||||
payouts_split: m.payouts_split
|
||||
})))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use super::ids::{ProjectId, UserId};
|
||||
use crate::models::users::Badges;
|
||||
use crate::models::users::{Badges, RecipientType, RecipientWallet};
|
||||
use chrono::{DateTime, Utc};
|
||||
use rust_decimal::Decimal;
|
||||
|
||||
pub struct User {
|
||||
pub id: UserId,
|
||||
@@ -13,7 +14,10 @@ pub struct User {
|
||||
pub created: DateTime<Utc>,
|
||||
pub role: String,
|
||||
pub badges: Badges,
|
||||
pub paypal_email: Option<String>,
|
||||
pub balance: Decimal,
|
||||
pub payout_wallet: Option<RecipientWallet>,
|
||||
pub payout_wallet_type: Option<RecipientType>,
|
||||
pub payout_address: Option<String>,
|
||||
}
|
||||
|
||||
impl User {
|
||||
@@ -57,7 +61,9 @@ impl User {
|
||||
"
|
||||
SELECT u.github_id, u.name, u.email,
|
||||
u.avatar_url, u.username, u.bio,
|
||||
u.created, u.role, u.badges, u.paypal_email
|
||||
u.created, u.role, u.badges,
|
||||
u.balance, u.payout_wallet, u.payout_wallet_type,
|
||||
u.payout_address
|
||||
FROM users u
|
||||
WHERE u.id = $1
|
||||
",
|
||||
@@ -79,7 +85,14 @@ impl User {
|
||||
role: row.role,
|
||||
badges: Badges::from_bits(row.badges as u64)
|
||||
.unwrap_or_default(),
|
||||
paypal_email: row.paypal_email,
|
||||
balance: row.balance,
|
||||
payout_wallet: row
|
||||
.payout_wallet
|
||||
.map(|x| RecipientWallet::from_string(&*x)),
|
||||
payout_wallet_type: row
|
||||
.payout_wallet_type
|
||||
.map(|x| RecipientType::from_string(&*x)),
|
||||
payout_address: row.payout_address,
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
@@ -97,7 +110,9 @@ impl User {
|
||||
"
|
||||
SELECT u.id, u.name, u.email,
|
||||
u.avatar_url, u.username, u.bio,
|
||||
u.created, u.role, u.badges, u.paypal_email
|
||||
u.created, u.role, u.badges,
|
||||
u.balance, u.payout_wallet, u.payout_wallet_type,
|
||||
u.payout_address
|
||||
FROM users u
|
||||
WHERE u.github_id = $1
|
||||
",
|
||||
@@ -119,7 +134,14 @@ impl User {
|
||||
role: row.role,
|
||||
badges: Badges::from_bits(row.badges as u64)
|
||||
.unwrap_or_default(),
|
||||
paypal_email: row.paypal_email,
|
||||
balance: row.balance,
|
||||
payout_wallet: row
|
||||
.payout_wallet
|
||||
.map(|x| RecipientWallet::from_string(&*x)),
|
||||
payout_wallet_type: row
|
||||
.payout_wallet_type
|
||||
.map(|x| RecipientType::from_string(&*x)),
|
||||
payout_address: row.payout_address,
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
@@ -137,7 +159,9 @@ impl User {
|
||||
"
|
||||
SELECT u.id, u.github_id, u.name, u.email,
|
||||
u.avatar_url, u.username, u.bio,
|
||||
u.created, u.role, u.badges, u.paypal_email
|
||||
u.created, u.role, u.badges,
|
||||
u.balance, u.payout_wallet, u.payout_wallet_type,
|
||||
u.payout_address
|
||||
FROM users u
|
||||
WHERE LOWER(u.username) = LOWER($1)
|
||||
",
|
||||
@@ -159,7 +183,14 @@ impl User {
|
||||
role: row.role,
|
||||
badges: Badges::from_bits(row.badges as u64)
|
||||
.unwrap_or_default(),
|
||||
paypal_email: row.paypal_email,
|
||||
balance: row.balance,
|
||||
payout_wallet: row
|
||||
.payout_wallet
|
||||
.map(|x| RecipientWallet::from_string(&*x)),
|
||||
payout_wallet_type: row
|
||||
.payout_wallet_type
|
||||
.map(|x| RecipientType::from_string(&*x)),
|
||||
payout_address: row.payout_address,
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
@@ -181,7 +212,9 @@ impl User {
|
||||
"
|
||||
SELECT u.id, u.github_id, u.name, u.email,
|
||||
u.avatar_url, u.username, u.bio,
|
||||
u.created, u.role, u.badges, u.paypal_email
|
||||
u.created, u.role, u.badges,
|
||||
u.balance, u.payout_wallet, u.payout_wallet_type,
|
||||
u.payout_address
|
||||
FROM users u
|
||||
WHERE u.id = ANY($1)
|
||||
",
|
||||
@@ -200,7 +233,14 @@ impl User {
|
||||
created: u.created,
|
||||
role: u.role,
|
||||
badges: Badges::from_bits(u.badges as u64).unwrap_or_default(),
|
||||
paypal_email: u.paypal_email,
|
||||
balance: u.balance,
|
||||
payout_wallet: u
|
||||
.payout_wallet
|
||||
.map(|x| RecipientWallet::from_string(&*x)),
|
||||
payout_wallet_type: u
|
||||
.payout_wallet_type
|
||||
.map(|x| RecipientType::from_string(&*x)),
|
||||
payout_address: u.payout_address,
|
||||
}))
|
||||
})
|
||||
.try_collect::<Vec<User>>()
|
||||
@@ -367,6 +407,16 @@ impl User {
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
DELETE FROM historical_payouts
|
||||
WHERE user_id = $1
|
||||
",
|
||||
id as UserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
DELETE FROM users
|
||||
|
||||
Reference in New Issue
Block a user