mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-06 02:00:46 +00:00
dashboard links (#1624)
This commit is contained in:
1 parent
1c654bfafa
commit
b011319abd
6 files changed
+29
No files matched your search
+3
@@ -27,6 +27,9 @@ pub struct ModeratorUserStripeCustomerIdEntry {
|
||||
pub stripe_customer_id: String,
|
||||
pub payments_namespace: PaymentsNamespace,
|
||||
pub source: ModeratorStripeCustomerIdSource,
|
||||
|
||||
/// Link to the customer in the Stripe dashboard for the namespace's account.
|
||||
pub stripe_dashboard_url: String,
|
||||
}
|
||||
|
||||
/// Which table the customer id was found in.
|
||||
|
||||
@@ -2,6 +2,8 @@ use stripe::Client;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ArtcraftStripeConfig {
|
||||
/// The Stripe account id (eg. "acct_..."), used to build dashboard links.
|
||||
pub stripe_account_id: String,
|
||||
pub secret_key: String,
|
||||
pub secret_webhook_signing_key: String,
|
||||
pub checkout_success_url: String,
|
||||
@@ -11,6 +13,8 @@ pub struct ArtcraftStripeConfig {
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ArtcraftStripeConfigWithClient {
|
||||
/// The Stripe account id (eg. "acct_..."), used to build dashboard links.
|
||||
pub stripe_account_id: String,
|
||||
pub secret_key: String,
|
||||
pub secret_webhook_signing_key: String,
|
||||
pub checkout_success_url: String,
|
||||
@@ -22,6 +26,7 @@ pub struct ArtcraftStripeConfigWithClient {
|
||||
impl ArtcraftStripeConfig {
|
||||
pub fn to_config_with_client(&self) -> ArtcraftStripeConfigWithClient {
|
||||
ArtcraftStripeConfigWithClient {
|
||||
stripe_account_id: self.stripe_account_id.clone(),
|
||||
secret_key: self.secret_key.clone(),
|
||||
secret_webhook_signing_key: self.secret_webhook_signing_key.clone(),
|
||||
checkout_success_url: self.checkout_success_url.clone(),
|
||||
|
||||
+16
@@ -11,6 +11,7 @@ use artcraft_api_defs::moderation::user_stripe_data::moderator_get_user_stripe_c
|
||||
ModeratorUserStripeCustomerIdEntry,
|
||||
};
|
||||
use mysql_queries::queries::users::user_stripe_customer_links::list_user_stripe_customer_links_for_user::list_user_stripe_customer_links_for_user;
|
||||
use enums::common::payments_namespace::PaymentsNamespace;
|
||||
use mysql_queries::queries::users::user_subscriptions::list_stripe_customer_ids_for_user_subscriptions::list_stripe_customer_ids_for_user_subscriptions;
|
||||
use tokens::tokens::users::UserToken;
|
||||
|
||||
@@ -67,12 +68,14 @@ pub async fn moderator_get_user_stripe_customer_ids_handler(
|
||||
let mut customer_ids = Vec::with_capacity(customer_links.len() + subscription_customer_ids.len());
|
||||
|
||||
customer_ids.extend(customer_links.into_iter().map(|link| ModeratorUserStripeCustomerIdEntry {
|
||||
stripe_dashboard_url: stripe_dashboard_customer_url(&server_state, link.payments_namespace, &link.stripe_customer_id),
|
||||
stripe_customer_id: link.stripe_customer_id,
|
||||
payments_namespace: link.payments_namespace,
|
||||
source: ModeratorStripeCustomerIdSource::CustomerLink,
|
||||
}));
|
||||
|
||||
customer_ids.extend(subscription_customer_ids.into_iter().map(|subscription| ModeratorUserStripeCustomerIdEntry {
|
||||
stripe_dashboard_url: stripe_dashboard_customer_url(&server_state, subscription.subscription_namespace, &subscription.stripe_customer_id),
|
||||
stripe_customer_id: subscription.stripe_customer_id,
|
||||
payments_namespace: subscription.subscription_namespace,
|
||||
source: ModeratorStripeCustomerIdSource::Subscription,
|
||||
@@ -83,3 +86,16 @@ pub async fn moderator_get_user_stripe_customer_ids_handler(
|
||||
customer_ids,
|
||||
}))
|
||||
}
|
||||
|
||||
/// Each payments namespace bills through a different Stripe account.
|
||||
fn stripe_dashboard_customer_url(
|
||||
server_state: &ServerState,
|
||||
payments_namespace: PaymentsNamespace,
|
||||
stripe_customer_id: &str,
|
||||
) -> String {
|
||||
let stripe_account_id = match payments_namespace {
|
||||
PaymentsNamespace::Artcraft => &server_state.stripe_artcraft.stripe_account_id,
|
||||
PaymentsNamespace::FakeYou => &server_state.stripe.stripe_account_id,
|
||||
};
|
||||
format!("https://dashboard.stripe.com/{}/customers/{}", stripe_account_id, stripe_customer_id)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ use errors::AnyhowResult;
|
||||
|
||||
pub fn setup_stripe_artcraft() -> AnyhowResult<ArtcraftStripeConfigWithClient> {
|
||||
Ok(ArtcraftStripeConfig {
|
||||
stripe_account_id: easyenv::get_env_string_required("STRIPE_ARTCRAFT_ACCOUNT_ID")?,
|
||||
secret_key: easyenv::get_env_string_required("STRIPE_ARTCRAFT_SECRET_KEY")?,
|
||||
secret_webhook_signing_key: easyenv::get_env_string_required("STRIPE_ARTCRAFT_SECRET_WEBHOOK_KEY")?,
|
||||
checkout_success_url: easyenv::get_env_string_required("STRIPE_ARTCRAFT_CHECKOUT_SUCCESS_URL")?,
|
||||
|
||||
@@ -31,5 +31,6 @@ pub fn setup_stripe_fakeyou() -> AnyhowResult<StripeSettings> {
|
||||
Ok(StripeSettings {
|
||||
config: stripe_configs,
|
||||
client: stripe_client,
|
||||
stripe_account_id: easyenv::get_env_string_required("STRIPE_FAKEYOU_ACCOUNT_ID")?,
|
||||
})
|
||||
}
|
||||
@@ -219,6 +219,9 @@ pub struct EphemeralInMemoryCaches {
|
||||
pub struct StripeSettings {
|
||||
pub config: StripeConfig,
|
||||
pub client: stripe::Client,
|
||||
|
||||
/// The Stripe account id (eg. "acct_..."), used to build dashboard links.
|
||||
pub stripe_account_id: String,
|
||||
}
|
||||
|
||||
/// Flags set at service startup
|
||||
|
||||
Reference in new issue
Block a user