Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

stripePaymentIntentId → stripeChargeMetadata

Steven Tey3848bc5b7ac7
diff --git a/apps/web/app/(ee)/api/stripe/webhook/charge-succeeded.ts b/apps/web/app/(ee)/api/stripe/webhook/charge-succeeded.ts
index 82c89c8e4b..04b3fe8205 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/charge-succeeded.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/charge-succeeded.ts
@@ -57,7 +57,7 @@ export async function chargeSucceeded(event: Stripe.Event) {
receiptUrl: receipt_url,
status: "completed",
paidAt: new Date(),
- stripePaymentIntentId: payment_intent as string,
+ stripeChargeMetadata: JSON.parse(JSON.stringify(charge)),
},
});
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.tsx
index ee1535bee4..1a66766748 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
@@ -39,15 +39,7 @@ export const GET = withSession(async ({ session, params }) => {
where: {
id: invoiceId,
},
- select: {
- id: true,
- amount: true,
- fee: true,
- total: true,
- status: true,
- number: true,
- createdAt: true,
- stripePaymentIntentId: true,
+ include: {
payouts: {
select: {
periodStart: true,
@@ -90,20 +82,16 @@ export const GET = withSession(async ({ session, params }) => {
});
}
- let customer: Stripe.Customer | null = null;
- let transaction: Stripe.PaymentIntent | null = null;
+ const customer = invoice.workspace.stripeId
+ ? ((await stripe.customers.retrieve(invoice.workspace.stripeId, {
+ expand: ["tax_ids"],
+ })) as Stripe.Customer | 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),
- ]);
+ const { amount: chargeAmount, currency: chargeCurrency } =
+ invoice.stripeChargeMetadata
+ ? (invoice.stripeChargeMetadata as unknown as Stripe.Charge)
+ : {};
const earliestPeriodStart = invoice.payouts.reduce(
(acc, payout) => {
@@ -159,14 +147,14 @@ export const GET = withSession(async ({ session, params }) => {
customer?.address?.country && customer.address.country === "AU";
const nonUsdTransactionDisplay =
- transaction && transaction.currency !== "usd"
+ chargeAmount && chargeCurrency && chargeCurrency !== "usd"
? ` (${currencyFormatter(
- transaction.amount / 100,
+ chargeAmount / 100,
{
minimumFractionDigits: 2,
maximumFractionDigits: 2,
},
- transaction.currency.toUpperCase(),
+ chargeCurrency.toUpperCase(),
)})`
: "";
diff --git a/packages/prisma/schema/invoice.prisma b/packages/prisma/schema/invoice.prisma
index a557f61256..58dfe56f95 100644
--- a/packages/prisma/schema/invoice.prisma
+++ b/packages/prisma/schema/invoice.prisma
@@ -10,12 +10,12 @@ model Invoice {
workspaceId String
number String? @unique // This starts with the customer’s unique invoicePrefix
status InvoiceStatus @default(processing)
- amount Int @default(0)
- fee Int @default(0)
- total Int @default(0)
+ amount Int @default(0) // amount in usd cents
+ fee Int @default(0) // fee in usd cents
+ total Int @default(0) // amount + fee in usd cents
receiptUrl String? @db.Text
failedReason String? @db.Text
- stripePaymentIntentId String?
+ stripeChargeMetadata Json? @db.Json // Stripe charge metadata
createdAt DateTime @default(now())
paidAt DateTime?