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 a140d14800..3237808ba0 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 @@ -117,7 +117,12 @@ pub async fn handle_webhook_event_enrichment( // This is the *required* event that enables the subscription! // These are fired on an interval - whatever the billing cadence is. info!("Event: {}, data: {:?}", stripe_event_descriptor, invoice); - return invoice_paid_handler(&invoice, server_environment, stripe_client).await; + return invoice_paid_handler( + &stripe_event_descriptor, + &invoice, + server_environment, + stripe_client + ).await; } /*EventObject::InvoicePaymentFailed(invoice) => { diff --git a/crates/service/plugins/billing_artcraft/src/endpoints/webhook/webhook_event_enrichment/invoice/invoice_paid_handler.rs b/crates/service/plugins/billing_artcraft/src/endpoints/webhook/webhook_event_enrichment/invoice/invoice_paid_handler.rs index 9e4b9b69b9..0d271c40b8 100644 --- a/crates/service/plugins/billing_artcraft/src/endpoints/webhook/webhook_event_enrichment/invoice/invoice_paid_handler.rs +++ b/crates/service/plugins/billing_artcraft/src/endpoints/webhook/webhook_event_enrichment/invoice/invoice_paid_handler.rs @@ -12,6 +12,7 @@ use log::{error, info, warn}; use reusable_types::server_environment::ServerEnvironment; use stripe::Client; use stripe_shared::{Invoice, InvoiceStatus}; +use crate::utils::stripe_event_descriptor::StripeEventDescriptor; // Handle event type: 'invoice.paid' // @@ -32,6 +33,7 @@ use stripe_shared::{Invoice, InvoiceStatus}; // appropriate date in the future (plus a day or two for leeway). // pub async fn invoice_paid_handler( + stripe_event_descriptor: &StripeEventDescriptor, invoice: &Invoice, server_environment: ServerEnvironment, stripe_client: &Client, @@ -46,10 +48,20 @@ pub async fn invoice_paid_handler( .as_ref() .map(|c| expand_customer_id(c)); - let maybe_stripe_subscription_id = invoice.subscription + // NB: We probably don't have a root-level subscription since this is a webhook. + let mut maybe_stripe_subscription_id = invoice.subscription .as_ref() .map(|s| expand_subscription_id(s)); + // NB: But we probably do have a parent object. + if maybe_stripe_subscription_id.is_none() { + maybe_stripe_subscription_id = invoice.parent + .as_ref() + .map(|parent| parent.subscription_details.as_ref()) + .flatten() + .map(|parent_sub| parent_sub.subscription.id().to_string()); + } + let mut event_log_summary = WebhookEventLogSummary { maybe_stripe_customer_id, maybe_user_token, @@ -64,14 +76,14 @@ pub async fn invoice_paid_handler( }; if !is_paid { - info!("Invoice is not paid..."); + info!("{} : invoice is not paid...", stripe_event_descriptor); return Ok(EnrichedWebhookEvent::from_actionless_log(event_log_summary)); } let subscription_id = match maybe_stripe_subscription_id { Some(subscription_id) => subscription_id, None => { - info!("Invoice is not for a subscription; skipping ..."); + info!("{} : invoice is not for a subscription; skipping ...", stripe_event_descriptor); return Ok(EnrichedWebhookEvent::from_actionless_log(event_log_summary)); } }; @@ -105,7 +117,7 @@ pub async fn invoice_paid_handler( } }; - info!("Invoice paid is for subscription."); + info!("{} : invoice paid is for subscription.", stripe_event_descriptor); Ok(EnrichedWebhookEvent { maybe_billing_action: Some(ArtcraftBillingAction::SubscriptionPaid(SubscriptionPaidEvent {