From 859897bedb72ccaeffd012bc696bd64f8e689e12 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Mon, 1 Sep 2025 01:50:43 -0400 Subject: [PATCH] cleanup endpoint --- .../configs/stripe_artcraft_product_info.rs | 2 + .../stripe_artcraft_product_info_list.rs | 13 +++++ ...rtcraft_create_checkout_session_handler.rs | 53 ++++++++++++------- .../routes/add_stripe_artcraft_routes.rs | 2 +- 4 files changed, 51 insertions(+), 19 deletions(-) diff --git a/crates/service/web/storyteller_web/src/configs/stripe_artcraft_product_info.rs b/crates/service/web/storyteller_web/src/configs/stripe_artcraft_product_info.rs index c420c44532..6193503481 100644 --- a/crates/service/web/storyteller_web/src/configs/stripe_artcraft_product_info.rs +++ b/crates/service/web/storyteller_web/src/configs/stripe_artcraft_product_info.rs @@ -2,4 +2,6 @@ pub struct StripeArtcraftProductInfo { pub product_id: &'static str, pub monthly_price_id: &'static str, + pub yearly_price_id: &'static str, } + diff --git a/crates/service/web/storyteller_web/src/configs/stripe_artcraft_product_info_list.rs b/crates/service/web/storyteller_web/src/configs/stripe_artcraft_product_info_list.rs index 9e4a2dc7ae..f350a3aa28 100644 --- a/crates/service/web/storyteller_web/src/configs/stripe_artcraft_product_info_list.rs +++ b/crates/service/web/storyteller_web/src/configs/stripe_artcraft_product_info_list.rs @@ -3,5 +3,18 @@ use crate::configs::stripe_artcraft_product_info::StripeArtcraftProductInfo; pub const ARTCRAFT_BASIC_SANDBOX : StripeArtcraftProductInfo = StripeArtcraftProductInfo { product_id: "prod_SyJURfbu2ixP7M", monthly_price_id: "price_1S2MrSEobp4xy4Tlwit8aeNE", + yearly_price_id: "price_1S2MrsEobp4xy4TlDG2skTkc", +}; + +pub const ARTCRAFT_PRO_SANDBOX : StripeArtcraftProductInfo = StripeArtcraftProductInfo { + product_id: "prod_SyJTy5arqKmaxT", + monthly_price_id: "price_1S2MqZEobp4xy4TlR9KLyitD", + yearly_price_id: "price_1S2MqyEobp4xy4Tl0ZXOK8Z0", +}; + +pub const ARTCRAFT_MAX_SANDBOX : StripeArtcraftProductInfo = StripeArtcraftProductInfo { + product_id: "prod_SyJSoHNUU81BjU", + monthly_price_id: "price_1S2MpGEobp4xy4TldyO9lAwd", + yearly_price_id: "price_1S2MppEobp4xy4Tln6xjTKKD", }; diff --git a/crates/service/web/storyteller_web/src/http_server/endpoints/stripe_artcraft/checkout/stripe_artcraft_create_checkout_session_handler.rs b/crates/service/web/storyteller_web/src/http_server/endpoints/stripe_artcraft/checkout/stripe_artcraft_create_checkout_session_handler.rs index 05a45c7016..5445a5ea90 100644 --- a/crates/service/web/storyteller_web/src/http_server/endpoints/stripe_artcraft/checkout/stripe_artcraft_create_checkout_session_handler.rs +++ b/crates/service/web/storyteller_web/src/http_server/endpoints/stripe_artcraft/checkout/stripe_artcraft_create_checkout_session_handler.rs @@ -1,5 +1,5 @@ use crate::configs::stripe_artcraft_metadata_keys::{STRIPE_ARTCRAFT_METADATA_EMAIL, STRIPE_ARTCRAFT_METADATA_TOLT_REFERRAL, STRIPE_ARTCRAFT_METADATA_USERNAME, STRIPE_ARTCRAFT_METADATA_USER_TOKEN}; -use crate::configs::stripe_artcraft_product_info_list::ARTCRAFT_BASIC_SANDBOX; +use crate::configs::stripe_artcraft_product_info_list::{ARTCRAFT_BASIC_SANDBOX, ARTCRAFT_MAX_SANDBOX, ARTCRAFT_PRO_SANDBOX}; use crate::http_server::common_responses::common_web_error::CommonWebError; use crate::state::server_state::ServerState; use actix_web::web::{Data, Json}; @@ -19,13 +19,34 @@ use utoipa::ToSchema; pub struct StripeArtcraftCreateCheckoutSessionRequest { /// The (non-Stripe) internal identifier for the product or subscription. /// This will be translated into a Stripe identifier. - internal_plan_key: Option, + plan: Option, + + cadence: Option, /// Optional Tolt referral code /// See: https://help.tolt.io/en/articles/6843411-how-to-set-up-stripe-with-tolt maybe_tolt_referral: Option, } +#[derive(Deserialize, ToSchema)] +pub enum PlanName { + #[serde(rename = "basic")] + Basic, + #[serde(rename = "pro")] + Pro, + #[serde(rename = "max")] + Max, +} + +#[derive(Deserialize, ToSchema)] +pub enum PlanBillingCadence { + #[serde(rename = "monthly")] + Monthly, + + #[serde(rename = "yearly")] + Yearly, +} + #[derive(Serialize, ToSchema)] pub struct StripeArtcraftCreateCheckoutSessionResponse { pub success: bool, @@ -36,7 +57,7 @@ pub struct StripeArtcraftCreateCheckoutSessionResponse { #[utoipa::path( get, tag = "Stripe (Artcraft)", - path = "/v1/stripe_artcraft/checkout/create", + path = "/v1/stripe_artcraft/checkout/create_subscription", params( ("request" = CreateCheckoutSessionRequest, description = "Payload for Request"), ), @@ -49,26 +70,22 @@ pub async fn stripe_artcraft_create_checkout_session_handler( request: Json, server_state: Data>, server_environment: Data, - //internal_product_to_stripe_lookup: Data, internal_user_lookup: Data, internal_session_cache_purge: Data, ) -> Result, CommonWebError> { - let maybe_internal_product_key = request.internal_plan_key.as_deref(); - - let internal_product_key = match maybe_internal_product_key { - None => return Err(CommonWebError::BadInputWithSimpleMessage("no product key supplied".to_string())), - Some(internal_product_key) => internal_product_key, + let plan = match request.plan { + None => return Err(CommonWebError::BadInputWithSimpleMessage("no plan supplied".to_string())), + Some(PlanName::Basic) => ARTCRAFT_BASIC_SANDBOX, + Some(PlanName::Pro) => ARTCRAFT_PRO_SANDBOX, + Some(PlanName::Max) => ARTCRAFT_MAX_SANDBOX, }; - //// TODO: - //let stripe_product = args.internal_product_to_stripe_lookup - // .lookup_stripe_product_from_internal_product_key(server_environment, internal_product_key) - // .map_err(|err| { - // error!("Error looking up product: {:?}", err); - // CommonWebError::ServerError // NB: This was probably *our* fault. - // })? - // .ok_or(CommonWebError::BadInputWithSimpleMessage("plan not found"))?; // Non-existing product + let price_id = match request.cadence { + None => return Err(CommonWebError::BadInputWithSimpleMessage("no cadence supplied".to_string())), + Some(PlanBillingCadence::Monthly) => plan.monthly_price_id.clone(), + Some(PlanBillingCadence::Yearly) => plan.yearly_price_id.clone(), + }; let maybe_user_metadata = internal_user_lookup .lookup_user_from_http_request(&http_request) @@ -177,7 +194,7 @@ pub async fn stripe_artcraft_create_checkout_session_handler( params.line_items = Some(vec![ CreateCheckoutSessionLineItems { - price: Some(ARTCRAFT_BASIC_SANDBOX.monthly_price_id.to_string()), + price: Some(price_id.to_string()), quantity: Some(1), ..Default::default() } diff --git a/crates/service/web/storyteller_web/src/http_server/routes/add_stripe_artcraft_routes.rs b/crates/service/web/storyteller_web/src/http_server/routes/add_stripe_artcraft_routes.rs index ec259bc7f0..301486e361 100644 --- a/crates/service/web/storyteller_web/src/http_server/routes/add_stripe_artcraft_routes.rs +++ b/crates/service/web/storyteller_web/src/http_server/routes/add_stripe_artcraft_routes.rs @@ -21,7 +21,7 @@ where .route(web::post().to(stripe_artcraft_webhook_handler)) .route(web::head().to(|| HttpResponse::Ok())) ) - .service(web::resource("/checkout/create") + .service(web::resource("/checkout/create_subscription") .route(web::post().to(stripe_artcraft_create_checkout_session_handler)) .route(web::head().to(|| HttpResponse::Ok())) )