Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
394 changes: 179 additions & 215 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ ariadne = { path = "packages/ariadne" }
async-compression = "0.4.32"
async-minecraft-ping = { path = "packages/async-minecraft-ping" }
async-recursion = "1.2.0"
async-stripe = { version = "0.41.0", default-features = false, features = [
"runtime-tokio-hyper-rustls",
async-stripe = { version = "=1.0.0-rc.10", default-features = false, features = [
"rustls-aws-lc-rs",
"rustls-tls-webpki-roots",
] }
async-stripe-core = { version = "=1.0.0-rc.10", default-features = false }
async-stripe-payment = { version = "=1.0.0-rc.10", default-features = false }
async-stripe-shared = { version = "=1.0.0-rc.10", default-features = false }
async-stripe-types = { version = "=1.0.0-rc.10", default-features = false }
async-stripe-webhook = { version = "=1.0.0-rc.10", default-features = false }
async-trait = "0.1.92"
async-tungstenite = { version = "0.35.0", default-features = false, features = ["futures-03-sink"] }
async-walkdir = "2.2.0"
Expand Down
18 changes: 17 additions & 1 deletion apps/labrinth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,23 @@ arc-swap = { workspace = true }
argon2 = { workspace = true }
ariadne = { workspace = true }
async-minecraft-ping = { workspace = true, features = ["srv"] }
async-stripe = { workspace = true, features = ["billing", "checkout", "connect", "webhook-events"] }
async-stripe = { workspace = true }
async-stripe-core = { workspace = true, features = [
"charge",
"customer",
"payment_intent",
"refund",
"serialize",
"setup_intent",
] }
async-stripe-payment = { workspace = true, features = [
"confirmation_token",
"payment_method",
"serialize",
] }
async-stripe-shared = { workspace = true, features = ["deserialize", "serialize"] }
async-stripe-types = { workspace = true, features = ["deserialize", "serialize"] }
async-stripe-webhook = { workspace = true }
async-trait = { workspace = true }
aws-sdk-s3 = { workspace = true }
base64 = { workspace = true }
Expand Down
51 changes: 20 additions & 31 deletions apps/labrinth/src/queue/billing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ use crate::util::archon::ArchonClient;
use crate::util::archon::{CreateServerRequest, Specs};
use crate::util::error::ApiContext as _;
use crate::util::error::Context;
use crate::util::stripe::StripeContext as _;
use ariadne::ids::base62_impl::to_base62;
use chrono::Utc;
use futures::FutureExt;
use futures::stream::{FuturesUnordered, StreamExt};
use std::collections::HashSet;
use std::str::FromStr;
use std::time::Instant;
use stripe::{self, Currency};
use stripe_core::payment_intent::RetrievePaymentIntent;
use stripe_core::refund::RetrieveRefund;
use stripe_shared::{CustomerId, PaymentIntentId, RefundId};
use tracing::{debug, error, info, warn};
use xredis::RedisPool;

Expand Down Expand Up @@ -205,7 +207,7 @@ async fn update_anrok_transactions(
let (pi, tax_platform_id) = if c.type_ == ChargeType::Refund {
// the payment_platform_id should be an re or a pyr

let refund_id: stripe::RefundId = c
let refund_id: RefundId = c
.payment_platform_id
.as_ref()
.and_then(|x| x.parse().ok())
Expand All @@ -214,15 +216,11 @@ async fn update_anrok_transactions(
.to_owned()
})?;

let refund = stripe::Refund::retrieve(
stripe_client,
&refund_id,
&["payment_intent.payment_method"],
)
.await
.wrap_failed_dependency_err(
"communicating with payment provider",
)?;
let refund = RetrieveRefund::new(refund_id.clone())
.expand(["payment_intent.payment_method".to_owned()])
.send(stripe_client)
.await
.wrap_stripe_err("communicating with payment provider")?;

let pi = refund
.payment_intent
Expand All @@ -233,7 +231,7 @@ async fn update_anrok_transactions(

(pi, anrok::transaction_id_stripe_pyr(&refund_id))
} else {
let stripe_id: stripe::PaymentIntentId = c
let stripe_id: PaymentIntentId = c
.payment_platform_id
.as_ref()
.and_then(|x| x.parse().ok())
Expand All @@ -243,15 +241,11 @@ async fn update_anrok_transactions(

// Attempt retrieving the address via the payment intent's payment method

let pi = stripe::PaymentIntent::retrieve(
stripe_client,
&stripe_id,
&["payment_method"],
)
.await
.wrap_failed_dependency_err(
"communicating with payment provider",
)?;
let pi = RetrievePaymentIntent::new(stripe_id.clone())
.expand(["payment_method".to_owned()])
.send(stripe_client)
.await
.wrap_stripe_err("communicating with payment provider")?;

let anrok_id = anrok::transaction_id_stripe_pi(&stripe_id);

Expand All @@ -271,7 +265,7 @@ async fn update_anrok_transactions(
.stripe_customer_id
.wrap_request_err("finding Stripe customer ID on user")?;

let customer_id = stripe_customer_id
let customer_id: CustomerId = stripe_customer_id
.parse()
.wrap_request_err("parsing request value")?;

Expand All @@ -282,17 +276,13 @@ async fn update_anrok_transactions(
None => {
warn!(
"A PaymentMethod for '{:?}' has no address; falling back to the customer's address",
pi.customer.map(|x| x.id())
pi.customer.map(|x| x.into_id())
);
}
};

let customer =
stripe::Customer::retrieve(stripe_client, &customer_id, &[])
.await
.wrap_failed_dependency_err(
"communicating with payment provider",
)?;
retrieve_customer(stripe_client, &customer_id, &[]).await?;

let Some(address) = customer.address else {
// We won't really be able to do anything about this.
Expand Down Expand Up @@ -685,8 +675,7 @@ pub async fn process_chargeable_charges(
continue;
};

let Ok(currency) =
Currency::from_str(&product_price.currency_code.to_lowercase())
let Some(currency) = parse_currency(&product_price.currency_code)
else {
warn!(
charge.id = charge.id.0,
Expand Down
Loading
Loading