You've already forked AstralRinth
forked from didirus/AstralRinth
Payouts code (#765)
* push to rebase * finish most * finish most * Finish impl * Finish paypal * run prep * Fix comp err
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
pub mod error;
|
||||
pub mod v2;
|
||||
pub mod v3;
|
||||
|
||||
pub use v3::analytics;
|
||||
pub use v3::collections;
|
||||
pub use v3::error;
|
||||
pub use v3::ids;
|
||||
pub use v3::images;
|
||||
pub use v3::notifications;
|
||||
@@ -11,6 +11,7 @@ pub use v3::oauth_clients;
|
||||
pub use v3::organizations;
|
||||
pub use v3::pack;
|
||||
pub use v3::pats;
|
||||
pub use v3::payouts;
|
||||
pub use v3::projects;
|
||||
pub use v3::reports;
|
||||
pub use v3::sessions;
|
||||
|
||||
@@ -7,6 +7,7 @@ pub use super::oauth_clients::OAuthClientAuthorizationId;
|
||||
pub use super::oauth_clients::{OAuthClientId, OAuthRedirectUriId};
|
||||
pub use super::organizations::OrganizationId;
|
||||
pub use super::pats::PatId;
|
||||
pub use super::payouts::PayoutId;
|
||||
pub use super::projects::{ProjectId, VersionId};
|
||||
pub use super::reports::ReportId;
|
||||
pub use super::sessions::SessionId;
|
||||
@@ -127,6 +128,7 @@ base62_id_impl!(ImageId, ImageId);
|
||||
base62_id_impl!(OAuthClientId, OAuthClientId);
|
||||
base62_id_impl!(OAuthRedirectUriId, OAuthRedirectUriId);
|
||||
base62_id_impl!(OAuthClientAuthorizationId, OAuthClientAuthorizationId);
|
||||
base62_id_impl!(PayoutId, PayoutId);
|
||||
|
||||
pub mod base62_impl {
|
||||
use serde::de::{self, Deserializer, Visitor};
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
pub mod analytics;
|
||||
pub mod collections;
|
||||
pub mod error;
|
||||
pub mod ids;
|
||||
pub mod images;
|
||||
pub mod notifications;
|
||||
@@ -8,6 +7,7 @@ pub mod oauth_clients;
|
||||
pub mod organizations;
|
||||
pub mod pack;
|
||||
pub mod pats;
|
||||
pub mod payouts;
|
||||
pub mod projects;
|
||||
pub mod reports;
|
||||
pub mod sessions;
|
||||
|
||||
176
src/models/v3/payouts.rs
Normal file
176
src/models/v3/payouts.rs
Normal file
@@ -0,0 +1,176 @@
|
||||
use crate::models::ids::{Base62Id, UserId};
|
||||
use chrono::{DateTime, Utc};
|
||||
use rust_decimal::Decimal;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
|
||||
#[serde(from = "Base62Id")]
|
||||
#[serde(into = "Base62Id")]
|
||||
pub struct PayoutId(pub u64);
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct Payout {
|
||||
pub id: PayoutId,
|
||||
pub user_id: UserId,
|
||||
pub status: PayoutStatus,
|
||||
pub created: DateTime<Utc>,
|
||||
#[serde(with = "rust_decimal::serde::float")]
|
||||
pub amount: Decimal,
|
||||
|
||||
#[serde(with = "rust_decimal::serde::float_option")]
|
||||
pub fee: Option<Decimal>,
|
||||
pub method: Option<PayoutMethodType>,
|
||||
/// the address this payout was sent to: ex: email, paypal email, venmo handle
|
||||
pub method_address: Option<String>,
|
||||
pub platform_id: Option<String>,
|
||||
}
|
||||
|
||||
impl Payout {
|
||||
pub fn from(data: crate::database::models::payout_item::Payout) -> Self {
|
||||
Self {
|
||||
id: data.id.into(),
|
||||
user_id: data.user_id.into(),
|
||||
status: data.status,
|
||||
created: data.created,
|
||||
amount: data.amount,
|
||||
fee: data.fee,
|
||||
method: data.method,
|
||||
method_address: data.method_address,
|
||||
platform_id: data.platform_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Copy, Clone, Eq, PartialEq, Debug)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum PayoutMethodType {
|
||||
Venmo,
|
||||
PayPal,
|
||||
Tremendous,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for PayoutMethodType {
|
||||
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(fmt, "{}", self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
impl PayoutMethodType {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
PayoutMethodType::Venmo => "venmo",
|
||||
PayoutMethodType::PayPal => "paypal",
|
||||
PayoutMethodType::Tremendous => "tremendous",
|
||||
PayoutMethodType::Unknown => "unknown",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_string(string: &str) -> PayoutMethodType {
|
||||
match string {
|
||||
"venmo" => PayoutMethodType::Venmo,
|
||||
"paypal" => PayoutMethodType::PayPal,
|
||||
"tremendous" => PayoutMethodType::Tremendous,
|
||||
_ => PayoutMethodType::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Copy, Clone, Eq, PartialEq, Debug)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum PayoutStatus {
|
||||
Success,
|
||||
InTransit,
|
||||
Cancelled,
|
||||
Cancelling,
|
||||
Failed,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for PayoutStatus {
|
||||
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(fmt, "{}", self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
impl PayoutStatus {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
PayoutStatus::Success => "success",
|
||||
PayoutStatus::InTransit => "in-transit",
|
||||
PayoutStatus::Cancelled => "cancelled",
|
||||
PayoutStatus::Cancelling => "cancelling",
|
||||
PayoutStatus::Failed => "failed",
|
||||
PayoutStatus::Unknown => "unknown",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_string(string: &str) -> PayoutStatus {
|
||||
match string {
|
||||
"success" => PayoutStatus::Success,
|
||||
"in-transit" => PayoutStatus::InTransit,
|
||||
"cancelled" => PayoutStatus::Cancelled,
|
||||
"cancelling" => PayoutStatus::Cancelling,
|
||||
"failed" => PayoutStatus::Failed,
|
||||
_ => PayoutStatus::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct PayoutMethod {
|
||||
pub id: String,
|
||||
#[serde(rename = "type")]
|
||||
pub type_: PayoutMethodType,
|
||||
pub name: String,
|
||||
pub supported_countries: Vec<String>,
|
||||
pub image_url: Option<String>,
|
||||
pub interval: PayoutInterval,
|
||||
pub fee: PayoutMethodFee,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct PayoutMethodFee {
|
||||
#[serde(with = "rust_decimal::serde::float")]
|
||||
pub percentage: Decimal,
|
||||
#[serde(with = "rust_decimal::serde::float")]
|
||||
pub min: Decimal,
|
||||
#[serde(with = "rust_decimal::serde::float_option")]
|
||||
pub max: Option<Decimal>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PayoutDecimal(pub Decimal);
|
||||
|
||||
impl Serialize for PayoutDecimal {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
rust_decimal::serde::float::serialize(&self.0, serializer)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for PayoutDecimal {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let decimal = rust_decimal::serde::float::deserialize(deserializer)?;
|
||||
Ok(PayoutDecimal(decimal))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum PayoutInterval {
|
||||
Standard {
|
||||
#[serde(with = "rust_decimal::serde::float")]
|
||||
min: Decimal,
|
||||
#[serde(with = "rust_decimal::serde::float")]
|
||||
max: Decimal,
|
||||
},
|
||||
Fixed {
|
||||
values: Vec<PayoutDecimal>,
|
||||
},
|
||||
}
|
||||
@@ -5,7 +5,7 @@ use chrono::{DateTime, Utc};
|
||||
use rust_decimal::Decimal;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug, Hash)]
|
||||
#[serde(from = "Base62Id")]
|
||||
#[serde(into = "Base62Id")]
|
||||
pub struct UserId(pub u64);
|
||||
@@ -61,9 +61,11 @@ pub struct User {
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct UserPayoutData {
|
||||
pub paypal_address: Option<String>,
|
||||
pub paypal_country: Option<String>,
|
||||
pub venmo_handle: Option<String>,
|
||||
#[serde(with = "rust_decimal::serde::float")]
|
||||
pub balance: Decimal,
|
||||
pub trolley_id: Option<String>,
|
||||
pub trolley_status: Option<RecipientStatus>,
|
||||
}
|
||||
|
||||
use crate::database::models::user_item::User as DBUser;
|
||||
@@ -134,89 +136,3 @@ impl Role {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum RecipientStatus {
|
||||
Active,
|
||||
Incomplete,
|
||||
Disabled,
|
||||
Archived,
|
||||
Suspended,
|
||||
Blocked,
|
||||
}
|
||||
|
||||
impl RecipientStatus {
|
||||
pub fn from_string(string: &str) -> RecipientStatus {
|
||||
match string {
|
||||
"active" => RecipientStatus::Active,
|
||||
"incomplete" => RecipientStatus::Incomplete,
|
||||
"disabled" => RecipientStatus::Disabled,
|
||||
"archived" => RecipientStatus::Archived,
|
||||
"suspended" => RecipientStatus::Suspended,
|
||||
"blocked" => RecipientStatus::Blocked,
|
||||
_ => RecipientStatus::Disabled,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
RecipientStatus::Active => "active",
|
||||
RecipientStatus::Incomplete => "incomplete",
|
||||
RecipientStatus::Disabled => "disabled",
|
||||
RecipientStatus::Archived => "archived",
|
||||
RecipientStatus::Suspended => "suspended",
|
||||
RecipientStatus::Blocked => "blocked",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Payout {
|
||||
pub created: DateTime<Utc>,
|
||||
pub amount: Decimal,
|
||||
pub status: PayoutStatus,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum PayoutStatus {
|
||||
Pending,
|
||||
Failed,
|
||||
Processed,
|
||||
Returned,
|
||||
Processing,
|
||||
}
|
||||
|
||||
impl PayoutStatus {
|
||||
pub fn from_string(string: &str) -> PayoutStatus {
|
||||
match string {
|
||||
"pending" => PayoutStatus::Pending,
|
||||
"failed" => PayoutStatus::Failed,
|
||||
"processed" => PayoutStatus::Processed,
|
||||
"returned" => PayoutStatus::Returned,
|
||||
"processing" => PayoutStatus::Processing,
|
||||
_ => PayoutStatus::Processing,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
PayoutStatus::Pending => "pending",
|
||||
PayoutStatus::Failed => "failed",
|
||||
PayoutStatus::Processed => "processed",
|
||||
PayoutStatus::Returned => "returned",
|
||||
PayoutStatus::Processing => "processing",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_failed(&self) -> bool {
|
||||
match self {
|
||||
PayoutStatus::Pending => false,
|
||||
PayoutStatus::Failed => true,
|
||||
PayoutStatus::Processed => false,
|
||||
PayoutStatus::Returned => true,
|
||||
PayoutStatus::Processing => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user