add: user seller_data
This commit is contained in:
parent
fdaa81422a
commit
e4468e4768
14 changed files with 150 additions and 777 deletions
|
@ -1,6 +1,7 @@
|
|||
use std::time::Duration;
|
||||
use std::{str::FromStr, time::Duration};
|
||||
|
||||
use axum::{http::HeaderMap, response::IntoResponse, Extension, Json};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::{
|
||||
auth::{User, Notification},
|
||||
moderation::AuditLogEntry,
|
||||
|
@ -8,7 +9,7 @@ use tetratto_core::model::{
|
|||
ApiReturn, Error,
|
||||
};
|
||||
use stripe::{EventObject, EventType};
|
||||
use crate::State;
|
||||
use crate::{get_user_from_token, State};
|
||||
|
||||
pub async fn stripe_webhook(
|
||||
Extension(data): Extension<State>,
|
||||
|
@ -320,3 +321,102 @@ pub async fn stripe_webhook(
|
|||
payload: (),
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn onboarding_account_link_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await);
|
||||
let user = match get_user_from_token!(jar, data.0) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
let client = match data.3 {
|
||||
Some(ref c) => c,
|
||||
None => return Json(Error::Unknown.into()),
|
||||
};
|
||||
|
||||
match stripe::AccountLink::create(
|
||||
&client,
|
||||
stripe::CreateAccountLink {
|
||||
account: match user.seller_data.account_id {
|
||||
Some(id) => stripe::AccountId::from_str(&id).unwrap(),
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
},
|
||||
type_: stripe::AccountLinkType::AccountOnboarding,
|
||||
collect: None,
|
||||
expand: &[],
|
||||
refresh_url: Some(&format!(
|
||||
"{}/auth/connections_link/seller/refresh",
|
||||
data.0.0.0.host
|
||||
)),
|
||||
return_url: Some(&format!(
|
||||
"{}/auth/connections_link/seller/return",
|
||||
data.0.0.0.host
|
||||
)),
|
||||
collection_options: None,
|
||||
},
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(x) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Acceptable".to_string(),
|
||||
payload: Some(x.url),
|
||||
}),
|
||||
Err(e) => Json(Error::MiscError(e.to_string()).into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn create_seller_account_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await);
|
||||
let mut user = match get_user_from_token!(jar, data.0) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
let client = match data.3 {
|
||||
Some(ref c) => c,
|
||||
None => return Json(Error::Unknown.into()),
|
||||
};
|
||||
|
||||
let account = match stripe::Account::create(
|
||||
&client,
|
||||
stripe::CreateAccount {
|
||||
type_: Some(stripe::AccountType::Express),
|
||||
capabilities: Some(stripe::CreateAccountCapabilities {
|
||||
card_payments: Some(stripe::CreateAccountCapabilitiesCardPayments {
|
||||
requested: Some(true),
|
||||
}),
|
||||
transfers: Some(stripe::CreateAccountCapabilitiesTransfers {
|
||||
requested: Some(true),
|
||||
}),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(a) => a,
|
||||
Err(e) => return Json(Error::MiscError(e.to_string()).into()),
|
||||
};
|
||||
|
||||
user.seller_data.account_id = Some(account.id.to_string());
|
||||
match data
|
||||
.0
|
||||
.update_user_seller_data(user.id, user.seller_data)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Acceptable".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => return Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue