diff --git a/infra/stacks/authentication-service/Pulumi.dev.yaml b/infra/stacks/authentication-service/Pulumi.dev.yaml index e369e876edd..fa0c5fe84cb 100644 --- a/infra/stacks/authentication-service/Pulumi.dev.yaml +++ b/infra/stacks/authentication-service/Pulumi.dev.yaml @@ -15,3 +15,4 @@ config: authentication-service:google_client_secret_key: google-client-secret-dev authentication-service:macro_api_token_private_secret_key: macro-api-token-private-key-dev authentication-service:stripe_webhook_secret_key: stripe-webhook-secret-dev + authentication-service:stripe_price_id: stripe-price-id-dev diff --git a/infra/stacks/authentication-service/Pulumi.prod.yaml b/infra/stacks/authentication-service/Pulumi.prod.yaml index c71c661c059..4dce1c118b8 100644 --- a/infra/stacks/authentication-service/Pulumi.prod.yaml +++ b/infra/stacks/authentication-service/Pulumi.prod.yaml @@ -15,3 +15,4 @@ config: authentication-service:google_client_secret_key: google-client-secret-prod authentication-service:macro_api_token_private_secret_key: macro-api-token-private-key-prod authentication-service:stripe_webhook_secret_key: stripe-webhook-secret-prod + authentication-service:stripe_price_id: stripe-price-id-prod diff --git a/infra/stacks/authentication-service/index.ts b/infra/stacks/authentication-service/index.ts index fddb044262f..45e7a81a461 100644 --- a/infra/stacks/authentication-service/index.ts +++ b/infra/stacks/authentication-service/index.ts @@ -95,6 +95,12 @@ const googleClientSecretKeyArn: pulumi.Output = aws.secretsmanager .getSecretVersionOutput({ secretId: GOOGLE_CLIENT_SECRET_KEY }) .apply((secret) => secret.arn); +const STRIPE_PRICE_ID_KEY = config.require(`stripe_price_id`); + +const stripePriceIdArn: pulumi.Output = aws.secretsmanager + .getSecretVersionOutput({ secretId: STRIPE_PRICE_ID_KEY }) + .apply((secret) => secret.arn); + const MACRO_API_TOKEN_PRIVATE_SECRET_KEY = config.require( `macro_api_token_private_secret_key` ); @@ -120,6 +126,7 @@ const secretKeyArns = [ pulumi.interpolate`${MACRO_API_TOKENS.macroApiTokenPublicKeyArn}`, pulumi.interpolate`${macroApiTokenSecretPrivateKeyArn}`, pulumi.interpolate`${stripeWebhookSecretKeyArn}`, + pulumi.interpolate`${stripePriceIdArn}`, ]; const vpc = get_coparse_api_vpc(); @@ -265,6 +272,10 @@ const service = new AuthenticationService('authentication-service', { name: 'STRIPE_WEBHOOK_SECRET_KEY', value: pulumi.interpolate`${stripeWebhookSecretKeyArn}`, }, + { + name: 'STRIPE_PRICE_ID', + value: pulumi.interpolate`${STRIPE_PRICE_ID_KEY}`, + }, ], }); diff --git a/rust/cloud-storage/authentication_service/src/config.rs b/rust/cloud-storage/authentication_service/src/config.rs index a61b996efdc..658f828c2b1 100644 --- a/rust/cloud-storage/authentication_service/src/config.rs +++ b/rust/cloud-storage/authentication_service/src/config.rs @@ -64,6 +64,9 @@ pub struct Config { /// The search event queue pub search_event_queue: String, + + /// The stripe price id for the professional subscription + pub stripe_price_id: String, } impl Config { @@ -118,6 +121,9 @@ impl Config { let search_event_queue = std::env::var("SEARCH_EVENT_QUEUE").context("SEARCH_EVENT_QUEUE must be provided")?; + let stripe_price_id = + std::env::var("STRIPE_PRICE_ID").context("STRIPE_PRICE_ID must be provided")?; + Ok(Config { base_url, database_url, @@ -138,6 +144,7 @@ impl Config { notification_service_url, notification_queue, search_event_queue, + stripe_price_id, environment, }) } diff --git a/rust/cloud-storage/authentication_service/src/main.rs b/rust/cloud-storage/authentication_service/src/main.rs index d2b4fedfe10..1db94a59cb9 100644 --- a/rust/cloud-storage/authentication_service/src/main.rs +++ b/rust/cloud-storage/authentication_service/src/main.rs @@ -114,6 +114,15 @@ async fn main() -> anyhow::Result<()> { .to_string(), }; + let stripe_price_id = match config.environment { + Environment::Local => config.stripe_price_id.clone(), + _ => secretsmanager_client + .get_secret_value(&config.stripe_price_id) + .await + .context("unable to get stripe price id")? + .to_string(), + }; + let auth_client = crate::service::fusionauth_client::FusionAuthClient::new( fusionauth_api_key, config.fusionauth_client_id.clone(), @@ -188,7 +197,7 @@ async fn main() -> anyhow::Result<()> { ); let teams_repo_impl = TeamRepositoryImpl::new(db.clone()); - let customer_repo_impl = CustomerRepositoryImpl::new(stripe_client.clone()); + let customer_repo_impl = CustomerRepositoryImpl::new(stripe_client.clone(), &stripe_price_id); let teams_service_impl = TeamServiceImpl::new( teams_repo_impl, diff --git a/rust/cloud-storage/teams/src/domain/model.rs b/rust/cloud-storage/teams/src/domain/model.rs index 5c11173f615..34ee692a552 100644 --- a/rust/cloud-storage/teams/src/domain/model.rs +++ b/rust/cloud-storage/teams/src/domain/model.rs @@ -186,11 +186,9 @@ pub enum RemoveUserFromTeamError { /// Arguments for creating a subscription #[derive(Debug, Clone)] -pub struct CreateSubscriptionArgs<'a> { +pub struct CreateSubscriptionArgs { /// The customer id pub customer_id: stripe::CustomerId, - /// The price id - pub price_id: &'a str, /// The quantity pub quantity: u64, /// The metadata to attach to the subscription diff --git a/rust/cloud-storage/teams/src/domain/team_service.rs b/rust/cloud-storage/teams/src/domain/team_service.rs index bf2f01f4e1a..707399a4b9a 100644 --- a/rust/cloud-storage/teams/src/domain/team_service.rs +++ b/rust/cloud-storage/teams/src/domain/team_service.rs @@ -105,7 +105,6 @@ where .customer_repository .create_subscription(CreateSubscriptionArgs { customer_id, - price_id: "price_1PnSgXJaD7zvQeOBfSYgOmZc", quantity: invited.len() as u64, metadata: Some( vec![ diff --git a/rust/cloud-storage/teams/src/outbound/customer_repo.rs b/rust/cloud-storage/teams/src/outbound/customer_repo.rs index 48b6aaca1fb..75d9e9fdbd8 100644 --- a/rust/cloud-storage/teams/src/outbound/customer_repo.rs +++ b/rust/cloud-storage/teams/src/outbound/customer_repo.rs @@ -14,13 +14,16 @@ use crate::domain::{ pub struct CustomerRepositoryImpl { /// The underlying stripe::Client connected to stripe. client: Arc, + /// The price id for the professional subscription + stripe_price_id: String, } impl CustomerRepositoryImpl { /// Creates a new instance of CustomerRepositoryImpl - pub fn new(stripe_client: stripe::Client) -> Self { + pub fn new(stripe_client: stripe::Client, stripe_price_id: &str) -> Self { Self { client: Arc::new(stripe_client), + stripe_price_id: stripe_price_id.to_string(), } } } @@ -28,12 +31,12 @@ impl CustomerRepositoryImpl { impl CustomerRepository for CustomerRepositoryImpl { async fn create_subscription( &self, - args: CreateSubscriptionArgs<'_>, + args: CreateSubscriptionArgs, ) -> Result { // Create the subscription let mut params = CreateSubscription::new(args.customer_id); params.items = Some(vec![CreateSubscriptionItems { - price: Some(args.price_id.to_string()), + price: Some(self.stripe_price_id.clone()), quantity: Some(args.quantity), ..Default::default() }]);