mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-19 08:05:20 +00:00
Merge pull request #131 from storytold/nov-08-mithoo
bump async-stripe, dealing with webhook handler failures/updates
This commit is contained in:
16 files changed
+54
-37
No files matched your search
Generated
+14
-12
@@ -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",
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
+2
@@ -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);
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -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()
|
||||
});
|
||||
}
|
||||
|
||||
+4
-4
@@ -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 {
|
||||
|
||||
+2
-2
@@ -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,
|
||||
|
||||
+3
-2
@@ -12,8 +12,9 @@ pub fn customer_created_handler(customer: &Customer) -> Result<StripeWebhookSumm
|
||||
let customer_id = customer.id.to_string();
|
||||
|
||||
// NB: Our internal user token.
|
||||
let maybe_user_token = customer.metadata.get(METADATA_USER_TOKEN)
|
||||
.map(|t| t.to_string());
|
||||
let maybe_user_token = customer.metadata
|
||||
.as_ref()
|
||||
.and_then(|m| m.get(METADATA_USER_TOKEN).clone().map(|t| t.to_string()));
|
||||
|
||||
Ok(StripeWebhookSummary {
|
||||
maybe_user_token,
|
||||
|
||||
+3
-2
@@ -11,8 +11,9 @@ pub fn customer_deleted_handler(customer: &Customer) -> Result<StripeWebhookSumm
|
||||
let customer_id = customer.id.to_string();
|
||||
|
||||
// NB: Our internal user token.
|
||||
let maybe_user_token = customer.metadata.get(METADATA_USER_TOKEN)
|
||||
.map(|t| t.to_string());
|
||||
let maybe_user_token = customer.metadata
|
||||
.as_ref()
|
||||
.and_then(|m| m.get(METADATA_USER_TOKEN).map(|t| t.to_string()));
|
||||
|
||||
Ok(StripeWebhookSummary {
|
||||
maybe_user_token,
|
||||
|
||||
+3
-2
@@ -11,8 +11,9 @@ pub fn customer_updated_handler(customer: &Customer) -> Result<StripeWebhookSumm
|
||||
let customer_id = customer.id.to_string();
|
||||
|
||||
// NB: Our internal user token.
|
||||
let maybe_user_token = customer.metadata.get(METADATA_USER_TOKEN)
|
||||
.map(|t| t.to_string());
|
||||
let maybe_user_token = customer.metadata
|
||||
.as_ref()
|
||||
.and_then(|m| m.get(METADATA_USER_TOKEN).map(|t| t.to_string()));
|
||||
|
||||
Ok(StripeWebhookSummary {
|
||||
maybe_user_token,
|
||||
|
||||
+1
-1
@@ -117,7 +117,7 @@ fn invoice_paid_extractor(invoice: &Invoice) -> AnyhowResult<Option<InvoicePaidD
|
||||
}
|
||||
InvoiceLineItemType::Subscription => {
|
||||
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()
|
||||
|
||||
+3
-2
@@ -18,8 +18,9 @@ pub fn invoice_payment_failed_handler(invoice: &Invoice) -> Result<StripeWebhook
|
||||
.map(|c| expand_customer_id(c));
|
||||
|
||||
// NB: Our internal user token.
|
||||
let maybe_user_token = invoice.metadata.get(METADATA_USER_TOKEN)
|
||||
.map(|t| t.to_string());
|
||||
let maybe_user_token = invoice.metadata
|
||||
.as_ref()
|
||||
.and_then(|m| m.get(METADATA_USER_TOKEN).map(|t| t.to_string()));
|
||||
|
||||
Ok(StripeWebhookSummary {
|
||||
maybe_user_token,
|
||||
|
||||
+3
-2
@@ -18,8 +18,9 @@ pub fn invoice_payment_succeeded_handler(invoice: &Invoice) -> Result<StripeWebh
|
||||
.map(|c| expand_customer_id(c));
|
||||
|
||||
// NB: Our internal user token.
|
||||
let maybe_user_token = invoice.metadata.get(METADATA_USER_TOKEN)
|
||||
.map(|t| t.to_string());
|
||||
let maybe_user_token = invoice.metadata
|
||||
.as_ref()
|
||||
.and_then(|m| m.get(METADATA_USER_TOKEN).map(|t| t.to_string()));
|
||||
|
||||
Ok(StripeWebhookSummary {
|
||||
maybe_user_token,
|
||||
|
||||
+3
-2
@@ -23,8 +23,9 @@ pub fn invoice_updated_handler(invoice: &Invoice) -> Result<StripeWebhookSummary
|
||||
.map(|c| expand_customer_id(c));
|
||||
|
||||
// NB: Our internal user token.
|
||||
let maybe_user_token = invoice.metadata.get(METADATA_USER_TOKEN)
|
||||
.map(|t| t.to_string());
|
||||
let maybe_user_token = invoice.metadata
|
||||
.as_ref()
|
||||
.and_then(|m| m.get(METADATA_USER_TOKEN).map(|t| t.to_string()));
|
||||
|
||||
Ok(StripeWebhookSummary {
|
||||
maybe_user_token,
|
||||
|
||||
@@ -144,7 +144,7 @@ jwt = "0.13.0"
|
||||
hyper = { version = "0.14.14" }
|
||||
|
||||
# Money
|
||||
async-stripe = { version = "0.15.0", features = ["runtime-tokio-hyper"] }
|
||||
async-stripe = { version = "0.25.2", features = ["runtime-tokio-hyper"] }
|
||||
|
||||
# Crypto
|
||||
bcrypt = "0.8" # password hashes
|
||||
|
||||
Reference in new issue
Block a user