You've already forked AstralRinth
forked from didirus/AstralRinth
Better ser/deser for payouts vals (#474)
This commit is contained in:
@@ -58,7 +58,7 @@ pub struct UserPayoutData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq)]
|
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq)]
|
||||||
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum RecipientType {
|
pub enum RecipientType {
|
||||||
Email,
|
Email,
|
||||||
Phone,
|
Phone,
|
||||||
@@ -90,10 +90,10 @@ impl RecipientType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq)]
|
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum RecipientWallet {
|
pub enum RecipientWallet {
|
||||||
Venmo,
|
Venmo,
|
||||||
PayPal,
|
Paypal,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for RecipientWallet {
|
impl std::fmt::Display for RecipientWallet {
|
||||||
@@ -106,16 +106,23 @@ impl RecipientWallet {
|
|||||||
pub fn from_string(string: &str) -> RecipientWallet {
|
pub fn from_string(string: &str) -> RecipientWallet {
|
||||||
match string {
|
match string {
|
||||||
"venmo" => RecipientWallet::Venmo,
|
"venmo" => RecipientWallet::Venmo,
|
||||||
_ => RecipientWallet::PayPal,
|
_ => RecipientWallet::Paypal,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_str(&self) -> &'static str {
|
pub fn as_str(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
RecipientWallet::PayPal => "paypal",
|
RecipientWallet::Paypal => "paypal",
|
||||||
RecipientWallet::Venmo => "venmo",
|
RecipientWallet::Venmo => "venmo",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn as_str_api(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
RecipientWallet::Paypal => "PayPal",
|
||||||
|
RecipientWallet::Venmo => "Venmo",
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::database::models::user_item::User as DBUser;
|
use crate::database::models::user_item::User as DBUser;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use crate::models::users::{RecipientType, RecipientWallet};
|
|
||||||
use crate::routes::ApiError;
|
use crate::routes::ApiError;
|
||||||
use chrono::{DateTime, Duration, Utc};
|
use chrono::{DateTime, Duration, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -22,8 +21,8 @@ pub struct PayoutItem {
|
|||||||
pub amount: PayoutAmount,
|
pub amount: PayoutAmount,
|
||||||
pub receiver: String,
|
pub receiver: String,
|
||||||
pub note: String,
|
pub note: String,
|
||||||
pub recipient_type: RecipientType,
|
pub recipient_type: String,
|
||||||
pub recipient_wallet: RecipientWallet,
|
pub recipient_wallet: String,
|
||||||
pub sender_item_id: String,
|
pub sender_item_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ pub async fn user_edit(
|
|||||||
|
|
||||||
if let Some(payout_data) = &new_user.payout_data {
|
if let Some(payout_data) = &new_user.payout_data {
|
||||||
if payout_data.payout_wallet_type == RecipientType::UserHandle
|
if payout_data.payout_wallet_type == RecipientType::UserHandle
|
||||||
&& payout_data.payout_wallet == RecipientWallet::PayPal
|
&& payout_data.payout_wallet == RecipientWallet::Paypal
|
||||||
{
|
{
|
||||||
return Err(ApiError::InvalidInput(
|
return Err(ApiError::InvalidInput(
|
||||||
"You cannot use a paypal wallet with a user handle!"
|
"You cannot use a paypal wallet with a user handle!"
|
||||||
@@ -741,8 +741,8 @@ pub async fn user_payouts_request(
|
|||||||
},
|
},
|
||||||
receiver: payout_address,
|
receiver: payout_address,
|
||||||
note: "Payment from Modrinth creator monetization program".to_string(),
|
note: "Payment from Modrinth creator monetization program".to_string(),
|
||||||
recipient_type: payout_wallet_type,
|
recipient_type: payout_wallet_type.to_string().to_uppercase(),
|
||||||
recipient_wallet: payout_wallet,
|
recipient_wallet: payout_wallet.as_str_api().to_string(),
|
||||||
sender_item_id: format!("{}-{}", UserId::from(id), Utc::now().timestamp()),
|
sender_item_id: format!("{}-{}", UserId::from(id), Utc::now().timestamp()),
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user