From bea0ba017cb62c48ecade857c8d61acdc386af86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20Talbot?= <108630700+fetchfern@users.noreply.github.com> Date: Fri, 3 Oct 2025 14:26:06 +0100 Subject: [PATCH] Fix interactive payments in non-USD currencies (#4476) * Use price's currency rather than inferred stripe currency in PaymentIntent * Correctly convert to stripe::Currency * Include original currency code in error message --- .../src/routes/internal/billing/payments.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/labrinth/src/routes/internal/billing/payments.rs b/apps/labrinth/src/routes/internal/billing/payments.rs index 9847ea9dd..5407e3356 100644 --- a/apps/labrinth/src/routes/internal/billing/payments.rs +++ b/apps/labrinth/src/routes/internal/billing/payments.rs @@ -536,7 +536,7 @@ pub async fn create_or_update_payment_intent( if let Some(payment_intent_id) = existing_payment_intent { let mut update_payment_intent = stripe::UpdatePaymentIntent { amount: Some(charge_data.amount + tax_amount), - currency: Some(inferred_stripe_currency), + currency: Some(charge_data.stripe_currency_code()?), customer: Some(customer_id), metadata: Some(metadata), ..Default::default() @@ -570,7 +570,7 @@ pub async fn create_or_update_payment_intent( } else { let mut intent = CreatePaymentIntent::new( charge_data.amount + tax_amount, - inferred_stripe_currency, + charge_data.stripe_currency_code()?, ); intent.customer = Some(customer_id); @@ -713,6 +713,17 @@ struct ChargeData { pub charge_type: ChargeType, } +impl ChargeData { + pub fn stripe_currency_code(&self) -> Result { + self.currency_code + .to_lowercase() + .parse::() + .map_err(|_| ApiError::InvalidInput( + format!("Invalid currency code '{}': could not convert to Stripe currency", &self.currency_code) + )) + } +} + async fn derive_charge_data_from_product_selector( pool: &PgPool, user_id: UserId,