The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update fxQuote logic
Steven Tey90745fc9fc7a
diff --git a/apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts b/apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.tsindex c528f556ec..3bd382351b 100644--- a/apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts+++ b/apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts@@ -113,12 +113,13 @@ export async function confirmPayouts({// convert the amount to EUR/CAD if the payment method is sepa_debit or acss_debitif (["sepa_debit", "acss_debit"].includes(paymentMethod.type)) {const fxQuote = await createFxQuote({- fromCurrency: "usd",- toCurrency: currency,+ fromCurrency: currency,+ toCurrency: "usd",});- const exchangeRate = fxQuote.rates["usd"].exchange_rate;+ const exchangeRate = fxQuote.rates[currency].exchange_rate;+ // if Stripe's FX rate is not available, use the cached rate from Redisif (!exchangeRate || exchangeRate <= 0) {throw new Error(`Failed to get exchange rate from Stripe for ${currency}.`,@@ -126,7 +127,7 @@ export async function confirmPayouts({}convertedTotal = Math.round(- total * exchangeRate * (1 + FOREX_MARKUP_RATE),+ (total / exchangeRate) * (1 + FOREX_MARKUP_RATE),);console.log(diff --git a/apps/web/lib/stripe/create-fx-quote.ts b/apps/web/lib/stripe/create-fx-quote.tsindex ef0059f444..e671d9bf7b 100644--- a/apps/web/lib/stripe/create-fx-quote.ts+++ b/apps/web/lib/stripe/create-fx-quote.ts@@ -7,7 +7,6 @@ const fxQuoteSchema = z.object({exchange_rate: z.number(),}),),- to_currency: z.string(),});export async function createFxQuote({@@ -17,23 +16,29 @@ export async function createFxQuote({fromCurrency: string;toCurrency: string;}) {- const body = new URLSearchParams();+ try {+ const body = new URLSearchParams();- body.append("from_currencies[]", fromCurrency);- body.append("to_currency", toCurrency);- body.append("lock_duration", "none");+ body.append("from_currencies[]", fromCurrency);+ body.append("to_currency", toCurrency);+ body.append("lock_duration", "none");- const fxQuoteResponse = await fetch("https://api.stripe.com/v1/fx_quotes", {- method: "POST",- headers: {- Authorization: `Bearer ${process.env.STRIPE_SECRET_KEY}`,- "Stripe-Version": "2025-05-28.basil;fx_quote_preview=v1",- "Content-Type": "application/x-www-form-urlencoded",- },- body,- });+ const fxQuoteResponse = await fetch("https://api.stripe.com/v1/fx_quotes", {+ method: "POST",+ headers: {+ Authorization: `Bearer ${process.env.STRIPE_SECRET_KEY}`,+ "Stripe-Version": "2025-05-28.basil;fx_quote_preview=v1",+ "Content-Type": "application/x-www-form-urlencoded",+ },+ body,+ });- const fxQuote = await fxQuoteResponse.json();+ const fxQuote = await fxQuoteResponse.json();- return fxQuoteSchema.parse(fxQuote);+ return fxQuoteSchema.parse(fxQuote);+ } catch (error) {+ throw new Error(+ `Failed to create FX quote for ${fromCurrency} to ${toCurrency}. ${JSON.stringify(error, null, 2)}`,+ );+ }}