The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Refactor currency conversion logic to use USD exchange rate and round converted total; streamline FX quote request body construction.
Kiran Kf99698f1d9cf
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 3b0174a7e5..54039b2069 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@@ -114,7 +114,7 @@ export async function confirmPayouts({toCurrency: currency,});- const exchangeRate = fxQuote.rates[currency].exchange_rate;+ const exchangeRate = fxQuote.rates["usd"].exchange_rate;if (exchangeRate === null) {throw new Error(@@ -123,7 +123,11 @@ export async function confirmPayouts({}// Add a 0.5% markup to the exchange rate to cover forex conversion spread- convertedTotal = total * exchangeRate * 1.005;+ convertedTotal = Math.round(total * exchangeRate * 1.005);++ console.log(+ `Currency conversion: ${total} usd -> ${convertedTotal} ${currency} using exchange rate ${exchangeRate}.`,+ );}// Generate the next invoice numberdiff --git a/apps/web/lib/stripe/create-fx-quote.ts b/apps/web/lib/stripe/create-fx-quote.tsindex 83e41ef0c9..ccd6d469a3 100644--- a/apps/web/lib/stripe/create-fx-quote.ts+++ b/apps/web/lib/stripe/create-fx-quote.ts@@ -17,6 +17,12 @@ export async function createFxQuote({fromCurrency: string;toCurrency: string;}) {+ const body = new URLSearchParams();++ 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: {@@ -24,11 +30,7 @@ export async function createFxQuote({"Stripe-Version": "2025-05-28.basil;fx_quote_preview=v1","Content-Type": "application/x-www-form-urlencoded",},- body: new URLSearchParams({- from_currencies: fromCurrency,- to_currency: toCurrency,- lock_duration: "none",- }),+ body,});const fxQuote = await fxQuoteResponse.json();diff --git a/apps/web/scripts/sepa.ts b/apps/web/scripts/sepa.tsnew file mode 100644index 0000000000..3b4fca0a2a--- /dev/null+++ b/apps/web/scripts/sepa.ts@@ -0,0 +1,61 @@+import { prisma } from "@dub/prisma";+import "dotenv-flow/config";+import { DIRECT_DEBIT_PAYMENT_TYPES_INFO, PAYMENT_METHOD_TYPES } from "@/lib/partners/constants";+import { APP_DOMAIN } from "@dub/utils";+import { stripe } from "@/lib/stripe";+import Stripe from "stripe";++async function main() {+ // const method = "sepa_debit";++ // const paymentMethodOption = DIRECT_DEBIT_PAYMENT_TYPES_INFO.find(+ // (type) => type.type === method,+ // )?.option;++ // const { url } = await stripe.checkout.sessions.create({+ // mode: "setup",+ // customer: "cus_SOsPjGOsIFVEcd",+ // payment_method_types: [+ // method as Stripe.Checkout.SessionCreateParams.PaymentMethodType,+ // ],+ // payment_method_options: {+ // [method]: paymentMethodOption,+ // },+ // currency: "usd",+ // success_url: `${APP_DOMAIN}/acme/settings/billing`,+ // cancel_url: `${APP_DOMAIN}/acme/settings/billing`,+ // });++ // console.log(url);++// const response = await stripe.paymentIntents.create({+// amount: 50000,+// customer: "cus_SOsPjGOsIFVEcd",+// payment_method_types: ["sepa_debit"],+// payment_method: "pm_1RdacNAlJJEpqkPV5e1qVEqN",+// currency: "eur",+// confirmation_method: "automatic",+// confirm: true,+// transfer_group: "inv_123455",+// statement_descriptor: "Dub Partners",+// description: `Dub Partners payout invoice (123)`,+// });++// console.log(response);++ const transfer = await stripe.transfers.create(+ {+ amount: 10000,+ currency: "usd",+ transfer_group: "inv_123455",+ destination: "acct_1QWV1RPPxgnqIfPu",+ description: `Dub Partners payout (123)`,+ // source_transaction: "py_3RdawSAlJJEpqkPV1VFv5n4z",+ // source_type: "bank_account"+ }+ );++ console.log(transfer);+}++main();