diff --git a/crates/service/plugins/billing_artcraft/src/endpoints/webhook/common/artcraft_billing_action.rs b/crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/artcraft_billing_action.rs similarity index 84% rename from crates/service/plugins/billing_artcraft/src/endpoints/webhook/common/artcraft_billing_action.rs rename to crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/artcraft_billing_action.rs index c83048b511..5ff2b1f318 100644 --- a/crates/service/plugins/billing_artcraft/src/endpoints/webhook/common/artcraft_billing_action.rs +++ b/crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/artcraft_billing_action.rs @@ -2,7 +2,7 @@ use crate::configs::credits_packs::stripe_artcraft_credits_pack_info::StripeArtc use tokens::tokens::users::UserToken; use tokens::tokens::wallets::WalletToken; -pub enum BillingAction { +pub enum ArtcraftBillingAction { /// An ignorable event. IgnorableEvent, @@ -29,9 +29,3 @@ pub struct WalletCreditsPurchaseEvent { pub quantity: u64, } -#[derive(Copy,Clone,Debug)] -pub enum IgnoreableEventType { - Other, - PaymentIntentFailed, - PaymentIntentForSubscription, -} diff --git a/crates/service/plugins/billing_artcraft/src/fulfillment/credits_pack/complete_credits_pack_purchase.rs b/crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/credits_pack/complete_credits_pack_purchase.rs similarity index 100% rename from crates/service/plugins/billing_artcraft/src/fulfillment/credits_pack/complete_credits_pack_purchase.rs rename to crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/credits_pack/complete_credits_pack_purchase.rs diff --git a/crates/service/plugins/billing_artcraft/src/fulfillment/credits_pack/mod.rs b/crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/credits_pack/mod.rs similarity index 100% rename from crates/service/plugins/billing_artcraft/src/fulfillment/credits_pack/mod.rs rename to crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/credits_pack/mod.rs diff --git a/crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/mod.rs b/crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/mod.rs new file mode 100644 index 0000000000..1b6c249e03 --- /dev/null +++ b/crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/mod.rs @@ -0,0 +1,4 @@ +pub (crate) mod subscriptions; +pub (crate) mod credits_pack; +pub (crate) mod transactionally_fulfill_artcraft_billing_action; +pub (crate) mod artcraft_billing_action; \ No newline at end of file diff --git a/crates/service/plugins/billing_artcraft/src/fulfillment/subscriptions/establish_subscription.rs b/crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/subscriptions/establish_subscription.rs similarity index 100% rename from crates/service/plugins/billing_artcraft/src/fulfillment/subscriptions/establish_subscription.rs rename to crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/subscriptions/establish_subscription.rs diff --git a/crates/service/plugins/billing_artcraft/src/fulfillment/subscriptions/mark_wallet_subscription_unpaid.rs b/crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/subscriptions/mark_wallet_subscription_unpaid.rs similarity index 100% rename from crates/service/plugins/billing_artcraft/src/fulfillment/subscriptions/mark_wallet_subscription_unpaid.rs rename to crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/subscriptions/mark_wallet_subscription_unpaid.rs diff --git a/crates/service/plugins/billing_artcraft/src/fulfillment/subscriptions/mod.rs b/crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/subscriptions/mod.rs similarity index 100% rename from crates/service/plugins/billing_artcraft/src/fulfillment/subscriptions/mod.rs rename to crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/subscriptions/mod.rs diff --git a/crates/service/plugins/billing_artcraft/src/fulfillment/subscriptions/renew_subscription.rs b/crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/subscriptions/renew_subscription.rs similarity index 100% rename from crates/service/plugins/billing_artcraft/src/fulfillment/subscriptions/renew_subscription.rs rename to crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/subscriptions/renew_subscription.rs diff --git a/crates/service/plugins/billing_artcraft/src/fulfillment/transactionally_fulfill_artcraft_billing_event.rs b/crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/transactionally_fulfill_artcraft_billing_action.rs similarity index 67% rename from crates/service/plugins/billing_artcraft/src/fulfillment/transactionally_fulfill_artcraft_billing_event.rs rename to crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/transactionally_fulfill_artcraft_billing_action.rs index aa5a10c4b8..2f9d13082f 100644 --- a/crates/service/plugins/billing_artcraft/src/fulfillment/transactionally_fulfill_artcraft_billing_event.rs +++ b/crates/service/plugins/billing_artcraft/src/billing_action_fulfillment/transactionally_fulfill_artcraft_billing_action.rs @@ -1,21 +1,21 @@ -use crate::endpoints::webhook::common::artcraft_billing_action::BillingAction; -use crate::fulfillment::credits_pack::complete_credits_pack_purchase::complete_credits_pack_purchase; +use crate::billing_action_fulfillment::artcraft_billing_action::ArtcraftBillingAction; +use crate::billing_action_fulfillment::credits_pack::complete_credits_pack_purchase::complete_credits_pack_purchase; use anyhow::anyhow; use errors::AnyhowResult; use log::{info, warn}; use sqlx::Transaction; pub async fn transactionally_fulfill_artcraft_billing_action( - event: &BillingAction, + event: &ArtcraftBillingAction, transaction: &mut Transaction<'_, sqlx::MySql>, ) -> AnyhowResult<()> { match event { - BillingAction::IgnorableEvent => { + ArtcraftBillingAction::IgnorableEvent => { warn!("Received ignorable billing action; nothing to fulfill."); return Ok(()) } - BillingAction::WalletCreditsPurchase(purchase) => { + ArtcraftBillingAction::WalletCreditsPurchase(purchase) => { info!("Completing credits pack purchase for user: {} ... ", purchase.owner_user_token.as_str()); complete_credits_pack_purchase( &purchase.owner_user_token, diff --git a/crates/service/plugins/billing_artcraft/src/endpoints/webhook/common/enriched_webhook_event.rs b/crates/service/plugins/billing_artcraft/src/endpoints/webhook/common/enriched_webhook_event.rs index c3085b2fe5..f48667aa00 100644 --- a/crates/service/plugins/billing_artcraft/src/endpoints/webhook/common/enriched_webhook_event.rs +++ b/crates/service/plugins/billing_artcraft/src/endpoints/webhook/common/enriched_webhook_event.rs @@ -1,10 +1,10 @@ -use crate::endpoints::webhook::common::artcraft_billing_action::BillingAction; +use crate::billing_action_fulfillment::artcraft_billing_action::ArtcraftBillingAction; use crate::endpoints::webhook::common::webhook_event_log_summary::WebhookEventLogSummary; pub struct EnrichedWebhookEvent { /// Higher-level events that we care about handling. /// Not all webhook requests have them. - pub maybe_billing_action: Option, + pub maybe_billing_action: Option, /// Details of what we'll write to the webhook event logs. /// In addition to important events, this includes some no-op events, diff --git a/crates/service/plugins/billing_artcraft/src/endpoints/webhook/common/mod.rs b/crates/service/plugins/billing_artcraft/src/endpoints/webhook/common/mod.rs index b930f8e269..4b38e60069 100644 --- a/crates/service/plugins/billing_artcraft/src/endpoints/webhook/common/mod.rs +++ b/crates/service/plugins/billing_artcraft/src/endpoints/webhook/common/mod.rs @@ -1,3 +1,2 @@ pub mod webhook_event_log_summary; -pub mod enriched_webhook_event; -pub mod artcraft_billing_action; \ No newline at end of file +pub mod enriched_webhook_event; \ No newline at end of file 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 66783f714d..63a248a074 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 @@ -1,10 +1,10 @@ use actix_web::web::{Bytes, Data, Json}; use actix_web::{web, HttpRequest, HttpResponse}; +use crate::billing_action_fulfillment::transactionally_fulfill_artcraft_billing_action::transactionally_fulfill_artcraft_billing_action; use crate::endpoints::webhook::common::enriched_webhook_event::EnrichedWebhookEvent; use crate::endpoints::webhook::stripe_artcraft_webhook_error::StripeArtcraftWebhookError; use crate::endpoints::webhook::webhook_event_enrichment::handle_webhook_event_enrichment::handle_webhook_event_enrichment; -use crate::fulfillment::transactionally_fulfill_artcraft_billing_event::transactionally_fulfill_artcraft_billing_action; use crate::utils::artcraft_stripe_config::ArtcraftStripeConfigWithClient; use crate::utils::verify_stripe_webhook_ip_address::verify_stripe_webhook_ip_address; use chrono::NaiveDateTime; diff --git a/crates/service/plugins/billing_artcraft/src/endpoints/webhook/webhook_event_enrichment/handle_webhook_event_enrichment.rs b/crates/service/plugins/billing_artcraft/src/endpoints/webhook/webhook_event_enrichment/handle_webhook_event_enrichment.rs index 0aad182960..1d352401f2 100644 --- a/crates/service/plugins/billing_artcraft/src/endpoints/webhook/webhook_event_enrichment/handle_webhook_event_enrichment.rs +++ b/crates/service/plugins/billing_artcraft/src/endpoints/webhook/webhook_event_enrichment/handle_webhook_event_enrichment.rs @@ -1,5 +1,3 @@ -use crate::endpoints::webhook::common::artcraft_billing_action::BillingAction::IgnorableEvent; -use crate::endpoints::webhook::common::artcraft_billing_action::{BillingAction, IgnoreableEventType}; use crate::endpoints::webhook::common::enriched_webhook_event::EnrichedWebhookEvent; use crate::endpoints::webhook::common::webhook_event_log_summary::WebhookEventLogSummary; use crate::endpoints::webhook::stripe_artcraft_webhook_error::StripeArtcraftWebhookError; diff --git a/crates/service/plugins/billing_artcraft/src/endpoints/webhook/webhook_event_enrichment/payment_intent/payment_intent_succeeded_extractor.rs b/crates/service/plugins/billing_artcraft/src/endpoints/webhook/webhook_event_enrichment/payment_intent/payment_intent_succeeded_extractor.rs index a1ca28cd0e..e0c5dace9f 100644 --- a/crates/service/plugins/billing_artcraft/src/endpoints/webhook/webhook_event_enrichment/payment_intent/payment_intent_succeeded_extractor.rs +++ b/crates/service/plugins/billing_artcraft/src/endpoints/webhook/webhook_event_enrichment/payment_intent/payment_intent_succeeded_extractor.rs @@ -1,12 +1,11 @@ +use crate::billing_action_fulfillment::artcraft_billing_action::{ArtcraftBillingAction, WalletCreditsPurchaseEvent}; use crate::configs::get_artcraft_product_by_stripe_id_and_env::get_artcraft_product_by_stripe_id_and_env; use crate::configs::stripe_artcraft_generic_product_info::StripeArtcraftGenericProductInfo; use crate::configs::subscriptions::stripe_artcraft_subscription_info::StripeArtcraftSubscriptionInfo; -use crate::endpoints::webhook::common::artcraft_billing_action::{BillingAction, IgnoreableEventType, WalletCreditsPurchaseEvent}; use crate::endpoints::webhook::common::enriched_webhook_event::EnrichedWebhookEvent; use crate::endpoints::webhook::common::webhook_event_log_summary::WebhookEventLogSummary; use crate::endpoints::webhook::stripe_artcraft_webhook_error::StripeArtcraftWebhookError; use crate::endpoints::webhook::webhook_event_enrichment::stripe_artcraft_webhook_summary::StripeArtcraftWebhookSummary; -use crate::fulfillment::credits_pack::complete_credits_pack_purchase::complete_credits_pack_purchase; use crate::requests::lookup_purchase_from_payment_intent_success::lookup_purchase_from_payment_intent_success; use crate::utils::expand_ids::expand_customer_id::expand_customer_id; use crate::utils::metadata::get_metadata_user_token::get_metadata_user_token; @@ -113,7 +112,7 @@ pub async fn payment_intent_succeeded_extractor( }; Ok(EnrichedWebhookEvent { - maybe_billing_action: Some(BillingAction::WalletCreditsPurchase(WalletCreditsPurchaseEvent { + maybe_billing_action: Some(ArtcraftBillingAction::WalletCreditsPurchase(WalletCreditsPurchaseEvent { owner_user_token: user_token, maybe_wallet_token: None, // TODO: Use the checkout session to set this ! pack: credits_pack.clone(), diff --git a/crates/service/plugins/billing_artcraft/src/fulfillment/mod.rs b/crates/service/plugins/billing_artcraft/src/fulfillment/mod.rs deleted file mode 100644 index 56d0576725..0000000000 --- a/crates/service/plugins/billing_artcraft/src/fulfillment/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub (crate) mod subscriptions; -pub (crate) mod credits_pack; -pub (crate) mod transactionally_fulfill_artcraft_billing_event; \ No newline at end of file diff --git a/crates/service/plugins/billing_artcraft/src/lib.rs b/crates/service/plugins/billing_artcraft/src/lib.rs index 6a71143329..50949522b1 100644 --- a/crates/service/plugins/billing_artcraft/src/lib.rs +++ b/crates/service/plugins/billing_artcraft/src/lib.rs @@ -1,5 +1,5 @@ +pub mod billing_action_fulfillment; pub mod configs; pub mod endpoints; -pub mod fulfillment; pub mod requests; pub mod utils; \ No newline at end of file