You've already forked AstralRinth
forked from didirus/AstralRinth
Tax compliance adjustments (#4414)
* tax compliance adjustments * chore: query cache, clippy, fmt
This commit is contained in:
committed by
GitHub
parent
5c00cb06f1
commit
47020f34b6
@@ -60,7 +60,8 @@ pub struct UserCompliance {
|
||||
pub last_checked: DateTime<Utc>,
|
||||
pub external_request_id: String,
|
||||
pub reference_id: String,
|
||||
pub form_type: FormType,
|
||||
pub form_type: Option<FormType>,
|
||||
pub requires_manual_review: bool,
|
||||
}
|
||||
|
||||
impl UserCompliance {
|
||||
@@ -87,13 +88,18 @@ impl UserCompliance {
|
||||
last_checked: row.last_checked,
|
||||
external_request_id: row.external_request_id,
|
||||
reference_id: row.reference_id,
|
||||
form_type: FormType::from_str_or_default(&row.form_type),
|
||||
form_type: row
|
||||
.form_type
|
||||
.as_deref()
|
||||
.map(FormType::from_str_or_default),
|
||||
requires_manual_review: row.requires_manual_review,
|
||||
});
|
||||
|
||||
Ok(maybe_compliance)
|
||||
}
|
||||
|
||||
pub async fn upsert<'a, E>(&mut self, exec: E) -> sqlx::Result<()>
|
||||
/// This either inserts the row into the table or updates the row, *except the requires_manual_review* column.
|
||||
pub async fn upsert_partial<'a, E>(&mut self, exec: E) -> sqlx::Result<()>
|
||||
where
|
||||
E: sqlx::PgExecutor<'a>,
|
||||
{
|
||||
@@ -109,9 +115,10 @@ impl UserCompliance {
|
||||
last_checked,
|
||||
external_request_id,
|
||||
reference_id,
|
||||
form_type
|
||||
form_type,
|
||||
requires_manual_review
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||
ON CONFLICT (user_id)
|
||||
DO UPDATE SET
|
||||
requested = EXCLUDED.requested,
|
||||
@@ -132,7 +139,8 @@ impl UserCompliance {
|
||||
self.last_checked,
|
||||
self.external_request_id,
|
||||
self.reference_id,
|
||||
self.form_type.as_str(),
|
||||
self.form_type.map(|s| s.as_str()),
|
||||
self.requires_manual_review,
|
||||
)
|
||||
.fetch_one(exec)
|
||||
.await?;
|
||||
@@ -157,7 +165,8 @@ impl UserCompliance {
|
||||
last_checked = $6,
|
||||
external_request_id = $7,
|
||||
reference_id = $8,
|
||||
form_type = $9
|
||||
form_type = $9,
|
||||
requires_manual_review = $10
|
||||
WHERE id = $1
|
||||
"#,
|
||||
self.id,
|
||||
@@ -168,7 +177,8 @@ impl UserCompliance {
|
||||
self.last_checked,
|
||||
self.external_request_id,
|
||||
self.reference_id,
|
||||
self.form_type.as_str(),
|
||||
self.form_type.map(|s| s.as_str()),
|
||||
self.requires_manual_review,
|
||||
)
|
||||
.execute(exec)
|
||||
.await?;
|
||||
|
||||
@@ -84,7 +84,8 @@ pub async fn post_compliance_form(
|
||||
reference_id: String::new(),
|
||||
e_delivery_consented: false,
|
||||
tin_matched: false,
|
||||
form_type: body.0.form_type,
|
||||
form_type: Some(body.0.form_type),
|
||||
requires_manual_review: false,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -108,10 +109,10 @@ pub async fn post_compliance_form(
|
||||
compliance.e_delivery_consented = false;
|
||||
compliance.tin_matched = false;
|
||||
compliance.signed = None;
|
||||
compliance.form_type = body.0.form_type;
|
||||
compliance.form_type = Some(body.0.form_type);
|
||||
compliance.last_checked = Utc::now() - COMPLIANCE_CHECK_DEBOUNCE;
|
||||
|
||||
compliance.upsert(&mut *txn).await?;
|
||||
compliance.upsert_partial(&mut *txn).await?;
|
||||
txn.commit().await?;
|
||||
|
||||
Ok(HttpResponse::Ok().json(toplevel))
|
||||
@@ -489,6 +490,8 @@ pub async fn create_payout(
|
||||
));
|
||||
}
|
||||
|
||||
let requires_manual_review;
|
||||
|
||||
if let Some(threshold) = tax_compliance_payout_threshold() {
|
||||
let maybe_compliance = update_compliance_status(&pool, user.id).await?;
|
||||
|
||||
@@ -501,9 +504,14 @@ pub async fn create_payout(
|
||||
let tin = model.tin_matched;
|
||||
let signed = model.signed.is_some();
|
||||
|
||||
requires_manual_review = Some(model.requires_manual_review);
|
||||
|
||||
(tin, signed, true, compliance_api_check_failed)
|
||||
}
|
||||
None => (false, false, false, false),
|
||||
None => {
|
||||
requires_manual_review = None;
|
||||
(false, false, false, false)
|
||||
}
|
||||
};
|
||||
|
||||
if !(tin_matched && signed)
|
||||
@@ -526,6 +534,22 @@ pub async fn create_payout(
|
||||
_ => "Tax compliance form is required to withdraw more!",
|
||||
}.to_owned()));
|
||||
}
|
||||
} else {
|
||||
requires_manual_review = None;
|
||||
}
|
||||
|
||||
let requires_manual_review = if let Some(r) = requires_manual_review {
|
||||
r
|
||||
} else {
|
||||
users_compliance::UserCompliance::get_by_user_id(&**pool, user.id)
|
||||
.await?
|
||||
.is_some_and(|x| x.requires_manual_review)
|
||||
};
|
||||
|
||||
if requires_manual_review {
|
||||
return Err(ApiError::InvalidInput(
|
||||
"More information is required to proceed. Please contact support (https://support.modrinth.com, support@modrinth.com)".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
let payout_method = payouts_queue
|
||||
@@ -953,8 +977,9 @@ pub async fn get_balance(
|
||||
form_completion_status = Some(
|
||||
update_compliance_status(&pool, user.id.into())
|
||||
.await?
|
||||
.filter(|x| x.model.form_type.is_some())
|
||||
.map_or(FormCompletionStatus::Unrequested, |compliance| {
|
||||
requested_form_type = Some(compliance.model.form_type);
|
||||
requested_form_type = compliance.model.form_type;
|
||||
|
||||
if compliance.compliance_api_check_failed {
|
||||
FormCompletionStatus::Unknown
|
||||
@@ -1060,6 +1085,7 @@ async fn update_compliance_status(
|
||||
if (compliance.signed.is_some() && compliance.tin_matched)
|
||||
|| Utc::now().signed_duration_since(compliance.last_checked)
|
||||
< COMPLIANCE_CHECK_DEBOUNCE
|
||||
|| compliance.form_type.is_none()
|
||||
{
|
||||
Ok(Some(ComplianceCheck {
|
||||
model: compliance,
|
||||
@@ -1087,7 +1113,10 @@ async fn update_compliance_status(
|
||||
compliance.e_delivery_consented =
|
||||
attributes.e_delivery_consented_at.is_some();
|
||||
|
||||
if compliance.form_type.requires_domestic_tin_match() {
|
||||
if compliance
|
||||
.form_type
|
||||
.is_some_and(|x| x.requires_domestic_tin_match())
|
||||
{
|
||||
compliance.tin_matched = attributes
|
||||
.tin_match_status
|
||||
.as_ref()
|
||||
|
||||
Reference in New Issue
Block a user