Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions infra/stacks/authentication-service/Pulumi.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions infra/stacks/authentication-service/Pulumi.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions infra/stacks/authentication-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ const googleClientSecretKeyArn: pulumi.Output<string> = 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<string> = 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`
);
Expand All @@ -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();
Expand Down Expand Up @@ -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}`,
},
],
});

Expand Down
7 changes: 7 additions & 0 deletions rust/cloud-storage/authentication_service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -138,6 +144,7 @@ impl Config {
notification_service_url,
notification_queue,
search_event_queue,
stripe_price_id,
environment,
})
}
Expand Down
11 changes: 10 additions & 1 deletion rust/cloud-storage/authentication_service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Comment thread
whutchinson98 marked this conversation as resolved.

let auth_client = crate::service::fusionauth_client::FusionAuthClient::new(
fusionauth_api_key,
config.fusionauth_client_id.clone(),
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions rust/cloud-storage/teams/src/domain/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion rust/cloud-storage/teams/src/domain/team_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ where
.customer_repository
.create_subscription(CreateSubscriptionArgs {
customer_id,
price_id: "price_1PnSgXJaD7zvQeOBfSYgOmZc",
quantity: invited.len() as u64,
metadata: Some(
vec![
Expand Down
9 changes: 6 additions & 3 deletions rust/cloud-storage/teams/src/outbound/customer_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,29 @@ use crate::domain::{
pub struct CustomerRepositoryImpl {
/// The underlying stripe::Client connected to stripe.
client: Arc<stripe::Client>,
/// 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(),
}
}
}

impl CustomerRepository for CustomerRepositoryImpl {
async fn create_subscription(
&self,
args: CreateSubscriptionArgs<'_>,
args: CreateSubscriptionArgs,
) -> Result<stripe::SubscriptionId, CustomerError> {
// 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()
}]);
Expand Down
Loading