You've already forked AstralRinth
forked from didirus/AstralRinth
Add tax compliance form related fields to GET /payout (#4274)
* Add form fields to GET payout * Fix TIN match status never being updated * Fmt + clippy * Remove unnecessary borrow
This commit is contained in:
committed by
GitHub
parent
a2c07c92f8
commit
ab539a313f
@@ -876,6 +876,16 @@ pub struct MethodFilter {
|
|||||||
pub country: Option<String>,
|
pub country: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "kebab-case")]
|
||||||
|
pub enum FormCompletionStatus {
|
||||||
|
Unknown,
|
||||||
|
Unrequested,
|
||||||
|
Unsigned,
|
||||||
|
TinMismatch,
|
||||||
|
Complete,
|
||||||
|
}
|
||||||
|
|
||||||
#[get("methods")]
|
#[get("methods")]
|
||||||
pub async fn payment_methods(
|
pub async fn payment_methods(
|
||||||
payouts_queue: web::Data<PayoutsQueue>,
|
payouts_queue: web::Data<PayoutsQueue>,
|
||||||
@@ -925,15 +935,53 @@ pub async fn get_balance(
|
|||||||
.await?
|
.await?
|
||||||
.1;
|
.1;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct Response {
|
||||||
|
#[serde(flatten)]
|
||||||
|
balance: UserBalance,
|
||||||
|
requested_form_type: Option<users_compliance::FormType>,
|
||||||
|
form_completion_status: Option<FormCompletionStatus>,
|
||||||
|
}
|
||||||
|
|
||||||
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))
|
let mut requested_form_type = None;
|
||||||
|
let mut form_completion_status = None;
|
||||||
|
|
||||||
|
// Only check compliance status if the compliance check is enabled (by having a value set for it)
|
||||||
|
if tax_compliance_payout_threshold().is_some() {
|
||||||
|
form_completion_status = Some(
|
||||||
|
update_compliance_status(&pool, user.id.into())
|
||||||
|
.await?
|
||||||
|
.map_or(FormCompletionStatus::Unrequested, |compliance| {
|
||||||
|
requested_form_type = Some(compliance.model.form_type);
|
||||||
|
|
||||||
|
if compliance.compliance_api_check_failed {
|
||||||
|
FormCompletionStatus::Unknown
|
||||||
|
} else if compliance.model.signed.is_some() {
|
||||||
|
if compliance.model.tin_matched {
|
||||||
|
FormCompletionStatus::Complete
|
||||||
|
} else {
|
||||||
|
FormCompletionStatus::TinMismatch
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
FormCompletionStatus::Unsigned
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(HttpResponse::Ok().json(Response {
|
||||||
|
balance,
|
||||||
|
requested_form_type,
|
||||||
|
form_completion_status,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_user_balance(
|
async fn get_user_balance(
|
||||||
user_id: crate::database::models::ids::DBUserId,
|
user_id: crate::database::models::ids::DBUserId,
|
||||||
pool: &PgPool,
|
pool: &PgPool,
|
||||||
) -> Result<UserBalance, sqlx::Error> {
|
) -> Result<UserBalance, ApiError> {
|
||||||
let payouts = sqlx::query!(
|
let payouts = sqlx::query!(
|
||||||
"
|
"
|
||||||
SELECT date_available, SUM(amount) sum
|
SELECT date_available, SUM(amount) sum
|
||||||
@@ -1007,7 +1055,7 @@ async fn update_compliance_status(
|
|||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
|
||||||
if compliance.signed.is_some()
|
if (compliance.signed.is_some() && compliance.tin_matched)
|
||||||
|| Utc::now().signed_duration_since(compliance.last_checked)
|
|| Utc::now().signed_duration_since(compliance.last_checked)
|
||||||
< COMPLIANCE_CHECK_DEBOUNCE
|
< COMPLIANCE_CHECK_DEBOUNCE
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user