diff --git a/Cargo.lock b/Cargo.lock index 5035a716ef..d24a9bf949 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -781,9 +781,9 @@ dependencies = [ [[package]] name = "async-stripe" -version = "0.15.0" +version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "218899c49b60727fcc0041f2823f9ee011419d1a485d1ee2cb784acf520898e7" +checksum = "e1b39347f478f57a40cbaf82cbaebb4a350acc757cda30fc7ff88707a11d1d81" dependencies = [ "chrono", "futures-util", @@ -794,7 +794,8 @@ dependencies = [ "hyper-tls", "serde", "serde_json", - "serde_qs 0.9.2", + "serde_path_to_error", + "serde_qs 0.10.1", "sha2 0.10.5", "smart-default", "smol_str", @@ -5156,22 +5157,22 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.152" +version = "1.0.179" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +checksum = "0a5bf42b8d227d4abf38a1ddb08602e229108a517cd4e5bb28f9c7eaafdce5c0" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.152" +version = "1.0.179" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +checksum = "741e124f5485c7e60c03b043f79f320bff3527f4bbf12cf3831750dc46a0ec2c" dependencies = [ "proc-macro2", "quote", - "syn 1.0.107", + "syn 2.0.26", ] [[package]] @@ -5187,10 +5188,11 @@ dependencies = [ [[package]] name = "serde_path_to_error" -version = "0.1.5" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0421d4f173fab82d72d6babf36d57fae38b994ca5c2d78e704260ba6d12118b" +checksum = "4beec8bce849d58d06238cb50db2e1c417cfeafa4c63f692b15c82b7c80f8335" dependencies = [ + "itoa 1.0.3", "serde", ] @@ -5207,9 +5209,9 @@ dependencies = [ [[package]] name = "serde_qs" -version = "0.9.2" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6af4cee6cd4b23b45e6709150d1e9af5c748131de7e3316a7c2b3008051ed725" +checksum = "8cac3f1e2ca2fe333923a1ae72caca910b98ed0630bb35ef6f8c8517d6e81afa" dependencies = [ "percent-encoding", "serde", diff --git a/crates/_types/reusable_types/src/stripe/stripe_subscription_status.rs b/crates/_types/reusable_types/src/stripe/stripe_subscription_status.rs index 754770e255..f9bdb5b71c 100644 --- a/crates/_types/reusable_types/src/stripe/stripe_subscription_status.rs +++ b/crates/_types/reusable_types/src/stripe/stripe_subscription_status.rs @@ -20,6 +20,7 @@ pub enum StripeSubscriptionStatus { PastDue, Trialing, Unpaid, + Paused, } impl StripeSubscriptionStatus { @@ -32,6 +33,7 @@ impl StripeSubscriptionStatus { StripeSubscriptionStatus::PastDue => "past_due", StripeSubscriptionStatus::Trialing => "trialing", StripeSubscriptionStatus::Unpaid => "unpaid", + StripeSubscriptionStatus::Paused => "paused" } } @@ -45,6 +47,7 @@ impl StripeSubscriptionStatus { "past_due" => Ok(Self::PastDue), "trialing" => Ok(Self::Trialing), "unpaid" => Ok(Self::Unpaid), + "paused" => Ok(Self::Paused), _ => Err(format!("invalid value: {:?}", value)), } } @@ -91,6 +94,7 @@ mod tests { assert_serialization(StripeSubscriptionStatus::PastDue, "past_due"); assert_serialization(StripeSubscriptionStatus::Trialing, "trialing"); assert_serialization(StripeSubscriptionStatus::Unpaid, "unpaid"); + assert_serialization(StripeSubscriptionStatus::Paused, "paused"); } #[test] @@ -102,6 +106,7 @@ mod tests { assert_eq!(StripeSubscriptionStatus::PastDue.as_str(), "past_due"); assert_eq!(StripeSubscriptionStatus::Trialing.as_str(), "trialing"); assert_eq!(StripeSubscriptionStatus::Unpaid.as_str(), "unpaid"); + assert_eq!(StripeSubscriptionStatus::Paused.as_str(), "paused"); } #[test] @@ -113,6 +118,7 @@ mod tests { assert_eq!(StripeSubscriptionStatus::from_str("past_due").unwrap(), StripeSubscriptionStatus::PastDue); assert_eq!(StripeSubscriptionStatus::from_str("trialing").unwrap(), StripeSubscriptionStatus::Trialing); assert_eq!(StripeSubscriptionStatus::from_str("unpaid").unwrap(), StripeSubscriptionStatus::Unpaid); + assert_eq!(StripeSubscriptionStatus::from_str("paused").unwrap(), StripeSubscriptionStatus::Paused); assert!(StripeSubscriptionStatus::from_str("foo").is_err()); } } diff --git a/crates/lib/elasticsearch_schema/src/searches/search_tts_models.rs b/crates/lib/elasticsearch_schema/src/searches/search_tts_models.rs index 4f19dc7e1d..1ae2cc18ca 100644 --- a/crates/lib/elasticsearch_schema/src/searches/search_tts_models.rs +++ b/crates/lib/elasticsearch_schema/src/searches/search_tts_models.rs @@ -30,7 +30,7 @@ pub async fn search_tts_models( let mut hits = response_json.get_mut("hits") .map(|hits| hits.take()); - let mut hits = hits.map(|mut hits| { + let hits = hits.map(|mut hits| { hits.get_mut("hits") .map(|hits| hits.take()) }).flatten(); diff --git a/crates/service/plugins/billing/Cargo.toml b/crates/service/plugins/billing/Cargo.toml index 7dab2d4295..b5eb2beb78 100644 --- a/crates/service/plugins/billing/Cargo.toml +++ b/crates/service/plugins/billing/Cargo.toml @@ -42,7 +42,7 @@ serde_json = "1.0.64" toml = "0.5.8" # Money -async-stripe = { version = "0.15.0", features = ["runtime-tokio-hyper"] } +async-stripe = { version = "0.25.2", features = ["runtime-tokio-hyper"] } # Async traits # NB: note: `async` trait functions are not currently supported diff --git a/crates/service/plugins/billing/src/stripe/helpers/enums/subscription_status_to_reusable_type.rs b/crates/service/plugins/billing/src/stripe/helpers/enums/subscription_status_to_reusable_type.rs index d0acafdb7b..e6f0a027c2 100644 --- a/crates/service/plugins/billing/src/stripe/helpers/enums/subscription_status_to_reusable_type.rs +++ b/crates/service/plugins/billing/src/stripe/helpers/enums/subscription_status_to_reusable_type.rs @@ -11,6 +11,7 @@ pub fn subscription_status_to_reusable_type(subscription_status: SubscriptionSta SubscriptionStatus::PastDue => StripeSubscriptionStatus::PastDue, SubscriptionStatus::Trialing => StripeSubscriptionStatus::Trialing, SubscriptionStatus::Unpaid => StripeSubscriptionStatus::Unpaid, + SubscriptionStatus::Paused => StripeSubscriptionStatus::Paused, } } @@ -31,5 +32,6 @@ pub mod tests { assert_eq!(subscription_status_to_reusable_type(SubscriptionStatus::PastDue), StripeSubscriptionStatus::PastDue); assert_eq!(subscription_status_to_reusable_type(SubscriptionStatus::Trialing), StripeSubscriptionStatus::Trialing); assert_eq!(subscription_status_to_reusable_type(SubscriptionStatus::Unpaid), StripeSubscriptionStatus::Unpaid); + assert_eq!(subscription_status_to_reusable_type(SubscriptionStatus::Paused), StripeSubscriptionStatus::Paused); } } diff --git a/crates/service/plugins/billing/src/stripe/http_endpoints/checkout/create/stripe_create_checkout_session_shared.rs b/crates/service/plugins/billing/src/stripe/http_endpoints/checkout/create/stripe_create_checkout_session_shared.rs index 735c1d77a2..30c31bfedf 100644 --- a/crates/service/plugins/billing/src/stripe/http_endpoints/checkout/create/stripe_create_checkout_session_shared.rs +++ b/crates/service/plugins/billing/src/stripe/http_endpoints/checkout/create/stripe_create_checkout_session_shared.rs @@ -75,7 +75,8 @@ pub async fn stripe_create_checkout_session_shared( }; let checkout_session = { - let mut params = CreateCheckoutSession::new(&cancel_url, &success_url); + let mut params = CreateCheckoutSession::new(&success_url); + params.cancel_url = Some(&cancel_url); // `client_reference_id` // Stripe Docs: @@ -127,7 +128,7 @@ pub async fn stripe_create_checkout_session_shared( // This cannot be used for non-subscription, one-off payments. // https://support.stripe.com/questions/using-metadata-with-checkout-sessions params.subscription_data = Some(CreateCheckoutSessionSubscriptionData { - metadata, + metadata: Some(metadata), ..Default::default() }); @@ -139,7 +140,7 @@ pub async fn stripe_create_checkout_session_shared( // This cannot be used for subscriptions. // https://support.stripe.com/questions/using-metadata-with-checkout-sessions params.payment_intent_data = Some(CreateCheckoutSessionPaymentIntentData { - metadata: metadata.clone(), + metadata: Some(metadata.clone()), ..Default::default() }); } diff --git a/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/stripe_webhook_handler.rs b/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/stripe_webhook_handler.rs index 875ed40795..02a0b6d5b3 100644 --- a/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/stripe_webhook_handler.rs +++ b/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/stripe_webhook_handler.rs @@ -70,7 +70,7 @@ pub async fn stripe_webhook_handler( let stripe_event_created_at = NaiveDateTime::from_timestamp(webhook_payload.created, 0); - let stripe_event_type = serde_json::to_string(&webhook_payload.event_type) + let stripe_event_type = serde_json::to_string(&webhook_payload.type_) .map(|s| s.replace("\"", "")) .map_err(|err| { error!("Could not deserialize webhook type: {:?}", err); @@ -82,7 +82,7 @@ pub async fn stripe_webhook_handler( info!("Stripe webhook event type: {} ({:?}); is production: {}, created at: {}, pending events to be handled: {}", &stripe_event_type, - &webhook_payload.event_type, + &webhook_payload.type_, stripe_is_production, &stripe_event_created_at, webhook_payload.pending_webhooks); @@ -117,7 +117,7 @@ pub async fn stripe_webhook_handler( // NB: // - "Webhook endpoints might occasionally receive the same event more than once." // - "Stripe does not guarantee delivery of events in the order in which they are generated." - match webhook_payload.event_type { + match webhook_payload.type_ { // =============== CHECKOUT SESSIONS =============== @@ -309,7 +309,7 @@ pub async fn stripe_webhook_handler( if unhandled_event_type { warn!("Unhandled Stripe webhook event type: {} ({:?})", &stripe_event_type, - &webhook_payload.event_type); + &webhook_payload.type_); } let query = InsertStripeWebhookEventLog { diff --git a/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/checkout_session/checkout_session_completed_handler.rs b/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/checkout_session/checkout_session_completed_handler.rs index dbe738f903..7f9b9414fb 100644 --- a/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/checkout_session/checkout_session_completed_handler.rs +++ b/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/checkout_session/checkout_session_completed_handler.rs @@ -20,8 +20,8 @@ pub fn checkout_session_completed_handler(checkout_session: CheckoutSession) -> .map(|c| expand_customer_id(c)); // NB: Our internal user token. - let maybe_user_token = checkout_session.metadata.get(METADATA_USER_TOKEN) - .map(|t| t.to_string()); + let maybe_user_token = checkout_session.metadata + .and_then(|m| m.get(METADATA_USER_TOKEN).map(|t| t.to_string())); Ok(StripeWebhookSummary { maybe_user_token, diff --git a/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/customer/customer_created_handler.rs b/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/customer/customer_created_handler.rs index d195589a9b..93f1f9e069 100644 --- a/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/customer/customer_created_handler.rs +++ b/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/customer/customer_created_handler.rs @@ -12,8 +12,9 @@ pub fn customer_created_handler(customer: &Customer) -> Result Result Result AnyhowResult { let maybe_subscription_id = line_item.subscription - .as_deref().map(|s| s.to_string()); + .as_ref().map(|s| expand_subscription_id(s)); let maybe_product_id = line_item.price .as_ref() diff --git a/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/invoice/invoice_payment_failed.rs b/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/invoice/invoice_payment_failed.rs index 0f78d6600c..bea7d8bda6 100644 --- a/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/invoice/invoice_payment_failed.rs +++ b/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/invoice/invoice_payment_failed.rs @@ -18,8 +18,9 @@ pub fn invoice_payment_failed_handler(invoice: &Invoice) -> Result Result Result