The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Enhance invoice retrieval to include Stripe payment intent details and update currency formatting to support dynamic currencies.
Kiran K4721aadc7951
diff --git a/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/route.tsx b/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/route.tsxindex 3165db8298..ee1535bee4 100644--- a/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/route.tsx+++ b/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/route.tsx@@ -47,6 +47,7 @@ export const GET = withSession(async ({ session, params }) => {status: true,number: true,createdAt: true,+ stripePaymentIntentId: true,payouts: {select: {periodStart: true,@@ -90,16 +91,20 @@ export const GET = withSession(async ({ session, params }) => {}let customer: Stripe.Customer | null = null;+ let transaction: Stripe.PaymentIntent | null = null;++ [customer, transaction] = await Promise.all([+ invoice.workspace.stripeId+ ? (stripe.customers.retrieve(invoice.workspace.stripeId, {+ expand: ["tax_ids"],+ }) as Promise<Stripe.Customer | null>)+ : Promise.resolve(null),++ invoice.stripePaymentIntentId+ ? stripe.paymentIntents.retrieve(invoice.stripePaymentIntentId)+ : Promise.resolve(null),+ ]);- if (invoice.workspace.stripeId) {- try {- customer = (await stripe.customers.retrieve(invoice.workspace.stripeId!, {- expand: ["tax_ids"],- })) as Stripe.Customer;- } catch (error) {- console.error(error);- }- }const earliestPeriodStart = invoice.payouts.reduce((acc, payout) => {if (!acc) return payout.periodStart;@@ -153,6 +158,18 @@ export const GET = withSession(async ({ session, params }) => {const AU_CUSTOMER =customer?.address?.country && customer.address.country === "AU";+ const nonUsdTransactionDisplay =+ transaction && transaction.currency !== "usd"+ ? ` (${currencyFormatter(+ transaction.amount / 100,+ {+ minimumFractionDigits: 2,+ maximumFractionDigits: 2,+ },+ transaction.currency.toUpperCase(),+ )})`+ : "";+const invoiceSummaryDetails = [{label: "Invoice amount",@@ -170,10 +187,10 @@ export const GET = withSession(async ({ session, params }) => {},{label: "Invoice total",- value: currencyFormatter(invoice.total / 100, {+ value: `${currencyFormatter(invoice.total / 100, {minimumFractionDigits: 2,maximumFractionDigits: 2,- }),+ })}${nonUsdTransactionDisplay}`,},// if customer is in EU or AU, add VAT/GST reverse charge note...(EU_CUSTOMER || AU_CUSTOMERdiff --git a/packages/utils/src/functions/currency-formatter.ts b/packages/utils/src/functions/currency-formatter.tsindex 38e82cc576..97a7099fdf 100644--- a/packages/utils/src/functions/currency-formatter.ts+++ b/packages/utils/src/functions/currency-formatter.ts@@ -1,10 +1,11 @@export const currencyFormatter = (value: number,options?: Intl.NumberFormatOptions,+ currency?: string,) =>Intl.NumberFormat("en-US", {style: "currency",- currency: "USD",+ currency: currency ?? "USD",maximumFractionDigits: 0,...options,}).format(value);