From aef0c2f76a8dc517cc3f2393c9ddb70eb50859f6 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 7 Sep 2025 15:26:49 -0400 Subject: [PATCH] compile errors --- .../stripe/insert_stripe_webhook_event_log.rs | 43 +++++++++++++------ .../stripe_artcraft_webhook_handler.rs | 12 +++--- .../handle_webhook_payload.rs | 3 +- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/crates/schema/database/mysql_queries/src/queries/billing/stripe/insert_stripe_webhook_event_log.rs b/crates/schema/database/mysql_queries/src/queries/billing/stripe/insert_stripe_webhook_event_log.rs index cf5e156eaf..ee73c4105f 100644 --- a/crates/schema/database/mysql_queries/src/queries/billing/stripe/insert_stripe_webhook_event_log.rs +++ b/crates/schema/database/mysql_queries/src/queries/billing/stripe/insert_stripe_webhook_event_log.rs @@ -1,8 +1,9 @@ use anyhow::anyhow; use chrono::NaiveDateTime; -use sqlx::{MySql, MySqlPool, Transaction}; - use errors::AnyhowResult; +use sqlx::mysql::MySqlArguments; +use sqlx::query::Query; +use sqlx::{MySql, MySqlPool, Transaction}; // TODO: Make a trait with default impls to handle common query concerns. @@ -20,9 +21,32 @@ pub struct InsertStripeWebhookEventLog { impl InsertStripeWebhookEventLog { - pub async fn insert(&self, transaction: &mut Transaction<'_, MySql>) -> AnyhowResult<()> { + pub async fn insert(&self, mysql_pool: &MySqlPool) -> AnyhowResult<()> { + let query_result = self.query() + .execute(mysql_pool).await; - let query = sqlx::query!( + let _record_id = match query_result { + Ok(res) => res.last_insert_id(), + Err(err) => return Err(anyhow!("Error creating stripe webhook event log: {:?}", err)), + }; + + Ok(()) + } + + pub async fn insert_transactional(&self, transaction: &mut Transaction<'_, MySql>) -> AnyhowResult<()> { + let query_result = self.query() + .execute(&mut **transaction).await; + + let _record_id = match query_result { + Ok(res) => res.last_insert_id(), + Err(err) => return Err(anyhow!("Error creating stripe webhook event log: {:?}", err)), + }; + + Ok(()) + } + + fn query(&self) -> Query { + sqlx::query!( r#" INSERT INTO stripe_webhook_event_logs SET @@ -45,15 +69,6 @@ SET &self.maybe_user_token, self.action_was_taken, self.should_ignore_retry, - ); - - let query_result = query.execute(transaction).await; - - let _record_id = match query_result { - Ok(res) => res.last_insert_id(), - Err(err) => return Err(anyhow!("Error creating stripe webhook event log: {:?}", err)), - }; - - Ok(()) + ) } } diff --git a/crates/service/plugins/billing_artcraft/src/endpoints/webhook/stripe_artcraft_webhook_handler.rs b/crates/service/plugins/billing_artcraft/src/endpoints/webhook/stripe_artcraft_webhook_handler.rs index 12f585c3c3..d087fc0e85 100644 --- a/crates/service/plugins/billing_artcraft/src/endpoints/webhook/stripe_artcraft_webhook_handler.rs +++ b/crates/service/plugins/billing_artcraft/src/endpoints/webhook/stripe_artcraft_webhook_handler.rs @@ -145,7 +145,7 @@ pub async fn stripe_artcraft_webhook_handler( stripe_event_type.clone(), stripe_is_production, &mut transaction - ).await?; + ).await; match result { Ok(()) => { @@ -172,18 +172,18 @@ async fn do_with_transaction( stripe_event_created_at: NaiveDateTime, stripe_event_type: String, stripe_is_production: bool, - mut transaction: - &mut Transaction + transaction: &mut Transaction<'_, MySql> ) -> Result<(), StripeArtcraftWebhookError> { let webhook_summary = handle_webhook_payload( - &mut transaction, + transaction, &stripe_config.client, - **server_environment, + server_environment, webhook_payload, &stripe_event_type, ).await?; + // NB: These records are uniquely keyed by ID, so this only happens once. let query = InsertStripeWebhookEventLog { stripe_event_id, stripe_event_type, @@ -196,7 +196,7 @@ async fn do_with_transaction( should_ignore_retry: webhook_summary.should_ignore_retry, }; - query.insert(transaction) + query.insert_transactional(transaction) .await .map_err(|err| { let reason = format!("Could not insert Stripe webhook event log: {:?}", err); diff --git a/crates/service/plugins/billing_artcraft/src/endpoints/webhook/webhook_event_handlers/handle_webhook_payload.rs b/crates/service/plugins/billing_artcraft/src/endpoints/webhook/webhook_event_handlers/handle_webhook_payload.rs index 46faa3fd35..0c0dbc61ea 100644 --- a/crates/service/plugins/billing_artcraft/src/endpoints/webhook/webhook_event_handlers/handle_webhook_payload.rs +++ b/crates/service/plugins/billing_artcraft/src/endpoints/webhook/webhook_event_handlers/handle_webhook_payload.rs @@ -87,6 +87,7 @@ pub async fn handle_webhook_payload( // =============== CUSTOMER SUBSCRIPTIONS =============== + /* TODO - temporary disable EventObject::CustomerSubscriptionCreated(subscription) => { info!("Event: {}, data: {:?}", webhook_payload.type_, subscription); // DO NOT USE TO PROVISION SERVICE. @@ -131,7 +132,7 @@ pub async fn handle_webhook_payload( server_environment, transaction, ).await?; - } + }*/ // =============== INVOICES ===============